gulp-preprocess 1.2.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "eslint:recommended",
3
+ "env": {
4
+ "node": true,
5
+ "mocha": true
6
+ }
7
+ }
package/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
1
  language: node_js
2
2
  node_js:
3
- - "0.10"
3
+ - 6
4
+ - 8
5
+ - 10
package/README.md CHANGED
@@ -1,8 +1,7 @@
1
- # gulp-preprocess [![Build Status](https://travis-ci.org/jas/gulp-preprocess.png?branch=master)](https://travis-ci.org/jas/gulp-preprocess) [![NPM version](https://badge.fury.io/js/gulp-preprocess.png)](http://badge.fury.io/js/gulp-preprocess)
1
+ # gulp-preprocess [![NPM version](https://img.shields.io/npm/v/gulp-preprocess.svg)](https://www.npmjs.com/package/gulp-preprocess) [![Build Status](https://img.shields.io/travis/pioug/gulp-preprocess.svg)](https://travis-ci.org/pioug/gulp-preprocess) [![Dependency Status](https://img.shields.io/david/pioug/gulp-preprocess.svg)](https://david-dm.org/pioug/gulp-preprocess)
2
2
 
3
3
  > [Gulp](http://gulpjs.com) plugin to preprocess HTML, JavaScript, and other files based on custom context or environment configuration
4
4
 
5
-
6
5
  ## Information
7
6
 
8
7
  <table>
@@ -11,7 +10,7 @@
11
10
  </tr>
12
11
  <tr>
13
12
  <td>Node Version</td>
14
- <td>>= 0.9.0</td>
13
+ <td>>= 6.14.3</td>
15
14
  </tr>
16
15
  <tr>
17
16
  <td>Gulp Version</td>
@@ -19,7 +18,6 @@
19
18
  </tr>
20
19
  </table>
21
20
 
22
-
23
21
  ## Usage
24
22
 
25
23
  ### Install
@@ -28,24 +26,25 @@
28
26
  npm install gulp-preprocess --save-dev
29
27
  ```
30
28
 
31
-
32
29
  ## Examples
33
30
 
34
31
  #### Gulpfile
35
32
 
36
33
  ```js
37
- var preprocess = require('gulp-preprocess');
34
+ var preprocess = require("gulp-preprocess");
38
35
 
39
- gulp.task('html', function() {
40
- gulp.src('./app/*.html')
41
- .pipe(preprocess({context: { NODE_ENV: 'production', DEBUG: true}})) //To set environment variables in-line
42
- .pipe(gulp.dest('./dist/'))
36
+ gulp.task("html", function() {
37
+ gulp
38
+ .src("./app/*.html")
39
+ .pipe(preprocess({ context: { NODE_ENV: "production", DEBUG: true } })) // To set environment variables in-line
40
+ .pipe(gulp.dest("./dist/"));
43
41
  });
44
42
 
45
- gulp.task('scripts', function() {
46
- gulp.src(['./app/*.js'])
43
+ gulp.task("scripts", function() {
44
+ gulp
45
+ .src(["./app/*.js"])
47
46
  .pipe(preprocess())
48
- .pipe(gulp.dest('./dist/'))
47
+ .pipe(gulp.dest("./dist/"));
49
48
  });
50
49
  ```
51
50
 
@@ -73,37 +72,38 @@ gulp.task('scripts', function() {
73
72
  #### Example JavaScript File
74
73
 
75
74
  ```js
76
- var configValue = '/* @echo FOO */' || 'default value';
75
+ var configValue = "/* @echo FOO */" || "default value";
77
76
 
78
77
  // @ifdef DEBUG
79
- someDebuggingCall()
78
+ someDebuggingCall();
80
79
  // @endif
81
80
  ```
82
81
 
83
82
  CoffeeScript files are also supported.
84
83
 
85
-
86
84
  #### More Examples
87
85
 
88
86
  `gulp-preprocess` uses [preprocess](https://github.com/jsoverson/preprocess#directive-syntax). More examples can be found in its [README](https://github.com/jsoverson/preprocess#directive-syntax).
89
87
 
90
-
91
88
  ## API
92
89
 
93
90
  ### preprocess(options)
94
91
 
95
92
  #### options.context
93
+
96
94
  Type: `Object`
97
95
  Default: `{}`
98
96
 
99
97
  Context for directives used in your preprocessed files. The default context consists of the current user environment variables. Custom context is merged with `process.env`.
100
98
 
101
99
  #### options.includeBase
100
+
102
101
  Type: `String`
103
102
 
104
103
  Base directory for included files. By default, the path to included files is relative to the file currently being processed.
105
104
 
106
105
  #### options.extension
106
+
107
107
  Type: `String`
108
108
 
109
109
  Override the file extension. This determines what [regular expressions are used for comments](https://github.com/jsoverson/preprocess/blob/master/lib/regexrules.js). You may wish to do this if you are using a custom extension or need to force a particular comment syntax (for example, to allow HTML-style comments in `.php` files).
package/index.js CHANGED
@@ -1,10 +1,10 @@
1
- var _ = require('lodash');
2
- var map = require('map-stream');
3
- var pp = require('preprocess');
4
- var path = require('path');
1
+ var _ = require("lodash");
2
+ var map = require("map-stream");
3
+ var pp = require("preprocess");
4
+ var path = require("path");
5
5
 
6
- module.exports = function (options) {
7
- var opts = _.merge({}, options);
6
+ module.exports = function(options) {
7
+ var opts = _.merge({}, options);
8
8
  var context = _.merge({}, process.env, opts.context);
9
9
 
10
10
  function ppStream(file, callback) {
@@ -12,17 +12,20 @@ module.exports = function (options) {
12
12
 
13
13
  // TODO: support streaming files
14
14
  if (file.isNull()) return callback(null, file); // pass along
15
- if (file.isStream()) return callback(new Error("gulp-preprocess: Streaming not supported"));
15
+ if (file.isStream())
16
+ return callback(new Error("gulp-preprocess: Streaming not supported"));
16
17
 
17
18
  context.src = file.path;
18
19
  context.srcDir = opts.includeBase || path.dirname(file.path);
19
- context.NODE_ENV = context.NODE_ENV || 'development';
20
+ context.NODE_ENV = context.NODE_ENV || "development";
20
21
 
21
- extension = _.isEmpty(opts.extension) ? getExtension(context.src) : opts.extension;
22
+ extension = _.isEmpty(opts.extension)
23
+ ? getExtension(context.src)
24
+ : opts.extension;
22
25
 
23
- contents = file.contents.toString('utf8');
26
+ contents = file.contents.toString("utf8");
24
27
  contents = pp.preprocess(contents, context, extension);
25
- file.contents = new Buffer(contents);
28
+ file.contents = Buffer.from(contents);
26
29
 
27
30
  callback(null, file);
28
31
  }
@@ -31,6 +34,6 @@ module.exports = function (options) {
31
34
  };
32
35
 
33
36
  function getExtension(filename) {
34
- var ext = path.extname(filename||'').split('.');
37
+ var ext = path.extname(filename || "").split(".");
35
38
  return ext[ext.length - 1];
36
39
  }
package/package.json CHANGED
@@ -1,32 +1,34 @@
1
1
  {
2
2
  "name": "gulp-preprocess",
3
3
  "description": "Gulp plugin to preprocess HTML, JavaScript, and other files based on custom context or environment configuration",
4
- "version": "1.2.0",
5
- "homepage": "http://github.com/jas/gulp-preprocess",
4
+ "version": "3.0.2",
5
+ "homepage": "http://github.com/pioug/gulp-preprocess",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "http://github.com/jas/gulp-preprocess.git"
8
+ "url": "http://github.com/pioug/gulp-preprocess.git"
9
9
  },
10
10
  "author": "Jason Sandmeyer",
11
11
  "main": "./index.js",
12
12
  "dependencies": {
13
- "lodash": "2.4.x",
14
- "map-stream": "0.1.x",
15
- "preprocess": "2.1.x"
13
+ "lodash": "^4.17.11",
14
+ "map-stream": "^0.1.x",
15
+ "preprocess": "^3.0.0"
16
16
  },
17
17
  "devDependencies": {
18
- "gulp-util": "2.2.x",
19
- "mocha": "*",
20
- "should": "*"
18
+ "eslint": "^5.13.0",
19
+ "mocha": "^5.2.0",
20
+ "prettier": "^1.16.4",
21
+ "should": "^13.2.3",
22
+ "vinyl": "^2.2.0"
21
23
  },
22
24
  "engines": {
23
- "node": ">= 0.9.0"
25
+ "node": ">= 6.14.3"
24
26
  },
25
27
  "scripts": {
26
28
  "test": "mocha --reporter spec"
27
29
  },
28
30
  "bugs": {
29
- "url": "https://github.com/jas/gulp-preprocess/issues"
31
+ "url": "https://github.com/pioug/gulp-preprocess/issues"
30
32
  },
31
33
  "directories": {
32
34
  "test": "test"
@@ -2,6 +2,8 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>dev title</title>
5
+
6
+
5
7
  </head>
6
8
  <body>
7
9
  <h1>bar</h1>
@@ -4,5 +4,7 @@ define [], ->
4
4
  "use strict"
5
5
 
6
6
  superExpensiveFunction()
7
+
8
+
7
9
  !foobar!
8
10
 
@@ -2,6 +2,8 @@
2
2
  <html>
3
3
  <head>
4
4
  <title>dev title</title>
5
+
6
+
5
7
  </head>
6
8
  <body>
7
9
  <h1>bar</h1>
@@ -6,6 +6,8 @@ define([], function () {
6
6
  bar
7
7
 
8
8
  superExpensiveFunction()
9
+
10
+
9
11
  !foobar!
10
12
 
11
13
 
package/test/main.js CHANGED
@@ -1,140 +1,144 @@
1
- var should = require('should');
2
- var gutil = require('gulp-util');
3
- var preprocess = require('../');
4
- var fs = require('fs');
1
+ var should = require("should");
2
+ var File = require("vinyl");
3
+ var preprocess = require("../");
4
+ var fs = require("fs");
5
5
 
6
- require('mocha');
6
+ require("mocha");
7
7
 
8
8
  function fixtureFile(fileName) {
9
- return new gutil.File({
10
- base: 'test/fixtures',
11
- cwd: 'test/',
12
- path: 'test/fixtures/' + fileName,
13
- contents: fs.readFileSync('test/fixtures/' + fileName)
9
+ return new File({
10
+ base: "test/fixtures",
11
+ cwd: "test/",
12
+ path: "test/fixtures/" + fileName,
13
+ contents: fs.readFileSync("test/fixtures/" + fileName)
14
14
  });
15
- };
15
+ }
16
16
 
17
- process.env['FAKEHOME'] = '/Users/jas';
17
+ process.env["FAKEHOME"] = "/Users/jas";
18
18
 
19
- describe('gulp-preprocess', function(){
20
- describe('preprocess()', function(){
21
-
22
- it('should preprocess html', function(done){
19
+ describe("gulp-preprocess", function() {
20
+ describe("preprocess()", function() {
21
+ it("should preprocess html", function(done) {
23
22
  var stream = preprocess({
24
23
  context: {
25
- firstOption: 'bar',
26
- secondOption: 'foo'
24
+ firstOption: "bar",
25
+ secondOption: "foo"
27
26
  }
28
27
  });
29
28
 
30
- var fakeFile = fixtureFile('test.html');
29
+ var fakeFile = fixtureFile("test.html");
31
30
 
32
- stream.once('data', function(newFile){
31
+ stream.once("data", function(newFile) {
33
32
  should.exist(newFile);
34
33
  should.exist(newFile.contents);
35
- String(newFile.contents).should.equal(fs.readFileSync('test/expected/test.html', 'utf8'));
34
+ String(newFile.contents).should.equal(
35
+ fs.readFileSync("test/expected/test.html", "utf8")
36
+ );
36
37
  done();
37
38
  });
38
39
  stream.write(fakeFile);
39
-
40
40
  });
41
41
 
42
- it('should preprocess javascript', function(done){
42
+ it("should preprocess javascript", function(done) {
43
43
  var stream = preprocess({
44
44
  context: {
45
- firstOption: 'bar',
46
- secondOption: 'foo'
45
+ firstOption: "bar",
46
+ secondOption: "foo"
47
47
  }
48
48
  });
49
49
 
50
- var fakeFile = fixtureFile('test.js');
50
+ var fakeFile = fixtureFile("test.js");
51
51
 
52
- stream.once('data', function(newFile){
52
+ stream.once("data", function(newFile) {
53
53
  should.exist(newFile);
54
54
  should.exist(newFile.contents);
55
- String(newFile.contents).should.equal(fs.readFileSync('test/expected/test.js', 'utf8'));
55
+ String(newFile.contents).should.equal(
56
+ fs.readFileSync("test/expected/test.js", "utf8")
57
+ );
56
58
  done();
57
59
  });
58
60
  stream.write(fakeFile);
59
-
60
61
  });
61
62
 
62
- it('should preprocess coffeescript', function(done){
63
+ it("should preprocess coffeescript", function(done) {
63
64
  var stream = preprocess({
64
65
  context: {
65
- firstOption: 'bar',
66
- secondOption: 'foo'
66
+ firstOption: "bar",
67
+ secondOption: "foo"
67
68
  }
68
69
  });
69
70
 
70
- var fakeFile = fixtureFile('test.coffee');
71
+ var fakeFile = fixtureFile("test.coffee");
71
72
 
72
- stream.once('data', function(newFile){
73
+ stream.once("data", function(newFile) {
73
74
  should.exist(newFile);
74
75
  should.exist(newFile.contents);
75
- String(newFile.contents).should.equal(fs.readFileSync('test/expected/test.coffee', 'utf8'));
76
+ String(newFile.contents).should.equal(
77
+ fs.readFileSync("test/expected/test.coffee", "utf8")
78
+ );
76
79
  done();
77
80
  });
78
81
  stream.write(fakeFile);
79
-
80
82
  });
81
83
 
82
- it('should preprocess without options object', function(done){
84
+ it("should preprocess without options object", function(done) {
83
85
  var stream = preprocess();
84
86
 
85
- var fakeFile = fixtureFile('test.coffee');
87
+ var fakeFile = fixtureFile("test.coffee");
86
88
 
87
- stream.once('data', function(newFile){
89
+ stream.once("data", function(newFile) {
88
90
  should.exist(newFile);
89
91
  should.exist(newFile.contents);
90
- String(newFile.contents).should.equal(fs.readFileSync('test/expected/test.coffee', 'utf8'));
92
+ String(newFile.contents).should.equal(
93
+ fs.readFileSync("test/expected/test.coffee", "utf8")
94
+ );
91
95
  done();
92
96
  });
93
97
  stream.write(fakeFile);
94
-
95
98
  });
96
99
 
97
- it('should preprocess html with custom base', function(done){
100
+ it("should preprocess html with custom base", function(done) {
98
101
  var stream = preprocess({
99
- includeBase: 'test/fixtures/base',
102
+ includeBase: "test/fixtures/base",
100
103
  context: {
101
- firstOption: 'bar',
102
- secondOption: 'foo'
104
+ firstOption: "bar",
105
+ secondOption: "foo"
103
106
  }
104
107
  });
105
108
 
106
- var fakeFile = fixtureFile('test.html');
109
+ var fakeFile = fixtureFile("test.html");
107
110
 
108
- stream.once('data', function(newFile){
111
+ stream.once("data", function(newFile) {
109
112
  should.exist(newFile);
110
113
  should.exist(newFile.contents);
111
- String(newFile.contents).should.equal(fs.readFileSync('test/expected/test-base.html', 'utf8'));
114
+ String(newFile.contents).should.equal(
115
+ fs.readFileSync("test/expected/test-base.html", "utf8")
116
+ );
112
117
  done();
113
118
  });
114
119
  stream.write(fakeFile);
115
-
116
120
  });
117
121
 
118
- it('should allow custom extension', function(done){
122
+ it("should allow custom extension", function(done) {
119
123
  var stream = preprocess({
120
- extension: 'html',
124
+ extension: "html",
121
125
  context: {
122
- firstOption: 'bar',
123
- secondOption: 'foo'
126
+ firstOption: "bar",
127
+ secondOption: "foo"
124
128
  }
125
129
  });
126
130
 
127
- var fakeFile = fixtureFile('test.php');
131
+ var fakeFile = fixtureFile("test.php");
128
132
 
129
- stream.once('data', function(newFile){
133
+ stream.once("data", function(newFile) {
130
134
  should.exist(newFile);
131
135
  should.exist(newFile.contents);
132
- String(newFile.contents).should.equal(fs.readFileSync('test/expected/test.html', 'utf8'));
136
+ String(newFile.contents).should.equal(
137
+ fs.readFileSync("test/expected/test.html", "utf8")
138
+ );
133
139
  done();
134
140
  });
135
141
  stream.write(fakeFile);
136
-
137
142
  });
138
-
139
143
  });
140
144
  });
package/.npmignore DELETED
@@ -1 +0,0 @@
1
- /node_modules/