balm-core 5.2.0 → 6.0.0-alpha.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/dist/index.cjs +2191 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +559 -0
- package/dist/index.d.ts +559 -0
- package/dist/index.js +2098 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -123
- package/src/balm.ts +103 -0
- package/src/bundler/esbuild.ts +47 -0
- package/src/bundler/index.ts +3 -0
- package/src/bundler/rollup.ts +39 -0
- package/src/bundler/webpack.ts +82 -0
- package/src/config/constants.ts +12 -0
- package/src/config/defaults.ts +209 -0
- package/src/config/index.ts +112 -0
- package/src/hooks/index.ts +192 -0
- package/src/index.ts +16 -0
- package/src/pipeline/file.ts +69 -0
- package/src/pipeline/index.ts +10 -0
- package/src/pipeline/pipeline.ts +132 -0
- package/src/pipeline/transforms/cache.ts +96 -0
- package/src/pipeline/transforms/htmlmin.ts +18 -0
- package/src/pipeline/transforms/less.ts +75 -0
- package/src/pipeline/transforms/postcss.ts +43 -0
- package/src/pipeline/transforms/rename.ts +37 -0
- package/src/pipeline/transforms/replace.ts +30 -0
- package/src/pipeline/transforms/sass.ts +106 -0
- package/src/pipeline/transforms/terser.ts +20 -0
- package/src/runner/dag.ts +77 -0
- package/src/runner/task.ts +38 -0
- package/src/shims.d.ts +5 -0
- package/src/tasks/cache.ts +58 -0
- package/src/tasks/clean.ts +21 -0
- package/src/tasks/copy.ts +36 -0
- package/src/tasks/ftp.ts +90 -0
- package/src/tasks/html.ts +78 -0
- package/src/tasks/index.ts +13 -0
- package/src/tasks/publish.ts +71 -0
- package/src/tasks/pwa.ts +49 -0
- package/src/tasks/remove.ts +24 -0
- package/src/tasks/replace.ts +34 -0
- package/src/tasks/script.ts +28 -0
- package/src/tasks/server.ts +89 -0
- package/src/tasks/style.ts +57 -0
- package/src/tasks/zip.ts +65 -0
- package/src/types/index.ts +200 -0
- package/src/utilities/file.ts +120 -0
- package/src/utilities/logger.ts +63 -0
- package/src/utilities/utils.ts +46 -0
- package/src/utilities/workspace.ts +38 -0
- package/src/watcher/index.ts +100 -0
- package/tsconfig.json +8 -0
- package/tsup.config.ts +12 -0
- package/README.md +0 -196
- package/index.d.ts +0 -360
- package/lib/balm.js +0 -49
- package/lib/bootstrap/check_config.js +0 -43
- package/lib/bootstrap/index.js +0 -87
- package/lib/bundler/esbuild/build.js +0 -26
- package/lib/bundler/esbuild/index.js +0 -7
- package/lib/bundler/esbuild/options.js +0 -7
- package/lib/bundler/esbuild/transform.js +0 -36
- package/lib/bundler/rollup/build.js +0 -52
- package/lib/bundler/rollup/entry.js +0 -28
- package/lib/bundler/rollup/index.js +0 -20
- package/lib/bundler/rollup/output.js +0 -20
- package/lib/bundler/rollup/plugins.js +0 -31
- package/lib/bundler/webpack/config/common.js +0 -135
- package/lib/bundler/webpack/config/dev.js +0 -12
- package/lib/bundler/webpack/config/env.js +0 -67
- package/lib/bundler/webpack/config/index.js +0 -6
- package/lib/bundler/webpack/config/prod.js +0 -39
- package/lib/bundler/webpack/config/regex.js +0 -10
- package/lib/bundler/webpack/entry.js +0 -65
- package/lib/bundler/webpack/index.js +0 -32
- package/lib/bundler/webpack/loaders.js +0 -50
- package/lib/bundler/webpack/output.js +0 -41
- package/lib/bundler/webpack/rules/asset.js +0 -33
- package/lib/bundler/webpack/rules/babel.js +0 -19
- package/lib/bundler/webpack/rules/css.js +0 -109
- package/lib/bundler/webpack/rules/html.js +0 -15
- package/lib/bundler/webpack/rules/index.js +0 -10
- package/lib/config/assets.js +0 -30
- package/lib/config/constants.js +0 -14
- package/lib/config/env.js +0 -35
- package/lib/config/extras.js +0 -6
- package/lib/config/ftp.js +0 -6
- package/lib/config/globals.js +0 -43
- package/lib/config/html.js +0 -22
- package/lib/config/images.js +0 -4
- package/lib/config/index.js +0 -63
- package/lib/config/logs.js +0 -11
- package/lib/config/paths.js +0 -46
- package/lib/config/pwa.js +0 -24
- package/lib/config/roots.js +0 -9
- package/lib/config/scripts.js +0 -162
- package/lib/config/server.js +0 -84
- package/lib/config/spinner.js +0 -9
- package/lib/config/styles.js +0 -67
- package/lib/hello.js +0 -19
- package/lib/hooks/index.js +0 -94
- package/lib/hooks/maker.js +0 -59
- package/lib/index.js +0 -5
- package/lib/middlewares/history.js +0 -6
- package/lib/middlewares/index.js +0 -11
- package/lib/middlewares/proxy.js +0 -28
- package/lib/middlewares/webpack.js +0 -26
- package/lib/plugins/htmlmin.js +0 -39
- package/lib/plugins/imagemin.js +0 -95
- package/lib/plugins/index.js +0 -27
- package/lib/plugins/jsmin.js +0 -37
- package/lib/plugins/less.js +0 -97
- package/lib/plugins/plumber.js +0 -87
- package/lib/plugins/postcss-plugins.js +0 -13
- package/lib/plugins/postcss.js +0 -117
- package/lib/plugins/rename.js +0 -51
- package/lib/plugins/replace.js +0 -91
- package/lib/plugins/sass-legacy.js +0 -131
- package/lib/plugins/sass.js +0 -134
- package/lib/plugins/sftp.js +0 -288
- package/lib/tasks/default.js +0 -46
- package/lib/tasks/foundation/balm.js +0 -72
- package/lib/tasks/foundation/balm_style.js +0 -65
- package/lib/tasks/foundation/index.js +0 -10
- package/lib/tasks/index.js +0 -48
- package/lib/tasks/private/build.js +0 -18
- package/lib/tasks/private/cache.js +0 -31
- package/lib/tasks/private/clean.js +0 -69
- package/lib/tasks/private/end.js +0 -24
- package/lib/tasks/private/extra.js +0 -35
- package/lib/tasks/private/font.js +0 -15
- package/lib/tasks/private/image.js +0 -37
- package/lib/tasks/private/index.js +0 -34
- package/lib/tasks/private/lint.js +0 -20
- package/lib/tasks/private/media.js +0 -15
- package/lib/tasks/private/modernizr.js +0 -59
- package/lib/tasks/private/pwa-cache.js +0 -32
- package/lib/tasks/private/script.js +0 -9
- package/lib/tasks/private/sprite.js +0 -105
- package/lib/tasks/private/start.js +0 -16
- package/lib/tasks/private/style.js +0 -9
- package/lib/tasks/private/workbox-sw.js +0 -15
- package/lib/tasks/public/copy.js +0 -16
- package/lib/tasks/public/esbuild.js +0 -18
- package/lib/tasks/public/ftp.js +0 -39
- package/lib/tasks/public/html.js +0 -65
- package/lib/tasks/public/index.js +0 -38
- package/lib/tasks/public/jsmin.js +0 -23
- package/lib/tasks/public/less.js +0 -21
- package/lib/tasks/public/postcss.js +0 -16
- package/lib/tasks/public/publish.js +0 -51
- package/lib/tasks/public/pwa.js +0 -84
- package/lib/tasks/public/remove.js +0 -46
- package/lib/tasks/public/replace.js +0 -26
- package/lib/tasks/public/rollup.js +0 -17
- package/lib/tasks/public/sass.js +0 -27
- package/lib/tasks/public/server.js +0 -130
- package/lib/tasks/public/url.js +0 -35
- package/lib/tasks/public/version.js +0 -23
- package/lib/tasks/public/webpack.js +0 -39
- package/lib/tasks/public/zip.js +0 -19
- package/lib/utilities/address.js +0 -55
- package/lib/utilities/cache-core.js +0 -66
- package/lib/utilities/color.js +0 -27
- package/lib/utilities/compiling.js +0 -24
- package/lib/utilities/detect-port.js +0 -100
- package/lib/utilities/escape-string-regexp.js +0 -10
- package/lib/utilities/file.js +0 -70
- package/lib/utilities/index.js +0 -8
- package/lib/utilities/loading.js +0 -37
- package/lib/utilities/logger.js +0 -99
- package/lib/utilities/merge-stream.js +0 -38
- package/lib/utilities/namespace.js +0 -11
- package/lib/utilities/public-url.js +0 -37
- package/lib/utilities/replacestream.js +0 -106
- package/lib/utilities/typeof.js +0 -5
- package/lib/utilities/utils.js +0 -43
- package/tslib/balm.js +0 -44
- package/tslib/bootstrap/check_config.js +0 -36
- package/tslib/bootstrap/index.js +0 -82
- package/tslib/bundler/esbuild/build.js +0 -30
- package/tslib/bundler/esbuild/index.js +0 -11
- package/tslib/bundler/esbuild/options.js +0 -7
- package/tslib/bundler/esbuild/transform.js +0 -38
- package/tslib/bundler/rollup/build.js +0 -17
- package/tslib/bundler/rollup/entry.js +0 -24
- package/tslib/bundler/rollup/index.js +0 -21
- package/tslib/bundler/rollup/output.js +0 -23
- package/tslib/bundler/rollup/plugins.js +0 -27
- package/tslib/bundler/webpack/config/common.js +0 -130
- package/tslib/bundler/webpack/config/dev.js +0 -14
- package/tslib/bundler/webpack/config/env.js +0 -44
- package/tslib/bundler/webpack/config/index.js +0 -8
- package/tslib/bundler/webpack/config/prod.js +0 -43
- package/tslib/bundler/webpack/config/regex.js +0 -10
- package/tslib/bundler/webpack/entry.js +0 -68
- package/tslib/bundler/webpack/index.js +0 -30
- package/tslib/bundler/webpack/loaders.js +0 -51
- package/tslib/bundler/webpack/output.js +0 -41
- package/tslib/bundler/webpack/rules/asset.js +0 -33
- package/tslib/bundler/webpack/rules/babel.js +0 -16
- package/tslib/bundler/webpack/rules/css.js +0 -95
- package/tslib/bundler/webpack/rules/html.js +0 -15
- package/tslib/bundler/webpack/rules/index.js +0 -10
- package/tslib/config/assets.js +0 -24
- package/tslib/config/constants.js +0 -14
- package/tslib/config/env.js +0 -43
- package/tslib/config/extras.js +0 -6
- package/tslib/config/ftp.js +0 -6
- package/tslib/config/globals.js +0 -47
- package/tslib/config/html.js +0 -17
- package/tslib/config/images.js +0 -4
- package/tslib/config/index.js +0 -56
- package/tslib/config/logs.js +0 -6
- package/tslib/config/paths.js +0 -30
- package/tslib/config/pwa.js +0 -18
- package/tslib/config/roots.js +0 -8
- package/tslib/config/scripts.js +0 -93
- package/tslib/config/server.js +0 -33
- package/tslib/config/spinner.js +0 -10
- package/tslib/config/styles.js +0 -37
- package/tslib/hello.js +0 -19
- package/tslib/hooks/index.js +0 -75
- package/tslib/hooks/maker.js +0 -66
- package/tslib/index.js +0 -5
- package/tslib/middlewares/history.js +0 -12
- package/tslib/middlewares/index.js +0 -18
- package/tslib/middlewares/proxy.js +0 -27
- package/tslib/middlewares/webpack.js +0 -29
- package/tslib/plugins/htmlmin.js +0 -38
- package/tslib/plugins/imagemin.js +0 -97
- package/tslib/plugins/index.js +0 -27
- package/tslib/plugins/jsmin.js +0 -39
- package/tslib/plugins/less.js +0 -90
- package/tslib/plugins/plumber.js +0 -81
- package/tslib/plugins/postcss-plugins.js +0 -24
- package/tslib/plugins/postcss.js +0 -111
- package/tslib/plugins/rename.js +0 -51
- package/tslib/plugins/replace.js +0 -72
- package/tslib/plugins/sass-legacy.js +0 -95
- package/tslib/plugins/sass.js +0 -109
- package/tslib/plugins/sftp.js +0 -258
- package/tslib/tasks/default.js +0 -59
- package/tslib/tasks/foundation/balm.js +0 -75
- package/tslib/tasks/foundation/balm_style.js +0 -68
- package/tslib/tasks/foundation/index.js +0 -10
- package/tslib/tasks/index.js +0 -43
- package/tslib/tasks/private/build.js +0 -15
- package/tslib/tasks/private/cache.js +0 -48
- package/tslib/tasks/private/clean.js +0 -82
- package/tslib/tasks/private/end.js +0 -21
- package/tslib/tasks/private/extra.js +0 -34
- package/tslib/tasks/private/font.js +0 -12
- package/tslib/tasks/private/image.js +0 -42
- package/tslib/tasks/private/index.js +0 -34
- package/tslib/tasks/private/lint.js +0 -17
- package/tslib/tasks/private/media.js +0 -12
- package/tslib/tasks/private/modernizr.js +0 -54
- package/tslib/tasks/private/pwa-cache.js +0 -32
- package/tslib/tasks/private/script.js +0 -9
- package/tslib/tasks/private/sprite.js +0 -93
- package/tslib/tasks/private/start.js +0 -13
- package/tslib/tasks/private/style.js +0 -12
- package/tslib/tasks/private/workbox-sw.js +0 -15
- package/tslib/tasks/public/copy.js +0 -18
- package/tslib/tasks/public/esbuild.js +0 -18
- package/tslib/tasks/public/ftp.js +0 -39
- package/tslib/tasks/public/html.js +0 -75
- package/tslib/tasks/public/index.js +0 -38
- package/tslib/tasks/public/jsmin.js +0 -24
- package/tslib/tasks/public/less.js +0 -21
- package/tslib/tasks/public/postcss.js +0 -16
- package/tslib/tasks/public/publish.js +0 -50
- package/tslib/tasks/public/pwa.js +0 -87
- package/tslib/tasks/public/remove.js +0 -44
- package/tslib/tasks/public/replace.js +0 -27
- package/tslib/tasks/public/rollup.js +0 -17
- package/tslib/tasks/public/sass.js +0 -27
- package/tslib/tasks/public/server.js +0 -129
- package/tslib/tasks/public/url.js +0 -35
- package/tslib/tasks/public/version.js +0 -27
- package/tslib/tasks/public/webpack.js +0 -41
- package/tslib/tasks/public/zip.js +0 -19
- package/tslib/utilities/address.js +0 -48
- package/tslib/utilities/cache-core.js +0 -57
- package/tslib/utilities/color.js +0 -33
- package/tslib/utilities/compiling.js +0 -16
- package/tslib/utilities/detect-port.js +0 -91
- package/tslib/utilities/escape-string-regexp.js +0 -7
- package/tslib/utilities/file.js +0 -78
- package/tslib/utilities/index.js +0 -8
- package/tslib/utilities/loading.js +0 -25
- package/tslib/utilities/logger.js +0 -92
- package/tslib/utilities/merge-stream.js +0 -34
- package/tslib/utilities/namespace.js +0 -12
- package/tslib/utilities/public-url.js +0 -31
- package/tslib/utilities/replacestream.js +0 -112
- package/tslib/utilities/typeof.js +0 -8
- package/tslib/utilities/utils.js +0 -38
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import webpackDevMiddleware from 'webpack-dev-middleware';
|
|
2
|
-
import webpackHotMiddleware from 'webpack-hot-middleware';
|
|
3
|
-
import { HMR_PATH } from '../config/constants.js';
|
|
4
|
-
function webpackMiddleware() {
|
|
5
|
-
const middleware = [];
|
|
6
|
-
if (BalmJS.webpackCompiler) {
|
|
7
|
-
middleware.push(webpackDevMiddleware(BalmJS.webpackCompiler, Object.assign({}, BalmJS.config.server.devOptions, {
|
|
8
|
-
headers: [
|
|
9
|
-
{
|
|
10
|
-
key: 'balm-core',
|
|
11
|
-
value: BalmJS.version
|
|
12
|
-
}
|
|
13
|
-
],
|
|
14
|
-
publicPath: BalmJS.file.publicUrlOrPath,
|
|
15
|
-
stats: false
|
|
16
|
-
})));
|
|
17
|
-
if (BalmJS.config.server.useHMR) {
|
|
18
|
-
middleware.push(webpackHotMiddleware(BalmJS.webpackCompiler, {
|
|
19
|
-
log: false,
|
|
20
|
-
path: HMR_PATH
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
BalmJS.logger.warn('webpack middleware', 'Webpack compiler is not ready');
|
|
26
|
-
}
|
|
27
|
-
return middleware;
|
|
28
|
-
}
|
|
29
|
-
export default webpackMiddleware;
|
package/tslib/plugins/htmlmin.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { minify } from 'html-minifier-terser';
|
|
2
|
-
const PLUGIN_NAME = 'htmlmin';
|
|
3
|
-
function gulpHtmlmin(options) {
|
|
4
|
-
options = BalmJS.utils.deepMerge({}, options);
|
|
5
|
-
function transform(file, encoding, callback) {
|
|
6
|
-
if (file.isNull()) {
|
|
7
|
-
callback(null, file);
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
async function htmlMinify(buf, enc, cb) {
|
|
11
|
-
try {
|
|
12
|
-
const minified = await minify(buf.toString(), options);
|
|
13
|
-
const contents = Buffer.from(minified);
|
|
14
|
-
if (cb === callback) {
|
|
15
|
-
file.contents = contents;
|
|
16
|
-
cb(null, file);
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
cb(null, contents);
|
|
20
|
-
callback(null, file);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
catch (e) {
|
|
24
|
-
const opts = Object.assign(options, { fileName: file.path });
|
|
25
|
-
const error = new PluginError(PLUGIN_NAME, e, opts);
|
|
26
|
-
cb === callback ? cb(error) : callback(error);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (file.isStream()) {
|
|
30
|
-
file.contents = file.contents.pipe(through2(htmlMinify));
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
htmlMinify(file.contents, null, callback);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return through2.obj(transform);
|
|
37
|
-
}
|
|
38
|
-
export default gulpHtmlmin;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import imagemin from 'imagemin';
|
|
2
|
-
import prettyBytes from 'pretty-bytes';
|
|
3
|
-
import through2Concurrent from 'through2-concurrent';
|
|
4
|
-
const PLUGIN_NAME = 'imagemin';
|
|
5
|
-
const defaultPlugins = ['gifsicle', 'mozjpeg', 'optipng', 'svgo'];
|
|
6
|
-
const loadPlugin = (plugin, ...args) => {
|
|
7
|
-
return async (input) => {
|
|
8
|
-
try {
|
|
9
|
-
const m = await import(`imagemin-${plugin}`);
|
|
10
|
-
const pluginFn = m.default(...args);
|
|
11
|
-
return pluginFn(input);
|
|
12
|
-
}
|
|
13
|
-
catch (_) {
|
|
14
|
-
BalmJS.logger.error(PLUGIN_NAME, `Could not load default plugin \`${plugin}\``);
|
|
15
|
-
return input;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
const exposePlugin = (plugin) => (...args) => loadPlugin(plugin, ...args);
|
|
20
|
-
const getDefaultPlugins = () => defaultPlugins.flatMap((plugin) => loadPlugin(plugin));
|
|
21
|
-
function gulpImagemin(customPlugins) {
|
|
22
|
-
if (typeof customPlugins === 'object' && !Array.isArray(customPlugins)) {
|
|
23
|
-
customPlugins = undefined;
|
|
24
|
-
}
|
|
25
|
-
const validExtensions = new Set(['.jpg', '.jpeg', '.png', '.gif', '.svg']);
|
|
26
|
-
let totalBytes = 0;
|
|
27
|
-
let totalSavedBytes = 0;
|
|
28
|
-
let totalFiles = 0;
|
|
29
|
-
function transform(file, encoding, callback) {
|
|
30
|
-
if (file.isNull()) {
|
|
31
|
-
callback(null, file);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
if (file.isStream()) {
|
|
35
|
-
callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
if (!validExtensions.has(node.path.extname(file.path).toLowerCase())) {
|
|
39
|
-
BalmJS.logger.info(PLUGIN_NAME, `Skipping unsupported image "${file.relative}"`);
|
|
40
|
-
callback(null, file);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
const plugins = customPlugins ?? getDefaultPlugins();
|
|
44
|
-
(async () => {
|
|
45
|
-
try {
|
|
46
|
-
const data = await imagemin.buffer(file.contents, {
|
|
47
|
-
plugins: plugins
|
|
48
|
-
});
|
|
49
|
-
const originalSize = file.contents.length;
|
|
50
|
-
const optimizedSize = data.length;
|
|
51
|
-
const saved = originalSize - optimizedSize;
|
|
52
|
-
const percent = originalSize > 0 ? (saved / originalSize) * 100 : 0;
|
|
53
|
-
const savedMessage = `saved ${prettyBytes(saved)} - ${percent
|
|
54
|
-
.toFixed(1)
|
|
55
|
-
.replace(/\.0$/, '')}%`;
|
|
56
|
-
const message = saved > 0 ? savedMessage : 'already optimized';
|
|
57
|
-
if (saved > 0) {
|
|
58
|
-
totalBytes += originalSize;
|
|
59
|
-
totalSavedBytes += saved;
|
|
60
|
-
totalFiles++;
|
|
61
|
-
}
|
|
62
|
-
BalmJS.logger.debug(PLUGIN_NAME, `${file.relative} (${message})`);
|
|
63
|
-
file.contents = Buffer.from(data);
|
|
64
|
-
callback(null, file);
|
|
65
|
-
}
|
|
66
|
-
catch (error) {
|
|
67
|
-
callback(new PluginError(PLUGIN_NAME, error, {
|
|
68
|
-
fileName: file.path
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
71
|
-
})();
|
|
72
|
-
}
|
|
73
|
-
function flush(callback) {
|
|
74
|
-
const percent = totalBytes > 0 ? (totalSavedBytes / totalBytes) * 100 : 0;
|
|
75
|
-
let message = `Minified ${totalFiles} image${totalFiles > 1 ? 's' : ''}`;
|
|
76
|
-
if (totalFiles > 0) {
|
|
77
|
-
message += ` (saved ${prettyBytes(totalSavedBytes)} - ${percent
|
|
78
|
-
.toFixed(1)
|
|
79
|
-
.replace(/\.0$/, '')}%)`;
|
|
80
|
-
}
|
|
81
|
-
BalmJS.logger.info(PLUGIN_NAME, message);
|
|
82
|
-
callback();
|
|
83
|
-
}
|
|
84
|
-
return through2Concurrent.obj({ maxConcurrency: 8 }, transform, flush);
|
|
85
|
-
}
|
|
86
|
-
const gifsicle = exposePlugin('gifsicle');
|
|
87
|
-
const mozjpeg = exposePlugin('mozjpeg');
|
|
88
|
-
const optipng = exposePlugin('optipng');
|
|
89
|
-
const svgo = exposePlugin('svgo');
|
|
90
|
-
const getDefaultImagePlugins = () => ({
|
|
91
|
-
gif: gifsicle(),
|
|
92
|
-
jpeg: mozjpeg(),
|
|
93
|
-
png: optipng(),
|
|
94
|
-
svg: svgo()
|
|
95
|
-
});
|
|
96
|
-
export default gulpImagemin;
|
|
97
|
-
export { getDefaultImagePlugins };
|
package/tslib/plugins/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import htmlmin from './htmlmin.js';
|
|
2
|
-
import imagemin from './imagemin.js';
|
|
3
|
-
import jsmin from './jsmin.js';
|
|
4
|
-
import less from './less.js';
|
|
5
|
-
import plumber from './plumber.js';
|
|
6
|
-
import postcss from './postcss.js';
|
|
7
|
-
import postcssPlugins from './postcss-plugins.js';
|
|
8
|
-
import rename from './rename.js';
|
|
9
|
-
import replace from './replace.js';
|
|
10
|
-
import sass from './sass.js';
|
|
11
|
-
import legacySass from './sass-legacy.js';
|
|
12
|
-
import sftp from './sftp.js';
|
|
13
|
-
const plugins = {
|
|
14
|
-
htmlmin,
|
|
15
|
-
imagemin,
|
|
16
|
-
jsmin,
|
|
17
|
-
less,
|
|
18
|
-
plumber,
|
|
19
|
-
postcss,
|
|
20
|
-
postcssPlugins,
|
|
21
|
-
rename,
|
|
22
|
-
replace,
|
|
23
|
-
sass,
|
|
24
|
-
legacySass,
|
|
25
|
-
sftp
|
|
26
|
-
};
|
|
27
|
-
BalmJS.plugins = plugins;
|
package/tslib/plugins/jsmin.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { minify } from 'terser';
|
|
2
|
-
const PLUGIN_NAME = 'jsmin';
|
|
3
|
-
async function jsMinify(file, opts, cb) {
|
|
4
|
-
const extname = node.path.extname(file.path);
|
|
5
|
-
if (extname === '.js') {
|
|
6
|
-
const code = {};
|
|
7
|
-
let content = file.contents.toString();
|
|
8
|
-
code[node.path.basename(file.path)] = content;
|
|
9
|
-
try {
|
|
10
|
-
const result = await minify(code, opts);
|
|
11
|
-
content = result.code;
|
|
12
|
-
file.contents = Buffer.from(content);
|
|
13
|
-
cb(null, file);
|
|
14
|
-
}
|
|
15
|
-
catch (e) {
|
|
16
|
-
const error = new PluginError(PLUGIN_NAME, e);
|
|
17
|
-
cb(error);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
else {
|
|
21
|
-
BalmJS.logger.error(PLUGIN_NAME, 'Invalid JS file');
|
|
22
|
-
}
|
|
23
|
-
return file;
|
|
24
|
-
}
|
|
25
|
-
function gulpJsmin(options) {
|
|
26
|
-
options = BalmJS.utils.deepMerge({}, options);
|
|
27
|
-
function transform(chunk, encoding, callback) {
|
|
28
|
-
if (chunk.isStream()) {
|
|
29
|
-
return this.emit('error', new PluginError(PLUGIN_NAME, 'Streams not supported'));
|
|
30
|
-
}
|
|
31
|
-
if (chunk.isNull()) {
|
|
32
|
-
callback(null, chunk);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
jsMinify(chunk, options, callback);
|
|
36
|
-
}
|
|
37
|
-
return through2.obj(transform);
|
|
38
|
-
}
|
|
39
|
-
export default gulpJsmin;
|
package/tslib/plugins/less.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import less from 'less';
|
|
2
|
-
import replaceExtension from 'replace-ext';
|
|
3
|
-
import applySourceMap from 'vinyl-sourcemaps-apply';
|
|
4
|
-
const PLUGIN_NAME = 'less';
|
|
5
|
-
function inlineSources(sourcemap) {
|
|
6
|
-
if (sourcemap.sourcesContent) {
|
|
7
|
-
return Promise.resolve(sourcemap);
|
|
8
|
-
}
|
|
9
|
-
return Promise.all(sourcemap.sources.map((source) => {
|
|
10
|
-
return new Promise((resolve, reject) => {
|
|
11
|
-
node.fs.readFile(source, 'utf8', (err, data) => {
|
|
12
|
-
if (err) {
|
|
13
|
-
reject(err);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
resolve(data);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
})).then((contents) => {
|
|
21
|
-
sourcemap.sourcesContent = contents;
|
|
22
|
-
return sourcemap;
|
|
23
|
-
}, () => sourcemap);
|
|
24
|
-
}
|
|
25
|
-
function renderLess(input, options) {
|
|
26
|
-
return new Promise((resolve, reject) => {
|
|
27
|
-
less.render(input, options, (error, output) => {
|
|
28
|
-
if (error) {
|
|
29
|
-
reject(error);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
const { css, imports } = output;
|
|
33
|
-
const result = {
|
|
34
|
-
css,
|
|
35
|
-
imports
|
|
36
|
-
};
|
|
37
|
-
if (options.sourceMap && output.map) {
|
|
38
|
-
result.sourcemap = JSON.parse(output.map);
|
|
39
|
-
inlineSources(result.sourcemap).then((map) => {
|
|
40
|
-
result.sourcemap = map;
|
|
41
|
-
resolve(result);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
resolve(result);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function gulpLess(customOptions) {
|
|
52
|
-
const options = Object.assign({}, {
|
|
53
|
-
compress: false,
|
|
54
|
-
paths: []
|
|
55
|
-
}, customOptions);
|
|
56
|
-
return through2.obj((file, enc, cb) => {
|
|
57
|
-
if (file.isNull()) {
|
|
58
|
-
return cb(null, file);
|
|
59
|
-
}
|
|
60
|
-
if (file.isStream()) {
|
|
61
|
-
return cb(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
|
|
62
|
-
}
|
|
63
|
-
const input = file.contents.toString();
|
|
64
|
-
options.filename = file.path;
|
|
65
|
-
if (file.sourceMap || options.sourcemap) {
|
|
66
|
-
options.sourceMap = true;
|
|
67
|
-
}
|
|
68
|
-
renderLess(input, options)
|
|
69
|
-
.then((output) => {
|
|
70
|
-
file.contents = Buffer.from(output.css);
|
|
71
|
-
file.path = replaceExtension(file.path, '.css');
|
|
72
|
-
if (output.sourcemap) {
|
|
73
|
-
output.sourcemap.file = file.relative;
|
|
74
|
-
output.sourcemap.sources = output.sourcemap.sources.map((source) => node.path.relative(file.base, source));
|
|
75
|
-
applySourceMap(file, output.sourcemap);
|
|
76
|
-
}
|
|
77
|
-
return file;
|
|
78
|
-
})
|
|
79
|
-
.then((file) => {
|
|
80
|
-
cb(null, file);
|
|
81
|
-
})
|
|
82
|
-
.catch((err) => {
|
|
83
|
-
err.lineNumber = err.line;
|
|
84
|
-
err.fileName = err.filename;
|
|
85
|
-
err.message = `${err.message} in file ${err.fileName} line no.${err.lineNumber}`;
|
|
86
|
-
return cb(new PluginError(PLUGIN_NAME, err));
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
export default gulpLess;
|
package/tslib/plugins/plumber.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'node:events';
|
|
2
|
-
const PLUGIN_NAME = 'plumber';
|
|
3
|
-
const emitter = new EventEmitter();
|
|
4
|
-
function removeDefaultHandler(stream, event) {
|
|
5
|
-
let found = false;
|
|
6
|
-
stream.listeners(event).forEach(function (item) {
|
|
7
|
-
if (item.name === `on${event}`) {
|
|
8
|
-
found = item;
|
|
9
|
-
this.removeListener(event, item);
|
|
10
|
-
}
|
|
11
|
-
}, stream);
|
|
12
|
-
return found;
|
|
13
|
-
}
|
|
14
|
-
function wrapPanicOnErrorHandler(stream) {
|
|
15
|
-
const oldHandler = removeDefaultHandler(stream, 'error');
|
|
16
|
-
if (oldHandler) {
|
|
17
|
-
stream.on('error', function onerror2(error) {
|
|
18
|
-
if (emitter.listenerCount('error') === 1) {
|
|
19
|
-
this.removeListener('error', onerror2);
|
|
20
|
-
oldHandler.call(stream, error);
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function defaultErrorHandler(error) {
|
|
26
|
-
if (emitter.listenerCount('error') < 3) {
|
|
27
|
-
BalmJS.logger.error(`${PLUGIN_NAME} - found unhandled error`, error.toString());
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function gulpPlumber(opts = {}) {
|
|
31
|
-
if (BalmJS.utils.isFunction(opts)) {
|
|
32
|
-
opts = { errorHandler: opts };
|
|
33
|
-
}
|
|
34
|
-
const through = through2.obj();
|
|
35
|
-
through._plumber = true;
|
|
36
|
-
if (opts.errorHandler !== false) {
|
|
37
|
-
through.errorHandler = BalmJS.utils.isFunction(opts.errorHandler)
|
|
38
|
-
? opts.errorHandler
|
|
39
|
-
: defaultErrorHandler;
|
|
40
|
-
}
|
|
41
|
-
function patchPipe(stream) {
|
|
42
|
-
if (stream.pipe2) {
|
|
43
|
-
wrapPanicOnErrorHandler(stream);
|
|
44
|
-
stream._pipe = stream._pipe || stream.pipe;
|
|
45
|
-
stream.pipe = stream.pipe2;
|
|
46
|
-
stream._plumbed = true;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
through.pipe2 = function pipe2(dest) {
|
|
50
|
-
if (!dest) {
|
|
51
|
-
throw new PluginError(PLUGIN_NAME, "Can't pipe to undefined");
|
|
52
|
-
}
|
|
53
|
-
this._pipe(dest);
|
|
54
|
-
if (dest._unplumbed) {
|
|
55
|
-
return dest;
|
|
56
|
-
}
|
|
57
|
-
removeDefaultHandler(this, 'error');
|
|
58
|
-
if (dest._plumber) {
|
|
59
|
-
return dest;
|
|
60
|
-
}
|
|
61
|
-
dest.pipe2 = pipe2;
|
|
62
|
-
if (opts.inherit !== false) {
|
|
63
|
-
patchPipe(dest);
|
|
64
|
-
}
|
|
65
|
-
if (this.errorHandler) {
|
|
66
|
-
dest.errorHandler = this.errorHandler;
|
|
67
|
-
dest.on('error', this.errorHandler.bind(dest));
|
|
68
|
-
}
|
|
69
|
-
dest._plumbed = true;
|
|
70
|
-
return dest;
|
|
71
|
-
};
|
|
72
|
-
patchPipe(through);
|
|
73
|
-
return through;
|
|
74
|
-
}
|
|
75
|
-
function stop() {
|
|
76
|
-
const through = through2.obj();
|
|
77
|
-
through._unplumbed = true;
|
|
78
|
-
return through;
|
|
79
|
-
}
|
|
80
|
-
export default gulpPlumber;
|
|
81
|
-
export { stop };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import atImport from 'postcss-import';
|
|
2
|
-
import postcssFlexbugsFixes from 'postcss-flexbugs-fixes';
|
|
3
|
-
import postcssPresetEnv from 'postcss-preset-env';
|
|
4
|
-
import autoprefixer from 'autoprefixer';
|
|
5
|
-
import cssnano from 'cssnano';
|
|
6
|
-
function getDefaultPostcssPlugins(isPostCSS = false, useTailwind = false) {
|
|
7
|
-
const defaultPostcssPlugins = isPostCSS || BalmJS.config.styles.extname === 'css'
|
|
8
|
-
? [
|
|
9
|
-
...(useTailwind ? ['tailwindcss'] : []),
|
|
10
|
-
atImport({ path: BalmJS.file.stylePaths }),
|
|
11
|
-
postcssFlexbugsFixes(),
|
|
12
|
-
postcssPresetEnv(BalmJS.config.styles.postcssEnvOptions)
|
|
13
|
-
]
|
|
14
|
-
: [];
|
|
15
|
-
const cssnanoPlugin = BalmJS.config.env.isProd || BalmJS.config.styles.minify
|
|
16
|
-
? [cssnano(BalmJS.config.styles.options)]
|
|
17
|
-
: [];
|
|
18
|
-
return defaultPostcssPlugins.concat([
|
|
19
|
-
autoprefixer(),
|
|
20
|
-
...cssnanoPlugin,
|
|
21
|
-
...BalmJS.config.styles.postcssPlugins
|
|
22
|
-
]);
|
|
23
|
-
}
|
|
24
|
-
export default getDefaultPostcssPlugins;
|
package/tslib/plugins/postcss.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { Transform } from 'node:stream';
|
|
2
|
-
import postcss from 'postcss';
|
|
3
|
-
import postcssLoadConfig from 'postcss-load-config';
|
|
4
|
-
import applySourceMap from 'vinyl-sourcemaps-apply';
|
|
5
|
-
const PLUGIN_NAME = 'postcss';
|
|
6
|
-
function gulpPostcss(cb) {
|
|
7
|
-
return function (plugins, options) {
|
|
8
|
-
if (Array.isArray(plugins)) {
|
|
9
|
-
return cb(() => Promise.resolve({
|
|
10
|
-
plugins: plugins,
|
|
11
|
-
options: options
|
|
12
|
-
}));
|
|
13
|
-
}
|
|
14
|
-
else if (typeof plugins === 'function') {
|
|
15
|
-
return cb((file) => Promise.resolve(plugins(file)));
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
const contextOptions = plugins || {};
|
|
19
|
-
return cb((file) => {
|
|
20
|
-
let configPath;
|
|
21
|
-
if (contextOptions.config) {
|
|
22
|
-
if (node.path.isAbsolute(contextOptions.config)) {
|
|
23
|
-
configPath = contextOptions.config;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
configPath = node.path.join(file.base, contextOptions.config);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
configPath = file.dirname;
|
|
31
|
-
}
|
|
32
|
-
const ctx = {
|
|
33
|
-
file,
|
|
34
|
-
options: contextOptions
|
|
35
|
-
};
|
|
36
|
-
return postcssLoadConfig(ctx, configPath);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
export default gulpPostcss((loadConfig) => {
|
|
42
|
-
const stream = new Transform({ objectMode: true });
|
|
43
|
-
stream._transform = function (file, encoding, cb) {
|
|
44
|
-
if (file.isNull()) {
|
|
45
|
-
return cb(null, file);
|
|
46
|
-
}
|
|
47
|
-
if (file.isStream()) {
|
|
48
|
-
return handleError('Streams are not supported!');
|
|
49
|
-
}
|
|
50
|
-
const isProtected = file.sourceMap
|
|
51
|
-
? { from: true, map: true }
|
|
52
|
-
: {};
|
|
53
|
-
const options = {
|
|
54
|
-
from: file.path,
|
|
55
|
-
to: file.path,
|
|
56
|
-
map: file.sourceMap ? { annotation: false } : false
|
|
57
|
-
};
|
|
58
|
-
loadConfig(file)
|
|
59
|
-
.then(function (config) {
|
|
60
|
-
const configOpts = config.options || {};
|
|
61
|
-
for (const opt in configOpts) {
|
|
62
|
-
if (Object.prototype.hasOwnProperty.call(configOpts, opt) &&
|
|
63
|
-
!isProtected[opt]) {
|
|
64
|
-
options[opt] = configOpts[opt];
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
BalmJS.logger.info(PLUGIN_NAME, `${file.relative}\nCannot override ${opt} option, because it is required by gulp-sourcemaps`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return postcss(config.plugins || []).process(file.contents, options);
|
|
71
|
-
})
|
|
72
|
-
.then(handleResult, handleError);
|
|
73
|
-
function handleResult(result) {
|
|
74
|
-
let map;
|
|
75
|
-
const warnings = result.warnings().join('\n');
|
|
76
|
-
file.contents = Buffer.from(result.css);
|
|
77
|
-
if (file.sourceMap) {
|
|
78
|
-
map = result.map.toJSON();
|
|
79
|
-
map.file = file.relative;
|
|
80
|
-
map.sources = [].map.call(map.sources, function (source) {
|
|
81
|
-
return node.path.join(node.path.dirname(file.relative), source);
|
|
82
|
-
});
|
|
83
|
-
applySourceMap(file, map);
|
|
84
|
-
}
|
|
85
|
-
if (warnings) {
|
|
86
|
-
BalmJS.logger.info(PLUGIN_NAME, `${file.relative}\nwarnings`);
|
|
87
|
-
}
|
|
88
|
-
setImmediate(function () {
|
|
89
|
-
cb(null, file);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
function handleError(error) {
|
|
93
|
-
const errorOptions = {
|
|
94
|
-
fileName: file.path,
|
|
95
|
-
showStack: true
|
|
96
|
-
};
|
|
97
|
-
if (error.name === 'CssSyntaxError') {
|
|
98
|
-
errorOptions.error = error;
|
|
99
|
-
errorOptions.fileName = error.file || file.path;
|
|
100
|
-
errorOptions.lineNumber = error.line;
|
|
101
|
-
errorOptions.showProperties = false;
|
|
102
|
-
errorOptions.showStack = false;
|
|
103
|
-
error = `${error.message}\n\n${error.showSourceCode()}\n`;
|
|
104
|
-
}
|
|
105
|
-
setImmediate(function () {
|
|
106
|
-
cb(new PluginError(PLUGIN_NAME, error, errorOptions));
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
return stream;
|
|
111
|
-
});
|
package/tslib/plugins/rename.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { Transform } from 'node:stream';
|
|
2
|
-
function gulpRename(obj, options = {}) {
|
|
3
|
-
const stream = new Transform({ objectMode: true });
|
|
4
|
-
const parsePath = (_path) => {
|
|
5
|
-
const extname = options.multiExt
|
|
6
|
-
? node.path.basename(_path).slice(node.path.basename(_path).indexOf('.'))
|
|
7
|
-
: node.path.extname(_path);
|
|
8
|
-
return {
|
|
9
|
-
dirname: node.path.dirname(_path),
|
|
10
|
-
basename: node.path.basename(_path, extname),
|
|
11
|
-
extname: extname
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
stream._transform = (chunk, unused, callback) => {
|
|
15
|
-
const file = chunk.clone();
|
|
16
|
-
let parsedPath = parsePath(file.relative);
|
|
17
|
-
let _path;
|
|
18
|
-
const type = typeof obj;
|
|
19
|
-
if (type === 'string' && obj !== '') {
|
|
20
|
-
_path = obj;
|
|
21
|
-
}
|
|
22
|
-
else if (type === 'function') {
|
|
23
|
-
const newParsedPath = obj(parsedPath, file);
|
|
24
|
-
if (typeof newParsedPath === 'object' && newParsedPath !== null) {
|
|
25
|
-
parsedPath = newParsedPath;
|
|
26
|
-
}
|
|
27
|
-
_path = node.path.join(parsedPath.dirname, parsedPath.basename + parsedPath.extname);
|
|
28
|
-
}
|
|
29
|
-
else if (type === 'object' && obj !== undefined && obj !== null) {
|
|
30
|
-
const _obj = obj;
|
|
31
|
-
const dirname = _obj.dirname || parsedPath.dirname;
|
|
32
|
-
const prefix = _obj.prefix || '';
|
|
33
|
-
const suffix = _obj.suffix || '';
|
|
34
|
-
const basename = _obj.basename || parsedPath.basename;
|
|
35
|
-
const extname = _obj.extname || parsedPath.extname;
|
|
36
|
-
const filename = prefix + basename + suffix + extname;
|
|
37
|
-
_path = node.path.join(dirname, filename);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
callback(new Error('Unsupported renaming parameter type supplied'), undefined);
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
file.path = node.path.join(file.base, _path);
|
|
44
|
-
if (file.sourceMap) {
|
|
45
|
-
file.sourceMap.file = file.relative;
|
|
46
|
-
}
|
|
47
|
-
callback(null, file);
|
|
48
|
-
};
|
|
49
|
-
return stream;
|
|
50
|
-
}
|
|
51
|
-
export default gulpRename;
|
package/tslib/plugins/replace.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { Transform } from 'node:stream';
|
|
2
|
-
import * as isTextModule from 'istextorbinary';
|
|
3
|
-
import rs from '../utilities/replacestream.js';
|
|
4
|
-
const isText = isTextModule.isText || isTextModule;
|
|
5
|
-
const defaultOptions = {
|
|
6
|
-
skipBinary: true
|
|
7
|
-
};
|
|
8
|
-
function gulpReplace(search, _replacement, options = {}) {
|
|
9
|
-
options = {
|
|
10
|
-
...defaultOptions,
|
|
11
|
-
...options
|
|
12
|
-
};
|
|
13
|
-
return new Transform({
|
|
14
|
-
objectMode: true,
|
|
15
|
-
transform: (file, encoding, callback) => {
|
|
16
|
-
if (file.isNull()) {
|
|
17
|
-
return callback(null, file);
|
|
18
|
-
}
|
|
19
|
-
let replacement = _replacement;
|
|
20
|
-
if (typeof _replacement === 'function') {
|
|
21
|
-
replacement = _replacement.bind({ file: file });
|
|
22
|
-
}
|
|
23
|
-
function doReplace() {
|
|
24
|
-
if (file.isStream()) {
|
|
25
|
-
file.contents = file.contents.pipe(rs(search, replacement));
|
|
26
|
-
return callback(null, file);
|
|
27
|
-
}
|
|
28
|
-
if (file.isBuffer()) {
|
|
29
|
-
const content = file.contents.toString();
|
|
30
|
-
if (search instanceof RegExp) {
|
|
31
|
-
file.contents = Buffer.from(content.replace(search, replacement));
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
const chunks = content.split(search);
|
|
35
|
-
let result;
|
|
36
|
-
if (typeof replacement === 'function') {
|
|
37
|
-
result = [chunks[0]];
|
|
38
|
-
for (let i = 1; i < chunks.length; i++) {
|
|
39
|
-
result.push(replacement(search));
|
|
40
|
-
result.push(chunks[i]);
|
|
41
|
-
}
|
|
42
|
-
result = result.join('');
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
result = chunks.join(replacement);
|
|
46
|
-
}
|
|
47
|
-
file.contents = Buffer.from(result);
|
|
48
|
-
}
|
|
49
|
-
return callback(null, file);
|
|
50
|
-
}
|
|
51
|
-
callback(null, file);
|
|
52
|
-
}
|
|
53
|
-
if (options.skipBinary) {
|
|
54
|
-
const isNode16 = process.version.split('.')[0] === 'v16';
|
|
55
|
-
if (isNode16) {
|
|
56
|
-
doReplace();
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
if (isText(file.path, file.contents)) {
|
|
60
|
-
doReplace();
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
callback(null, file);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
doReplace();
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
export default gulpReplace;
|