js-build-tools 6.6.0 → 6.8.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/LICENSE +674 -674
- package/README.md +768 -701
- package/babel.config.js +28 -28
- package/dist/build.js +75 -75
- package/dist/bundle.js +19 -19
- package/dist/bundleMinify.js +7 -7
- package/dist/compileReadme.js +4 -4
- package/dist/copyFiles.js +17 -17
- package/dist/copyFonts.js +4 -4
- package/dist/default.js +5 -5
- package/dist/dist.js +4 -4
- package/dist/distMinify.js +4 -4
- package/dist/docs.js +7 -7
- package/dist/images.js +4 -4
- package/dist/jsdocDocs.js +6 -6
- package/dist/lint.js +16 -16
- package/dist/partials/addToReadme.js +9 -9
- package/dist/partials/beginWatcher.js +4 -4
- package/dist/partials/cacheFiles.js +121 -0
- package/dist/partials/clean.js +5 -5
- package/dist/partials/copyFor.js +9 -9
- package/dist/partials/distFor.js +6 -6
- package/dist/partials/distForSrc.js +5 -5
- package/dist/partials/distSeries.js +7 -7
- package/dist/partials/imagesFor.js +155 -93
- package/dist/partials/jsdocDocsFor.js +64 -51
- package/dist/partials/lintSource.js +51 -51
- package/dist/partials/loadPeer.js +99 -99
- package/dist/partials/loadPlaywright.js +14 -14
- package/dist/partials/minifyFor.js +20 -20
- package/dist/partials/neostandardLint.js +175 -175
- package/dist/partials/readmeTemplate.js +4 -4
- package/dist/partials/removeDirectory.js +11 -11
- package/dist/partials/resolveDocsMethod.js +6 -6
- package/dist/partials/runOnChange.js +31 -31
- package/dist/partials/sassFor.js +6 -6
- package/dist/partials/serveStatic.js +9 -9
- package/dist/partials/tsFor.js +32 -32
- package/dist/partials/typeDocsFor.js +264 -264
- package/dist/partials.js +183 -176
- package/dist/partials.min.js +1 -1
- package/dist/sourceLint.js +18 -18
- package/dist/test-helpers/setUp.js +6 -4
- package/dist/testFull.js +5 -5
- package/dist/testQuick.js +5 -5
- package/dist/typeDocs.js +5 -5
- package/dist/typeScript.js +4 -4
- package/dist/utilities/convertMjsFilesForDocs.js +12 -12
- package/dist/utilities/dotGet.js +54 -54
- package/dist/utilities/dotNotate.js +79 -79
- package/dist/utilities/dotSet.js +45 -45
- package/dist/utilities/esmNamedExportsToCjs.js +15 -15
- package/dist/utilities/getBundleConfigs.js +9 -9
- package/dist/utilities/isObject.js +6 -6
- package/dist/utilities/strAfter.js +7 -7
- package/dist/utilities/strBefore.js +7 -7
- package/dist/watchFull.js +4 -4
- package/dist/watchTest.js +4 -4
- package/functions/build.mjs +72 -72
- package/functions/build.test.mjs +760 -759
- package/functions/bundle.mjs +44 -44
- package/functions/bundle.test.mjs +219 -219
- package/functions/bundleMinify.mjs +16 -16
- package/functions/bundleMinify.test.mjs +37 -37
- package/functions/compileReadme.mjs +9 -9
- package/functions/compileReadme.test.mjs +18 -18
- package/functions/copyFiles.mjs +32 -32
- package/functions/copyFiles.test.mjs +78 -78
- package/functions/copyFonts.mjs +9 -9
- package/functions/copyFonts.test.mjs +32 -32
- package/functions/default.mjs +12 -12
- package/functions/default.test.mjs +33 -33
- package/functions/dist.mjs +8 -8
- package/functions/dist.test.mjs +44 -44
- package/functions/distMinify.mjs +9 -9
- package/functions/distMinify.test.mjs +15 -15
- package/functions/docs.mjs +13 -13
- package/functions/docs.test.mjs +45 -45
- package/functions/gulpConfigEntries.test.mjs +23 -23
- package/functions/images.mjs +8 -8
- package/functions/images.test.mjs +140 -142
- package/functions/jsdocDocs.mjs +10 -10
- package/functions/jsdocEsmExports.test.mjs +24 -24
- package/functions/lint.mjs +9 -9
- package/functions/partials/addToReadme.mjs +25 -25
- package/functions/partials/addToReadme.test.mjs +34 -34
- package/functions/partials/beginWatcher.mjs +9 -9
- package/functions/partials/beginWatcher.test.mjs +19 -19
- package/functions/partials/cacheFiles.mjs +114 -0
- package/functions/partials/cacheFiles.test.mjs +151 -0
- package/functions/partials/clean.mjs +13 -13
- package/functions/partials/clean.test.mjs +22 -22
- package/functions/partials/copyFor.mjs +15 -15
- package/functions/partials/copyFor.test.mjs +53 -53
- package/functions/partials/distFor.mjs +22 -22
- package/functions/partials/distFor.test.mjs +195 -195
- package/functions/partials/distForSrc.mjs +11 -11
- package/functions/partials/distForSrc.test.mjs +18 -18
- package/functions/partials/distSeries.mjs +21 -21
- package/functions/partials/distSeries.test.mjs +34 -34
- package/functions/partials/imagesFor.mjs +147 -83
- package/functions/partials/imagesFor.test.mjs +311 -287
- package/functions/partials/jsdocDocsFor.mjs +163 -152
- package/functions/partials/jsdocDocsFor.test.mjs +182 -152
- package/functions/partials/lintSource.mjs +41 -41
- package/functions/partials/loadPeer.mjs +76 -76
- package/functions/partials/loadPeer.test.mjs +58 -58
- package/functions/partials/loadPlaywright.mjs +23 -23
- package/functions/partials/loadPlaywright.test.mjs +70 -70
- package/functions/partials/minifyFor.mjs +15 -15
- package/functions/partials/minifyFor.test.mjs +49 -49
- package/functions/partials/neostandardLint.mjs +142 -142
- package/functions/partials/neostandardLint.test.mjs +131 -131
- package/functions/partials/readmeTemplate.mjs +12 -12
- package/functions/partials/readmeTemplate.test.mjs +34 -34
- package/functions/partials/removeDirectory.mjs +34 -34
- package/functions/partials/removeDirectory.test.mjs +72 -72
- package/functions/partials/resolveDocsMethod.mjs +10 -10
- package/functions/partials/resolveDocsMethod.test.mjs +33 -33
- package/functions/partials/runOnChange.mjs +54 -54
- package/functions/partials/runOnChange.test.mjs +95 -95
- package/functions/partials/sassFor.mjs +25 -25
- package/functions/partials/sassFor.test.mjs +81 -81
- package/functions/partials/serveStatic.mjs +47 -47
- package/functions/partials/serveStatic.test.mjs +71 -71
- package/functions/partials/tsFor.mjs +92 -92
- package/functions/partials/tsFor.test.mjs +88 -88
- package/functions/partials/typeDocsFor.mjs +231 -231
- package/functions/partials/typeDocsFor.test.mjs +263 -263
- package/functions/partials.mjs +32 -31
- package/functions/partials.test.mjs +7 -7
- package/functions/sass.mjs +4 -4
- package/functions/sass.test.mjs +31 -31
- package/functions/sourceLint.mjs +13 -13
- package/functions/sourceLint.test.mjs +166 -166
- package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +40 -40
- package/functions/test-helpers/setUp.mjs +102 -100
- package/functions/test-helpers/setUp.test.mjs +19 -19
- package/functions/testFull.mjs +17 -17
- package/functions/testFull.test.mjs +17 -17
- package/functions/testHelpers.mjs +10 -10
- package/functions/testHelpers.test.mjs +7 -7
- package/functions/testQuick.mjs +17 -17
- package/functions/testQuick.test.mjs +17 -17
- package/functions/typeDocs.mjs +9 -9
- package/functions/typeDocs.test.mjs +11 -11
- package/functions/typeScript.mjs +8 -8
- package/functions/typeScript.test.mjs +11 -11
- package/functions/utilities/convertMjsFilesForDocs.mjs +34 -34
- package/functions/utilities/convertMjsFilesForDocs.test.mjs +58 -58
- package/functions/utilities/dotGet.mjs +49 -49
- package/functions/utilities/dotNotate.mjs +73 -73
- package/functions/utilities/dotNotate.test.mjs +41 -41
- package/functions/utilities/dotSet.mjs +40 -40
- package/functions/utilities/esmNamedExportsToCjs.mjs +30 -30
- package/functions/utilities/esmNamedExportsToCjs.test.mjs +47 -47
- package/functions/utilities/getBundleConfigs.mjs +30 -30
- package/functions/utilities/isObject.mjs +8 -8
- package/functions/utilities/strAfter.mjs +12 -12
- package/functions/utilities/strBefore.mjs +12 -12
- package/functions/watchFull.mjs +9 -9
- package/functions/watchFull.test.mjs +41 -41
- package/functions/watchTest.mjs +10 -10
- package/functions/watchTest.test.mjs +49 -49
- package/gulp.config.js +4 -4
- package/gulp.config.mjs +349 -340
- package/gulpfile.base.js +51 -51
- package/gulpfile.base.mjs +29 -29
- package/jsdoc.base.js +16 -16
- package/jsdoc.esmExports.js +17 -17
- package/package.json +146 -145
- package/dist/test-helpers/isolateGulpCache.js +0 -25
- package/functions/test-helpers/isolateGulpCache.mjs +0 -16
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.cacheFiles = void 0;
|
|
7
|
+
var _crypto = require("crypto");
|
|
8
|
+
var _promises = require("fs/promises");
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _stream = require("stream");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
// Marks a file sent to the plugin with its cache file and its path, so its result is cached even if the plugin renames it
|
|
13
|
+
const cacheFile = Symbol('cacheFile');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The cache file for a file's contents: a hash of the cache name, the fingerprint and the contents, so the same file
|
|
17
|
+
* with other plugin settings or plugin versions gets a result of its own.
|
|
18
|
+
* @private
|
|
19
|
+
* @param {string} directory
|
|
20
|
+
* @param {string} name
|
|
21
|
+
* @param {string} fingerprint
|
|
22
|
+
* @param {Buffer} contents
|
|
23
|
+
* @returns {string}
|
|
24
|
+
*/
|
|
25
|
+
const cachePath = (directory, name, fingerprint, contents) => _path.default.join(directory, name, (0, _crypto.createHash)('sha256').update(name).update('\0').update(fingerprint).update('\0').update(contents).digest('hex'));
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Write through a temporary file and rename it, so a reader (another build or test worker) never sees a half-written
|
|
29
|
+
* result.
|
|
30
|
+
* @private
|
|
31
|
+
* @param {string} file
|
|
32
|
+
* @param {Buffer} contents
|
|
33
|
+
* @returns {Promise<void>}
|
|
34
|
+
*/
|
|
35
|
+
const writeAtomic = async (file, contents) => {
|
|
36
|
+
await (0, _promises.mkdir)(_path.default.dirname(file), {
|
|
37
|
+
recursive: true
|
|
38
|
+
});
|
|
39
|
+
const temporary = `${file}.${(0, _crypto.randomUUID)()}.tmp`;
|
|
40
|
+
await (0, _promises.writeFile)(temporary, contents);
|
|
41
|
+
await (0, _promises.rename)(temporary, file);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Run a gulp plugin only on files it hasn't processed before. A file whose contents (with this cache name and
|
|
46
|
+
* fingerprint) were processed by an earlier run gets that run's result from the cache instead, and skips the plugin.
|
|
47
|
+
* Replaces gulp-cache, which kept one cache for every process in the system's temp folder.
|
|
48
|
+
*
|
|
49
|
+
* A result is cached when the plugin passes on the file object it was given (as gulp plugins usually do); a plugin
|
|
50
|
+
* that makes new file objects still works, its results just aren't cached. When the plugin renames a file, the cache
|
|
51
|
+
* keeps the new name too (next to the result, as `<entry>.path`), so a cached file is renamed the same way. Entries
|
|
52
|
+
* are never pruned: delete the directory to start over.
|
|
53
|
+
* @memberOf module:partials
|
|
54
|
+
* @param {stream.Transform} plugin - The gulp plugin stream to run on uncached files (e.g. imagemin()).
|
|
55
|
+
* @param {Object} options
|
|
56
|
+
* @param {string} options.directory - Where cached results are kept (see images.cacheDir).
|
|
57
|
+
* @param {string} [options.name='default'] - The cache's folder; keeps results of different plugin settings apart.
|
|
58
|
+
* @param {string} [options.fingerprint=''] - Anything else that changes the plugin's output, such as its version and
|
|
59
|
+
* options: when it changes, earlier results are no longer used.
|
|
60
|
+
* @returns {stream.Transform}
|
|
61
|
+
*/
|
|
62
|
+
const cacheFiles = (plugin, {
|
|
63
|
+
directory,
|
|
64
|
+
name = 'default',
|
|
65
|
+
fingerprint = ''
|
|
66
|
+
}) => {
|
|
67
|
+
const writes = [];
|
|
68
|
+
const pluginDone = new Promise((resolve, reject) => {
|
|
69
|
+
plugin.on('end', resolve);
|
|
70
|
+
plugin.on('error', reject);
|
|
71
|
+
});
|
|
72
|
+
// The error also reaches the stream (below); this only stops it from being reported a second time as unhandled
|
|
73
|
+
pluginDone.catch(() => {});
|
|
74
|
+
const stream = new _stream.Transform({
|
|
75
|
+
objectMode: true,
|
|
76
|
+
transform(file, encoding, callback) {
|
|
77
|
+
if (!file.isBuffer()) {
|
|
78
|
+
callback(null, file);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const cached = cachePath(directory, name, fingerprint, file.contents);
|
|
82
|
+
(0, _promises.readFile)(cached).then(async contents => {
|
|
83
|
+
file.contents = contents;
|
|
84
|
+
// Written before the result, so it's there whenever the result is
|
|
85
|
+
const renamed = await (0, _promises.readFile)(`${cached}.path`, 'utf8').catch(() => undefined);
|
|
86
|
+
if (renamed !== undefined) {
|
|
87
|
+
file.path = _path.default.join(_path.default.dirname(file.path), renamed);
|
|
88
|
+
}
|
|
89
|
+
callback(null, file);
|
|
90
|
+
}, () => {
|
|
91
|
+
file[cacheFile] = {
|
|
92
|
+
cached,
|
|
93
|
+
from: file.path
|
|
94
|
+
};
|
|
95
|
+
plugin.write(file);
|
|
96
|
+
callback();
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
flush(callback) {
|
|
100
|
+
plugin.end();
|
|
101
|
+
pluginDone.then(() => Promise.all(writes)).then(() => callback(), callback);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
plugin.on('data', file => {
|
|
105
|
+
const tag = file[cacheFile];
|
|
106
|
+
delete file[cacheFile];
|
|
107
|
+
if (tag && file.isBuffer()) {
|
|
108
|
+
const {
|
|
109
|
+
cached,
|
|
110
|
+
from
|
|
111
|
+
} = tag;
|
|
112
|
+
const renamed = file.path === from ? Promise.resolve() : writeAtomic(`${cached}.path`, _path.default.relative(_path.default.dirname(from), file.path));
|
|
113
|
+
// The cache only saves time: a result that can't be written is processed again next run, not a failed build
|
|
114
|
+
writes.push(renamed.then(() => writeAtomic(cached, file.contents)).catch(() => {}));
|
|
115
|
+
}
|
|
116
|
+
stream.push(file);
|
|
117
|
+
});
|
|
118
|
+
plugin.on('error', error => stream.destroy(error));
|
|
119
|
+
return stream;
|
|
120
|
+
};
|
|
121
|
+
exports.cacheFiles = cacheFiles;
|
package/dist/partials/clean.js
CHANGED
|
@@ -11,11 +11,11 @@ var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
|
11
11
|
var _removeDirectory = require("./removeDirectory.js");
|
|
12
12
|
var cache;
|
|
13
13
|
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
14
|
-
/**
|
|
15
|
-
* Deletes all the distribution and browser files (used before create a new build).
|
|
16
|
-
* Configure array of directories to remove with 'cleanPaths'.
|
|
17
|
-
* @memberOf module:partials
|
|
18
|
-
* @returns {Promise<string[]> | *}
|
|
14
|
+
/**
|
|
15
|
+
* Deletes all the distribution and browser files (used before create a new build).
|
|
16
|
+
* Configure array of directories to remove with 'cleanPaths'.
|
|
17
|
+
* @memberOf module:partials
|
|
18
|
+
* @returns {Promise<string[]> | *}
|
|
19
19
|
*/
|
|
20
20
|
const clean = () => gulpConfig.get('cleanPaths').reduce((promise, path) => promise.then(() => (0, _removeDirectory.removeDirectory)(path)), Promise.resolve());
|
|
21
21
|
exports.clean = clean;
|
package/dist/partials/copyFor.js
CHANGED
|
@@ -5,15 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.copyFor = void 0;
|
|
7
7
|
var _gulp = require("gulp");
|
|
8
|
-
/**
|
|
9
|
-
* Copy some files to a different location.
|
|
10
|
-
* @memberOf module:partials
|
|
11
|
-
* @param {string|array} srcPath
|
|
12
|
-
* @param {string} destPath
|
|
13
|
-
* @param {Object} [options]
|
|
14
|
-
* @param {string} [options.base] - Passed through to gulp's own src(pattern, {base}), to preserve srcPath's own
|
|
15
|
-
* subdirectory structure in destPath instead of flattening it.
|
|
16
|
-
* @returns {stream.Stream}
|
|
8
|
+
/**
|
|
9
|
+
* Copy some files to a different location.
|
|
10
|
+
* @memberOf module:partials
|
|
11
|
+
* @param {string|array} srcPath
|
|
12
|
+
* @param {string} destPath
|
|
13
|
+
* @param {Object} [options]
|
|
14
|
+
* @param {string} [options.base] - Passed through to gulp's own src(pattern, {base}), to preserve srcPath's own
|
|
15
|
+
* subdirectory structure in destPath instead of flattening it.
|
|
16
|
+
* @returns {stream.Stream}
|
|
17
17
|
*/
|
|
18
18
|
// encoding: false copies the bytes untouched - Gulp 5's default utf8 handling corrupts binary files such as fonts.
|
|
19
19
|
const copyFor = (srcPath, destPath, {
|
package/dist/partials/distFor.js
CHANGED
|
@@ -13,12 +13,12 @@ var _through = _interopRequireDefault(require("through2"));
|
|
|
13
13
|
var cache;
|
|
14
14
|
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
15
15
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
-
/**
|
|
17
|
-
* Build the distribution for a given source pattern.
|
|
18
|
-
* @memberOf module:partials
|
|
19
|
-
* @param {string|array} [srcPath='src/config/path/dist/for']
|
|
20
|
-
* @param {string} [destPath='dist/config/path']
|
|
21
|
-
* @returns {stream.Stream}
|
|
16
|
+
/**
|
|
17
|
+
* Build the distribution for a given source pattern.
|
|
18
|
+
* @memberOf module:partials
|
|
19
|
+
* @param {string|array} [srcPath='src/config/path/dist/for']
|
|
20
|
+
* @param {string} [destPath='dist/config/path']
|
|
21
|
+
* @returns {stream.Stream}
|
|
22
22
|
*/
|
|
23
23
|
const distFor = (srcPath = (0, _distForSrc.distForSrc)(), destPath = gulpConfig.get('dist.to')) => (0, _gulp.src)(srcPath).pipe((0, _gulpBabel.default)()).pipe(_through.default.obj(function (file, enc, callback) {
|
|
24
24
|
const regex = /\.mjs(['"]\s*\))/gi;
|
|
@@ -8,11 +8,11 @@ exports.distForSrc = void 0;
|
|
|
8
8
|
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
9
9
|
var cache;
|
|
10
10
|
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
11
|
-
/**
|
|
12
|
-
* Retrieve the correct distFor search path based on TS Config.
|
|
13
|
-
* @memberOf module:partials
|
|
14
|
-
* @param {module:gulpConfig~FlagStringSetting} [useTs='config/for/ts']
|
|
15
|
-
* @returns {string}
|
|
11
|
+
/**
|
|
12
|
+
* Retrieve the correct distFor search path based on TS Config.
|
|
13
|
+
* @memberOf module:partials
|
|
14
|
+
* @param {module:gulpConfig~FlagStringSetting} [useTs='config/for/ts']
|
|
15
|
+
* @returns {string}
|
|
16
16
|
*/
|
|
17
17
|
const distForSrc = (useTs = gulpConfig.get('typescript.enabled')) => useTs ? gulpConfig.get('browser.from') : gulpConfig.get('dist.from');
|
|
18
18
|
exports.distForSrc = distForSrc;
|
|
@@ -12,13 +12,13 @@ var _gulp = require("gulp");
|
|
|
12
12
|
var _tsFor = require("./tsFor.js");
|
|
13
13
|
var cache;
|
|
14
14
|
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
15
|
-
/**
|
|
16
|
-
* When using TypeScript, ensure that we process the ts first then run babel (dist)
|
|
17
|
-
* @memberOf module:partials
|
|
18
|
-
* @param {string} [srcPath='src/config/path/dist/for']
|
|
19
|
-
* @param {string} [distFinalPath='dist/config/path']
|
|
20
|
-
* @param {string} [tsSearch='ts/search/config/path']
|
|
21
|
-
* @returns {function(null=): stream.Stream}
|
|
15
|
+
/**
|
|
16
|
+
* When using TypeScript, ensure that we process the ts first then run babel (dist)
|
|
17
|
+
* @memberOf module:partials
|
|
18
|
+
* @param {string} [srcPath='src/config/path/dist/for']
|
|
19
|
+
* @param {string} [distFinalPath='dist/config/path']
|
|
20
|
+
* @param {string} [tsSearch='ts/search/config/path']
|
|
21
|
+
* @returns {function(null=): stream.Stream}
|
|
22
22
|
*/
|
|
23
23
|
const distSeries = (srcPath = (0, _distForSrc.distForSrc)(), distFinalPath = gulpConfig.get('dist.to'), tsSearch = gulpConfig.get('typescript.from')) => {
|
|
24
24
|
const typescript = (0, _tsFor.tsFor)(tsSearch, distFinalPath);
|
|
@@ -1,94 +1,156 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.loadImageminPlugins = exports.loadImagemin = exports.imagesFor = exports.imageminPlugins = void 0;
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
*
|
|
60
|
-
* @
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.loadImageminPlugins = exports.loadImagemin = exports.imagesFor = exports.imageminVersions = exports.imageminPlugins = void 0;
|
|
8
|
+
require("core-js/modules/es.json.stringify.js");
|
|
9
|
+
var _fs = require("fs");
|
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
|
11
|
+
var _cacheFiles = require("./cacheFiles.js");
|
|
12
|
+
var _loadPeer = require("./loadPeer.js");
|
|
13
|
+
var _gulp = require("gulp");
|
|
14
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
15
|
+
var cache;
|
|
16
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
17
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
const installHint = 'Add it to your project with: npm install --save-dev github:jheagle/gulp-imagemin#common-js-compatibility ' + '(the CommonJS-compatible fork - upstream gulp-imagemin is ESM-only and cannot be require()d by this package\'s CommonJS build).';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Load `gulp-imagemin`, an optional peer dependency: image optimization is off by default and its binary-download
|
|
22
|
+
* dependency chain is heavy, so it is only required once the images task actually runs, and it is resolved from the
|
|
23
|
+
* consuming project's own directory rather than from this package.
|
|
24
|
+
* @memberOf module:partials
|
|
25
|
+
* @param {string} [projectPath=process.cwd()] - The project directory to resolve `gulp-imagemin` from.
|
|
26
|
+
* @returns {Function} The gulp-imagemin plugin factory.
|
|
27
|
+
* @throws {Error} With install instructions when gulp-imagemin is missing or is the ESM-only upstream release.
|
|
28
|
+
*/
|
|
29
|
+
const loadImagemin = (projectPath = process.cwd()) => {
|
|
30
|
+
const loaded = (0, _loadPeer.requirePeer)('gulp-imagemin', {
|
|
31
|
+
task: 'images',
|
|
32
|
+
installHint,
|
|
33
|
+
esmOnlyMessage: `gulp-imagemin could not be loaded because it is ESM-only. ${installHint}`,
|
|
34
|
+
projectPath
|
|
35
|
+
});
|
|
36
|
+
return loaded && (loaded.__esModule || loaded.default) ? loaded.default : loaded;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Load the plugins `gulp-imagemin` exports by name (gifsicle, mozjpeg, optipng and svgo), each a promise of a plugin
|
|
41
|
+
* factory, for when they need options of their own (see images.jpegQuality). Resolved like {@link loadImagemin}.
|
|
42
|
+
* @memberOf module:partials
|
|
43
|
+
* @param {string} [projectPath=process.cwd()] - The project directory to resolve `gulp-imagemin` from.
|
|
44
|
+
* @returns {Object<string, Promise<Function>>} The plugin factories, by name.
|
|
45
|
+
*/
|
|
46
|
+
exports.loadImagemin = loadImagemin;
|
|
47
|
+
const loadImageminPlugins = (projectPath = process.cwd()) => (0, _loadPeer.requirePeer)('gulp-imagemin', {
|
|
48
|
+
task: 'images',
|
|
49
|
+
installHint,
|
|
50
|
+
esmOnlyMessage: `gulp-imagemin could not be loaded because it is ESM-only. ${installHint}`,
|
|
51
|
+
projectPath
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// The plugins imagemin runs when it isn't given any, in its own order
|
|
55
|
+
exports.loadImageminPlugins = loadImageminPlugins;
|
|
56
|
+
const defaultPluginNames = ['gifsicle', 'mozjpeg', 'optipng', 'svgo'];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The plugins imagemin uses by default, with mozjpeg set to the given JPEG quality instead of its own default (75).
|
|
60
|
+
* @memberOf module:partials
|
|
61
|
+
* @param {number} jpegQuality - The mozjpeg quality, 0 to 100.
|
|
62
|
+
* @param {Object<string, Promise<Function>>} [plugins=loadImageminPlugins()] - The plugin factories, by name.
|
|
63
|
+
* @returns {Array<Promise<Function>>} The plugins, in imagemin's default order.
|
|
64
|
+
*/
|
|
65
|
+
const imageminPlugins = (jpegQuality, plugins = loadImageminPlugins()) => defaultPluginNames.map(name => Promise.resolve(plugins[name]).then(makePlugin => name === 'mozjpeg' ? makePlugin({
|
|
66
|
+
quality: jpegQuality
|
|
67
|
+
}) : makePlugin()));
|
|
68
|
+
|
|
69
|
+
// The packages that decide imagemin's output: the wrapper and imagemin, then each plugin with the engine it runs
|
|
70
|
+
exports.imageminPlugins = imageminPlugins;
|
|
71
|
+
const imageminPackages = [['gulp-imagemin'], ['imagemin'], ['imagemin-gifsicle', 'gifsicle'], ['imagemin-mozjpeg', 'mozjpeg'], ['imagemin-optipng', 'optipng-bin'], ['imagemin-svgo', 'svgo']];
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Find an installed package the way Node does, from a directory up through each node_modules folder. Reads the
|
|
75
|
+
* package.json directly, so it also works for ESM-only packages that don't export it.
|
|
76
|
+
* @private
|
|
77
|
+
* @param {string} name
|
|
78
|
+
* @param {string} fromDirectory
|
|
79
|
+
* @returns {{directory: string, version: string}|undefined}
|
|
80
|
+
*/
|
|
81
|
+
const findPackage = (name, fromDirectory) => {
|
|
82
|
+
for (let directory = _path.default.resolve(fromDirectory);; directory = _path.default.dirname(directory)) {
|
|
83
|
+
const file = _path.default.join(directory, 'node_modules', name, 'package.json');
|
|
84
|
+
if ((0, _fs.existsSync)(file)) {
|
|
85
|
+
return {
|
|
86
|
+
directory: _path.default.dirname(file),
|
|
87
|
+
version: JSON.parse((0, _fs.readFileSync)(file, 'utf8')).version
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (directory === _path.default.dirname(directory)) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The installed versions of the packages that decide imagemin's output, so the image cache stops using results made
|
|
98
|
+
* by older versions after an upgrade (see images.cacheDir).
|
|
99
|
+
* @memberOf module:partials
|
|
100
|
+
* @param {string} [projectPath=process.cwd()] - The project directory gulp-imagemin is installed in.
|
|
101
|
+
* @returns {Object<string, string>} Each package's version by name; a package that isn't installed is left out.
|
|
102
|
+
*/
|
|
103
|
+
const imageminVersions = (projectPath = process.cwd()) => {
|
|
104
|
+
const gulpImagemin = findPackage('gulp-imagemin', projectPath);
|
|
105
|
+
const versions = {};
|
|
106
|
+
if (!gulpImagemin) {
|
|
107
|
+
return versions;
|
|
108
|
+
}
|
|
109
|
+
for (const [wrapper, engine] of imageminPackages) {
|
|
110
|
+
const found = findPackage(wrapper, gulpImagemin.directory);
|
|
111
|
+
if (found) {
|
|
112
|
+
versions[wrapper] = found.version;
|
|
113
|
+
const engineFound = engine && findPackage(engine, found.directory);
|
|
114
|
+
if (engineFound) {
|
|
115
|
+
versions[engine] = engineFound.version;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return versions;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Move and optimize images into the browser directory.
|
|
124
|
+
* @memberOf module:partials
|
|
125
|
+
* @param {string|array} [imageSrc=src/images/pattern]
|
|
126
|
+
* @param {string} [imageDest=dest/image/folder]
|
|
127
|
+
* @return {stream.Stream}
|
|
128
|
+
*/
|
|
129
|
+
exports.imageminVersions = imageminVersions;
|
|
130
|
+
const imagesFor = (imageSrc = gulpConfig.get('images.from'), imageDest = gulpConfig.get('images.to')) => {
|
|
131
|
+
const imagemin = loadImagemin();
|
|
132
|
+
const jpegQuality = gulpConfig.get('images.jpegQuality');
|
|
133
|
+
// Left unset, imagemin runs its default plugins with their own defaults
|
|
134
|
+
const plugins = jpegQuality ? imageminPlugins(jpegQuality) : undefined;
|
|
135
|
+
const options = {
|
|
136
|
+
interlaced: true,
|
|
137
|
+
silent: true,
|
|
138
|
+
verbose: false
|
|
139
|
+
};
|
|
140
|
+
// Gulp 5 reads files as utf8 text unless told otherwise, which corrupts binary images.
|
|
141
|
+
return (0, _gulp.src)(imageSrc, {
|
|
142
|
+
encoding: false
|
|
143
|
+
}).pipe(
|
|
144
|
+
// Only images imagemin hasn't optimized before go through it; the rest come from the cache
|
|
145
|
+
(0, _cacheFiles.cacheFiles)(imagemin(plugins, options), {
|
|
146
|
+
directory: gulpConfig.get('images.cacheDir'),
|
|
147
|
+
// Each quality gets results of its own
|
|
148
|
+
name: jpegQuality ? `jpeg-quality-${jpegQuality}` : 'default',
|
|
149
|
+
// A new imagemin (or plugin, or engine) version, or other options, makes new results
|
|
150
|
+
fingerprint: JSON.stringify({
|
|
151
|
+
options,
|
|
152
|
+
versions: imageminVersions()
|
|
153
|
+
})
|
|
154
|
+
})).pipe((0, _gulp.dest)(imageDest));
|
|
155
|
+
};
|
|
94
156
|
exports.imagesFor = imagesFor;
|