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,37 +0,0 @@
1
- import { URL } from 'node:url';
2
- import { DOMAIN } from '../config/constants.js';
3
-
4
- /**
5
- * Returns a URL or a path with slash at the end
6
- * In production can be URL, absolute path, relative path
7
- * In development always will be an absolute path
8
- * In development can use `path` module functions for operations
9
- */
10
- function getPublicUrlOrPath(homepage, envPublicUrl) {
11
- const stubDomain = DOMAIN;
12
- if (envPublicUrl) {
13
- // ensure last slash exists
14
- envPublicUrl = envPublicUrl.endsWith('/') ? envPublicUrl : envPublicUrl + '/';
15
-
16
- // validate if `envPublicUrl` is a URL or path like
17
- // `stubDomain` is ignored if `envPublicUrl` contains a domain
18
- const validPublicUrl = new URL(envPublicUrl, stubDomain);
19
- return BalmJS.config.env.isDev ? envPublicUrl.startsWith('.') ? '/' : validPublicUrl.pathname :
20
- // Some apps do not use client-side routing with pushState.
21
- // For these, "homepage" can be set to "." to enable relative asset paths.
22
- envPublicUrl;
23
- }
24
- if (homepage) {
25
- // strip last slash if exists
26
- homepage = homepage.endsWith('/') ? homepage : homepage + '/';
27
-
28
- // validate if `homepage` is a URL or path like and use just pathname
29
- const validHomepagePathname = new URL(homepage, stubDomain).pathname;
30
- return BalmJS.config.env.isDev ? homepage.startsWith('.') ? '/' : validHomepagePathname :
31
- // Some apps do not use client-side routing with pushState.
32
- // For these, "homepage" can be set to "." to enable relative asset paths.
33
- homepage.startsWith('.') ? homepage : validHomepagePathname;
34
- }
35
- return '/';
36
- }
37
- export default getPublicUrlOrPath;
@@ -1,106 +0,0 @@
1
- import { Transform } from 'readable-stream';
2
- import escapeRegExp from './escape-string-regexp.js';
3
- function createReplaceFn(replace, isRegEx) {
4
- function regexReplaceFunction(...args) {
5
- let newReplace = replace;
6
-
7
- // ability to us $1 with captures
8
- // Start at 1 and end at length - 2 to avoid the match parameter and offset
9
- // And string parameters
10
- const paramLength = [...args].length - 2;
11
- for (let i = 1; i < paramLength; i++) {
12
- newReplace = newReplace.replace(new RegExp(`\\$${i}`, 'g'), [...args][i] || '');
13
- }
14
- return newReplace;
15
- }
16
- if (!(replace instanceof Function)) {
17
- return isRegEx ? regexReplaceFunction : () => {
18
- return replace;
19
- };
20
- }
21
- return replace;
22
- }
23
- function matchFromRegex(regex, options) {
24
- if (options.regExpFlags) {
25
- regex = new RegExp(regex.source, options.regExpFlags);
26
- }
27
-
28
- // If there is no global flag then there can only be one match
29
- if (!regex.global) {
30
- options.limit = 1;
31
- }
32
- return regex;
33
- }
34
- function matchFromString(str, options) {
35
- if (options.regExpFlags) {
36
- return new RegExp(escapeRegExp(str), options.regExpFlags);
37
- }
38
- return new RegExp(escapeRegExp(str), options.ignoreCase ? 'gmi' : 'gm');
39
- }
40
- function replaceStream(search, replace, opts) {
41
- const options = Object.assign({
42
- limit: Infinity,
43
- encoding: 'utf8',
44
- maxMatchLen: 100
45
- }, opts);
46
- let tail = '';
47
- let totalMatches = 0;
48
- const isRegex = search instanceof RegExp;
49
- const replaceFn = createReplaceFn(replace, isRegex);
50
- let match;
51
- if (isRegex) {
52
- match = matchFromRegex(search, options);
53
- } else {
54
- match = matchFromString(search, options);
55
- options.maxMatchLen = search.length;
56
- }
57
- function getDataToAppend(before, match) {
58
- let dataToAppend = before;
59
- totalMatches++;
60
- dataToAppend += isRegex ? replaceFn.apply(this, match.concat([match.index.toString(), match.input])) : replaceFn(match[0]);
61
- return dataToAppend;
62
- }
63
- function getDataToQueue(matchCount, haystack, rewritten, lastPos) {
64
- if (matchCount > 0) {
65
- if (haystack.length > tail.length) {
66
- return rewritten + haystack.slice(lastPos, haystack.length - tail.length);
67
- }
68
- return rewritten;
69
- }
70
- return haystack.slice(0, haystack.length - tail.length);
71
- }
72
- function transform(chunk, encoding, callback) {
73
- let matches;
74
- let lastPos = 0;
75
- let matchCount = 0;
76
- let rewritten = '';
77
- const haystack = `${tail}${chunk.toString(options.encoding)}`;
78
- tail = '';
79
- while (totalMatches < options.limit && (matches = match.exec(haystack)) !== null) {
80
- matchCount++;
81
- const before = haystack.slice(lastPos, matches.index);
82
- const regexMatch = matches;
83
- lastPos = matches.index + regexMatch[0].length;
84
- if (lastPos > haystack.length && regexMatch[0].length < options.maxMatchLen) {
85
- tail = regexMatch[0];
86
- } else {
87
- const dataToAppend = getDataToAppend(before, regexMatch);
88
- rewritten += dataToAppend;
89
- }
90
- }
91
- if (tail.length < 1) tail = haystack.slice(lastPos).length > options.maxMatchLen ? haystack.slice(lastPos).slice(0 - options.maxMatchLen) : haystack.slice(lastPos);
92
- const dataToQueue = getDataToQueue(matchCount, haystack, rewritten, lastPos);
93
- callback(null, dataToQueue);
94
- }
95
- function flush(callback) {
96
- if (tail) {
97
- this.push(tail);
98
- }
99
- callback();
100
- }
101
- return new Transform({
102
- transform,
103
- flush
104
- });
105
- }
106
- export default replaceStream;
@@ -1,5 +0,0 @@
1
- const reTypeOf = /(?:^\[object\s(.*?)\]$)/;
2
- function getType(obj) {
3
- return Object.prototype.toString.call(obj).replace(reTypeOf, '$1').toLowerCase();
4
- }
5
- export default getType;
@@ -1,43 +0,0 @@
1
- import getType from './typeof.js';
2
- function isString(str) {
3
- return getType(str) === 'string';
4
- }
5
- function isObject(obj) {
6
- return getType(obj) === 'object';
7
- }
8
- function isArray(arr) {
9
- return Array.isArray(arr);
10
- }
11
- function isFunction(fn) {
12
- const type = getType(fn);
13
- return type === 'function' || type === 'generatorfunction';
14
- }
15
-
16
- // Deep merge two objects
17
- function deepMerge(target, source) {
18
- if (isObject(target) && isObject(source)) {
19
- Object.keys(source).forEach(key => {
20
- if (isObject(source[key])) {
21
- if (!target[key]) {
22
- Object.assign(target, {
23
- [key]: {}
24
- });
25
- }
26
- deepMerge(target[key], source[key]);
27
- } else {
28
- Object.assign(target, {
29
- [key]: source[key]
30
- });
31
- }
32
- });
33
- }
34
- return target;
35
- }
36
- export default {
37
- getType,
38
- isString,
39
- isObject,
40
- isArray,
41
- isFunction,
42
- deepMerge
43
- };
package/tslib/balm.js DELETED
@@ -1,44 +0,0 @@
1
- import './config/index.js';
2
- import './utilities/index.js';
3
- import './plugins/index.js';
4
- import registerTasks from './tasks/index.js';
5
- import { setConfig, setTask } from './bootstrap/index.js';
6
- import loading from './utilities/loading.js';
7
- class Balm {
8
- #config;
9
- constructor() {
10
- BalmJS.loading = false;
11
- loading.succeed();
12
- this.#config = setConfig({});
13
- }
14
- get config() {
15
- return this.#config;
16
- }
17
- set config(value) {
18
- this.#config = setConfig(value);
19
- BalmJS.config = this.#config;
20
- }
21
- set beforeTask(name) {
22
- BalmJS.beforeTask = setTask(name);
23
- }
24
- set afterTask(name) {
25
- BalmJS.afterTask = setTask(name);
26
- }
27
- go(recipe = NOOP) {
28
- if (BalmJS.utils.isFunction(recipe)) {
29
- registerTasks(recipe);
30
- }
31
- else {
32
- BalmJS.logger.error('initialization', 'BalmJS API: `balm.go(mix => {});`');
33
- }
34
- }
35
- reset() {
36
- BalmJS.tasks = new Map();
37
- BalmJS.recipes = [];
38
- BalmJS.recipeIndex = 0;
39
- BalmJS.beforeTask = undefined;
40
- BalmJS.afterTask = undefined;
41
- BalmJS.config.useDefaults = true;
42
- }
43
- }
44
- export default Balm;
@@ -1,36 +0,0 @@
1
- import { DOMAIN } from '../config/constants.js';
2
- const docsBaseURL = `${DOMAIN}/docs/config`;
3
- function upgradeGuide(key, value, message) {
4
- const page = key === 'scripts' ? 'scripts-webpack' : key.toLowerCase();
5
- return `${message} See ${docsBaseURL}/${page}.html#${key}-${value.toLowerCase()}`;
6
- }
7
- function upgradeRenamed(version, configCategory, from, to) {
8
- if (BalmJS.config[configCategory][from]) {
9
- BalmJS.logger.warn(`balm@${version}+ config`, upgradeGuide(configCategory, to, `'${configCategory}.${from}' was renamed to '${configCategory}.${to}'.`));
10
- }
11
- }
12
- function upgradeMigrated(version, configName, from, to) {
13
- if (BalmJS.config[from][configName]) {
14
- BalmJS.logger.warn(`balm@${version}+ config`, upgradeGuide(to, configName, `'${from}.${configName}' was migrated to '${to}.${configName}'.`));
15
- }
16
- }
17
- function upgradeDeprecated(version, configCategory, configName) {
18
- if (BalmJS.config[configCategory][configName]) {
19
- BalmJS.logger.warn(`balm@${version}+ config`, `'${configCategory}.${configName}' was deprecated.`);
20
- }
21
- }
22
- function checkConfig() {
23
- upgradeRenamed('2.5.0', 'scripts', 'disableDefaultLoaders', 'defaultLoaders');
24
- upgradeMigrated('2.11.0', 'postcssLoaderOptions', 'styles', 'scripts');
25
- upgradeRenamed('2.22.0', 'images', 'defaultPlugins', 'plugins');
26
- upgradeRenamed('3.0.0', 'styles', 'minified', 'minify');
27
- upgradeRenamed('3.9.0', 'scripts', 'options', 'minifyOptions');
28
- upgradeRenamed('3.16.0', 'scripts', 'inject', 'useCache');
29
- upgradeDeprecated('3.17.0', 'styles', 'darkSass');
30
- upgradeDeprecated('3.19.0', 'scripts', 'useCache');
31
- upgradeDeprecated('4.0.0', 'scripts', 'libraryTarget');
32
- upgradeDeprecated('4.5.0', 'scripts', 'excludeUrlResource');
33
- upgradeDeprecated('4.5.0', 'scripts', 'urlLoaderOptions');
34
- upgradeRenamed('4.29.0', 'server', 'proxyConfig', 'proxyOptions');
35
- }
36
- export default checkConfig;
@@ -1,82 +0,0 @@
1
- import checkConfig from './check_config.js';
2
- import { ASSETS_TYPES } from '../config/constants.js';
3
- function createQuickPath(config, rootKey) {
4
- const result = {};
5
- const rootValue = config.roots[rootKey];
6
- for (const pathKey of Object.keys(config.paths[rootKey])) {
7
- const pathValue = config.paths[rootKey][pathKey];
8
- result[pathKey] =
9
- rootKey === 'target' && ASSETS_TYPES.includes(pathKey)
10
- ? node.path.join(rootValue, BalmJS.config.assets.virtualDir, BalmJS.file.assetsSuffixPath, pathValue)
11
- : node.path.join(rootValue, pathValue);
12
- }
13
- return rootKey === 'source'
14
- ? result
15
- : result;
16
- }
17
- function ready(config) {
18
- config.src = createQuickPath(config, 'source');
19
- config.dest = createQuickPath(config, config.env.isProd || !config.inFrontend ? 'target' : 'tmp');
20
- config.dest.static = node.path.join(config.dest.base, BalmJS.config.assets.virtualDir, BalmJS.file.assetsSuffixPath);
21
- config.assets.static = node.path.join(config.assets.root, config.assets.mainDir, BalmJS.file.assetsSuffixPath);
22
- for (const assetType of ASSETS_TYPES) {
23
- config.assets[assetType] = node.path.join(config.assets.static, config.paths.target[assetType]);
24
- }
25
- const HMR_ENV = config.useDefaults &&
26
- config.env.isDev &&
27
- !config.env.inSSR &&
28
- !config.env.isMP;
29
- const HMR_Enabling = config.scripts.bundler === BalmJS.Bundler.webpack && !config.scripts.ie8;
30
- config.server.useHMR = HMR_ENV && HMR_Enabling;
31
- if (/^electron-.*/.test(config.scripts.target)) {
32
- config.env.inDesktopApp = true;
33
- }
34
- config.scripts.useCache =
35
- config.env.isProd && config.assets.cache && config.scripts.injectHtml;
36
- return config;
37
- }
38
- function resetConfig() {
39
- BalmJS.config.roots.target = 'dist';
40
- BalmJS.config.roots.tmp = '.tmp';
41
- return BalmJS.config;
42
- }
43
- function setConfig(customConfig) {
44
- const defaultConfig = resetConfig();
45
- const newConfig = BalmJS.utils.deepMerge(defaultConfig, customConfig);
46
- checkConfig();
47
- let config = BalmJS.utils.deepMerge(newConfig, {
48
- paths: {
49
- tmp: newConfig.paths.target
50
- }
51
- });
52
- if (!config.inFrontend) {
53
- if (config.roots.target === 'dist') {
54
- config.roots.target = config.assets.mainDir;
55
- }
56
- config.roots.tmp = config.roots.target;
57
- }
58
- config = ready(config);
59
- BalmJS.logger.success('balm configuration', config, {
60
- pre: true
61
- });
62
- return config;
63
- }
64
- function setTask(name) {
65
- let result = undefined;
66
- if (BalmJS.utils.isFunction(name)) {
67
- result = name;
68
- }
69
- else if (BalmJS.utils.isString(name)) {
70
- if (gulp.tree().nodes.includes(name)) {
71
- result = name;
72
- }
73
- else {
74
- BalmJS.logger.error('before/end task', 'Invalid gulp task name');
75
- }
76
- }
77
- else {
78
- BalmJS.logger.error('before/end task', 'Task must be a string (gulp task name) or function');
79
- }
80
- return result;
81
- }
82
- export { setConfig, setTask };
@@ -1,30 +0,0 @@
1
- import { build } from 'esbuild';
2
- import { minifyOptions } from './options.js';
3
- const esBuild = (entryPoints, output, customBuildOptions, callback) => {
4
- const defaultBuildOptions = {
5
- entryPoints: BalmJS.file.absPaths(entryPoints),
6
- outdir: BalmJS.file.absPath(output),
7
- bundle: BalmJS.config.env.isProd
8
- };
9
- const buildOptions = BalmJS.config.env.isProd
10
- ? Object.assign(defaultBuildOptions, minifyOptions)
11
- : defaultBuildOptions;
12
- const options = Object.assign(buildOptions, BalmJS.config.scripts.buildOptions, customBuildOptions);
13
- BalmJS.logger.debug('esbuild bundler - build', {
14
- input: options.entryPoints,
15
- output: options.outdir
16
- }, {
17
- pre: true
18
- });
19
- BalmJS.logger.success('esbuild options', options, {
20
- pre: true
21
- });
22
- build(options)
23
- .catch((error) => {
24
- BalmJS.logger.error('esbuild', error.message);
25
- })
26
- .finally(() => {
27
- callback();
28
- });
29
- };
30
- export default esBuild;
@@ -1,11 +0,0 @@
1
- import build from './build.js';
2
- import transform from './transform.js';
3
- const esbuild = (input, output, customOptions, callback) => {
4
- const entryPoints = BalmJS.utils.isString(input)
5
- ? [input]
6
- : input;
7
- BalmJS.config.scripts.useTransform
8
- ? transform(entryPoints, output, customOptions, callback)
9
- : build(entryPoints, output, customOptions, callback);
10
- };
11
- export default esbuild;
@@ -1,7 +0,0 @@
1
- const minifyOptions = {
2
- minify: true,
3
- minifyWhitespace: true,
4
- minifyIdentifiers: true,
5
- minifySyntax: true
6
- };
7
- export { minifyOptions };
@@ -1,38 +0,0 @@
1
- import { transform } from 'esbuild';
2
- import { minifyOptions } from './options.js';
3
- const esTransform = (entryPoints, output, customTransformOptions, callback) => {
4
- const build = {
5
- output: BalmJS.file.absPath(output)
6
- };
7
- const transformOptions = BalmJS.config.env.isProd
8
- ? Object.assign({}, minifyOptions)
9
- : {};
10
- const options = Object.assign(transformOptions, BalmJS.config.scripts.transformOptions, customTransformOptions);
11
- (async () => {
12
- try {
13
- for await (const entryPoint of entryPoints) {
14
- build.input = BalmJS.file.absPath(entryPoint);
15
- BalmJS.logger.debug('esbuild bundler - transform', {
16
- input: build.input,
17
- output: build.output
18
- }, {
19
- pre: true
20
- });
21
- const filename = entryPoint.split('/').pop();
22
- if (filename && node.fs.existsSync(build.input)) {
23
- const inputCode = node.fs.readFileSync(build.input, 'utf8');
24
- const result = await transform(inputCode, options);
25
- node.fs.mkdirSync(build.output, { recursive: true });
26
- node.fs.writeFileSync(node.path.join(build.output, filename), result.code);
27
- }
28
- else {
29
- BalmJS.logger.warn('esbuild', `Invalid entry point: ${entryPoint}`);
30
- }
31
- }
32
- }
33
- finally {
34
- callback();
35
- }
36
- })();
37
- };
38
- export default esTransform;
@@ -1,17 +0,0 @@
1
- const build = async (bundle, outputOptions) => {
2
- const { output } = await bundle.generate(outputOptions);
3
- for (const chunkOrAsset of output) {
4
- if (chunkOrAsset.type === 'asset') {
5
- BalmJS.logger.debug('rollup bundler - Asset', chunkOrAsset, {
6
- pre: true
7
- });
8
- }
9
- else {
10
- BalmJS.logger.debug('rollup bundler - Chunk', chunkOrAsset.modules, {
11
- pre: true
12
- });
13
- }
14
- }
15
- return await bundle.write(outputOptions);
16
- };
17
- export default build;
@@ -1,24 +0,0 @@
1
- import { getInputPlugins } from './plugins.js';
2
- function getEntry(inputOptions) {
3
- const inputPlugins = getInputPlugins(inputOptions);
4
- const options = Object.assign({}, BalmJS.config.scripts.inputOptions, inputOptions);
5
- options.plugins = inputPlugins;
6
- const { input } = options;
7
- let rollupEntries = input;
8
- if (BalmJS.utils.isObject(input)) {
9
- const entries = input;
10
- Object.keys(entries).forEach((entryAlias) => {
11
- entries[entryAlias] = BalmJS.file.absPath(entries[entryAlias]);
12
- });
13
- rollupEntries = entries;
14
- }
15
- else {
16
- rollupEntries = BalmJS.file.absPaths(input);
17
- }
18
- options.input = rollupEntries;
19
- BalmJS.logger.debug('rollup input options', options, {
20
- pre: true
21
- });
22
- return options;
23
- }
24
- export default getEntry;
@@ -1,21 +0,0 @@
1
- import { rollup } from 'rollup';
2
- import getEntry from './entry.js';
3
- import getOutput from './output.js';
4
- import build from './build.js';
5
- const buildLibrary = async (inputOptions, outputOptions) => {
6
- inputOptions = getEntry(inputOptions);
7
- outputOptions = getOutput(outputOptions);
8
- const rollupOptions = Object.assign({}, inputOptions, {
9
- output: outputOptions
10
- });
11
- const bundle = await rollup(rollupOptions);
12
- if (Array.isArray(outputOptions)) {
13
- for await (const outputOption of outputOptions) {
14
- await build(bundle, outputOption);
15
- }
16
- }
17
- else {
18
- await build(bundle, outputOptions);
19
- }
20
- };
21
- export default buildLibrary;
@@ -1,23 +0,0 @@
1
- import { getOutputPlugins } from './plugins.js';
2
- function setOutput(outputOptions) {
3
- const outputPlugins = getOutputPlugins(outputOptions);
4
- outputOptions = Object.assign({}, BalmJS.config.scripts.outputOptions, outputOptions);
5
- outputOptions.plugins = outputPlugins;
6
- if (outputOptions.dir) {
7
- outputOptions.dir = BalmJS.file.absPath(outputOptions.dir);
8
- }
9
- else {
10
- outputOptions.file = BalmJS.file.absPath(outputOptions.file);
11
- }
12
- return outputOptions;
13
- }
14
- function getOutput(outputOptions) {
15
- const options = Array.isArray(outputOptions)
16
- ? outputOptions.map((outputOption) => setOutput(outputOption))
17
- : setOutput(outputOptions);
18
- BalmJS.logger.debug('rollup output options', options, {
19
- pre: true
20
- });
21
- return options;
22
- }
23
- export default getOutput;
@@ -1,27 +0,0 @@
1
- import terser from '@rollup/plugin-terser';
2
- function getInputPlugins(customInputOptions) {
3
- const { inputOptions } = BalmJS.config.scripts;
4
- const inputPlugins = [];
5
- if (inputOptions.plugins) {
6
- inputPlugins.push(...inputOptions.plugins);
7
- }
8
- if (customInputOptions.plugins) {
9
- inputPlugins.push(...customInputOptions.plugins);
10
- }
11
- return inputPlugins;
12
- }
13
- function getOutputPlugins(customOutputOptions) {
14
- const { outputOptions } = BalmJS.config.scripts;
15
- const outputPlugins = [];
16
- if (outputOptions.plugins) {
17
- outputPlugins.push(...outputOptions.plugins);
18
- }
19
- if (BalmJS.config.env.isProd) {
20
- outputPlugins.push(terser(BalmJS.config.scripts.minifyOptions));
21
- }
22
- if (customOutputOptions.plugins) {
23
- outputPlugins.push(...customOutputOptions.plugins);
24
- }
25
- return outputPlugins;
26
- }
27
- export { getInputPlugins, getOutputPlugins };