js-build-tools 2.4.0 → 3.0.1
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/README.md +334 -205
- package/dist/build.js +59 -48
- package/dist/build.min.js +1 -1
- package/dist/bundle.js +12 -13
- package/dist/bundle.min.js +1 -1
- package/dist/bundleLint.js +17 -18
- package/dist/bundleLint.min.js +1 -1
- package/dist/bundleMinify.js +8 -9
- package/dist/bundleMinify.min.js +1 -1
- package/dist/copyFonts.js +12 -0
- package/dist/copyFonts.min.js +1 -0
- package/dist/default.js +1 -1
- package/dist/default.min.js +1 -1
- package/dist/dist.js +7 -8
- package/dist/distLint.js +17 -18
- package/dist/distLint.min.js +1 -1
- package/dist/distMinify.js +8 -9
- package/dist/distMinify.min.js +1 -1
- package/dist/images.js +11 -0
- package/dist/images.min.js +1 -0
- package/dist/partials/addToReadme.js +13 -14
- package/dist/partials/beginWatcher.js +9 -10
- package/dist/partials/clean.js +10 -11
- package/dist/partials/copyFor.js +16 -0
- package/dist/partials/distFor.js +16 -17
- package/dist/partials/distForSrc.js +9 -10
- package/dist/partials/distSeries.js +19 -20
- package/dist/partials/imagesFor.js +34 -0
- package/dist/partials/minifyFor.js +15 -16
- package/dist/partials/readmeTemplate.js +11 -12
- package/dist/partials/removeDirectory.js +11 -12
- package/dist/partials/runOnChange.js +27 -27
- package/dist/partials/sassFor.js +20 -21
- package/dist/partials/tsFor.js +20 -21
- package/dist/partials.js +35 -31
- package/dist/partials.min.js +1 -1
- package/dist/test-helpers/setUp.js +52 -60
- package/dist/testFull.js +17 -18
- package/dist/testFull.min.js +1 -1
- package/dist/testHelpers.js +10 -28
- package/dist/testHelpers.min.js +1 -1
- package/dist/testQuick.js +19 -20
- package/dist/testQuick.min.js +1 -1
- package/dist/typeScript.js +7 -8
- package/dist/utilities/dotGet.js +50 -0
- package/dist/utilities/dotNotate.js +77 -0
- package/dist/utilities/dotSet.js +44 -0
- package/dist/utilities/isObject.js +10 -0
- package/dist/utilities/strAfter.js +14 -0
- package/dist/utilities/strBefore.js +14 -0
- package/dist/watchFull.js +10 -11
- package/dist/watchTest.js +13 -14
- package/dist/watchTest.min.js +1 -1
- package/functions/build.js +15 -5
- package/functions/build.test.js +278 -42
- package/functions/bundle.js +3 -4
- package/functions/bundle.test.js +6 -6
- package/functions/bundleLint.js +2 -3
- package/functions/bundleLint.test.js +5 -5
- package/functions/bundleMinify.js +1 -2
- package/functions/bundleMinify.test.js +1 -1
- package/functions/copyFonts.js +11 -0
- package/functions/copyFonts.test.js +31 -0
- package/functions/default.js +1 -1
- package/functions/default.test.js +2 -2
- package/functions/dist.js +0 -1
- package/functions/dist.test.js +1 -1
- package/functions/distLint.js +2 -3
- package/functions/distLint.test.js +3 -3
- package/functions/distMinify.js +1 -2
- package/functions/distMinify.test.js +1 -1
- package/functions/images.js +10 -0
- package/functions/images.test.js +138 -0
- package/functions/partials/addToReadme.js +2 -3
- package/functions/partials/addToReadme.test.js +2 -2
- package/functions/partials/beginWatcher.js +1 -2
- package/functions/partials/beginWatcher.test.js +1 -1
- package/functions/partials/clean.js +0 -1
- package/functions/partials/copyFor.js +13 -0
- package/functions/partials/copyFor.test.js +34 -0
- package/functions/partials/distFor.js +1 -2
- package/functions/partials/distFor.test.js +4 -4
- package/functions/partials/distForSrc.js +3 -4
- package/functions/partials/distForSrc.test.js +6 -6
- package/functions/partials/distSeries.js +2 -3
- package/functions/partials/distSeries.test.js +5 -5
- package/functions/partials/imagesFor.js +33 -0
- package/functions/partials/imagesFor.test.js +143 -0
- package/functions/partials/minifyFor.js +0 -1
- package/functions/partials/minifyFor.test.js +1 -1
- package/functions/partials/readmeTemplate.js +3 -4
- package/functions/partials/readmeTemplate.test.js +2 -2
- package/functions/partials/removeDirectory.js +0 -1
- package/functions/partials/runOnChange.js +5 -6
- package/functions/partials/runOnChange.test.js +9 -9
- package/functions/partials/sassFor.js +1 -2
- package/functions/partials/sassFor.test.js +3 -3
- package/functions/partials/tsFor.js +3 -4
- package/functions/partials/tsFor.test.js +2 -2
- package/functions/partials.js +5 -1
- package/functions/partials.test.js +1 -1
- package/functions/sass.test.js +2 -2
- package/functions/test-helpers/setUp.js +24 -32
- package/functions/testFull.js +2 -3
- package/functions/testFull.test.js +1 -1
- package/functions/testHelpers.js +3 -20
- package/functions/testHelpers.test.js +1 -1
- package/functions/testQuick.js +1 -2
- package/functions/testQuick.test.js +1 -1
- package/functions/typeScript.js +0 -1
- package/functions/typeScript.test.js +0 -2
- package/functions/utilities/dotGet.js +47 -0
- package/functions/utilities/dotNotate.js +68 -0
- package/functions/utilities/dotSet.js +41 -0
- package/functions/utilities/isObject.js +9 -0
- package/functions/utilities/strAfter.js +13 -0
- package/functions/utilities/strBefore.js +13 -0
- package/functions/watchFull.js +0 -1
- package/functions/watchFull.test.js +1 -1
- package/functions/watchTest.js +1 -2
- package/functions/watchTest.test.js +1 -1
- package/gulp.config.js +153 -79
- package/gulpfile.base.js +5 -1
- package/jsdoc.base.js +1 -1
- package/package.json +13 -9
- package/vendor/array-union/index.js +31 -0
- package/vendor/easy-transform-stream/index.js +54 -0
- package/vendor/globby/gitignore.js +96 -0
- package/vendor/globby/index.js +191 -0
- package/vendor/globby/node_modules/slash/index.js +16 -0
- package/vendor/globby/stream-utils.js +58 -0
- package/vendor/globby/to-path.js +20 -0
- package/vendor/gulp-imagemin/index.js +128 -0
- package/vendor/gulp-imagemin/node_modules/chalk/source/index.js +265 -0
- package/vendor/gulp-imagemin/node_modules/chalk/source/utilities.js +36 -0
- package/vendor/gulp-imagemin/node_modules/chalk/source/vendor/ansi-styles/index.js +217 -0
- package/vendor/gulp-imagemin/node_modules/chalk/source/vendor/supports-color/index.js +154 -0
- package/vendor/gulp-plugin-extras/index.js +42 -0
- package/vendor/gulp-plugin-extras/node_modules/chalk/source/index.js +265 -0
- package/vendor/gulp-plugin-extras/node_modules/chalk/source/utilities.js +36 -0
- package/vendor/gulp-plugin-extras/node_modules/chalk/source/vendor/ansi-styles/index.js +217 -0
- package/vendor/gulp-plugin-extras/node_modules/chalk/source/vendor/supports-color/index.js +154 -0
- package/vendor/gulp-plugin-extras/plugin-error.js +145 -0
- package/vendor/ignore/index.js +468 -0
- package/vendor/imagemin/index.js +90 -0
- package/vendor/imagemin-gifsicle/index.js +33 -0
- package/vendor/imagemin-mozjpeg/index.js +100 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/index.js +260 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/lib/command.js +47 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/lib/error.js +102 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/lib/kill.js +123 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/lib/promise.js +47 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/lib/stdio.js +50 -0
- package/vendor/imagemin-mozjpeg/node_modules/execa/lib/stream.js +124 -0
- package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/core.js +238 -0
- package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/main.js +89 -0
- package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/realtime.js +24 -0
- package/vendor/imagemin-mozjpeg/node_modules/human-signals/build/src/signals.js +44 -0
- package/vendor/imagemin-mozjpeg/node_modules/is-stream/index.js +25 -0
- package/vendor/imagemin-mozjpeg/node_modules/mimic-fn/index.js +70 -0
- package/vendor/imagemin-mozjpeg/node_modules/npm-run-path/index.js +52 -0
- package/vendor/imagemin-mozjpeg/node_modules/onetime/index.js +43 -0
- package/vendor/imagemin-mozjpeg/node_modules/path-key/index.js +20 -0
- package/vendor/imagemin-mozjpeg/node_modules/strip-final-newline/index.js +17 -0
- package/vendor/imagemin-optipng/index.js +44 -0
- package/vendor/imagemin-svgo/index.js +27 -0
- package/vendor/is-jpg/index.js +12 -0
- package/vendor/junk/index.js +49 -0
- package/vendor/mozjpeg/index.js +9 -0
- package/vendor/mozjpeg/lib/index.js +18 -0
- package/vendor/mozjpeg/package.json +49 -0
- package/vendor/mozjpeg/vendor/cjpeg +0 -0
- package/vendor/mozjpeg/vendor/source/mozjpeg.tar.gz +0 -0
- package/vendor/p-pipe/index.js +22 -0
- package/vendor/plur/index.js +32 -0
- package/vendor/pretty-bytes/index.js +71 -0
- package/vendor/slash/index.js +12 -0
- package/dist/test-helpers/circularObject.js +0 -50
- package/dist/test-helpers/countMatches.js +0 -12
- package/dist/test-helpers/deepReferenceObject.js +0 -20
- package/dist/test-helpers/domItem.js +0 -33
- package/dist/test-helpers/jsonDom.js +0 -20
- package/dist/test-helpers/linkedList.js +0 -23
- package/dist/test-helpers/logObject.js +0 -21
- package/dist/test-helpers/multiReferenceObject.js +0 -20
- package/dist/test-helpers/nodeTree.js +0 -28
- package/functions/test-helpers/circularObject.js +0 -28
- package/functions/test-helpers/circularObject.test.js +0 -14
- package/functions/test-helpers/countMatches.js +0 -11
- package/functions/test-helpers/countMatches.test.js +0 -9
- package/functions/test-helpers/deepReferenceObject.js +0 -25
- package/functions/test-helpers/deepReferenceObject.test.js +0 -7
- package/functions/test-helpers/domItem.js +0 -31
- package/functions/test-helpers/domItem.test.js +0 -12
- package/functions/test-helpers/jsonDom.js +0 -16
- package/functions/test-helpers/jsonDom.test.js +0 -12
- package/functions/test-helpers/linkedList.js +0 -10
- package/functions/test-helpers/linkedList.test.js +0 -22
- package/functions/test-helpers/logObject.js +0 -18
- package/functions/test-helpers/logObject.test.js +0 -20
- package/functions/test-helpers/multiReferenceObject.js +0 -25
- package/functions/test-helpers/multiReferenceObject.test.js +0 -14
- package/functions/test-helpers/nodeTree.js +0 -11
- package/functions/test-helpers/nodeTree.test.js +0 -18
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
require("core-js/modules/es.array.unscopables.flat.js");
|
|
8
|
+
require("core-js/modules/esnext.set.add-all.js");
|
|
9
|
+
require("core-js/modules/esnext.set.delete-all.js");
|
|
10
|
+
require("core-js/modules/esnext.set.difference.js");
|
|
11
|
+
require("core-js/modules/esnext.set.every.js");
|
|
12
|
+
require("core-js/modules/esnext.set.filter.js");
|
|
13
|
+
require("core-js/modules/esnext.set.find.js");
|
|
14
|
+
require("core-js/modules/esnext.set.intersection.js");
|
|
15
|
+
require("core-js/modules/esnext.set.is-disjoint-from.js");
|
|
16
|
+
require("core-js/modules/esnext.set.is-subset-of.js");
|
|
17
|
+
require("core-js/modules/esnext.set.is-superset-of.js");
|
|
18
|
+
require("core-js/modules/esnext.set.join.js");
|
|
19
|
+
require("core-js/modules/esnext.set.map.js");
|
|
20
|
+
require("core-js/modules/esnext.set.reduce.js");
|
|
21
|
+
require("core-js/modules/esnext.set.some.js");
|
|
22
|
+
require("core-js/modules/esnext.set.symmetric-difference.js");
|
|
23
|
+
require("core-js/modules/esnext.set.union.js");
|
|
24
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
25
|
+
const arrayUnion = function () {
|
|
26
|
+
for (var _len = arguments.length, arguments_ = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
27
|
+
arguments_[_key] = arguments[_key];
|
|
28
|
+
}
|
|
29
|
+
return [...new Set(arguments_.flat())];
|
|
30
|
+
};
|
|
31
|
+
var _default = exports.default = arrayUnion;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transformStream;
|
|
7
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
8
|
+
var _nodeStream = require("node:stream");
|
|
9
|
+
function transformStream() {
|
|
10
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
11
|
+
let transformer = arguments.length > 1 ? arguments[1] : undefined;
|
|
12
|
+
let flusher = arguments.length > 2 ? arguments[2] : undefined;
|
|
13
|
+
if (typeof options === 'function') {
|
|
14
|
+
flusher = transformer;
|
|
15
|
+
transformer = options;
|
|
16
|
+
}
|
|
17
|
+
return new _nodeStream.Transform({
|
|
18
|
+
...options,
|
|
19
|
+
transform(chunk, encoding, callback) {
|
|
20
|
+
(async () => {
|
|
21
|
+
try {
|
|
22
|
+
const value = await transformer(chunk, encoding, this);
|
|
23
|
+
|
|
24
|
+
// If the callback throws, we don't want to cause an infinite recursion.
|
|
25
|
+
try {
|
|
26
|
+
callback(undefined, value);
|
|
27
|
+
} catch {}
|
|
28
|
+
} catch (error) {
|
|
29
|
+
callback(error);
|
|
30
|
+
}
|
|
31
|
+
})();
|
|
32
|
+
},
|
|
33
|
+
flush(callback) {
|
|
34
|
+
if (typeof flusher !== 'function') {
|
|
35
|
+
callback();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
(async () => {
|
|
39
|
+
try {
|
|
40
|
+
for await (const chunk of flusher(this)) {
|
|
41
|
+
this.push(chunk);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// If the callback throws, we don't want to cause an infinite recursion.
|
|
45
|
+
try {
|
|
46
|
+
callback();
|
|
47
|
+
} catch {}
|
|
48
|
+
} catch (error) {
|
|
49
|
+
callback(error);
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isGitIgnoredSync = exports.isGitIgnored = void 0;
|
|
7
|
+
require("core-js/modules/esnext.async-iterator.filter.js");
|
|
8
|
+
require("core-js/modules/esnext.async-iterator.map.js");
|
|
9
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
10
|
+
require("core-js/modules/esnext.iterator.filter.js");
|
|
11
|
+
require("core-js/modules/esnext.iterator.map.js");
|
|
12
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
13
|
+
var _nodeProcess = _interopRequireDefault(require("node:process"));
|
|
14
|
+
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
15
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
16
|
+
var _fastGlob = _interopRequireDefault(require("fast-glob"));
|
|
17
|
+
var _index = _interopRequireDefault(require("../ignore/index.js"));
|
|
18
|
+
var _index2 = _interopRequireDefault(require("./node_modules/slash/index.js"));
|
|
19
|
+
var _toPath = _interopRequireDefault(require("./to-path.js"));
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
const DEFAULT_IGNORE = ['**/node_modules/**', '**/flow-typed/**', '**/coverage/**', '**/.git'];
|
|
22
|
+
const mapGitIgnorePatternTo = base => ignore => {
|
|
23
|
+
if (ignore.startsWith('!')) {
|
|
24
|
+
return '!' + _nodePath.default.posix.join(base, ignore.slice(1));
|
|
25
|
+
}
|
|
26
|
+
return _nodePath.default.posix.join(base, ignore);
|
|
27
|
+
};
|
|
28
|
+
const parseGitIgnore = (content, options) => {
|
|
29
|
+
const base = (0, _index2.default)(_nodePath.default.relative(options.cwd, _nodePath.default.dirname(options.fileName)));
|
|
30
|
+
return content.split(/\r?\n/).filter(Boolean).filter(line => !line.startsWith('#')).map(mapGitIgnorePatternTo(base));
|
|
31
|
+
};
|
|
32
|
+
const reduceIgnore = files => {
|
|
33
|
+
const ignores = (0, _index.default)();
|
|
34
|
+
for (const file of files) {
|
|
35
|
+
ignores.add(parseGitIgnore(file.content, {
|
|
36
|
+
cwd: file.cwd,
|
|
37
|
+
fileName: file.filePath
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
return ignores;
|
|
41
|
+
};
|
|
42
|
+
const ensureAbsolutePathForCwd = (cwd, p) => {
|
|
43
|
+
cwd = (0, _index2.default)(cwd);
|
|
44
|
+
if (_nodePath.default.isAbsolute(p)) {
|
|
45
|
+
if ((0, _index2.default)(p).startsWith(cwd)) {
|
|
46
|
+
return p;
|
|
47
|
+
}
|
|
48
|
+
throw new Error("Path ".concat(p, " is not in cwd ").concat(cwd));
|
|
49
|
+
}
|
|
50
|
+
return _nodePath.default.join(cwd, p);
|
|
51
|
+
};
|
|
52
|
+
const getIsIgnoredPredicate = (ignores, cwd) => p => ignores.ignores((0, _index2.default)(_nodePath.default.relative(cwd, ensureAbsolutePathForCwd(cwd, (0, _toPath.default)(p.path || p)))));
|
|
53
|
+
const getFile = async (file, cwd) => {
|
|
54
|
+
const filePath = _nodePath.default.join(cwd, file);
|
|
55
|
+
const content = await _nodeFs.default.promises.readFile(filePath, 'utf8');
|
|
56
|
+
return {
|
|
57
|
+
cwd,
|
|
58
|
+
filePath,
|
|
59
|
+
content
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
const getFileSync = (file, cwd) => {
|
|
63
|
+
const filePath = _nodePath.default.join(cwd, file);
|
|
64
|
+
const content = _nodeFs.default.readFileSync(filePath, 'utf8');
|
|
65
|
+
return {
|
|
66
|
+
cwd,
|
|
67
|
+
filePath,
|
|
68
|
+
content
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
const normalizeOptions = function () {
|
|
72
|
+
let {
|
|
73
|
+
ignore = [],
|
|
74
|
+
cwd = (0, _index2.default)(_nodeProcess.default.cwd())
|
|
75
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
76
|
+
return {
|
|
77
|
+
ignore: [...DEFAULT_IGNORE, ...ignore],
|
|
78
|
+
cwd: (0, _toPath.default)(cwd)
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
const isGitIgnored = async options => {
|
|
82
|
+
options = normalizeOptions(options);
|
|
83
|
+
const paths = await (0, _fastGlob.default)('**/.gitignore', options);
|
|
84
|
+
const files = await Promise.all(paths.map(file => getFile(file, options.cwd)));
|
|
85
|
+
const ignores = reduceIgnore(files);
|
|
86
|
+
return getIsIgnoredPredicate(ignores, options.cwd);
|
|
87
|
+
};
|
|
88
|
+
exports.isGitIgnored = isGitIgnored;
|
|
89
|
+
const isGitIgnoredSync = options => {
|
|
90
|
+
options = normalizeOptions(options);
|
|
91
|
+
const paths = _fastGlob.default.sync('**/.gitignore', options);
|
|
92
|
+
const files = paths.map(file => getFileSync(file, options.cwd));
|
|
93
|
+
const ignores = reduceIgnore(files);
|
|
94
|
+
return getIsIgnoredPredicate(ignores, options.cwd);
|
|
95
|
+
};
|
|
96
|
+
exports.isGitIgnoredSync = isGitIgnoredSync;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isDynamicPattern = exports.globbySync = exports.globbyStream = exports.globby = exports.generateGlobTasks = void 0;
|
|
7
|
+
Object.defineProperty(exports, "isGitIgnored", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _gitignore.isGitIgnored;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "isGitIgnoredSync", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () {
|
|
16
|
+
return _gitignore.isGitIgnoredSync;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
require("core-js/modules/es.array.unscopables.flat.js");
|
|
20
|
+
require("core-js/modules/esnext.async-iterator.every.js");
|
|
21
|
+
require("core-js/modules/esnext.async-iterator.filter.js");
|
|
22
|
+
require("core-js/modules/esnext.async-iterator.map.js");
|
|
23
|
+
require("core-js/modules/esnext.async-iterator.some.js");
|
|
24
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
25
|
+
require("core-js/modules/esnext.iterator.every.js");
|
|
26
|
+
require("core-js/modules/esnext.iterator.filter.js");
|
|
27
|
+
require("core-js/modules/esnext.iterator.map.js");
|
|
28
|
+
require("core-js/modules/esnext.iterator.some.js");
|
|
29
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
30
|
+
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
31
|
+
var _index = _interopRequireDefault(require("../array-union/index.js"));
|
|
32
|
+
var _merge = _interopRequireDefault(require("merge2"));
|
|
33
|
+
var _fastGlob = _interopRequireDefault(require("fast-glob"));
|
|
34
|
+
var _dirGlob = _interopRequireDefault(require("dir-glob"));
|
|
35
|
+
var _toPath = _interopRequireDefault(require("./to-path.js"));
|
|
36
|
+
var _gitignore = require("./gitignore.js");
|
|
37
|
+
var _streamUtils = require("./stream-utils.js");
|
|
38
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
39
|
+
const DEFAULT_FILTER = () => false;
|
|
40
|
+
const isNegative = pattern => pattern[0] === '!';
|
|
41
|
+
const assertPatternsInput = patterns => {
|
|
42
|
+
if (!patterns.every(pattern => typeof pattern === 'string')) {
|
|
43
|
+
throw new TypeError('Patterns must be a string or an array of strings');
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const checkCwdOption = options => {
|
|
47
|
+
if (!options.cwd) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
let stat;
|
|
51
|
+
try {
|
|
52
|
+
stat = _nodeFs.default.statSync(options.cwd);
|
|
53
|
+
} catch {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!stat.isDirectory()) {
|
|
57
|
+
throw new Error('The `cwd` option must be a path to a directory');
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const getPathString = p => p.stats instanceof _nodeFs.default.Stats ? p.path : p;
|
|
61
|
+
const generateGlobTasks = function (patterns) {
|
|
62
|
+
let taskOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
63
|
+
patterns = (0, _index.default)([patterns].flat());
|
|
64
|
+
assertPatternsInput(patterns);
|
|
65
|
+
const globTasks = [];
|
|
66
|
+
taskOptions = {
|
|
67
|
+
ignore: [],
|
|
68
|
+
expandDirectories: true,
|
|
69
|
+
...taskOptions,
|
|
70
|
+
cwd: (0, _toPath.default)(taskOptions.cwd)
|
|
71
|
+
};
|
|
72
|
+
checkCwdOption(taskOptions);
|
|
73
|
+
for (const [index, pattern] of patterns.entries()) {
|
|
74
|
+
if (isNegative(pattern)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const ignore = patterns.slice(index).filter(pattern => isNegative(pattern)).map(pattern => pattern.slice(1));
|
|
78
|
+
const options = {
|
|
79
|
+
...taskOptions,
|
|
80
|
+
ignore: [...taskOptions.ignore, ...ignore]
|
|
81
|
+
};
|
|
82
|
+
globTasks.push({
|
|
83
|
+
pattern,
|
|
84
|
+
options
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return globTasks;
|
|
88
|
+
};
|
|
89
|
+
exports.generateGlobTasks = generateGlobTasks;
|
|
90
|
+
const globDirectories = (task, fn) => {
|
|
91
|
+
let options = {};
|
|
92
|
+
if (task.options.cwd) {
|
|
93
|
+
options.cwd = task.options.cwd;
|
|
94
|
+
}
|
|
95
|
+
if (Array.isArray(task.options.expandDirectories)) {
|
|
96
|
+
options = {
|
|
97
|
+
...options,
|
|
98
|
+
files: task.options.expandDirectories
|
|
99
|
+
};
|
|
100
|
+
} else if (typeof task.options.expandDirectories === 'object') {
|
|
101
|
+
options = {
|
|
102
|
+
...options,
|
|
103
|
+
...task.options.expandDirectories
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return fn(task.pattern, options);
|
|
107
|
+
};
|
|
108
|
+
const getPattern = (task, fn) => task.options.expandDirectories ? globDirectories(task, fn) : [task.pattern];
|
|
109
|
+
const getFilterSync = options => options && options.gitignore ? (0, _gitignore.isGitIgnoredSync)({
|
|
110
|
+
cwd: options.cwd,
|
|
111
|
+
ignore: options.ignore
|
|
112
|
+
}) : DEFAULT_FILTER;
|
|
113
|
+
const globToTask = task => async glob => {
|
|
114
|
+
const {
|
|
115
|
+
options
|
|
116
|
+
} = task;
|
|
117
|
+
if (options.ignore && Array.isArray(options.ignore) && options.expandDirectories) {
|
|
118
|
+
options.ignore = await (0, _dirGlob.default)(options.ignore);
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
pattern: glob,
|
|
122
|
+
options
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
const globToTaskSync = task => glob => {
|
|
126
|
+
const {
|
|
127
|
+
options
|
|
128
|
+
} = task;
|
|
129
|
+
if (options.ignore && Array.isArray(options.ignore) && options.expandDirectories) {
|
|
130
|
+
options.ignore = _dirGlob.default.sync(options.ignore);
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
pattern: glob,
|
|
134
|
+
options
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
const globby = async (patterns, options) => {
|
|
138
|
+
const globTasks = generateGlobTasks(patterns, options);
|
|
139
|
+
const getFilter = async () => options && options.gitignore ? (0, _gitignore.isGitIgnored)({
|
|
140
|
+
cwd: options.cwd,
|
|
141
|
+
ignore: options.ignore
|
|
142
|
+
}) : DEFAULT_FILTER;
|
|
143
|
+
const getTasks = async () => {
|
|
144
|
+
const tasks = await Promise.all(globTasks.map(async task => {
|
|
145
|
+
const globs = await getPattern(task, _dirGlob.default);
|
|
146
|
+
return Promise.all(globs.map(globToTask(task)));
|
|
147
|
+
}));
|
|
148
|
+
return (0, _index.default)(...tasks);
|
|
149
|
+
};
|
|
150
|
+
const [filter, tasks] = await Promise.all([getFilter(), getTasks()]);
|
|
151
|
+
const paths = await Promise.all(tasks.map(task => (0, _fastGlob.default)(task.pattern, task.options)));
|
|
152
|
+
return (0, _index.default)(...paths).filter(path_ => !filter(getPathString(path_)));
|
|
153
|
+
};
|
|
154
|
+
exports.globby = globby;
|
|
155
|
+
const globbySync = (patterns, options) => {
|
|
156
|
+
const globTasks = generateGlobTasks(patterns, options);
|
|
157
|
+
const tasks = [];
|
|
158
|
+
for (const task of globTasks) {
|
|
159
|
+
const newTask = getPattern(task, _dirGlob.default.sync).map(globToTaskSync(task));
|
|
160
|
+
tasks.push(...newTask);
|
|
161
|
+
}
|
|
162
|
+
const filter = getFilterSync(options);
|
|
163
|
+
let matches = [];
|
|
164
|
+
for (const task of tasks) {
|
|
165
|
+
matches = (0, _index.default)(matches, _fastGlob.default.sync(task.pattern, task.options));
|
|
166
|
+
}
|
|
167
|
+
return matches.filter(path_ => !filter(path_));
|
|
168
|
+
};
|
|
169
|
+
exports.globbySync = globbySync;
|
|
170
|
+
const globbyStream = (patterns, options) => {
|
|
171
|
+
const globTasks = generateGlobTasks(patterns, options);
|
|
172
|
+
const tasks = [];
|
|
173
|
+
for (const task of globTasks) {
|
|
174
|
+
const newTask = getPattern(task, _dirGlob.default.sync).map(globToTaskSync(task));
|
|
175
|
+
tasks.push(...newTask);
|
|
176
|
+
}
|
|
177
|
+
const filter = getFilterSync(options);
|
|
178
|
+
const filterStream = new _streamUtils.FilterStream(p => !filter(p));
|
|
179
|
+
const uniqueStream = new _streamUtils.UniqueStream();
|
|
180
|
+
return (0, _merge.default)(tasks.map(task => _fastGlob.default.stream(task.pattern, task.options))).pipe(filterStream).pipe(uniqueStream);
|
|
181
|
+
};
|
|
182
|
+
exports.globbyStream = globbyStream;
|
|
183
|
+
const isDynamicPattern = function (patterns) {
|
|
184
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
185
|
+
options = {
|
|
186
|
+
...options,
|
|
187
|
+
cwd: (0, _toPath.default)(options.cwd)
|
|
188
|
+
};
|
|
189
|
+
return [patterns].flat().some(pattern => _fastGlob.default.isDynamicPattern(pattern, options));
|
|
190
|
+
};
|
|
191
|
+
exports.isDynamicPattern = isDynamicPattern;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = slash;
|
|
7
|
+
require("core-js/modules/es.string.replace.js");
|
|
8
|
+
function slash(path) {
|
|
9
|
+
const isExtendedLengthPath = /^\\\\\?\\/.test(path);
|
|
10
|
+
const hasNonAscii = /[^\u0000-\u0080]+/.test(path); // eslint-disable-line no-control-regex
|
|
11
|
+
|
|
12
|
+
if (isExtendedLengthPath || hasNonAscii) {
|
|
13
|
+
return path;
|
|
14
|
+
}
|
|
15
|
+
return path.replace(/\\/g, '/');
|
|
16
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.UniqueStream = exports.FilterStream = void 0;
|
|
7
|
+
require("core-js/modules/esnext.set.add-all.js");
|
|
8
|
+
require("core-js/modules/esnext.set.delete-all.js");
|
|
9
|
+
require("core-js/modules/esnext.set.difference.js");
|
|
10
|
+
require("core-js/modules/esnext.set.every.js");
|
|
11
|
+
require("core-js/modules/esnext.set.filter.js");
|
|
12
|
+
require("core-js/modules/esnext.set.find.js");
|
|
13
|
+
require("core-js/modules/esnext.set.intersection.js");
|
|
14
|
+
require("core-js/modules/esnext.set.is-disjoint-from.js");
|
|
15
|
+
require("core-js/modules/esnext.set.is-subset-of.js");
|
|
16
|
+
require("core-js/modules/esnext.set.is-superset-of.js");
|
|
17
|
+
require("core-js/modules/esnext.set.join.js");
|
|
18
|
+
require("core-js/modules/esnext.set.map.js");
|
|
19
|
+
require("core-js/modules/esnext.set.reduce.js");
|
|
20
|
+
require("core-js/modules/esnext.set.some.js");
|
|
21
|
+
require("core-js/modules/esnext.set.symmetric-difference.js");
|
|
22
|
+
require("core-js/modules/esnext.set.union.js");
|
|
23
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
24
|
+
var _nodeStream = require("node:stream");
|
|
25
|
+
class ObjectTransform extends _nodeStream.Transform {
|
|
26
|
+
constructor() {
|
|
27
|
+
super({
|
|
28
|
+
objectMode: true
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
class FilterStream extends ObjectTransform {
|
|
33
|
+
constructor(filter) {
|
|
34
|
+
super();
|
|
35
|
+
this._filter = filter;
|
|
36
|
+
}
|
|
37
|
+
_transform(data, encoding, callback) {
|
|
38
|
+
if (this._filter(data)) {
|
|
39
|
+
this.push(data);
|
|
40
|
+
}
|
|
41
|
+
callback();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.FilterStream = FilterStream;
|
|
45
|
+
class UniqueStream extends ObjectTransform {
|
|
46
|
+
constructor() {
|
|
47
|
+
super();
|
|
48
|
+
this._pushed = new Set();
|
|
49
|
+
}
|
|
50
|
+
_transform(data, encoding, callback) {
|
|
51
|
+
if (!this._pushed.has(data)) {
|
|
52
|
+
this.push(data);
|
|
53
|
+
this._pushed.add(data);
|
|
54
|
+
}
|
|
55
|
+
callback();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.UniqueStream = UniqueStream;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
8
|
+
require("core-js/modules/web.url.js");
|
|
9
|
+
require("core-js/modules/web.url-search-params.js");
|
|
10
|
+
var _nodeUrl = require("node:url");
|
|
11
|
+
const toPath = urlOrPath => {
|
|
12
|
+
if (!urlOrPath) {
|
|
13
|
+
return urlOrPath;
|
|
14
|
+
}
|
|
15
|
+
if (urlOrPath instanceof URL) {
|
|
16
|
+
urlOrPath = urlOrPath.href;
|
|
17
|
+
}
|
|
18
|
+
return urlOrPath.startsWith('file://') ? (0, _nodeUrl.fileURLToPath)(urlOrPath) : urlOrPath;
|
|
19
|
+
};
|
|
20
|
+
var _default = exports.default = toPath;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
async function exportGulpImagemin () {
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = gulpImagemin;
|
|
8
|
+
exports.svgo = exports.optipng = exports.mozjpeg = exports.gifsicle = void 0;
|
|
9
|
+
require("core-js/modules/es.array.unscopables.flat-map.js");
|
|
10
|
+
require("core-js/modules/es.string.replace.js");
|
|
11
|
+
require("core-js/modules/esnext.set.add-all.js");
|
|
12
|
+
require("core-js/modules/esnext.set.delete-all.js");
|
|
13
|
+
require("core-js/modules/esnext.set.difference.js");
|
|
14
|
+
require("core-js/modules/esnext.set.every.js");
|
|
15
|
+
require("core-js/modules/esnext.set.filter.js");
|
|
16
|
+
require("core-js/modules/esnext.set.find.js");
|
|
17
|
+
require("core-js/modules/esnext.set.intersection.js");
|
|
18
|
+
require("core-js/modules/esnext.set.is-disjoint-from.js");
|
|
19
|
+
require("core-js/modules/esnext.set.is-subset-of.js");
|
|
20
|
+
require("core-js/modules/esnext.set.is-superset-of.js");
|
|
21
|
+
require("core-js/modules/esnext.set.join.js");
|
|
22
|
+
require("core-js/modules/esnext.set.map.js");
|
|
23
|
+
require("core-js/modules/esnext.set.reduce.js");
|
|
24
|
+
require("core-js/modules/esnext.set.some.js");
|
|
25
|
+
require("core-js/modules/esnext.set.symmetric-difference.js");
|
|
26
|
+
require("core-js/modules/esnext.set.union.js");
|
|
27
|
+
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
28
|
+
require("core-js/modules/web.dom-collections.iterator.js");
|
|
29
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
30
|
+
var _nodeProcess = _interopRequireDefault(require("node:process"));
|
|
31
|
+
var _index = _interopRequireDefault(require("../pretty-bytes/index.js"));
|
|
32
|
+
var _index2 = _interopRequireDefault(require("./node_modules/chalk/source/index.js"));
|
|
33
|
+
var _index3 = _interopRequireDefault(require("../imagemin/index.js"));
|
|
34
|
+
var _index4 = _interopRequireDefault(require("../plur/index.js"));
|
|
35
|
+
var _index5 = require("../gulp-plugin-extras/index.js");
|
|
36
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
38
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
39
|
+
const PLUGIN_NAME = 'gulp-imagemin';
|
|
40
|
+
const defaultPlugins = ['gifsicle', 'mozjpeg', 'optipng', 'svgo'];
|
|
41
|
+
const loadPlugin = async function (pluginName) {
|
|
42
|
+
try {
|
|
43
|
+
const {
|
|
44
|
+
default: plugin
|
|
45
|
+
} = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))("../imagemin-".concat(pluginName, "/index.js"));
|
|
46
|
+
for (var _len = arguments.length, arguments_ = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
47
|
+
arguments_[_key - 1] = arguments[_key];
|
|
48
|
+
}
|
|
49
|
+
return plugin(...arguments_);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.log('er', error);
|
|
52
|
+
console.log("".concat(PLUGIN_NAME, ": Could not load default plugin `").concat(pluginName, "`"));
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const exposePlugin = async plugin => function () {
|
|
56
|
+
for (var _len2 = arguments.length, arguments_ = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
57
|
+
arguments_[_key2] = arguments[_key2];
|
|
58
|
+
}
|
|
59
|
+
return loadPlugin(plugin, ...arguments_);
|
|
60
|
+
};
|
|
61
|
+
const getDefaultPlugins = async () => Promise.all(defaultPlugins.flatMap(plugin => loadPlugin(plugin)));
|
|
62
|
+
function gulpImagemin(plugins, options) {
|
|
63
|
+
if (typeof plugins === 'object' && !Array.isArray(plugins)) {
|
|
64
|
+
options = plugins;
|
|
65
|
+
plugins = undefined;
|
|
66
|
+
}
|
|
67
|
+
options = {
|
|
68
|
+
// TODO: Remove this when Gulp gets a real logger with levels
|
|
69
|
+
silent: _nodeProcess.default.argv.includes('--silent'),
|
|
70
|
+
verbose: _nodeProcess.default.argv.includes('--verbose'),
|
|
71
|
+
...options
|
|
72
|
+
};
|
|
73
|
+
const validExtensions = new Set(['.jpg', '.jpeg', '.png', '.gif', '.svg']);
|
|
74
|
+
let totalBytes = 0;
|
|
75
|
+
let totalSavedBytes = 0;
|
|
76
|
+
let totalFiles = 0;
|
|
77
|
+
return (0, _index5.gulpPlugin)('gulp-imagemin', async file => {
|
|
78
|
+
var _plugins;
|
|
79
|
+
if (!validExtensions.has(_nodePath.default.extname(file.path).toLowerCase())) {
|
|
80
|
+
if (options.verbose) {
|
|
81
|
+
console.log("".concat(PLUGIN_NAME, ": Skipping unsupported image ").concat(_index2.default.blue(file.relative)));
|
|
82
|
+
}
|
|
83
|
+
return file;
|
|
84
|
+
}
|
|
85
|
+
if (Array.isArray(plugins)) {
|
|
86
|
+
plugins = await Promise.all(plugins);
|
|
87
|
+
}
|
|
88
|
+
const localPlugins = (_plugins = plugins) !== null && _plugins !== void 0 ? _plugins : await getDefaultPlugins();
|
|
89
|
+
const data = await _index3.default.buffer(file.contents, {
|
|
90
|
+
plugins: localPlugins
|
|
91
|
+
});
|
|
92
|
+
const originalSize = file.contents.length;
|
|
93
|
+
const optimizedSize = data.length;
|
|
94
|
+
const saved = originalSize - optimizedSize;
|
|
95
|
+
const percent = originalSize > 0 ? saved / originalSize * 100 : 0;
|
|
96
|
+
const savedMessage = "saved ".concat((0, _index.default)(saved), " - ").concat(percent.toFixed(1).replace(/\.0$/, ''), "%");
|
|
97
|
+
const message = saved > 0 ? savedMessage : 'already optimized';
|
|
98
|
+
if (saved > 0) {
|
|
99
|
+
totalBytes += originalSize;
|
|
100
|
+
totalSavedBytes += saved;
|
|
101
|
+
totalFiles++;
|
|
102
|
+
}
|
|
103
|
+
if (options.verbose) {
|
|
104
|
+
console.log("".concat(PLUGIN_NAME, ":"), _index2.default.green('✔ ') + file.relative + _index2.default.gray(" (".concat(message, ")")));
|
|
105
|
+
}
|
|
106
|
+
file.contents = data;
|
|
107
|
+
return file;
|
|
108
|
+
}, {
|
|
109
|
+
async *onFinish() {
|
|
110
|
+
// eslint-disable-line require-yield
|
|
111
|
+
if (!options.silent) {
|
|
112
|
+
const percent = totalBytes > 0 ? totalSavedBytes / totalBytes * 100 : 0;
|
|
113
|
+
let message = "Minified ".concat(totalFiles, " ").concat((0, _index4.default)('image', totalFiles));
|
|
114
|
+
if (totalFiles > 0) {
|
|
115
|
+
message += _index2.default.gray(" (saved ".concat((0, _index.default)(totalSavedBytes), " - ").concat(percent.toFixed(1).replace(/\.0$/, ''), "%)"));
|
|
116
|
+
}
|
|
117
|
+
console.log("".concat(PLUGIN_NAME, ":"), message);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const gifsicle = exports.gifsicle = await exposePlugin('gifsicle');
|
|
123
|
+
const mozjpeg = exports.mozjpeg = await exposePlugin('mozjpeg');
|
|
124
|
+
const optipng = exports.optipng = await exposePlugin('optipng');
|
|
125
|
+
const svgo = exports.svgo = await exposePlugin('svgo');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
exportGulpImagemin()
|