gulp-preprocess 4.0.2 → 6.0.0
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/.github/workflows/test.yaml +6 -4
- package/.oxignore +2 -0
- package/.oxlintrc.json +6 -0
- package/README.md +9 -7
- package/index.js +9 -10
- package/package.json +40 -42
- package/test/main.js +50 -53
- package/.eslintrc +0 -7
|
@@ -5,11 +5,13 @@ jobs:
|
|
|
5
5
|
runs-on: ubuntu-latest
|
|
6
6
|
strategy:
|
|
7
7
|
matrix:
|
|
8
|
-
node: [
|
|
8
|
+
node: ["lts/*", "node"]
|
|
9
9
|
steps:
|
|
10
|
-
- uses: actions/checkout@
|
|
11
|
-
- uses: actions/setup-node@
|
|
10
|
+
- uses: actions/checkout@v4
|
|
11
|
+
- uses: actions/setup-node@v4
|
|
12
12
|
with:
|
|
13
13
|
node-version: ${{ matrix.node }}
|
|
14
14
|
- run: npm install
|
|
15
|
-
- run: npm run
|
|
15
|
+
- run: npm run format:check
|
|
16
|
+
- run: npm run lint
|
|
17
|
+
- run: npm test
|
package/.oxignore
ADDED
package/.oxlintrc.json
ADDED
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# gulp-preprocess [](https://www.npmjs.com/package/gulp-preprocess) [](https://www.npmjs.com/package/gulp-preprocess) [](https://github.com/pioug/gulp-preprocess/actions/workflows/test.yaml)
|
|
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
|
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
</tr>
|
|
11
11
|
<tr>
|
|
12
12
|
<td>Node Version</td>
|
|
13
|
-
<td>>=
|
|
13
|
+
<td>>= 24</td>
|
|
14
14
|
</tr>
|
|
15
15
|
<tr>
|
|
16
16
|
<td>Gulp Version</td>
|
|
@@ -36,7 +36,7 @@ var preprocess = require("gulp-preprocess");
|
|
|
36
36
|
gulp.task("html", function () {
|
|
37
37
|
gulp
|
|
38
38
|
.src("./app/*.html")
|
|
39
|
-
.pipe(preprocess({ context: { NODE_ENV: "production", DEBUG: true } })) // To set environment variables
|
|
39
|
+
.pipe(preprocess({ context: { NODE_ENV: "production", DEBUG: true } })) // To set environment variables inline
|
|
40
40
|
.pipe(gulp.dest("./dist/"));
|
|
41
41
|
});
|
|
42
42
|
|
|
@@ -54,14 +54,16 @@ gulp.task("scripts", function () {
|
|
|
54
54
|
<!-- @if NODE_ENV='production' -->
|
|
55
55
|
<script src="some/production/lib/like/analytics.js"></script>
|
|
56
56
|
<!-- @endif -->
|
|
57
|
-
|
|
58
57
|
</head>
|
|
59
58
|
<body>
|
|
60
59
|
<!-- @ifdef DEBUG -->
|
|
61
|
-
<h1>
|
|
60
|
+
<h1>
|
|
61
|
+
Debugging mode -
|
|
62
|
+
<!-- @echo RELEASE_TAG -->
|
|
63
|
+
</h1>
|
|
62
64
|
<!-- @endif -->
|
|
63
65
|
<p>
|
|
64
|
-
|
|
66
|
+
<!-- @include welcome_message.txt -->
|
|
65
67
|
</p>
|
|
66
68
|
</body>
|
|
67
69
|
```
|
|
@@ -91,7 +93,7 @@ CoffeeScript files are also supported.
|
|
|
91
93
|
Type: `Object`
|
|
92
94
|
Default: `{}`
|
|
93
95
|
|
|
94
|
-
Context for directives used in your preprocessed files. The default context consists of the current
|
|
96
|
+
Context for directives used in your preprocessed files. The default context consists of the current environment variables. Custom context is merged with `process.env`.
|
|
95
97
|
|
|
96
98
|
#### options.includeBase
|
|
97
99
|
|
package/index.js
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
|
-
var _ = require("lodash");
|
|
2
1
|
var pp = require("preprocess");
|
|
3
2
|
var path = require("path");
|
|
4
|
-
var
|
|
3
|
+
var Transform = require("node:stream").Transform;
|
|
5
4
|
|
|
6
5
|
module.exports = function (options) {
|
|
7
|
-
var opts =
|
|
8
|
-
var context =
|
|
6
|
+
var opts = Object.assign({}, options);
|
|
7
|
+
var context = Object.assign({}, process.env, opts.context);
|
|
9
8
|
|
|
10
9
|
function ppStream(file, encoding, callback) {
|
|
11
10
|
var contents, extension;
|
|
12
11
|
|
|
13
12
|
// TODO: support streaming files
|
|
14
13
|
if (file.isNull()) return callback(null, file); // pass along
|
|
15
|
-
if (file.isStream())
|
|
16
|
-
return callback(new Error("gulp-preprocess: Streaming not supported"));
|
|
14
|
+
if (file.isStream()) return callback(new Error("gulp-preprocess: Streaming not supported"));
|
|
17
15
|
|
|
18
16
|
context.src = file.path;
|
|
19
17
|
context.srcDir = opts.includeBase || path.dirname(file.path);
|
|
20
18
|
context.NODE_ENV = context.NODE_ENV || "development";
|
|
21
19
|
|
|
22
|
-
extension =
|
|
23
|
-
? getExtension(context.src)
|
|
24
|
-
: opts.extension;
|
|
20
|
+
extension = opts.extension ?? getExtension(context.src);
|
|
25
21
|
|
|
26
22
|
contents = file.contents.toString("utf8");
|
|
27
23
|
contents = pp.preprocess(contents, context, extension);
|
|
@@ -30,7 +26,10 @@ module.exports = function (options) {
|
|
|
30
26
|
callback(null, file);
|
|
31
27
|
}
|
|
32
28
|
|
|
33
|
-
return
|
|
29
|
+
return new Transform({
|
|
30
|
+
objectMode: true,
|
|
31
|
+
transform: ppStream,
|
|
32
|
+
});
|
|
34
33
|
};
|
|
35
34
|
|
|
36
35
|
function getExtension(filename) {
|
package/package.json
CHANGED
|
@@ -1,54 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gulp-preprocess",
|
|
3
|
+
"version": "6.0.0",
|
|
3
4
|
"description": "Gulp plugin to preprocess HTML, JavaScript, and other files based on custom context or environment configuration",
|
|
4
|
-
"version": "4.0.2",
|
|
5
|
-
"homepage": "http://github.com/pioug/gulp-preprocess",
|
|
6
|
-
"repository": {
|
|
7
|
-
"type": "git",
|
|
8
|
-
"url": "http://github.com/pioug/gulp-preprocess.git"
|
|
9
|
-
},
|
|
10
|
-
"author": "Jason Sandmeyer",
|
|
11
|
-
"main": "./index.js",
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"lodash": "^4.17.15",
|
|
14
|
-
"preprocess": "^3.0.0",
|
|
15
|
-
"through2": "^4.0.2"
|
|
16
|
-
},
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"eslint": "7.24.0",
|
|
19
|
-
"mocha": "^8.3.2",
|
|
20
|
-
"prettier": "^2.2.1",
|
|
21
|
-
"should": "^13.2.3",
|
|
22
|
-
"vinyl": "^2.2.0"
|
|
23
|
-
},
|
|
24
|
-
"engines": {
|
|
25
|
-
"node": ">= 14"
|
|
26
|
-
},
|
|
27
|
-
"scripts": {
|
|
28
|
-
"test": "mocha --reporter spec"
|
|
29
|
-
},
|
|
30
|
-
"bugs": {
|
|
31
|
-
"url": "https://github.com/pioug/gulp-preprocess/issues"
|
|
32
|
-
},
|
|
33
|
-
"directories": {
|
|
34
|
-
"test": "test"
|
|
35
|
-
},
|
|
36
5
|
"keywords": [
|
|
37
|
-
"
|
|
38
|
-
"gulp-plugin",
|
|
39
|
-
"preprocessor",
|
|
40
|
-
"html",
|
|
41
|
-
"javascript",
|
|
6
|
+
"ENV",
|
|
42
7
|
"coffeescript",
|
|
8
|
+
"conditional",
|
|
43
9
|
"debug",
|
|
10
|
+
"echo",
|
|
44
11
|
"environment",
|
|
45
|
-
"ENV",
|
|
46
|
-
"conditional",
|
|
47
|
-
"include",
|
|
48
12
|
"exclude",
|
|
13
|
+
"gulp-plugin",
|
|
14
|
+
"gulpplugin",
|
|
15
|
+
"html",
|
|
49
16
|
"ifdef",
|
|
50
17
|
"ifndef",
|
|
51
|
-
"
|
|
18
|
+
"include",
|
|
19
|
+
"javascript",
|
|
20
|
+
"preprocessor"
|
|
52
21
|
],
|
|
53
|
-
"
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/pioug/gulp-preprocess/issues"
|
|
24
|
+
},
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"author": "Jason Sandmeyer",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/pioug/gulp-preprocess.git"
|
|
30
|
+
},
|
|
31
|
+
"main": "index.js",
|
|
32
|
+
"exports": "./index.js",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"format": "oxfmt --write \"**/*.{js,json,yml,yaml,md}\" --ignore-path .oxignore",
|
|
35
|
+
"format:check": "oxfmt --check \"**/*.{js,json,yml,yaml,md}\" --ignore-path .oxignore",
|
|
36
|
+
"lint": "oxlint --deny-warnings . --ignore-path .oxignore",
|
|
37
|
+
"prepublishOnly": "npm run format:check && npm run lint && npm test",
|
|
38
|
+
"test": "mocha"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"preprocess": "^3.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"mocha": "^12.0.0-beta-9",
|
|
45
|
+
"oxfmt": "^0.32.0",
|
|
46
|
+
"oxlint": "^1.47.0",
|
|
47
|
+
"vinyl": "^3.0.0"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=24.0.0"
|
|
51
|
+
}
|
|
54
52
|
}
|
package/test/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var assert = require("assert");
|
|
2
2
|
var File = require("vinyl");
|
|
3
3
|
var preprocess = require("../");
|
|
4
4
|
var fs = require("fs");
|
|
@@ -10,132 +10,129 @@ function fixtureFile(fileName) {
|
|
|
10
10
|
base: "test/fixtures",
|
|
11
11
|
cwd: "test/",
|
|
12
12
|
path: "test/fixtures/" + fileName,
|
|
13
|
-
contents: fs.readFileSync("test/fixtures/" + fileName)
|
|
13
|
+
contents: fs.readFileSync("test/fixtures/" + fileName),
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
process.env["FAKEHOME"] = "/Users/jas";
|
|
18
18
|
|
|
19
|
-
describe("gulp-preprocess", function() {
|
|
20
|
-
describe("preprocess()", function() {
|
|
21
|
-
it("should preprocess html", function(done) {
|
|
19
|
+
describe("gulp-preprocess", function () {
|
|
20
|
+
describe("preprocess()", function () {
|
|
21
|
+
it("should preprocess html", function (done) {
|
|
22
22
|
var stream = preprocess({
|
|
23
23
|
context: {
|
|
24
24
|
firstOption: "bar",
|
|
25
|
-
secondOption: "foo"
|
|
26
|
-
}
|
|
25
|
+
secondOption: "foo",
|
|
26
|
+
},
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
var fakeFile = fixtureFile("test.html");
|
|
30
30
|
|
|
31
|
-
stream.once("data", function(newFile) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
String(newFile.contents).
|
|
35
|
-
fs.readFileSync("test/expected/test.html", "utf8")
|
|
36
|
-
);
|
|
31
|
+
stream.once("data", function (newFile) {
|
|
32
|
+
assert(newFile);
|
|
33
|
+
assert(newFile.contents);
|
|
34
|
+
assert.equal(String(newFile.contents), fs.readFileSync("test/expected/test.html", "utf8"));
|
|
37
35
|
done();
|
|
38
36
|
});
|
|
39
37
|
stream.write(fakeFile);
|
|
40
38
|
});
|
|
41
39
|
|
|
42
|
-
it("should preprocess javascript", function(done) {
|
|
40
|
+
it("should preprocess javascript", function (done) {
|
|
43
41
|
var stream = preprocess({
|
|
44
42
|
context: {
|
|
45
43
|
firstOption: "bar",
|
|
46
|
-
secondOption: "foo"
|
|
47
|
-
}
|
|
44
|
+
secondOption: "foo",
|
|
45
|
+
},
|
|
48
46
|
});
|
|
49
47
|
|
|
50
48
|
var fakeFile = fixtureFile("test.js");
|
|
51
49
|
|
|
52
|
-
stream.once("data", function(newFile) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
String(newFile.contents).
|
|
56
|
-
fs.readFileSync("test/expected/test.js", "utf8")
|
|
57
|
-
);
|
|
50
|
+
stream.once("data", function (newFile) {
|
|
51
|
+
assert(newFile);
|
|
52
|
+
assert(newFile.contents);
|
|
53
|
+
assert.equal(String(newFile.contents), fs.readFileSync("test/expected/test.js", "utf8"));
|
|
58
54
|
done();
|
|
59
55
|
});
|
|
60
56
|
stream.write(fakeFile);
|
|
61
57
|
});
|
|
62
58
|
|
|
63
|
-
it("should preprocess coffeescript", function(done) {
|
|
59
|
+
it("should preprocess coffeescript", function (done) {
|
|
64
60
|
var stream = preprocess({
|
|
65
61
|
context: {
|
|
66
62
|
firstOption: "bar",
|
|
67
|
-
secondOption: "foo"
|
|
68
|
-
}
|
|
63
|
+
secondOption: "foo",
|
|
64
|
+
},
|
|
69
65
|
});
|
|
70
66
|
|
|
71
67
|
var fakeFile = fixtureFile("test.coffee");
|
|
72
68
|
|
|
73
|
-
stream.once("data", function(newFile) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
69
|
+
stream.once("data", function (newFile) {
|
|
70
|
+
assert(newFile);
|
|
71
|
+
assert(newFile.contents);
|
|
72
|
+
assert.equal(
|
|
73
|
+
String(newFile.contents),
|
|
74
|
+
fs.readFileSync("test/expected/test.coffee", "utf8"),
|
|
78
75
|
);
|
|
79
76
|
done();
|
|
80
77
|
});
|
|
81
78
|
stream.write(fakeFile);
|
|
82
79
|
});
|
|
83
80
|
|
|
84
|
-
it("should preprocess without options object", function(done) {
|
|
81
|
+
it("should preprocess without options object", function (done) {
|
|
85
82
|
var stream = preprocess();
|
|
86
83
|
|
|
87
84
|
var fakeFile = fixtureFile("test.coffee");
|
|
88
85
|
|
|
89
|
-
stream.once("data", function(newFile) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
stream.once("data", function (newFile) {
|
|
87
|
+
assert(newFile);
|
|
88
|
+
assert(newFile.contents);
|
|
89
|
+
assert.equal(
|
|
90
|
+
String(newFile.contents),
|
|
91
|
+
fs.readFileSync("test/expected/test.coffee", "utf8"),
|
|
94
92
|
);
|
|
95
93
|
done();
|
|
96
94
|
});
|
|
97
95
|
stream.write(fakeFile);
|
|
98
96
|
});
|
|
99
97
|
|
|
100
|
-
it("should preprocess html with custom base", function(done) {
|
|
98
|
+
it("should preprocess html with custom base", function (done) {
|
|
101
99
|
var stream = preprocess({
|
|
102
100
|
includeBase: "test/fixtures/base",
|
|
103
101
|
context: {
|
|
104
102
|
firstOption: "bar",
|
|
105
|
-
secondOption: "foo"
|
|
106
|
-
}
|
|
103
|
+
secondOption: "foo",
|
|
104
|
+
},
|
|
107
105
|
});
|
|
108
106
|
|
|
109
107
|
var fakeFile = fixtureFile("test.html");
|
|
110
108
|
|
|
111
|
-
stream.once("data", function(newFile) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
109
|
+
stream.once("data", function (newFile) {
|
|
110
|
+
assert(newFile);
|
|
111
|
+
assert(newFile.contents);
|
|
112
|
+
assert.equal(
|
|
113
|
+
String(newFile.contents),
|
|
114
|
+
fs.readFileSync("test/expected/test-base.html", "utf8"),
|
|
116
115
|
);
|
|
117
116
|
done();
|
|
118
117
|
});
|
|
119
118
|
stream.write(fakeFile);
|
|
120
119
|
});
|
|
121
120
|
|
|
122
|
-
it("should allow custom extension", function(done) {
|
|
121
|
+
it("should allow custom extension", function (done) {
|
|
123
122
|
var stream = preprocess({
|
|
124
123
|
extension: "html",
|
|
125
124
|
context: {
|
|
126
125
|
firstOption: "bar",
|
|
127
|
-
secondOption: "foo"
|
|
128
|
-
}
|
|
126
|
+
secondOption: "foo",
|
|
127
|
+
},
|
|
129
128
|
});
|
|
130
129
|
|
|
131
130
|
var fakeFile = fixtureFile("test.php");
|
|
132
131
|
|
|
133
|
-
stream.once("data", function(newFile) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
String(newFile.contents).
|
|
137
|
-
fs.readFileSync("test/expected/test.html", "utf8")
|
|
138
|
-
);
|
|
132
|
+
stream.once("data", function (newFile) {
|
|
133
|
+
assert(newFile);
|
|
134
|
+
assert(newFile.contents);
|
|
135
|
+
assert.equal(String(newFile.contents), fs.readFileSync("test/expected/test.html", "utf8"));
|
|
139
136
|
done();
|
|
140
137
|
});
|
|
141
138
|
stream.write(fakeFile);
|