balm-core 5.2.0 → 6.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (299) hide show
  1. package/dist/index.cjs +2191 -0
  2. package/dist/index.cjs.map +1 -0
  3. package/dist/index.d.cts +559 -0
  4. package/dist/index.d.ts +559 -0
  5. package/dist/index.js +2098 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +48 -123
  8. package/src/balm.ts +103 -0
  9. package/src/bundler/esbuild.ts +47 -0
  10. package/src/bundler/index.ts +3 -0
  11. package/src/bundler/rollup.ts +39 -0
  12. package/src/bundler/webpack.ts +82 -0
  13. package/src/config/constants.ts +12 -0
  14. package/src/config/defaults.ts +209 -0
  15. package/src/config/index.ts +112 -0
  16. package/src/hooks/index.ts +192 -0
  17. package/src/index.ts +16 -0
  18. package/src/pipeline/file.ts +69 -0
  19. package/src/pipeline/index.ts +10 -0
  20. package/src/pipeline/pipeline.ts +132 -0
  21. package/src/pipeline/transforms/cache.ts +96 -0
  22. package/src/pipeline/transforms/htmlmin.ts +18 -0
  23. package/src/pipeline/transforms/less.ts +75 -0
  24. package/src/pipeline/transforms/postcss.ts +43 -0
  25. package/src/pipeline/transforms/rename.ts +37 -0
  26. package/src/pipeline/transforms/replace.ts +30 -0
  27. package/src/pipeline/transforms/sass.ts +106 -0
  28. package/src/pipeline/transforms/terser.ts +20 -0
  29. package/src/runner/dag.ts +77 -0
  30. package/src/runner/task.ts +38 -0
  31. package/src/shims.d.ts +5 -0
  32. package/src/tasks/cache.ts +58 -0
  33. package/src/tasks/clean.ts +21 -0
  34. package/src/tasks/copy.ts +36 -0
  35. package/src/tasks/ftp.ts +90 -0
  36. package/src/tasks/html.ts +78 -0
  37. package/src/tasks/index.ts +13 -0
  38. package/src/tasks/publish.ts +71 -0
  39. package/src/tasks/pwa.ts +49 -0
  40. package/src/tasks/remove.ts +24 -0
  41. package/src/tasks/replace.ts +34 -0
  42. package/src/tasks/script.ts +28 -0
  43. package/src/tasks/server.ts +89 -0
  44. package/src/tasks/style.ts +57 -0
  45. package/src/tasks/zip.ts +65 -0
  46. package/src/types/index.ts +200 -0
  47. package/src/utilities/file.ts +120 -0
  48. package/src/utilities/logger.ts +63 -0
  49. package/src/utilities/utils.ts +46 -0
  50. package/src/utilities/workspace.ts +38 -0
  51. package/src/watcher/index.ts +100 -0
  52. package/tsconfig.json +8 -0
  53. package/tsup.config.ts +12 -0
  54. package/README.md +0 -196
  55. package/index.d.ts +0 -360
  56. package/lib/balm.js +0 -49
  57. package/lib/bootstrap/check_config.js +0 -43
  58. package/lib/bootstrap/index.js +0 -87
  59. package/lib/bundler/esbuild/build.js +0 -26
  60. package/lib/bundler/esbuild/index.js +0 -7
  61. package/lib/bundler/esbuild/options.js +0 -7
  62. package/lib/bundler/esbuild/transform.js +0 -36
  63. package/lib/bundler/rollup/build.js +0 -52
  64. package/lib/bundler/rollup/entry.js +0 -28
  65. package/lib/bundler/rollup/index.js +0 -20
  66. package/lib/bundler/rollup/output.js +0 -20
  67. package/lib/bundler/rollup/plugins.js +0 -31
  68. package/lib/bundler/webpack/config/common.js +0 -135
  69. package/lib/bundler/webpack/config/dev.js +0 -12
  70. package/lib/bundler/webpack/config/env.js +0 -67
  71. package/lib/bundler/webpack/config/index.js +0 -6
  72. package/lib/bundler/webpack/config/prod.js +0 -39
  73. package/lib/bundler/webpack/config/regex.js +0 -10
  74. package/lib/bundler/webpack/entry.js +0 -65
  75. package/lib/bundler/webpack/index.js +0 -32
  76. package/lib/bundler/webpack/loaders.js +0 -50
  77. package/lib/bundler/webpack/output.js +0 -41
  78. package/lib/bundler/webpack/rules/asset.js +0 -33
  79. package/lib/bundler/webpack/rules/babel.js +0 -19
  80. package/lib/bundler/webpack/rules/css.js +0 -109
  81. package/lib/bundler/webpack/rules/html.js +0 -15
  82. package/lib/bundler/webpack/rules/index.js +0 -10
  83. package/lib/config/assets.js +0 -30
  84. package/lib/config/constants.js +0 -14
  85. package/lib/config/env.js +0 -35
  86. package/lib/config/extras.js +0 -6
  87. package/lib/config/ftp.js +0 -6
  88. package/lib/config/globals.js +0 -43
  89. package/lib/config/html.js +0 -22
  90. package/lib/config/images.js +0 -4
  91. package/lib/config/index.js +0 -63
  92. package/lib/config/logs.js +0 -11
  93. package/lib/config/paths.js +0 -46
  94. package/lib/config/pwa.js +0 -24
  95. package/lib/config/roots.js +0 -9
  96. package/lib/config/scripts.js +0 -162
  97. package/lib/config/server.js +0 -84
  98. package/lib/config/spinner.js +0 -9
  99. package/lib/config/styles.js +0 -67
  100. package/lib/hello.js +0 -19
  101. package/lib/hooks/index.js +0 -94
  102. package/lib/hooks/maker.js +0 -59
  103. package/lib/index.js +0 -5
  104. package/lib/middlewares/history.js +0 -6
  105. package/lib/middlewares/index.js +0 -11
  106. package/lib/middlewares/proxy.js +0 -28
  107. package/lib/middlewares/webpack.js +0 -26
  108. package/lib/plugins/htmlmin.js +0 -39
  109. package/lib/plugins/imagemin.js +0 -95
  110. package/lib/plugins/index.js +0 -27
  111. package/lib/plugins/jsmin.js +0 -37
  112. package/lib/plugins/less.js +0 -97
  113. package/lib/plugins/plumber.js +0 -87
  114. package/lib/plugins/postcss-plugins.js +0 -13
  115. package/lib/plugins/postcss.js +0 -117
  116. package/lib/plugins/rename.js +0 -51
  117. package/lib/plugins/replace.js +0 -91
  118. package/lib/plugins/sass-legacy.js +0 -131
  119. package/lib/plugins/sass.js +0 -134
  120. package/lib/plugins/sftp.js +0 -288
  121. package/lib/tasks/default.js +0 -46
  122. package/lib/tasks/foundation/balm.js +0 -72
  123. package/lib/tasks/foundation/balm_style.js +0 -65
  124. package/lib/tasks/foundation/index.js +0 -10
  125. package/lib/tasks/index.js +0 -48
  126. package/lib/tasks/private/build.js +0 -18
  127. package/lib/tasks/private/cache.js +0 -31
  128. package/lib/tasks/private/clean.js +0 -69
  129. package/lib/tasks/private/end.js +0 -24
  130. package/lib/tasks/private/extra.js +0 -35
  131. package/lib/tasks/private/font.js +0 -15
  132. package/lib/tasks/private/image.js +0 -37
  133. package/lib/tasks/private/index.js +0 -34
  134. package/lib/tasks/private/lint.js +0 -20
  135. package/lib/tasks/private/media.js +0 -15
  136. package/lib/tasks/private/modernizr.js +0 -59
  137. package/lib/tasks/private/pwa-cache.js +0 -32
  138. package/lib/tasks/private/script.js +0 -9
  139. package/lib/tasks/private/sprite.js +0 -105
  140. package/lib/tasks/private/start.js +0 -16
  141. package/lib/tasks/private/style.js +0 -9
  142. package/lib/tasks/private/workbox-sw.js +0 -15
  143. package/lib/tasks/public/copy.js +0 -16
  144. package/lib/tasks/public/esbuild.js +0 -18
  145. package/lib/tasks/public/ftp.js +0 -39
  146. package/lib/tasks/public/html.js +0 -65
  147. package/lib/tasks/public/index.js +0 -38
  148. package/lib/tasks/public/jsmin.js +0 -23
  149. package/lib/tasks/public/less.js +0 -21
  150. package/lib/tasks/public/postcss.js +0 -16
  151. package/lib/tasks/public/publish.js +0 -51
  152. package/lib/tasks/public/pwa.js +0 -84
  153. package/lib/tasks/public/remove.js +0 -46
  154. package/lib/tasks/public/replace.js +0 -26
  155. package/lib/tasks/public/rollup.js +0 -17
  156. package/lib/tasks/public/sass.js +0 -27
  157. package/lib/tasks/public/server.js +0 -130
  158. package/lib/tasks/public/url.js +0 -35
  159. package/lib/tasks/public/version.js +0 -23
  160. package/lib/tasks/public/webpack.js +0 -39
  161. package/lib/tasks/public/zip.js +0 -19
  162. package/lib/utilities/address.js +0 -55
  163. package/lib/utilities/cache-core.js +0 -66
  164. package/lib/utilities/color.js +0 -27
  165. package/lib/utilities/compiling.js +0 -24
  166. package/lib/utilities/detect-port.js +0 -100
  167. package/lib/utilities/escape-string-regexp.js +0 -10
  168. package/lib/utilities/file.js +0 -70
  169. package/lib/utilities/index.js +0 -8
  170. package/lib/utilities/loading.js +0 -37
  171. package/lib/utilities/logger.js +0 -99
  172. package/lib/utilities/merge-stream.js +0 -38
  173. package/lib/utilities/namespace.js +0 -11
  174. package/lib/utilities/public-url.js +0 -37
  175. package/lib/utilities/replacestream.js +0 -106
  176. package/lib/utilities/typeof.js +0 -5
  177. package/lib/utilities/utils.js +0 -43
  178. package/tslib/balm.js +0 -44
  179. package/tslib/bootstrap/check_config.js +0 -36
  180. package/tslib/bootstrap/index.js +0 -82
  181. package/tslib/bundler/esbuild/build.js +0 -30
  182. package/tslib/bundler/esbuild/index.js +0 -11
  183. package/tslib/bundler/esbuild/options.js +0 -7
  184. package/tslib/bundler/esbuild/transform.js +0 -38
  185. package/tslib/bundler/rollup/build.js +0 -17
  186. package/tslib/bundler/rollup/entry.js +0 -24
  187. package/tslib/bundler/rollup/index.js +0 -21
  188. package/tslib/bundler/rollup/output.js +0 -23
  189. package/tslib/bundler/rollup/plugins.js +0 -27
  190. package/tslib/bundler/webpack/config/common.js +0 -130
  191. package/tslib/bundler/webpack/config/dev.js +0 -14
  192. package/tslib/bundler/webpack/config/env.js +0 -44
  193. package/tslib/bundler/webpack/config/index.js +0 -8
  194. package/tslib/bundler/webpack/config/prod.js +0 -43
  195. package/tslib/bundler/webpack/config/regex.js +0 -10
  196. package/tslib/bundler/webpack/entry.js +0 -68
  197. package/tslib/bundler/webpack/index.js +0 -30
  198. package/tslib/bundler/webpack/loaders.js +0 -51
  199. package/tslib/bundler/webpack/output.js +0 -41
  200. package/tslib/bundler/webpack/rules/asset.js +0 -33
  201. package/tslib/bundler/webpack/rules/babel.js +0 -16
  202. package/tslib/bundler/webpack/rules/css.js +0 -95
  203. package/tslib/bundler/webpack/rules/html.js +0 -15
  204. package/tslib/bundler/webpack/rules/index.js +0 -10
  205. package/tslib/config/assets.js +0 -24
  206. package/tslib/config/constants.js +0 -14
  207. package/tslib/config/env.js +0 -43
  208. package/tslib/config/extras.js +0 -6
  209. package/tslib/config/ftp.js +0 -6
  210. package/tslib/config/globals.js +0 -47
  211. package/tslib/config/html.js +0 -17
  212. package/tslib/config/images.js +0 -4
  213. package/tslib/config/index.js +0 -56
  214. package/tslib/config/logs.js +0 -6
  215. package/tslib/config/paths.js +0 -30
  216. package/tslib/config/pwa.js +0 -18
  217. package/tslib/config/roots.js +0 -8
  218. package/tslib/config/scripts.js +0 -93
  219. package/tslib/config/server.js +0 -33
  220. package/tslib/config/spinner.js +0 -10
  221. package/tslib/config/styles.js +0 -37
  222. package/tslib/hello.js +0 -19
  223. package/tslib/hooks/index.js +0 -75
  224. package/tslib/hooks/maker.js +0 -66
  225. package/tslib/index.js +0 -5
  226. package/tslib/middlewares/history.js +0 -12
  227. package/tslib/middlewares/index.js +0 -18
  228. package/tslib/middlewares/proxy.js +0 -27
  229. package/tslib/middlewares/webpack.js +0 -29
  230. package/tslib/plugins/htmlmin.js +0 -38
  231. package/tslib/plugins/imagemin.js +0 -97
  232. package/tslib/plugins/index.js +0 -27
  233. package/tslib/plugins/jsmin.js +0 -39
  234. package/tslib/plugins/less.js +0 -90
  235. package/tslib/plugins/plumber.js +0 -81
  236. package/tslib/plugins/postcss-plugins.js +0 -24
  237. package/tslib/plugins/postcss.js +0 -111
  238. package/tslib/plugins/rename.js +0 -51
  239. package/tslib/plugins/replace.js +0 -72
  240. package/tslib/plugins/sass-legacy.js +0 -95
  241. package/tslib/plugins/sass.js +0 -109
  242. package/tslib/plugins/sftp.js +0 -258
  243. package/tslib/tasks/default.js +0 -59
  244. package/tslib/tasks/foundation/balm.js +0 -75
  245. package/tslib/tasks/foundation/balm_style.js +0 -68
  246. package/tslib/tasks/foundation/index.js +0 -10
  247. package/tslib/tasks/index.js +0 -43
  248. package/tslib/tasks/private/build.js +0 -15
  249. package/tslib/tasks/private/cache.js +0 -48
  250. package/tslib/tasks/private/clean.js +0 -82
  251. package/tslib/tasks/private/end.js +0 -21
  252. package/tslib/tasks/private/extra.js +0 -34
  253. package/tslib/tasks/private/font.js +0 -12
  254. package/tslib/tasks/private/image.js +0 -42
  255. package/tslib/tasks/private/index.js +0 -34
  256. package/tslib/tasks/private/lint.js +0 -17
  257. package/tslib/tasks/private/media.js +0 -12
  258. package/tslib/tasks/private/modernizr.js +0 -54
  259. package/tslib/tasks/private/pwa-cache.js +0 -32
  260. package/tslib/tasks/private/script.js +0 -9
  261. package/tslib/tasks/private/sprite.js +0 -93
  262. package/tslib/tasks/private/start.js +0 -13
  263. package/tslib/tasks/private/style.js +0 -12
  264. package/tslib/tasks/private/workbox-sw.js +0 -15
  265. package/tslib/tasks/public/copy.js +0 -18
  266. package/tslib/tasks/public/esbuild.js +0 -18
  267. package/tslib/tasks/public/ftp.js +0 -39
  268. package/tslib/tasks/public/html.js +0 -75
  269. package/tslib/tasks/public/index.js +0 -38
  270. package/tslib/tasks/public/jsmin.js +0 -24
  271. package/tslib/tasks/public/less.js +0 -21
  272. package/tslib/tasks/public/postcss.js +0 -16
  273. package/tslib/tasks/public/publish.js +0 -50
  274. package/tslib/tasks/public/pwa.js +0 -87
  275. package/tslib/tasks/public/remove.js +0 -44
  276. package/tslib/tasks/public/replace.js +0 -27
  277. package/tslib/tasks/public/rollup.js +0 -17
  278. package/tslib/tasks/public/sass.js +0 -27
  279. package/tslib/tasks/public/server.js +0 -129
  280. package/tslib/tasks/public/url.js +0 -35
  281. package/tslib/tasks/public/version.js +0 -27
  282. package/tslib/tasks/public/webpack.js +0 -41
  283. package/tslib/tasks/public/zip.js +0 -19
  284. package/tslib/utilities/address.js +0 -48
  285. package/tslib/utilities/cache-core.js +0 -57
  286. package/tslib/utilities/color.js +0 -33
  287. package/tslib/utilities/compiling.js +0 -16
  288. package/tslib/utilities/detect-port.js +0 -91
  289. package/tslib/utilities/escape-string-regexp.js +0 -7
  290. package/tslib/utilities/file.js +0 -78
  291. package/tslib/utilities/index.js +0 -8
  292. package/tslib/utilities/loading.js +0 -25
  293. package/tslib/utilities/logger.js +0 -92
  294. package/tslib/utilities/merge-stream.js +0 -34
  295. package/tslib/utilities/namespace.js +0 -12
  296. package/tslib/utilities/public-url.js +0 -31
  297. package/tslib/utilities/replacestream.js +0 -112
  298. package/tslib/utilities/typeof.js +0 -8
  299. package/tslib/utilities/utils.js +0 -38
