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.
Files changed (301) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/index.cjs +2625 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +569 -0
  5. package/dist/index.d.ts +569 -0
  6. package/dist/index.js +2527 -0
  7. package/dist/index.js.map +1 -0
  8. package/package.json +49 -123
  9. package/src/balm.ts +108 -0
  10. package/src/bundler/esbuild.ts +47 -0
  11. package/src/bundler/index.ts +3 -0
  12. package/src/bundler/rollup.ts +45 -0
  13. package/src/bundler/webpack.ts +124 -0
  14. package/src/config/constants.ts +12 -0
  15. package/src/config/defaults.ts +209 -0
  16. package/src/config/index.ts +112 -0
  17. package/src/hooks/index.ts +224 -0
  18. package/src/index.ts +16 -0
  19. package/src/pipeline/file.ts +69 -0
  20. package/src/pipeline/index.ts +10 -0
  21. package/src/pipeline/pipeline.ts +135 -0
  22. package/src/pipeline/transforms/cache.ts +146 -0
  23. package/src/pipeline/transforms/htmlmin.ts +18 -0
  24. package/src/pipeline/transforms/less.ts +75 -0
  25. package/src/pipeline/transforms/postcss.ts +43 -0
  26. package/src/pipeline/transforms/rename.ts +37 -0
  27. package/src/pipeline/transforms/replace.ts +30 -0
  28. package/src/pipeline/transforms/sass.ts +106 -0
  29. package/src/pipeline/transforms/terser.ts +20 -0
  30. package/src/runner/dag.ts +77 -0
  31. package/src/runner/task.ts +38 -0
  32. package/src/shims.d.ts +5 -0
  33. package/src/tasks/cache.ts +72 -0
  34. package/src/tasks/clean.ts +21 -0
  35. package/src/tasks/copy.ts +36 -0
  36. package/src/tasks/ftp.ts +90 -0
  37. package/src/tasks/html.ts +232 -0
  38. package/src/tasks/index.ts +14 -0
  39. package/src/tasks/publish.ts +71 -0
  40. package/src/tasks/pwa.ts +99 -0
  41. package/src/tasks/remove.ts +24 -0
  42. package/src/tasks/replace.ts +34 -0
  43. package/src/tasks/script.ts +28 -0
  44. package/src/tasks/server.ts +183 -0
  45. package/src/tasks/static.ts +104 -0
  46. package/src/tasks/style.ts +57 -0
  47. package/src/tasks/zip.ts +65 -0
  48. package/src/types/index.ts +202 -0
  49. package/src/utilities/file.ts +120 -0
  50. package/src/utilities/logger.ts +63 -0
  51. package/src/utilities/utils.ts +46 -0
  52. package/src/utilities/workspace.ts +38 -0
  53. package/src/watcher/index.ts +100 -0
  54. package/tsconfig.json +8 -0
  55. package/tsup.config.ts +12 -0
  56. package/README.md +0 -196
  57. package/index.d.ts +0 -360
  58. package/lib/balm.js +0 -49
  59. package/lib/bootstrap/check_config.js +0 -43
  60. package/lib/bootstrap/index.js +0 -87
  61. package/lib/bundler/esbuild/build.js +0 -26
  62. package/lib/bundler/esbuild/index.js +0 -7
  63. package/lib/bundler/esbuild/options.js +0 -7
  64. package/lib/bundler/esbuild/transform.js +0 -36
  65. package/lib/bundler/rollup/build.js +0 -52
  66. package/lib/bundler/rollup/entry.js +0 -28
  67. package/lib/bundler/rollup/index.js +0 -20
  68. package/lib/bundler/rollup/output.js +0 -20
  69. package/lib/bundler/rollup/plugins.js +0 -31
  70. package/lib/bundler/webpack/config/common.js +0 -135
  71. package/lib/bundler/webpack/config/dev.js +0 -12
  72. package/lib/bundler/webpack/config/env.js +0 -67
  73. package/lib/bundler/webpack/config/index.js +0 -6
  74. package/lib/bundler/webpack/config/prod.js +0 -39
  75. package/lib/bundler/webpack/config/regex.js +0 -10
  76. package/lib/bundler/webpack/entry.js +0 -65
  77. package/lib/bundler/webpack/index.js +0 -32
  78. package/lib/bundler/webpack/loaders.js +0 -50
  79. package/lib/bundler/webpack/output.js +0 -41
  80. package/lib/bundler/webpack/rules/asset.js +0 -33
  81. package/lib/bundler/webpack/rules/babel.js +0 -19
  82. package/lib/bundler/webpack/rules/css.js +0 -109
  83. package/lib/bundler/webpack/rules/html.js +0 -15
  84. package/lib/bundler/webpack/rules/index.js +0 -10
  85. package/lib/config/assets.js +0 -30
  86. package/lib/config/constants.js +0 -14
  87. package/lib/config/env.js +0 -35
  88. package/lib/config/extras.js +0 -6
  89. package/lib/config/ftp.js +0 -6
  90. package/lib/config/globals.js +0 -43
  91. package/lib/config/html.js +0 -22
  92. package/lib/config/images.js +0 -4
  93. package/lib/config/index.js +0 -63
  94. package/lib/config/logs.js +0 -11
  95. package/lib/config/paths.js +0 -46
  96. package/lib/config/pwa.js +0 -24
  97. package/lib/config/roots.js +0 -9
  98. package/lib/config/scripts.js +0 -162
  99. package/lib/config/server.js +0 -84
  100. package/lib/config/spinner.js +0 -9
  101. package/lib/config/styles.js +0 -67
  102. package/lib/hello.js +0 -19
  103. package/lib/hooks/index.js +0 -94
  104. package/lib/hooks/maker.js +0 -59
  105. package/lib/index.js +0 -5
  106. package/lib/middlewares/history.js +0 -6
  107. package/lib/middlewares/index.js +0 -11
  108. package/lib/middlewares/proxy.js +0 -28
  109. package/lib/middlewares/webpack.js +0 -26
  110. package/lib/plugins/htmlmin.js +0 -39
  111. package/lib/plugins/imagemin.js +0 -95
  112. package/lib/plugins/index.js +0 -27
  113. package/lib/plugins/jsmin.js +0 -37
  114. package/lib/plugins/less.js +0 -97
  115. package/lib/plugins/plumber.js +0 -87
  116. package/lib/plugins/postcss-plugins.js +0 -13
  117. package/lib/plugins/postcss.js +0 -117
  118. package/lib/plugins/rename.js +0 -51
  119. package/lib/plugins/replace.js +0 -91
  120. package/lib/plugins/sass-legacy.js +0 -131
  121. package/lib/plugins/sass.js +0 -134
  122. package/lib/plugins/sftp.js +0 -288
  123. package/lib/tasks/default.js +0 -46
  124. package/lib/tasks/foundation/balm.js +0 -72
  125. package/lib/tasks/foundation/balm_style.js +0 -65
  126. package/lib/tasks/foundation/index.js +0 -10
  127. package/lib/tasks/index.js +0 -48
  128. package/lib/tasks/private/build.js +0 -18
  129. package/lib/tasks/private/cache.js +0 -31
  130. package/lib/tasks/private/clean.js +0 -69
  131. package/lib/tasks/private/end.js +0 -24
  132. package/lib/tasks/private/extra.js +0 -35
  133. package/lib/tasks/private/font.js +0 -15
  134. package/lib/tasks/private/image.js +0 -37
  135. package/lib/tasks/private/index.js +0 -34
  136. package/lib/tasks/private/lint.js +0 -20
  137. package/lib/tasks/private/media.js +0 -15
  138. package/lib/tasks/private/modernizr.js +0 -59
  139. package/lib/tasks/private/pwa-cache.js +0 -32
  140. package/lib/tasks/private/script.js +0 -9
  141. package/lib/tasks/private/sprite.js +0 -105
  142. package/lib/tasks/private/start.js +0 -16
  143. package/lib/tasks/private/style.js +0 -9
  144. package/lib/tasks/private/workbox-sw.js +0 -15
  145. package/lib/tasks/public/copy.js +0 -16
  146. package/lib/tasks/public/esbuild.js +0 -18
  147. package/lib/tasks/public/ftp.js +0 -39
  148. package/lib/tasks/public/html.js +0 -65
  149. package/lib/tasks/public/index.js +0 -38
  150. package/lib/tasks/public/jsmin.js +0 -23
  151. package/lib/tasks/public/less.js +0 -21
  152. package/lib/tasks/public/postcss.js +0 -16
  153. package/lib/tasks/public/publish.js +0 -51
  154. package/lib/tasks/public/pwa.js +0 -84
  155. package/lib/tasks/public/remove.js +0 -46
  156. package/lib/tasks/public/replace.js +0 -26
  157. package/lib/tasks/public/rollup.js +0 -17
  158. package/lib/tasks/public/sass.js +0 -27
  159. package/lib/tasks/public/server.js +0 -130
  160. package/lib/tasks/public/url.js +0 -35
  161. package/lib/tasks/public/version.js +0 -23
  162. package/lib/tasks/public/webpack.js +0 -39
  163. package/lib/tasks/public/zip.js +0 -19
  164. package/lib/utilities/address.js +0 -55
  165. package/lib/utilities/cache-core.js +0 -66
  166. package/lib/utilities/color.js +0 -27
  167. package/lib/utilities/compiling.js +0 -24
  168. package/lib/utilities/detect-port.js +0 -100
  169. package/lib/utilities/escape-string-regexp.js +0 -10
  170. package/lib/utilities/file.js +0 -70
  171. package/lib/utilities/index.js +0 -8
  172. package/lib/utilities/loading.js +0 -37
  173. package/lib/utilities/logger.js +0 -99
  174. package/lib/utilities/merge-stream.js +0 -38
  175. package/lib/utilities/namespace.js +0 -11
  176. package/lib/utilities/public-url.js +0 -37
  177. package/lib/utilities/replacestream.js +0 -106
  178. package/lib/utilities/typeof.js +0 -5
  179. package/lib/utilities/utils.js +0 -43
  180. package/tslib/balm.js +0 -44
  181. package/tslib/bootstrap/check_config.js +0 -36
  182. package/tslib/bootstrap/index.js +0 -82
  183. package/tslib/bundler/esbuild/build.js +0 -30
  184. package/tslib/bundler/esbuild/index.js +0 -11
  185. package/tslib/bundler/esbuild/options.js +0 -7
  186. package/tslib/bundler/esbuild/transform.js +0 -38
  187. package/tslib/bundler/rollup/build.js +0 -17
  188. package/tslib/bundler/rollup/entry.js +0 -24
  189. package/tslib/bundler/rollup/index.js +0 -21
  190. package/tslib/bundler/rollup/output.js +0 -23
  191. package/tslib/bundler/rollup/plugins.js +0 -27
  192. package/tslib/bundler/webpack/config/common.js +0 -130
  193. package/tslib/bundler/webpack/config/dev.js +0 -14
  194. package/tslib/bundler/webpack/config/env.js +0 -44
  195. package/tslib/bundler/webpack/config/index.js +0 -8
  196. package/tslib/bundler/webpack/config/prod.js +0 -43
  197. package/tslib/bundler/webpack/config/regex.js +0 -10
  198. package/tslib/bundler/webpack/entry.js +0 -68
  199. package/tslib/bundler/webpack/index.js +0 -30
  200. package/tslib/bundler/webpack/loaders.js +0 -51
  201. package/tslib/bundler/webpack/output.js +0 -41
  202. package/tslib/bundler/webpack/rules/asset.js +0 -33
  203. package/tslib/bundler/webpack/rules/babel.js +0 -16
  204. package/tslib/bundler/webpack/rules/css.js +0 -95
  205. package/tslib/bundler/webpack/rules/html.js +0 -15
  206. package/tslib/bundler/webpack/rules/index.js +0 -10
  207. package/tslib/config/assets.js +0 -24
  208. package/tslib/config/constants.js +0 -14
  209. package/tslib/config/env.js +0 -43
  210. package/tslib/config/extras.js +0 -6
  211. package/tslib/config/ftp.js +0 -6
  212. package/tslib/config/globals.js +0 -47
  213. package/tslib/config/html.js +0 -17
  214. package/tslib/config/images.js +0 -4
  215. package/tslib/config/index.js +0 -56
  216. package/tslib/config/logs.js +0 -6
  217. package/tslib/config/paths.js +0 -30
  218. package/tslib/config/pwa.js +0 -18
  219. package/tslib/config/roots.js +0 -8
  220. package/tslib/config/scripts.js +0 -93
  221. package/tslib/config/server.js +0 -33
  222. package/tslib/config/spinner.js +0 -10
  223. package/tslib/config/styles.js +0 -37
  224. package/tslib/hello.js +0 -19
  225. package/tslib/hooks/index.js +0 -75
  226. package/tslib/hooks/maker.js +0 -66
  227. package/tslib/index.js +0 -5
  228. package/tslib/middlewares/history.js +0 -12
  229. package/tslib/middlewares/index.js +0 -18
  230. package/tslib/middlewares/proxy.js +0 -27
  231. package/tslib/middlewares/webpack.js +0 -29
  232. package/tslib/plugins/htmlmin.js +0 -38
  233. package/tslib/plugins/imagemin.js +0 -97
  234. package/tslib/plugins/index.js +0 -27
  235. package/tslib/plugins/jsmin.js +0 -39
  236. package/tslib/plugins/less.js +0 -90
  237. package/tslib/plugins/plumber.js +0 -81
  238. package/tslib/plugins/postcss-plugins.js +0 -24
  239. package/tslib/plugins/postcss.js +0 -111
  240. package/tslib/plugins/rename.js +0 -51
  241. package/tslib/plugins/replace.js +0 -72
  242. package/tslib/plugins/sass-legacy.js +0 -95
  243. package/tslib/plugins/sass.js +0 -109
  244. package/tslib/plugins/sftp.js +0 -258
  245. package/tslib/tasks/default.js +0 -59
  246. package/tslib/tasks/foundation/balm.js +0 -75
  247. package/tslib/tasks/foundation/balm_style.js +0 -68
  248. package/tslib/tasks/foundation/index.js +0 -10
  249. package/tslib/tasks/index.js +0 -43
  250. package/tslib/tasks/private/build.js +0 -15
  251. package/tslib/tasks/private/cache.js +0 -48
  252. package/tslib/tasks/private/clean.js +0 -82
  253. package/tslib/tasks/private/end.js +0 -21
  254. package/tslib/tasks/private/extra.js +0 -34
  255. package/tslib/tasks/private/font.js +0 -12
  256. package/tslib/tasks/private/image.js +0 -42
  257. package/tslib/tasks/private/index.js +0 -34
  258. package/tslib/tasks/private/lint.js +0 -17
  259. package/tslib/tasks/private/media.js +0 -12
  260. package/tslib/tasks/private/modernizr.js +0 -54
  261. package/tslib/tasks/private/pwa-cache.js +0 -32
  262. package/tslib/tasks/private/script.js +0 -9
  263. package/tslib/tasks/private/sprite.js +0 -93
  264. package/tslib/tasks/private/start.js +0 -13
  265. package/tslib/tasks/private/style.js +0 -12
  266. package/tslib/tasks/private/workbox-sw.js +0 -15
  267. package/tslib/tasks/public/copy.js +0 -18
  268. package/tslib/tasks/public/esbuild.js +0 -18
  269. package/tslib/tasks/public/ftp.js +0 -39
  270. package/tslib/tasks/public/html.js +0 -75
  271. package/tslib/tasks/public/index.js +0 -38
  272. package/tslib/tasks/public/jsmin.js +0 -24
  273. package/tslib/tasks/public/less.js +0 -21
  274. package/tslib/tasks/public/postcss.js +0 -16
  275. package/tslib/tasks/public/publish.js +0 -50
  276. package/tslib/tasks/public/pwa.js +0 -87
  277. package/tslib/tasks/public/remove.js +0 -44
  278. package/tslib/tasks/public/replace.js +0 -27
  279. package/tslib/tasks/public/rollup.js +0 -17
  280. package/tslib/tasks/public/sass.js +0 -27
  281. package/tslib/tasks/public/server.js +0 -129
  282. package/tslib/tasks/public/url.js +0 -35
  283. package/tslib/tasks/public/version.js +0 -27
  284. package/tslib/tasks/public/webpack.js +0 -41
  285. package/tslib/tasks/public/zip.js +0 -19
  286. package/tslib/utilities/address.js +0 -48
  287. package/tslib/utilities/cache-core.js +0 -57
  288. package/tslib/utilities/color.js +0 -33
  289. package/tslib/utilities/compiling.js +0 -16
  290. package/tslib/utilities/detect-port.js +0 -91
  291. package/tslib/utilities/escape-string-regexp.js +0 -7
  292. package/tslib/utilities/file.js +0 -78
  293. package/tslib/utilities/index.js +0 -8
  294. package/tslib/utilities/loading.js +0 -25
  295. package/tslib/utilities/logger.js +0 -92
  296. package/tslib/utilities/merge-stream.js +0 -34
  297. package/tslib/utilities/namespace.js +0 -12
  298. package/tslib/utilities/public-url.js +0 -31
  299. package/tslib/utilities/replacestream.js +0 -112
  300. package/tslib/utilities/typeof.js +0 -8
  301. 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;
@@ -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;
@@ -1,7 +0,0 @@
1
- const escapeStringRegexp = (str) => {
2
- if (typeof str !== 'string') {
3
- throw new TypeError('Expected a string');
4
- }
5
- return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
6
- };
7
- export default escapeStringRegexp;
@@ -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();
@@ -1,8 +0,0 @@
1
- import utils from './utils.js';
2
- import logger from './logger.js';
3
- import file from './file.js';
4
- import toNamespace from './namespace.js';
5
- BalmJS.utils = utils;
6
- BalmJS.logger = logger;
7
- BalmJS.file = file;
8
- BalmJS.toNamespace = toNamespace;
@@ -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;