gulp-preprocess-file
Advanced tools
Comparing version 1.0.1 to 1.1.1
var through = require('through2'); | ||
var gutil = require('gulp-util'); | ||
var PluginError = gutil.PluginError; | ||
var _ = require('lodash') | ||
var pp = require('preprocess'); | ||
@@ -9,6 +10,5 @@ | ||
function gulpPreprocessFile(options) { | ||
options = options || {} | ||
if (Object.prototype.toString.call(options) !== '[object Object]') { | ||
throw new PluginError(PLUGIN_NAME, 'parameter must be an Object!'); | ||
} | ||
var opts = _.merge({}, options) | ||
var context = _.merge({}, process.env, opts.context) | ||
var extension = _.merge({}, opts.extension) | ||
@@ -29,3 +29,3 @@ // create stream | ||
if (file.isBuffer()) { | ||
var content = pp.preprocess(file.contents.toString(), options) | ||
var content = pp.preprocess(file.contents.toString(), context, extension) | ||
file.contents = new Buffer(content) | ||
@@ -32,0 +32,0 @@ } |
{ | ||
"name": "gulp-preprocess-file", | ||
"version": "1.0.1", | ||
"version": "1.1.1", | ||
"description": "A Gulp plugin for Preprocess files based off environment configuration. Based on Preprocess package", | ||
@@ -26,2 +26,3 @@ "main": "lib/index.js", | ||
"gulp-util": "^3.0.8", | ||
"lodash": "^4.17.10", | ||
"preprocess": "^3.1.0", | ||
@@ -28,0 +29,0 @@ "through2": "^2.0.3" |
111
README.md
# gulp-preprocess-file | ||
A Gulp plugin for Preprocess files based off environment configuration. Based on Preprocess package | ||
> A Gulp plugin for Preprocess files based off environment configuration. Based on Preprocess package | ||
@@ -17,3 +17,3 @@ | ||
## Examples | ||
## html examples | ||
@@ -25,3 +25,3 @@ **Gulpfile** | ||
gulp.task('html', function() { | ||
gulp.task('test:html', () => { | ||
gulp.src('./src/*.html') | ||
@@ -31,7 +31,13 @@ .pipe(preprocess({ | ||
NODE_ENV: 'production', | ||
title: 'Hello gulp' | ||
title: 'this is a title', | ||
cdnFile: function(file) { | ||
return 'https://cdn.com/' + file | ||
} | ||
}, | ||
extension: { | ||
srcDir: './src/' | ||
} | ||
})) | ||
.pipe(gulp.dest('./dist/')) | ||
}); | ||
.pipe(gulp.dest('dist/')) | ||
}) | ||
``` | ||
@@ -43,12 +49,14 @@ | ||
<body> | ||
<h1><!-- @echo title --></h1> | ||
<!-- @include ./text.html --> | ||
<h1><!-- @echo title --></h1> | ||
<!-- @include ./includes/text.html --> | ||
<!-- @if NODE_ENV='production' --> | ||
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js"></script> | ||
<!-- @endif --> | ||
<script> | ||
var title = '<!-- @echo title -->' || 'Default' | ||
</script> | ||
<!-- @if NODE_ENV!='production' --> | ||
<script src="./libs/jquery.min.js"></script> | ||
<!-- @endif --> | ||
<!-- @if NODE_ENV='production' --> | ||
<script src="<!-- @exec cdnFile('dist/jquery.min.js') -->"></script> | ||
<!-- @endif --> | ||
<script> | ||
var title = '<!-- @echo title -->' || 'Title' | ||
</script> | ||
</body> | ||
@@ -58,6 +66,77 @@ ``` | ||
more: [preprocess](https://github.com/jsoverson/preprocess) | ||
## Javascript/css examples | ||
**Gulpfile** | ||
```js | ||
var preprocess = require('gulp-preprocess-file'); | ||
gulp.task('test:js', () => { | ||
gulp.src(['./script/*.js']) | ||
.pipe(preprocess({ | ||
context: { | ||
NODE_ENV: 'production', | ||
name: 'John', | ||
}, | ||
extension: { | ||
type: 'js' | ||
} | ||
})) | ||
.pipe(gulp.dest('dist/')) | ||
}) | ||
``` | ||
**test.js file** | ||
```js | ||
var ENV = '/* @echo NODE_ENV */' || 'development' | ||
/* @if NODE_ENV='production' ** | ||
console.log('production') | ||
/* @endif */ | ||
// @if NODE_ENV='production' | ||
console.log('my name is /* @echo name */') | ||
// @endif | ||
``` | ||
more: [preprocess#configuration](https://github.com/jsoverson/preprocess#configuration) | ||
# API | ||
```js | ||
preprocess(options) | ||
``` | ||
**options** | ||
Type: `Object` | ||
more: [preprocess#api](https://github.com/jsoverson/preprocess#api) | ||
**options.context** | ||
Type: `Object` | ||
more: [preprocess#context](https://github.com/jsoverson/preprocess#context) | ||
**options.extension** | ||
Type: `Object` | ||
more: [preprocess#options](https://github.com/jsoverson/preprocess#options) | ||
# License | ||
@@ -64,0 +143,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4591
142
4
1
+ Addedlodash@^4.17.10
+ Addedlodash@4.17.21(transitive)