@@ -1,65 +0,0 @@
1
- import BalmTask from './balm.js';
2
- import { ASSET } from '../../config/constants.js';
3
- class BalmStyleTask extends BalmTask {
4
- constructor(name) {
5
- super(name);
6
- let extname;
7
- switch (name) {
8
- case 'sass':
9
- extname = '{scss,sass}';
10
- break;
11
- case 'less':
12
- extname = 'less';
13
- break;
14
- default:
15
- extname = 'css';
16
- }
17
- if (Array.isArray(BalmJS.config.styles.entry)) {
18
- this.defaultInput = BalmJS.config.styles.entry.map(styleEntry => node.path.join(BalmJS.config.src.css, styleEntry));
19
- } else {
20
- if (BalmJS.config.styles.entry) {
21
- this.defaultInput = node.path.join(BalmJS.config.src.css, BalmJS.config.styles.entry);
22
- } else {
23
- this.defaultInput = node.path.join(BalmJS.config.src.css, '**', `!(_*).${extname}`);
24
- }
25
- }
26
- this.defaultOutput = BalmJS.config.env.isMP ? node.path.join(BalmJS.config.dest.base, ASSET.mpDir, BalmJS.config.paths.target.css) : BalmJS.config.dest.css;
27
- }
28
- handleStyle(style, output, options) {
29
- BalmJS.logger.debug(`${this.name} entry`, this.defaultInput, {
30
- pre: true
31
- });
32
- const taskName = `${this.name} task`;
33
- const shouldUseSourceMap = !(BalmJS.config.env.isProd || BalmJS.config.styles.minify);
34
- let stream = gulp.src(this.input, Object.assign({
35
- sourcemaps: shouldUseSourceMap,
36
- allowEmpty: true
37
- }, this.gulpSrcOptions)).pipe(BalmJS.plugins.plumber(function (error) {
38
- // https://github.com/floatdrop/gulp-plumber/issues/30
39
- BalmJS.logger.error(taskName, error.message);
40
- // Must emit end event for any dependent streams to pick up on this. Destroying the stream
41
- // ensures nothing else in that stream gets done, for example, if we're dealing with five
42
- // files, after an error in one of them, any other won't carry on. Doing destroy without
43
- // ending it first will not notify depending streams, tasks like `watch` will hang up.
44
- this.emit('end');
45
- this.destroy();
46
- }));
47
- switch (style) {
48
- case 'sass':
49
- stream = stream.pipe(node.isLegacySass ? BalmJS.plugins.legacySass(options) : BalmJS.plugins.sass(options));
50
- break;
51
- case 'less':
52
- stream = stream.pipe(BalmJS.plugins.less(options));
53
- break;
54
- default:
55
- }
56
- return stream.pipe(BalmJS.plugins.postcss(BalmJS.plugins.postcssPlugins(style === 'postcss'))).pipe($.if(BalmJS.config.env.isMP, BalmJS.plugins.rename({
57
- extname: '.wxss'
58
- }))).pipe(gulp.dest(output, {
59
- sourcemaps: shouldUseSourceMap
60
- })).pipe(server.reload({
61
- stream: true
62
- }));
63
- }
64
- }
65
- export default BalmStyleTask;
@@ -1,10 +0,0 @@
1
- import BalmTask from './balm.js';
2
- import BalmStyleTask from './balm_style.js';
3
- BalmJS.BalmTask = BalmTask;
4
- BalmJS.BalmStyleTask = BalmStyleTask;
5
- BalmJS.tasks = new Map(); // Main tasks
6
- BalmJS.recipes = []; // Sub tasks
7
- BalmJS.recipeIndex = 0;
8
- BalmJS.server = null;
9
- BalmJS.watchFtpFile = '';
10
- BalmJS.watching = false;
@@ -1,48 +0,0 @@
1
- import './foundation/index.js';
2
- import PRIVATE_TASKS from './private/index.js';
3
- import PUBLIC_TASKS from './public/index.js';
4
- import DefaultTask from './default.js';
5
- import BalmHooks from '../hooks/index.js';
6
- function registerTasks(recipe) {
7
- const AwesomeTasks = BalmJS.utils.deepMerge(PRIVATE_TASKS, PUBLIC_TASKS);
8
-
9
- // 1. Register balm tasks
10
- const depsTasks = [];
11
- const nonDepsTasks = [];
12
- Object.values(AwesomeTasks).forEach(AwesomeTask => {
13
- const awesomeTask = new AwesomeTask();
14
- awesomeTask.deps ? depsTasks.push(awesomeTask) : nonDepsTasks.push(awesomeTask);
15
- });
16
- nonDepsTasks.forEach(task => {
17
- const taskName = task.taskName;
18
- const taskFunction = task.fn;
19
- gulp.task(taskName, taskFunction);
20
- BalmJS.tasks.set(task.name, task);
21
- });
22
- depsTasks.forEach(task => {
23
- const taskName = task.taskName;
24
- const taskFunction = task.deps.length ? gulp.series(...BalmJS.toNamespace(task.deps)) : callback => {
25
- callback();
26
- };
27
- gulp.task(taskName, taskFunction);
28
- BalmJS.tasks.set(task.name, task);
29
- });
30
-
31
- // 2. Register balm hooks
32
- try {
33
- recipe(new BalmHooks());
34
- } catch (error) {
35
- const {
36
- message
37
- } = error;
38
- BalmJS.logger.error('balm hook', message);
39
- }
40
-
41
- // 3. Register balm default task
42
- const defaultTask = new DefaultTask();
43
- gulp.task(defaultTask.taskName, gulp.series(...defaultTask.startTask, ...defaultTask.mainTasks, ...defaultTask.subTasks, ...defaultTask.endTask));
44
-
45
- // 4. Run
46
- gulp.parallel('balm:default')();
47
- }
48
- export default registerTasks;
@@ -1,18 +0,0 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
- import gulpSize from 'gulp-size';
5
- class BuildTask extends BalmJS.BalmTask {
6
- constructor() {
7
- super('build');
8
- _defineProperty(this, "fn", () => {
9
- this.init();
10
- return this.src.pipe(gulpSize({
11
- title: this.name,
12
- gzip: true
13
- }));
14
- });
15
- this.defaultInput = BalmJS.file.matchAllFiles(BalmJS.config.dest.base);
16
- }
17
- }
18
- export default BuildTask;
@@ -1,31 +0,0 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
- import revAll from 'gulp-rev-all';
5
- import { ASSETS_TYPES, CHUNK, ASSET } from '../../config/constants.js';
6
- class CacheTask extends BalmJS.BalmTask {
7
- constructor() {
8
- super('cache');
9
- _defineProperty(this, "fn", () => {
10
- this.init();
11
- this.gulpSrcOptions = {
12
- base: this.output
13
- };
14
- return this.src.pipe(revAll.revision(BalmJS.config.assets.options)).pipe($.if(/\.html$/, BalmJS.file.setPublicPath())).pipe(gulp.dest(this.output)).pipe($.revDeleteOriginal({
15
- exclude: /\.html$/
16
- })).pipe(revAll.manifestFile()).pipe(gulp.dest(this.output));
17
- });
18
- const defaultIncludes = BalmJS.config.scripts.useCache ? ASSETS_TYPES.filter(assetType => assetType !== 'js').map(assetType => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetType])) : ASSETS_TYPES.map(assetType => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetType]));
19
- const defaultExcludes = [node.path.join(`!${BalmJS.config.dest.js}`, CHUNK.dir, '*'), node.path.join(`!${BalmJS.config.dest.js}`, ASSET.dir, '*'), node.path.join(`!${BalmJS.config.dest.base}`, BalmJS.config.pwa.manifest)];
20
- const customIncludes = BalmJS.config.assets.includes;
21
- const customExcludes = BalmJS.config.assets.excludes.map(filename => {
22
- return `!${filename}`;
23
- });
24
- this.defaultInput = [...defaultIncludes, ...defaultExcludes, ...(BalmJS.config.inFrontend ? [node.path.join(BalmJS.config.dest.base, '*.html')] : []), ...customIncludes, ...customExcludes];
25
- this.defaultOutput = BalmJS.config.inFrontend ? BalmJS.config.dest.base : BalmJS.config.dest.static;
26
- this.gulpSrcOptions = {
27
- base: this.defaultOutput
28
- };
29
- }
30
- }
31
- export default CacheTask;
@@ -1,69 +0,0 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
- function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
5
- function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
6
- function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
7
- function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
8
- import { deleteAsync } from 'del';
9
- import { ASSETS_TYPES } from '../../config/constants.js';
10
- function unique(arr) {
11
- const obj = {};
12
- const result = [];
13
- for (let i = 0, len = arr.length; i < len; i++) {
14
- if (!obj[arr[i]]) {
15
- obj[arr[i]] = true;
16
- result.push(arr[i].replace(/\\/g, '/')); // NOTE: compatible with windows for `del@5.x`
17
- }
18
- }
19
- return result;
20
- }
21
- var _getAssetsDir = /*#__PURE__*/new WeakMap();
22
- class CleanTask extends BalmJS.BalmTask {
23
- constructor() {
24
- super('clean');
25
- _classPrivateFieldInitSpec(this, _getAssetsDir, (rootKey = 'assets') => {
26
- return unique(ASSETS_TYPES.map(assetType => BalmJS.config[rootKey][assetType]));
27
- });
28
- _defineProperty(this, "fn", async callback => {
29
- const taskName = `${this.name} task`;
30
- const directories = BalmJS.config.inFrontend ? this.dirInFrontend : this.dirInBackend;
31
- if (BalmJS.config.env.isProd && !BalmJS.config.assets.root) {
32
- BalmJS.logger.warn(taskName, 'Remote root path is empty');
33
- }
34
- BalmJS.logger.debug(taskName, {
35
- directories
36
- }, {
37
- pre: true
38
- });
39
- const deletedPaths = await deleteAsync(directories, {
40
- force: true
41
- });
42
- BalmJS.logger.warn(taskName, {
43
- deletedPaths
44
- }, {
45
- pre: true
46
- });
47
- callback();
48
- });
49
- }
50
- get remoteRootDir() {
51
- return BalmJS.config.assets.root.trim().length ? [BalmJS.config.assets.root] : [];
52
- }
53
- get remoteAppDir() {
54
- return BalmJS.config.assets.subDir ? [BalmJS.config.assets.static] : _classPrivateFieldGet(_getAssetsDir, this).call(this);
55
- }
56
- get dirInFrontend() {
57
- const isLocal = !node.path.isAbsolute(BalmJS.config.assets.root);
58
- BalmJS.logger.info(`${this.name} task`, `'${BalmJS.config.assets.root}' is local directory: ${isLocal}`);
59
- return BalmJS.config.env.isProd ? [BalmJS.file.absPath(BalmJS.config.roots.target), ...(isLocal ? this.remoteRootDir : this.remoteAppDir)] : [BalmJS.file.absPath(BalmJS.config.roots.tmp)];
60
- }
61
- get dirInBackend() {
62
- const hasBuildDir = BalmJS.config.assets.cache && !!(BalmJS.config.assets.buildDir || BalmJS.config.assets.subDir);
63
- const buildDirInProd = hasBuildDir ? [BalmJS.config.dest.static] : [];
64
- const buildDirInDev = hasBuildDir ? [node.path.join(BalmJS.config.dest.static, BalmJS.config.assets.buildDir)] // NOTE: fix for `BalmJS.file.assetsSuffixPath` in development
65
- : [];
66
- return [...(BalmJS.config.env.isProd && hasBuildDir ? buildDirInProd : [...buildDirInDev, ..._classPrivateFieldGet(_getAssetsDir, this).call(this, 'dest')])];
67
- }
68
- }
69
- export default CleanTask;
@@ -1,24 +0,0 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
- class EndTask extends BalmJS.BalmTask {
5
- constructor() {
6
- super('end');
7
- _defineProperty(this, "fn", async callback => {
8
- if (BalmJS.utils.isFunction(BalmJS.afterTask)) {
9
- await BalmJS.afterTask();
10
- }
11
- this.time();
12
- BalmJS.emitter.emit('exit');
13
- callback();
14
- });
15
- }
16
- time() {
17
- const end = process.hrtime(BalmJS.start);
18
- const timeInMs = Math.ceil((end[0] * 1000000000 + end[1]) / 1000000);
19
- BalmJS.logger.info('execution time', `${timeInMs}ms`, {
20
- logLevel: BalmJS.LogLevel.Error
21
- });
22
- }
23
- }
24
- export default EndTask;
@@ -1,35 +0,0 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
- class ExtraTask extends BalmJS.BalmTask {
5
- constructor() {
6
- super('extra');
7
- _defineProperty(this, "fn", () => {
8
- this.init();
9
- this.gulpSrcOptions = {
10
- dot: true
11
- };
12
- return this.src.pipe(gulp.dest(this.output));
13
- });
14
- const includeGlobs = [];
15
- if (BalmJS.config.extras.includes.length) {
16
- for (const filename of BalmJS.config.extras.includes) {
17
- includeGlobs.push(node.path.join(BalmJS.config.src.base, filename));
18
- }
19
- }
20
- const excludeGlobs = [];
21
- if (BalmJS.config.extras.excludes.length) {
22
- for (const filename of BalmJS.config.extras.excludes) {
23
- excludeGlobs.push(node.path.join(`!${BalmJS.config.src.base}`, filename));
24
- }
25
- }
26
- const defaultGlobs = [node.path.join(BalmJS.config.src.base, '*.*'),
27
- // All files but ignore all folders in the app root directory
28
- node.path.join(`!${BalmJS.config.src.base}`, '*.html'), node.path.join(`!${BalmJS.config.src.base}`, BalmJS.config.pwa.manifest), ...includeGlobs,
29
- // e.g. CNAME
30
- ...excludeGlobs];
31
- this.defaultInput = defaultGlobs;
32
- this.defaultOutput = BalmJS.config.dest.base;
33
- }
34
- }
35
- export default ExtraTask;
@@ -1,15 +0,0 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
- class FontTask extends BalmJS.BalmTask {
5
- constructor() {
6
- super('font');
7
- _defineProperty(this, "fn", () => {
8
- this.init();
9
- return this.src.pipe(gulp.dest(this.output));
10
- });
11
- this.defaultInput = BalmJS.file.matchAllFiles(BalmJS.config.src.font, '*.{eot,svg,ttf,woff,woff2}');
12
- this.defaultOutput = BalmJS.config.dest.font;
13
- }
14
- }
15
- export default FontTask;
@@ -1,37 +0,0 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
- import { getDefaultImagePlugins } from '../../plugins/imagemin.js';
5
- class ImageTask extends BalmJS.BalmTask {
6
- constructor() {
7
- super('image');
8
- _defineProperty(this, "fn", () => {
9
- this.init();
10
- const balmImage = () => {
11
- return gulp.src(BalmJS.file.absPaths(this.input), {
12
- since: gulp.lastRun(balmImage),
13
- encoding: false
14
- }).pipe(BalmJS.plugins.plumber(error => {
15
- BalmJS.logger.error(`${this.name} task`, error);
16
- })).pipe(BalmJS.plugins.imagemin(this.plugins)).pipe(gulp.dest(this.output));
17
- };
18
- return balmImage();
19
- });
20
- const excludeGlobs = [];
21
- for (const imageFolder of BalmJS.config.styles.sprites) {
22
- excludeGlobs.push(node.path.join(`!${BalmJS.config.src.img}`, imageFolder));
23
- excludeGlobs.push(node.path.join(`!${BalmJS.config.src.img}`, imageFolder, '*.png'));
24
- }
25
- this.defaultInput = [BalmJS.file.matchAllFiles(BalmJS.config.src.img), ...excludeGlobs];
26
- this.defaultOutput = BalmJS.config.dest.img;
27
- if (BalmJS.utils.isArray(BalmJS.config.images.plugins)) {
28
- this.plugins = BalmJS.config.images.plugins; // Using custom imagemin plugins
29
- } else {
30
- const defaultPlugins = Object.assign(getDefaultImagePlugins(), BalmJS.config.images.plugins);
31
- const enablePlugins = Object.keys(defaultPlugins).filter(key => defaultPlugins[key]);
32
- this.plugins = enablePlugins.map(key => defaultPlugins[key]);
33
- BalmJS.logger.debug(`${this.name} task - plugins`, enablePlugins);
34
- }
35
- }
36
- }
37
- export default ImageTask;
@@ -1,34 +0,0 @@
1
- import StartTask from './start.js';
2
- import CleanTask from './clean.js';
3
- import SpriteTask from './sprite.js';
4
- import StyleTask from './style.js';
5
- import LintTask from './lint.js';
6
- import ScriptTask from './script.js';
7
- import ImageTask from './image.js';
8
- import FontTask from './font.js';
9
- import MediaTask from './media.js';
10
- import ModernizrTask from './modernizr.js';
11
- import ExtraTask from './extra.js';
12
- import BuildTask from './build.js';
13
- import CacheTask from './cache.js';
14
- import WorkboxSwTask from './workbox-sw.js';
15
- import PwaCacheTask from './pwa-cache.js';
16
- import EndTask from './end.js';
17
- export default {
18
- StartTask,
19
- CleanTask,
20
- SpriteTask,
21
- StyleTask,
22
- LintTask,
23
- ScriptTask,
24
- ImageTask,
25
- FontTask,
26
- MediaTask,
27
- ModernizrTask,
28
- ExtraTask,
29
- BuildTask,
30
- CacheTask,
31
- WorkboxSwTask,
32
- PwaCacheTask,
33
- EndTask
34
- };
@@ -1,20 +0,0 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
- class LintTask extends BalmJS.BalmTask {
5
- constructor() {
6
- super('lint');
7
- _defineProperty(this, "fn", () => {
8
- this.init();
9
- return this.src.pipe($.eslint({
10
- fix: true
11
- })).pipe(server.reload({
12
- stream: true,
13
- once: true
14
- })).pipe($.eslint.format()).pipe($.if(!server.active, $.eslint.failAfterError())).pipe(gulp.dest(this.output));
15
- });
16
- this.defaultOutput = BalmJS.config.src.js;
17
- this.defaultInput = BalmJS.file.matchAllFiles(this.defaultOutput, '*.js');
18
- }
19
- }
20
- export default LintTask;
@@ -1,15 +0,0 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
- class MediaTask extends BalmJS.BalmTask {
5
- constructor() {
6
- super('media');
7
- _defineProperty(this, "fn", () => {
8
- this.init();
9
- return this.src.pipe(gulp.dest(this.output));
10
- });
11
- this.defaultInput = BalmJS.file.matchAllFiles(BalmJS.config.src.media);
12
- this.defaultOutput = BalmJS.config.dest.media;
13
- }
14
- }
15
- export default MediaTask;
@@ -1,59 +0,0 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
- function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
5
- function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
6
- function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
7
- function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
8
- import { build } from 'modernizr';
9
- var _readConfig = /*#__PURE__*/new WeakMap();
10
- var _createDir = /*#__PURE__*/new WeakMap();
11
- var _generateScript = /*#__PURE__*/new WeakMap();
12
- class ModernizrTask extends BalmJS.BalmTask {
13
- constructor() {
14
- super('modernizr');
15
- _classPrivateFieldInitSpec(this, _readConfig, () => {
16
- return new Promise((resolve, reject) => {
17
- node.fs.readFile(this.input, 'utf8', (err, data) => {
18
- if (err) reject(err);
19
- resolve(JSON.parse(data));
20
- });
21
- });
22
- });
23
- _classPrivateFieldInitSpec(this, _createDir, () => {
24
- return new Promise((resolve, reject) => {
25
- node.fs.mkdir(BalmJS.file.absPath(BalmJS.config.dest.js), {
26
- recursive: true
27
- }, err => {
28
- if (err) reject(err);
29
- resolve();
30
- });
31
- });
32
- });
33
- _classPrivateFieldInitSpec(this, _generateScript, config => {
34
- return new Promise((resolve, reject) => {
35
- build(config, content => {
36
- node.fs.writeFile(this.output, content, err => {
37
- if (err) reject(err);
38
- resolve(content);
39
- });
40
- });
41
- });
42
- });
43
- _defineProperty(this, "fn", async callback => {
44
- this.init();
45
- if (node.fs.existsSync(this.input)) {
46
- const [config] = await Promise.all([_classPrivateFieldGet(_readConfig, this).call(this), _classPrivateFieldGet(_createDir, this).call(this)]);
47
- await _classPrivateFieldGet(_generateScript, this).call(this, config);
48
- } else {
49
- BalmJS.logger.warn(`${this.name} task`, `The '${this.input}' does not exist`, {
50
- logLevel: BalmJS.LogLevel.Info
51
- });
52
- }
53
- callback();
54
- });
55
- this.defaultInput = `${this.name}.json`;
56
- this.defaultOutput = node.path.join(BalmJS.config.dest.js, `${this.name}.js`);
57
- }
58
- }
59
- export default ModernizrTask;
@@ -1,32 +0,0 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
- function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
- import { deleteAsync } from 'del';
5
- class PwaCacheTask extends BalmJS.BalmTask {
6
- constructor() {
7
- super('pwa-cache');
8
- _defineProperty(this, "fn", () => {
9
- this.init();
10
- const swDest = typeof this.input === 'string' && this.input ? BalmJS.file.absPath(this.input) : '';
11
- if (!swDest || !node.fs.existsSync(swDest)) {
12
- return Promise.resolve();
13
- }
14
- const newVersion = BalmJS.config.pwa.version || Date.now().toString();
15
- BalmJS.logger.info('pwa - version', newVersion);
16
- const stream = this.src.pipe(BalmJS.plugins.replace('{{ version }}', newVersion)).pipe($.if(BalmJS.config.env.isProd, BalmJS.plugins.jsmin(BalmJS.config.scripts.minifyOptions))).pipe(gulp.dest(this.output));
17
- this.clear();
18
- return stream;
19
- });
20
- this.defaultOutput = BalmJS.config.dest.base;
21
- this.defaultInput = node.path.join(this.defaultOutput, BalmJS.config.pwa.swDestFilename);
22
- }
23
- clear() {
24
- if (BalmJS.config.pwa.swSrcFilename !== BalmJS.config.pwa.swDestFilename) {
25
- const swOrigin = BalmJS.file.absPath(node.path.join(BalmJS.config.dest.base, BalmJS.config.pwa.swSrcFilename));
26
- deleteAsync(swOrigin, {
27
- force: true
28
- });
29
- }
30
- }
31
- }
32
- export default PwaCacheTask;
@@ -1,9 +0,0 @@
1
- class ScriptTask extends BalmJS.BalmTask {
2
- constructor() {
3
- super('script');
4
- }
5
- get deps() {
6
- return [BalmJS.config.scripts.bundler];
7
- }
8
- }
9
- export default ScriptTask;
@@ -1,105 +0,0 @@
1
- function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
2
- function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
3
- function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
4
- function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
5
- import mergeStream from '../../utilities/merge-stream.js';
6
- var _tasks = /*#__PURE__*/new WeakMap();
7
- var _getParams = /*#__PURE__*/new WeakMap();
8
- class SpriteTask extends BalmJS.BalmTask {
9
- constructor() {
10
- super('sprite');
11
- _classPrivateFieldInitSpec(this, _tasks, []);
12
- _classPrivateFieldInitSpec(this, _getParams, (spriteItem, spriteOptions) => {
13
- const stylesConfig = Object.assign(spriteOptions, BalmJS.config.styles);
14
- const spriteName = `${spriteItem.folderName}-${this.name}s`;
15
- const imageTarget = stylesConfig.imageTarget || BalmJS.config.paths.target.img;
16
- let defaultParams = Object.assign({
17
- padding: 1
18
- }, {
19
- imgName: `${spriteName}.png`,
20
- // E.g. 'awesome-sprites.png'
21
- cssName: `_${spriteItem.folderName}.${stylesConfig.extname}`,
22
- // E.g. "_awesome.{css,sass,scss,less}"
23
- imgPath: `${stylesConfig.imageBasePath}${imageTarget}/${spriteName}.png`,
24
- // E.g. "../img/awesome-sprites.png"
25
- cssVarMap: sprite => {
26
- sprite.name = `${spriteItem.folderName}-${sprite.name}`; // E.g. "awesome-icon-name"
27
- },
28
- cssSpritesheetName: `${spriteItem.folderName}-spritesheet`,
29
- // E.g. "awesome-spritesheet"
30
- cssOpts: {
31
- cssSelector: sprite => `.${sprite.name}` // className in css file: '.icon-awesome'
32
- }
33
- });
34
- if (stylesConfig.spriteRetina) {
35
- defaultParams = Object.assign(defaultParams, {
36
- retinaSrcFilter: `${spriteItem.retinaSrc}`,
37
- retinaImgName: `${spriteName}@2x.png`,
38
- // E.g. 'awesome-sprites@2x.png'
39
- retinaImgPath: `${stylesConfig.imageBasePath}${imageTarget}/${spriteName}@2x.png`,
40
- // E.g. "../img/awesome-sprites@2x.png"
41
- cssVarMap: sprite => {
42
- sprite.name = `${spriteItem.folderName}-${sprite.name}`; // E.g. "awesome-icon-name"
43
- },
44
- cssRetinaSpritesheetName: `${spriteItem.folderName}-spritesheet-2x`,
45
- // E.g. "awesome-spritesheet-2x"
46
- cssRetinaGroupsName: `${spriteItem.folderName}-retina-groups` // E.g. "awesome-retina-groups"
47
- });
48
- }
49
- return Object.assign(defaultParams, stylesConfig.spriteParams);
50
- });
51
- this.defaultInput = BalmJS.config.styles.sprites;
52
- this.defaultOutput = BalmJS.config.dest.img;
53
- if (this.defaultInput.length) {
54
- this.init();
55
- this.collect();
56
- }
57
- }
58
- collect(spriteOptions = {}) {
59
- const spriteList = [];
60
- for (const spriteName of this.input) {
61
- spriteList.push({
62
- src: `${BalmJS.config.src.img}/${spriteName}/*.png`,
63
- retinaSrc: `${BalmJS.config.src.img}/${spriteName}/*@2x.png`,
64
- folderName: spriteName
65
- });
66
- }
67
- for (let key = 0, len = spriteList.length; key < len; key++) {
68
- const spriteItem = spriteList[key];
69
- const spriteTaskName = `${this.name}:${spriteItem.folderName}`; // E.g. 'sprite:awesome'
70
- const spriteConfig = {
71
- input: BalmJS.file.absPath(spriteItem.src),
72
- imgOutput: BalmJS.file.absPath(this.output),
73
- cssOutput: BalmJS.file.absPath(`${BalmJS.config.src.css}/${this.name}s`) // E.g. 'path/to/css/sprites'
74
- };
75
- BalmJS.logger.debug(`${this.name} task`, spriteConfig, {
76
- pre: true
77
- });
78
- spriteConfig.params = _classPrivateFieldGet(_getParams, this).call(this, spriteItem, spriteOptions);
79
- gulp.task(BalmJS.toNamespace(spriteTaskName), () => {
80
- const spriteData = gulp.src(spriteConfig.input, {
81
- encoding: false
82
- }).pipe(BalmJS.plugins.plumber(error => {
83
- BalmJS.logger.error(`${this.name} task`, error.message);
84
- })).pipe($.spritesmith(spriteConfig.params));
85
- const imgStream = spriteData.img.pipe(gulp.dest(spriteConfig.imgOutput));
86
- const cssStream = spriteData.css.pipe(gulp.dest(spriteConfig.cssOutput));
87
- return mergeStream(imgStream, cssStream);
88
- });
89
- _classPrivateFieldGet(_tasks, this).push(spriteTaskName);
90
- }
91
- }
92
- recipe(input, output, spriteOptions = {}) {
93
- if (input.length) {
94
- if (output && !spriteOptions.imageTarget) {
95
- spriteOptions.imageTarget = output.split('/').pop();
96
- }
97
- this.init(input, output);
98
- this.collect(spriteOptions);
99
- }
100
- }
101
- get deps() {
102
- return _classPrivateFieldGet(_tasks, this);
103
- }
104
- }
105
- export default SpriteTask;