balm-core 5.2.0 → 6.0.0-alpha.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/CHANGELOG.md +16 -0
- package/dist/index.cjs +2625 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +569 -0
- package/dist/index.d.ts +569 -0
- package/dist/index.js +2527 -0
- package/dist/index.js.map +1 -0
- package/package.json +49 -123
- package/src/balm.ts +108 -0
- package/src/bundler/esbuild.ts +47 -0
- package/src/bundler/index.ts +3 -0
- package/src/bundler/rollup.ts +45 -0
- package/src/bundler/webpack.ts +124 -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 +224 -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 +135 -0
- package/src/pipeline/transforms/cache.ts +146 -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 +72 -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 +232 -0
- package/src/tasks/index.ts +14 -0
- package/src/tasks/publish.ts +71 -0
- package/src/tasks/pwa.ts +99 -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 +183 -0
- package/src/tasks/static.ts +104 -0
- package/src/tasks/style.ts +57 -0
- package/src/tasks/zip.ts +65 -0
- package/src/types/index.ts +202 -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,41 +0,0 @@
|
|
|
1
|
-
import { webpack, webpackConfig } from '../../bundler/webpack/index.js';
|
|
2
|
-
import compiling from '../../utilities/compiling.js';
|
|
3
|
-
class WebpackTask extends BalmJS.BalmTask {
|
|
4
|
-
constructor() {
|
|
5
|
-
super('webpack');
|
|
6
|
-
}
|
|
7
|
-
recipe(input, output, customOptions = {}, fn) {
|
|
8
|
-
const balmBundler = (callback) => {
|
|
9
|
-
this.init(input || BalmJS.config.scripts.entry, output);
|
|
10
|
-
const isHook = !!input;
|
|
11
|
-
compiling.start();
|
|
12
|
-
BalmJS.webpackCompiler = webpack(webpackConfig(this.input, this.output, customOptions, isHook), (error, stats) => {
|
|
13
|
-
compiling.stop();
|
|
14
|
-
try {
|
|
15
|
-
const scriptLogLevel = stats.hasErrors()
|
|
16
|
-
? BalmJS.LogLevel.Error
|
|
17
|
-
: stats.hasWarnings()
|
|
18
|
-
? BalmJS.LogLevel.Warn
|
|
19
|
-
: BalmJS.LogLevel.Info;
|
|
20
|
-
if (BalmJS.config.logs.level <= scriptLogLevel) {
|
|
21
|
-
console.log(stats.toString(BalmJS.config.scripts.stats));
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
BalmJS.logger.error(`${this.name} task`, error.stack || error);
|
|
26
|
-
if (error.details) {
|
|
27
|
-
BalmJS.logger.error(`${this.name} task`, error.details);
|
|
28
|
-
}
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
fn && fn();
|
|
32
|
-
callback();
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
return balmBundler;
|
|
36
|
-
}
|
|
37
|
-
get fn() {
|
|
38
|
-
return this.recipe();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
export default WebpackTask;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import zip from 'gulp-zip';
|
|
2
|
-
class ZipTask extends BalmJS.BalmTask {
|
|
3
|
-
constructor() {
|
|
4
|
-
super('zip');
|
|
5
|
-
this.defaultInput = BalmJS.file.matchAllFiles(BalmJS.config.roots.target);
|
|
6
|
-
this.defaultOutput = '.';
|
|
7
|
-
}
|
|
8
|
-
recipe(input, output, filename = 'archive.zip') {
|
|
9
|
-
const balmZip = () => {
|
|
10
|
-
this.init(input, output);
|
|
11
|
-
return this.src.pipe(zip(filename)).pipe(gulp.dest(this.output));
|
|
12
|
-
};
|
|
13
|
-
return balmZip;
|
|
14
|
-
}
|
|
15
|
-
fn(callback) {
|
|
16
|
-
callback();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export default ZipTask;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import os from 'node:os';
|
|
2
|
-
const platform = os.platform();
|
|
3
|
-
function getInterfaceName() {
|
|
4
|
-
let val = 'eth';
|
|
5
|
-
if (platform === 'darwin') {
|
|
6
|
-
val = 'en';
|
|
7
|
-
}
|
|
8
|
-
else if (platform === 'win32') {
|
|
9
|
-
val = null;
|
|
10
|
-
}
|
|
11
|
-
return val;
|
|
12
|
-
}
|
|
13
|
-
function getInterface(family) {
|
|
14
|
-
const interfaces = os.networkInterfaces();
|
|
15
|
-
const name = getInterfaceName();
|
|
16
|
-
family = family || 'IPv4';
|
|
17
|
-
for (let i = -1; i < 8; i++) {
|
|
18
|
-
const interfaceName = `${name}${i >= 0 ? i : ''}`;
|
|
19
|
-
const items = interfaces[interfaceName];
|
|
20
|
-
if (items) {
|
|
21
|
-
for (let j = 0, len = items.length; j < len; j++) {
|
|
22
|
-
const item = items[j];
|
|
23
|
-
if (item.family === family) {
|
|
24
|
-
return item;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
for (const k in interfaces) {
|
|
30
|
-
const items = interfaces[k];
|
|
31
|
-
if (items) {
|
|
32
|
-
for (let i = 0, len = items.length; i < len; i++) {
|
|
33
|
-
const item = items[i];
|
|
34
|
-
if (item.family === family && item.address !== '127.0.0.1') {
|
|
35
|
-
return item;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
function ip() {
|
|
43
|
-
const item = getInterface('IPv4');
|
|
44
|
-
return item && item.address;
|
|
45
|
-
}
|
|
46
|
-
export default {
|
|
47
|
-
ip
|
|
48
|
-
};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import Module from 'node:module';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
|
-
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
5
|
-
import loading from './loading.js';
|
|
6
|
-
const _require = Module.prototype.require;
|
|
7
|
-
const SAVE_FILE = path.join(homedir(), process.env.BALM_CORE_CACHE || '.balm-core-cache.json');
|
|
8
|
-
function cacheBalmCore() {
|
|
9
|
-
let nameCache;
|
|
10
|
-
let originLastFilename;
|
|
11
|
-
try {
|
|
12
|
-
nameCache = existsSync(SAVE_FILE)
|
|
13
|
-
? JSON.parse(readFileSync(SAVE_FILE, 'utf-8'))
|
|
14
|
-
: {};
|
|
15
|
-
originLastFilename = nameCache.lastFilename || '';
|
|
16
|
-
}
|
|
17
|
-
catch (err) {
|
|
18
|
-
nameCache = {};
|
|
19
|
-
}
|
|
20
|
-
let currentModuleCache;
|
|
21
|
-
let pathToLoad;
|
|
22
|
-
Module.prototype.require = function cachePathsRequire(name) {
|
|
23
|
-
currentModuleCache = nameCache[this.filename];
|
|
24
|
-
if (!currentModuleCache) {
|
|
25
|
-
currentModuleCache = {};
|
|
26
|
-
if (/\/balm-core\//.test(this.filename)) {
|
|
27
|
-
nameCache[this.filename] = currentModuleCache;
|
|
28
|
-
nameCache.lastFilename = this.filename;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (currentModuleCache[name] &&
|
|
32
|
-
typeof currentModuleCache[name] === 'string' &&
|
|
33
|
-
existsSync(currentModuleCache[name])) {
|
|
34
|
-
pathToLoad = currentModuleCache[name];
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
pathToLoad = Module._resolveFilename(name, this);
|
|
38
|
-
currentModuleCache[name] = pathToLoad;
|
|
39
|
-
}
|
|
40
|
-
if (BalmJS.loading) {
|
|
41
|
-
loading.render();
|
|
42
|
-
}
|
|
43
|
-
return _require.call(this, pathToLoad);
|
|
44
|
-
};
|
|
45
|
-
BalmJS.emitter.once('exit', function () {
|
|
46
|
-
if (nameCache.lastFilename !== originLastFilename) {
|
|
47
|
-
try {
|
|
48
|
-
writeFileSync(SAVE_FILE, JSON.stringify(nameCache, null, 2), 'utf-8');
|
|
49
|
-
}
|
|
50
|
-
catch (error) {
|
|
51
|
-
const err = error;
|
|
52
|
-
console.error(`BalmJS: Failed saving cache: ${err.toString()}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
export default cacheBalmCore;
|
package/tslib/utilities/color.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import ansiColors from 'ansi-colors';
|
|
2
|
-
const COLOR = {
|
|
3
|
-
PREFIX: 'bg',
|
|
4
|
-
SUFFIX: 'Bright'
|
|
5
|
-
};
|
|
6
|
-
function getStyle(colorStyle = {
|
|
7
|
-
color: 'white'
|
|
8
|
-
}) {
|
|
9
|
-
const color = colorStyle.color.toLowerCase();
|
|
10
|
-
let fn = colorStyle.background
|
|
11
|
-
? COLOR.PREFIX + color.replace(/^[a-z]/, (str) => str.toUpperCase())
|
|
12
|
-
: color;
|
|
13
|
-
if (colorStyle.bright) {
|
|
14
|
-
fn += COLOR.SUFFIX;
|
|
15
|
-
}
|
|
16
|
-
const colors = ansiColors;
|
|
17
|
-
const render = colorStyle.modifier
|
|
18
|
-
? colors[colorStyle.modifier][fn]
|
|
19
|
-
: colors[fn];
|
|
20
|
-
const symbols = ansiColors.symbols;
|
|
21
|
-
const icon = colorStyle.symbol && symbols[colorStyle.symbol]
|
|
22
|
-
? `${symbols[colorStyle.symbol]} `
|
|
23
|
-
: '';
|
|
24
|
-
return {
|
|
25
|
-
icon,
|
|
26
|
-
render
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function color(label, colorStyle) {
|
|
30
|
-
const result = getStyle(colorStyle);
|
|
31
|
-
return result.render(`${result.icon}${label}`);
|
|
32
|
-
}
|
|
33
|
-
export default color;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import loading from './loading.js';
|
|
2
|
-
class BalmCompiling {
|
|
3
|
-
#firstCompile = true;
|
|
4
|
-
start() {
|
|
5
|
-
if (!BalmJS.useCacache && this.#firstCompile) {
|
|
6
|
-
loading.render('Compiling to JS...');
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
stop() {
|
|
10
|
-
if (!BalmJS.useCacache && this.#firstCompile) {
|
|
11
|
-
this.#firstCompile = false;
|
|
12
|
-
loading.clear();
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export default new BalmCompiling();
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import net from 'node:net';
|
|
2
|
-
import address from './address.js';
|
|
3
|
-
const UTIL_NAME = 'detect port';
|
|
4
|
-
const MAX_PORT = 65535;
|
|
5
|
-
function listen(port, host, callback) {
|
|
6
|
-
const server = new net.Server();
|
|
7
|
-
server.on('error', (error) => {
|
|
8
|
-
server.close();
|
|
9
|
-
if (error.code === 'ENOTFOUND') {
|
|
10
|
-
BalmJS.logger.error(UTIL_NAME, `ignore dns ENOTFOUND error, get free ${host}:${port}`, {
|
|
11
|
-
logLevel: BalmJS.LogLevel.Debug
|
|
12
|
-
});
|
|
13
|
-
return callback(null, port);
|
|
14
|
-
}
|
|
15
|
-
return callback(error);
|
|
16
|
-
});
|
|
17
|
-
server.listen(port, host, () => {
|
|
18
|
-
port = server.address().port;
|
|
19
|
-
server.close();
|
|
20
|
-
BalmJS.logger.debug(UTIL_NAME, `get free ${host}:${port}`);
|
|
21
|
-
return callback(null, port);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
function tryListen(port, maxPort, host, callback) {
|
|
25
|
-
function handleError(err) {
|
|
26
|
-
if (err) {
|
|
27
|
-
BalmJS.logger.error(UTIL_NAME, err.message, {
|
|
28
|
-
logLevel: BalmJS.LogLevel.Debug
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
port++;
|
|
32
|
-
if (port >= maxPort) {
|
|
33
|
-
BalmJS.logger.warn(UTIL_NAME, `port: ${port} >= maxPort: ${maxPort}, give up and use random port`, {
|
|
34
|
-
logLevel: BalmJS.LogLevel.Debug
|
|
35
|
-
});
|
|
36
|
-
port = 0;
|
|
37
|
-
maxPort = 0;
|
|
38
|
-
}
|
|
39
|
-
tryListen(port, maxPort, host, callback);
|
|
40
|
-
}
|
|
41
|
-
if (host) {
|
|
42
|
-
listen(port, host, (error, realPort) => {
|
|
43
|
-
if (error) {
|
|
44
|
-
if (error.code === 'EADDRNOTAVAIL') {
|
|
45
|
-
return callback(new Error('the ip that is not unkonwn on the machine'));
|
|
46
|
-
}
|
|
47
|
-
return handleError();
|
|
48
|
-
}
|
|
49
|
-
callback(null, realPort);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
listen(port, null, (error, realPort) => {
|
|
54
|
-
if (port === 0) {
|
|
55
|
-
return callback(error, realPort);
|
|
56
|
-
}
|
|
57
|
-
if (error) {
|
|
58
|
-
return handleError(error);
|
|
59
|
-
}
|
|
60
|
-
listen(port, '0.0.0.0', (error) => {
|
|
61
|
-
if (error) {
|
|
62
|
-
return handleError(error);
|
|
63
|
-
}
|
|
64
|
-
listen(port, 'localhost', (error) => {
|
|
65
|
-
if (error && error.code !== 'EADDRNOTAVAIL') {
|
|
66
|
-
return handleError(error);
|
|
67
|
-
}
|
|
68
|
-
listen(port, address.ip(), (error, realPort) => {
|
|
69
|
-
if (error) {
|
|
70
|
-
return handleError(error);
|
|
71
|
-
}
|
|
72
|
-
callback(null, realPort);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function detectPort(port, host) {
|
|
80
|
-
let maxPort = port + 10;
|
|
81
|
-
if (maxPort > MAX_PORT) {
|
|
82
|
-
maxPort = MAX_PORT;
|
|
83
|
-
}
|
|
84
|
-
BalmJS.logger.debug(UTIL_NAME, `detect free port between [${port}, ${maxPort}]`);
|
|
85
|
-
return new Promise((resolve) => {
|
|
86
|
-
tryListen(port, maxPort, host, (error, realPort) => {
|
|
87
|
-
resolve(realPort);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
export default detectPort;
|
package/tslib/utilities/file.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import getPublicUrlOrPath from './public-url.js';
|
|
2
|
-
import { PUBLIC_URL } from '../config/constants.js';
|
|
3
|
-
const appDirectory = node.fs.realpathSync(process.cwd());
|
|
4
|
-
class File {
|
|
5
|
-
resolveApp(relativePath) {
|
|
6
|
-
return node.path.resolve(appDirectory, relativePath);
|
|
7
|
-
}
|
|
8
|
-
get publicUrlOrPath() {
|
|
9
|
-
return getPublicUrlOrPath(requireModule(this.resolveApp('package.json'))
|
|
10
|
-
.homepage, process.env.PUBLIC_URL);
|
|
11
|
-
}
|
|
12
|
-
get stylePaths() {
|
|
13
|
-
return [
|
|
14
|
-
node.path.resolve(BalmJS.config.workspace, '.'),
|
|
15
|
-
node.path.resolve(BalmJS.config.workspace, 'node_modules'),
|
|
16
|
-
...BalmJS.config.styles.atImportPaths
|
|
17
|
-
];
|
|
18
|
-
}
|
|
19
|
-
get assetsSuffixPath() {
|
|
20
|
-
return !BalmJS.config.inFrontend &&
|
|
21
|
-
BalmJS.config.env.isProd &&
|
|
22
|
-
BalmJS.config.assets.cache
|
|
23
|
-
? node.path.join(BalmJS.config.assets.subDir, BalmJS.config.assets.buildDir)
|
|
24
|
-
: BalmJS.config.assets.subDir;
|
|
25
|
-
}
|
|
26
|
-
get defaultEntry() {
|
|
27
|
-
return node.path.join(BalmJS.config.src.js, 'index.js');
|
|
28
|
-
}
|
|
29
|
-
get templateBasePath() {
|
|
30
|
-
return BalmJS.config.scripts.injectHtml
|
|
31
|
-
? BalmJS.config.src.base
|
|
32
|
-
: BalmJS.config.src.html;
|
|
33
|
-
}
|
|
34
|
-
absPath(_path) {
|
|
35
|
-
return node.path.resolve(BalmJS.config.workspace, _path);
|
|
36
|
-
}
|
|
37
|
-
absPaths(_paths) {
|
|
38
|
-
let paths;
|
|
39
|
-
if (BalmJS.utils.isArray(_paths)) {
|
|
40
|
-
paths = [];
|
|
41
|
-
for (const _path of _paths) {
|
|
42
|
-
const result = /^!(.+)$/.exec(_path);
|
|
43
|
-
if (result) {
|
|
44
|
-
paths.push('!' + this.absPath(result[1]));
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
paths.push(this.absPath(_path));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
paths = this.absPath(_paths);
|
|
53
|
-
}
|
|
54
|
-
return paths;
|
|
55
|
-
}
|
|
56
|
-
matchAllFiles(_path, _file) {
|
|
57
|
-
return node.path.join(_path, '**', _file || '*');
|
|
58
|
-
}
|
|
59
|
-
assetsPath(_path) {
|
|
60
|
-
return BalmJS.config.env.isProd || !BalmJS.config.inFrontend
|
|
61
|
-
? node.path.posix.join(BalmJS.config.assets.virtualDir, this.assetsSuffixPath, _path)
|
|
62
|
-
: _path;
|
|
63
|
-
}
|
|
64
|
-
setPublicPath() {
|
|
65
|
-
const publicPathSrc = `${PUBLIC_URL}/`;
|
|
66
|
-
const publicPathDest = BalmJS.config.env.inDesktopApp
|
|
67
|
-
? `.${this.publicUrlOrPath}`
|
|
68
|
-
: this.publicUrlOrPath;
|
|
69
|
-
BalmJS.logger.debug(`set public path`, {
|
|
70
|
-
regex: publicPathSrc,
|
|
71
|
-
replacement: publicPathDest
|
|
72
|
-
}, {
|
|
73
|
-
pre: true
|
|
74
|
-
});
|
|
75
|
-
return BalmJS.plugins.replace(publicPathSrc, publicPathDest);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
export default new File();
|
package/tslib/utilities/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import readline from 'readline';
|
|
2
|
-
import spinner from '../config/spinner.js';
|
|
3
|
-
class BalmLoading {
|
|
4
|
-
#stream = process.stderr;
|
|
5
|
-
#frameIndex = 0;
|
|
6
|
-
#frameCount = spinner.frames.length;
|
|
7
|
-
get frame() {
|
|
8
|
-
const currentFrame = spinner.frames[this.#frameIndex];
|
|
9
|
-
this.#frameIndex = ++this.#frameIndex % this.#frameCount;
|
|
10
|
-
return currentFrame;
|
|
11
|
-
}
|
|
12
|
-
clear() {
|
|
13
|
-
readline.clearLine(this.#stream, 0);
|
|
14
|
-
readline.cursorTo(this.#stream, 0);
|
|
15
|
-
}
|
|
16
|
-
render(text = `${this.frame} BalmJS is initializing...`) {
|
|
17
|
-
this.clear();
|
|
18
|
-
this.#stream.write(text);
|
|
19
|
-
}
|
|
20
|
-
succeed() {
|
|
21
|
-
this.clear();
|
|
22
|
-
console.log(`BalmJS core version: ${BalmJS.version}`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
export default new BalmLoading();
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import util from 'node:util';
|
|
2
|
-
import fancyLog from 'fancy-log';
|
|
3
|
-
import color from './color.js';
|
|
4
|
-
const LOG = {
|
|
5
|
-
FORMAT: '%s %s %s',
|
|
6
|
-
PREFIX: color('BalmJS', {
|
|
7
|
-
color: 'blue',
|
|
8
|
-
background: true,
|
|
9
|
-
bright: true
|
|
10
|
-
}),
|
|
11
|
-
OK: {
|
|
12
|
-
color: 'green',
|
|
13
|
-
bright: true,
|
|
14
|
-
symbol: 'check'
|
|
15
|
-
},
|
|
16
|
-
DEBUG: {
|
|
17
|
-
color: 'blue',
|
|
18
|
-
bright: true,
|
|
19
|
-
symbol: 'mark'
|
|
20
|
-
},
|
|
21
|
-
INFO: {
|
|
22
|
-
color: 'cyan',
|
|
23
|
-
bright: true,
|
|
24
|
-
symbol: 'info'
|
|
25
|
-
},
|
|
26
|
-
WARN: {
|
|
27
|
-
color: 'yellow',
|
|
28
|
-
bright: true,
|
|
29
|
-
symbol: 'warning'
|
|
30
|
-
},
|
|
31
|
-
ERROR: {
|
|
32
|
-
color: 'red',
|
|
33
|
-
bright: true,
|
|
34
|
-
symbol: 'cross'
|
|
35
|
-
},
|
|
36
|
-
beginning: '$'.padStart(36, '*'),
|
|
37
|
-
end: '^'.padEnd(36, '.')
|
|
38
|
-
};
|
|
39
|
-
class Logger {
|
|
40
|
-
#log = (obj, pre = false) => {
|
|
41
|
-
const options = Object.assign({
|
|
42
|
-
showHidden: false,
|
|
43
|
-
depth: 2,
|
|
44
|
-
colors: true
|
|
45
|
-
}, BalmJS.config.logs.formatOptions);
|
|
46
|
-
return pre ? util.inspect(obj, options) : obj;
|
|
47
|
-
};
|
|
48
|
-
success(label, message, options = {}) {
|
|
49
|
-
const logOptions = Object.assign({
|
|
50
|
-
logLevel: BalmJS.LogLevel.Trace
|
|
51
|
-
}, options);
|
|
52
|
-
if (BalmJS.config.logs.level <= logOptions.logLevel) {
|
|
53
|
-
console.log(LOG.beginning);
|
|
54
|
-
fancyLog(LOG.FORMAT, LOG.PREFIX, color(`<${label}>`, LOG.OK), this.#log(message, logOptions.pre));
|
|
55
|
-
console.log(LOG.end);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
debug(label, message, options = {}) {
|
|
59
|
-
const logOptions = Object.assign({
|
|
60
|
-
logLevel: BalmJS.LogLevel.Debug
|
|
61
|
-
}, options);
|
|
62
|
-
if (BalmJS.config.logs.level <= logOptions.logLevel) {
|
|
63
|
-
fancyLog.info(LOG.FORMAT, LOG.PREFIX, color(`<${label}>`, LOG.DEBUG), this.#log(message, logOptions.pre));
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
info(label, message, options = {}) {
|
|
67
|
-
const logOptions = Object.assign({
|
|
68
|
-
logLevel: BalmJS.LogLevel.Info
|
|
69
|
-
}, options);
|
|
70
|
-
if (BalmJS.config.logs.level <= logOptions.logLevel) {
|
|
71
|
-
fancyLog.info(LOG.FORMAT, LOG.PREFIX, color(`<${label}>`, LOG.INFO), this.#log(message, logOptions.pre));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
warn(label, message, options = {}) {
|
|
75
|
-
const logOptions = Object.assign({
|
|
76
|
-
logLevel: BalmJS.LogLevel.Warn
|
|
77
|
-
}, options);
|
|
78
|
-
if (BalmJS.config.logs.level <= logOptions.logLevel) {
|
|
79
|
-
fancyLog.warn(LOG.FORMAT, LOG.PREFIX, color(`<${label}>`, LOG.WARN), this.#log(message, logOptions.pre));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
error(label, message, options = {}) {
|
|
83
|
-
const logOptions = Object.assign({
|
|
84
|
-
logLevel: BalmJS.LogLevel.Error,
|
|
85
|
-
pre: false
|
|
86
|
-
}, options);
|
|
87
|
-
if (BalmJS.config.logs.level <= logOptions.logLevel) {
|
|
88
|
-
fancyLog.error(LOG.FORMAT, LOG.PREFIX, color(`<${label}>`, LOG.ERROR), this.#log(message, logOptions.pre));
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
export default new Logger();
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { PassThrough } from 'node:stream';
|
|
2
|
-
function mergeStream(...args) {
|
|
3
|
-
let sources = [];
|
|
4
|
-
const output = new PassThrough({ objectMode: true });
|
|
5
|
-
output.setMaxListeners(0);
|
|
6
|
-
function remove(source) {
|
|
7
|
-
sources = sources.filter((it) => {
|
|
8
|
-
return it !== source;
|
|
9
|
-
});
|
|
10
|
-
if (!sources.length && output.readable) {
|
|
11
|
-
output.end();
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
function add(source) {
|
|
15
|
-
if (Array.isArray(source)) {
|
|
16
|
-
source.forEach(add);
|
|
17
|
-
return this;
|
|
18
|
-
}
|
|
19
|
-
sources.push(source);
|
|
20
|
-
source.once('end', remove.bind(null, source));
|
|
21
|
-
source.once('error', output.emit.bind(output, 'error'));
|
|
22
|
-
source.pipe(output, { end: false });
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
function isEmpty() {
|
|
26
|
-
return sources.length == 0;
|
|
27
|
-
}
|
|
28
|
-
output.add = add;
|
|
29
|
-
output.isEmpty = isEmpty;
|
|
30
|
-
output.on('unpipe', remove);
|
|
31
|
-
[...args].slice().forEach(add);
|
|
32
|
-
return output;
|
|
33
|
-
}
|
|
34
|
-
export default mergeStream;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const NAMESPACE = 'balm';
|
|
2
|
-
function toNamespace(taskName) {
|
|
3
|
-
let result = 'unknown';
|
|
4
|
-
if (BalmJS.utils.isArray(taskName)) {
|
|
5
|
-
result = taskName.map((name) => `${NAMESPACE}:${name}`);
|
|
6
|
-
}
|
|
7
|
-
else {
|
|
8
|
-
result = `${NAMESPACE}:${taskName}`;
|
|
9
|
-
}
|
|
10
|
-
return result;
|
|
11
|
-
}
|
|
12
|
-
export default toNamespace;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { URL } from 'node:url';
|
|
2
|
-
import { DOMAIN } from '../config/constants.js';
|
|
3
|
-
function getPublicUrlOrPath(homepage, envPublicUrl) {
|
|
4
|
-
const stubDomain = DOMAIN;
|
|
5
|
-
if (envPublicUrl) {
|
|
6
|
-
envPublicUrl = envPublicUrl.endsWith('/')
|
|
7
|
-
? envPublicUrl
|
|
8
|
-
: envPublicUrl + '/';
|
|
9
|
-
const validPublicUrl = new URL(envPublicUrl, stubDomain);
|
|
10
|
-
return BalmJS.config.env.isDev
|
|
11
|
-
? envPublicUrl.startsWith('.')
|
|
12
|
-
? '/'
|
|
13
|
-
: validPublicUrl.pathname
|
|
14
|
-
:
|
|
15
|
-
envPublicUrl;
|
|
16
|
-
}
|
|
17
|
-
if (homepage) {
|
|
18
|
-
homepage = homepage.endsWith('/') ? homepage : homepage + '/';
|
|
19
|
-
const validHomepagePathname = new URL(homepage, stubDomain).pathname;
|
|
20
|
-
return BalmJS.config.env.isDev
|
|
21
|
-
? homepage.startsWith('.')
|
|
22
|
-
? '/'
|
|
23
|
-
: validHomepagePathname
|
|
24
|
-
:
|
|
25
|
-
homepage.startsWith('.')
|
|
26
|
-
? homepage
|
|
27
|
-
: validHomepagePathname;
|
|
28
|
-
}
|
|
29
|
-
return '/';
|
|
30
|
-
}
|
|
31
|
-
export default getPublicUrlOrPath;
|