balm-core 5.0.2 → 5.1.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 (49) hide show
  1. package/README.md +1 -1
  2. package/index.d.ts +7 -0
  3. package/lib/config/globals.js +14 -1
  4. package/lib/plugins/imagemin.js +15 -10
  5. package/lib/plugins/index.js +2 -0
  6. package/lib/plugins/postcss.js +2 -2
  7. package/lib/plugins/rename.js +1 -3
  8. package/lib/plugins/replace.js +3 -1
  9. package/lib/plugins/sass-legacy.js +131 -0
  10. package/lib/plugins/sass.js +66 -125
  11. package/lib/tasks/foundation/balm.js +2 -2
  12. package/lib/tasks/foundation/balm_style.js +1 -2
  13. package/lib/tasks/private/cache.js +0 -5
  14. package/lib/tasks/private/image.js +2 -2
  15. package/lib/tasks/public/sass.js +1 -2
  16. package/package.json +46 -46
  17. package/tslib/balm.js +5 -8
  18. package/tslib/config/globals.js +21 -1
  19. package/tslib/plugins/imagemin.js +15 -10
  20. package/tslib/plugins/index.js +2 -0
  21. package/tslib/plugins/rename.js +1 -1
  22. package/tslib/plugins/replace.js +2 -1
  23. package/tslib/plugins/sass-legacy.js +95 -0
  24. package/tslib/plugins/sass.js +62 -124
  25. package/tslib/tasks/foundation/balm.js +10 -8
  26. package/tslib/tasks/foundation/balm_style.js +3 -2
  27. package/tslib/tasks/private/build.js +7 -7
  28. package/tslib/tasks/private/cache.js +10 -13
  29. package/tslib/tasks/private/clean.js +28 -31
  30. package/tslib/tasks/private/end.js +8 -8
  31. package/tslib/tasks/private/extra.js +7 -7
  32. package/tslib/tasks/private/font.js +4 -4
  33. package/tslib/tasks/private/image.js +16 -16
  34. package/tslib/tasks/private/lint.js +9 -9
  35. package/tslib/tasks/private/media.js +4 -4
  36. package/tslib/tasks/private/modernizr.js +40 -43
  37. package/tslib/tasks/private/pwa-cache.js +11 -11
  38. package/tslib/tasks/private/sprite.js +36 -39
  39. package/tslib/tasks/private/start.js +7 -7
  40. package/tslib/tasks/private/workbox-sw.js +4 -4
  41. package/tslib/tasks/public/html.js +23 -26
  42. package/tslib/tasks/public/publish.js +13 -16
  43. package/tslib/tasks/public/remove.js +8 -11
  44. package/tslib/tasks/public/sass.js +1 -2
  45. package/tslib/tasks/public/server.js +34 -37
  46. package/tslib/tasks/public/url.js +16 -19
  47. package/tslib/utilities/compiling.js +4 -9
  48. package/tslib/utilities/loading.js +8 -14
  49. package/tslib/utilities/logger.js +13 -18
@@ -37,7 +37,6 @@ class BalmStyleTask extends BalmTask {
37
37
  const shouldUseSourceMap = !(BalmJS.config.env.isProd || BalmJS.config.styles.minify);
38
38
  let stream = gulp
39
39
  .src(this.input, Object.assign({
40
- encoding: false,
41
40
  sourcemaps: shouldUseSourceMap,
42
41
  allowEmpty: true
43
42
  }, this.gulpSrcOptions))
@@ -48,7 +47,9 @@ class BalmStyleTask extends BalmTask {
48
47
  }));
49
48
  switch (style) {
50
49
  case 'sass':
51
- stream = stream.pipe(BalmJS.plugins.sass(options));
50
+ stream = stream.pipe(node.isLegacySass
51
+ ? BalmJS.plugins.legacySass(options)
52
+ : BalmJS.plugins.sass(options));
52
53
  break;
53
54
  case 'less':
54
55
  stream = stream.pipe(BalmJS.plugins.less(options));
@@ -2,14 +2,14 @@ import gulpSize from 'gulp-size';
2
2
  class BuildTask extends BalmJS.BalmTask {
3
3
  constructor() {
4
4
  super('build');
5
- this.fn = () => {
6
- this.init();
7
- return this.src.pipe(gulpSize({
8
- title: this.name,
9
- gzip: true
10
- }));
11
- };
12
5
  this.defaultInput = BalmJS.file.matchAllFiles(BalmJS.config.dest.base);
13
6
  }
7
+ fn = () => {
8
+ this.init();
9
+ return this.src.pipe(gulpSize({
10
+ title: this.name,
11
+ gzip: true
12
+ }));
13
+ };
14
14
  }
15
15
  export default BuildTask;
@@ -3,16 +3,6 @@ import { ASSETS_TYPES, CHUNK, ASSET } from '../../config/constants.js';
3
3
  class CacheTask extends BalmJS.BalmTask {
4
4
  constructor() {
5
5
  super('cache');
6
- this.fn = () => {
7
- this.init();
8
- return this.src
9
- .pipe(revAll.revision(BalmJS.config.assets.options))
10
- .pipe($.if(/\.html$/, BalmJS.file.setPublicPath()))
11
- .pipe(gulp.dest(this.output))
12
- .pipe($.revDeleteOriginal())
13
- .pipe(revAll.manifestFile())
14
- .pipe(gulp.dest(this.output));
15
- };
16
6
  const defaultIncludes = BalmJS.config.scripts.useCache
17
7
  ? ASSETS_TYPES.filter((assetType) => assetType !== 'js').map((assetType) => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetType]))
18
8
  : ASSETS_TYPES.map((assetType) => BalmJS.file.matchAllFiles(BalmJS.config.dest[assetType]));
@@ -37,9 +27,16 @@ class CacheTask extends BalmJS.BalmTask {
37
27
  this.defaultOutput = BalmJS.config.inFrontend
38
28
  ? BalmJS.config.dest.base
39
29
  : BalmJS.config.dest.static;
40
- this.gulpSrcOptions = {
41
- base: BalmJS.config.dest.base
42
- };
43
30
  }
31
+ fn = () => {
32
+ this.init();
33
+ return this.src
34
+ .pipe(revAll.revision(BalmJS.config.assets.options))
35
+ .pipe($.if(/\.html$/, BalmJS.file.setPublicPath()))
36
+ .pipe(gulp.dest(this.output))
37
+ .pipe($.revDeleteOriginal())
38
+ .pipe(revAll.manifestFile())
39
+ .pipe(gulp.dest(this.output));
40
+ };
44
41
  }
45
42
  export default CacheTask;
@@ -1,5 +1,3 @@
1
- var _CleanTask_getAssetsDir;
2
- import { __classPrivateFieldGet } from "tslib";
3
1
  import { deleteAsync } from 'del';
4
2
  import { ASSETS_TYPES } from '../../config/constants.js';
5
3
  function unique(arr) {
@@ -16,33 +14,10 @@ function unique(arr) {
16
14
  class CleanTask extends BalmJS.BalmTask {
17
15
  constructor() {
18
16
  super('clean');
19
- _CleanTask_getAssetsDir.set(this, (rootKey = 'assets') => {
20
- return unique(ASSETS_TYPES.map((assetType) => BalmJS.config[rootKey][assetType]));
21
- });
22
- this.fn = async (callback) => {
23
- const taskName = `${this.name} task`;
24
- const directories = BalmJS.config.inFrontend
25
- ? this.dirInFrontend
26
- : this.dirInBackend;
27
- if (BalmJS.config.env.isProd && !BalmJS.config.assets.root) {
28
- BalmJS.logger.warn(taskName, 'Remote root path is empty');
29
- }
30
- BalmJS.logger.debug(taskName, {
31
- directories
32
- }, {
33
- pre: true
34
- });
35
- const deletedPaths = await deleteAsync(directories, {
36
- force: true
37
- });
38
- BalmJS.logger.warn(taskName, {
39
- deletedPaths
40
- }, {
41
- pre: true
42
- });
43
- callback();
44
- };
45
17
  }
18
+ #getAssetsDir = (rootKey = 'assets') => {
19
+ return unique(ASSETS_TYPES.map((assetType) => BalmJS.config[rootKey][assetType]));
20
+ };
46
21
  get remoteRootDir() {
47
22
  return BalmJS.config.assets.root.trim().length
48
23
  ? [BalmJS.config.assets.root]
@@ -51,7 +26,7 @@ class CleanTask extends BalmJS.BalmTask {
51
26
  get remoteAppDir() {
52
27
  return BalmJS.config.assets.subDir
53
28
  ? [BalmJS.config.assets.static]
54
- : __classPrivateFieldGet(this, _CleanTask_getAssetsDir, "f").call(this);
29
+ : this.#getAssetsDir();
55
30
  }
56
31
  get dirInFrontend() {
57
32
  const isLocal = !node.path.isAbsolute(BalmJS.config.assets.root);
@@ -77,9 +52,31 @@ class CleanTask extends BalmJS.BalmTask {
77
52
  return [
78
53
  ...(BalmJS.config.env.isProd && hasBuildDir
79
54
  ? buildDirInProd
80
- : [...buildDirInDev, ...__classPrivateFieldGet(this, _CleanTask_getAssetsDir, "f").call(this, 'dest')])
55
+ : [...buildDirInDev, ...this.#getAssetsDir('dest')])
81
56
  ];
82
57
  }
58
+ fn = async (callback) => {
59
+ const taskName = `${this.name} task`;
60
+ const directories = BalmJS.config.inFrontend
61
+ ? this.dirInFrontend
62
+ : this.dirInBackend;
63
+ if (BalmJS.config.env.isProd && !BalmJS.config.assets.root) {
64
+ BalmJS.logger.warn(taskName, 'Remote root path is empty');
65
+ }
66
+ BalmJS.logger.debug(taskName, {
67
+ directories
68
+ }, {
69
+ pre: true
70
+ });
71
+ const deletedPaths = await deleteAsync(directories, {
72
+ force: true
73
+ });
74
+ BalmJS.logger.warn(taskName, {
75
+ deletedPaths
76
+ }, {
77
+ pre: true
78
+ });
79
+ callback();
80
+ };
83
81
  }
84
- _CleanTask_getAssetsDir = new WeakMap();
85
82
  export default CleanTask;
@@ -1,14 +1,6 @@
1
1
  class EndTask extends BalmJS.BalmTask {
2
2
  constructor() {
3
3
  super('end');
4
- this.fn = async (callback) => {
5
- if (BalmJS.utils.isFunction(BalmJS.afterTask)) {
6
- await BalmJS.afterTask();
7
- }
8
- this.time();
9
- BalmJS.emitter.emit('exit');
10
- callback();
11
- };
12
4
  }
13
5
  time() {
14
6
  const end = process.hrtime(BalmJS.start);
@@ -17,5 +9,13 @@ class EndTask extends BalmJS.BalmTask {
17
9
  logLevel: BalmJS.LogLevel.Error
18
10
  });
19
11
  }
12
+ fn = async (callback) => {
13
+ if (BalmJS.utils.isFunction(BalmJS.afterTask)) {
14
+ await BalmJS.afterTask();
15
+ }
16
+ this.time();
17
+ BalmJS.emitter.emit('exit');
18
+ callback();
19
+ };
20
20
  }
21
21
  export default EndTask;
@@ -1,13 +1,6 @@
1
1
  class ExtraTask extends BalmJS.BalmTask {
2
2
  constructor() {
3
3
  super('extra');
4
- this.fn = () => {
5
- this.init();
6
- this.gulpSrcOptions = {
7
- dot: true
8
- };
9
- return this.src.pipe(gulp.dest(this.output));
10
- };
11
4
  const includeGlobs = [];
12
5
  if (BalmJS.config.extras.includes.length) {
13
6
  for (const filename of BalmJS.config.extras.includes) {
@@ -30,5 +23,12 @@ class ExtraTask extends BalmJS.BalmTask {
30
23
  this.defaultInput = defaultGlobs;
31
24
  this.defaultOutput = BalmJS.config.dest.base;
32
25
  }
26
+ fn = () => {
27
+ this.init();
28
+ this.gulpSrcOptions = {
29
+ dot: true
30
+ };
31
+ return this.src.pipe(gulp.dest(this.output));
32
+ };
33
33
  }
34
34
  export default ExtraTask;
@@ -1,12 +1,12 @@
1
1
  class FontTask extends BalmJS.BalmTask {
2
2
  constructor() {
3
3
  super('font');
4
- this.fn = () => {
5
- this.init();
6
- return this.src.pipe(gulp.dest(this.output));
7
- };
8
4
  this.defaultInput = BalmJS.file.matchAllFiles(BalmJS.config.src.font, '*.{eot,svg,ttf,woff,woff2}');
9
5
  this.defaultOutput = BalmJS.config.dest.font;
10
6
  }
7
+ fn = () => {
8
+ this.init();
9
+ return this.src.pipe(gulp.dest(this.output));
10
+ };
11
11
  }
12
12
  export default FontTask;
@@ -2,22 +2,6 @@ import { getDefaultImagePlugins } from '../../plugins/imagemin.js';
2
2
  class ImageTask extends BalmJS.BalmTask {
3
3
  constructor() {
4
4
  super('image');
5
- this.fn = () => {
6
- this.init();
7
- const balmImage = () => {
8
- return gulp
9
- .src(BalmJS.file.absPaths(this.input), {
10
- encoding: false,
11
- since: gulp.lastRun(balmImage)
12
- })
13
- .pipe(BalmJS.plugins.plumber((error) => {
14
- BalmJS.logger.error(`${this.name} task`, error);
15
- }))
16
- .pipe(BalmJS.plugins.imagemin(this.plugins))
17
- .pipe(gulp.dest(this.output));
18
- };
19
- return balmImage();
20
- };
21
5
  const excludeGlobs = [];
22
6
  for (const imageFolder of BalmJS.config.styles.sprites) {
23
7
  excludeGlobs.push(node.path.join(`!${BalmJS.config.src.img}`, imageFolder));
@@ -38,5 +22,21 @@ class ImageTask extends BalmJS.BalmTask {
38
22
  BalmJS.logger.debug(`${this.name} task - plugins`, enablePlugins);
39
23
  }
40
24
  }
25
+ fn = () => {
26
+ this.init();
27
+ const balmImage = () => {
28
+ return gulp
29
+ .src(BalmJS.file.absPaths(this.input), {
30
+ since: gulp.lastRun(balmImage),
31
+ encoding: false
32
+ })
33
+ .pipe(BalmJS.plugins.plumber((error) => {
34
+ BalmJS.logger.error(`${this.name} task`, error);
35
+ }))
36
+ .pipe(BalmJS.plugins.imagemin(this.plugins))
37
+ .pipe(gulp.dest(this.output));
38
+ };
39
+ return balmImage();
40
+ };
41
41
  }
42
42
  export default ImageTask;
@@ -1,17 +1,17 @@
1
1
  class LintTask extends BalmJS.BalmTask {
2
2
  constructor() {
3
3
  super('lint');
4
- this.fn = () => {
5
- this.init();
6
- return this.src
7
- .pipe($.eslint({ fix: true }))
8
- .pipe(server.reload({ stream: true, once: true }))
9
- .pipe($.eslint.format())
10
- .pipe($.if(!server.active, $.eslint.failAfterError()))
11
- .pipe(gulp.dest(this.output));
12
- };
13
4
  this.defaultOutput = BalmJS.config.src.js;
14
5
  this.defaultInput = BalmJS.file.matchAllFiles(this.defaultOutput, '*.js');
15
6
  }
7
+ fn = () => {
8
+ this.init();
9
+ return this.src
10
+ .pipe($.eslint({ fix: true }))
11
+ .pipe(server.reload({ stream: true, once: true }))
12
+ .pipe($.eslint.format())
13
+ .pipe($.if(!server.active, $.eslint.failAfterError()))
14
+ .pipe(gulp.dest(this.output));
15
+ };
16
16
  }
17
17
  export default LintTask;
@@ -1,12 +1,12 @@
1
1
  class MediaTask extends BalmJS.BalmTask {
2
2
  constructor() {
3
3
  super('media');
4
- this.fn = () => {
5
- this.init();
6
- return this.src.pipe(gulp.dest(this.output));
7
- };
8
4
  this.defaultInput = BalmJS.file.matchAllFiles(BalmJS.config.src.media);
9
5
  this.defaultOutput = BalmJS.config.dest.media;
10
6
  }
7
+ fn = () => {
8
+ this.init();
9
+ return this.src.pipe(gulp.dest(this.output));
10
+ };
11
11
  }
12
12
  export default MediaTask;
@@ -1,57 +1,54 @@
1
- var _ModernizrTask_readConfig, _ModernizrTask_createDir, _ModernizrTask_generateScript;
2
- import { __classPrivateFieldGet } from "tslib";
3
1
  import { build } from 'modernizr';
4
2
  class ModernizrTask extends BalmJS.BalmTask {
5
3
  constructor() {
6
4
  super('modernizr');
7
- _ModernizrTask_readConfig.set(this, () => {
8
- return new Promise((resolve, reject) => {
9
- node.fs.readFile(this.input, 'utf8', (err, data) => {
10
- if (err)
11
- reject(err);
12
- resolve(JSON.parse(data));
13
- });
5
+ this.defaultInput = `${this.name}.json`;
6
+ this.defaultOutput = node.path.join(BalmJS.config.dest.js, `${this.name}.js`);
7
+ }
8
+ #readConfig = () => {
9
+ return new Promise((resolve, reject) => {
10
+ node.fs.readFile(this.input, 'utf8', (err, data) => {
11
+ if (err)
12
+ reject(err);
13
+ resolve(JSON.parse(data));
14
+ });
15
+ });
16
+ };
17
+ #createDir = () => {
18
+ return new Promise((resolve, reject) => {
19
+ node.fs.mkdir(BalmJS.file.absPath(BalmJS.config.dest.js), { recursive: true }, (err) => {
20
+ if (err)
21
+ reject(err);
22
+ resolve();
14
23
  });
15
24
  });
16
- _ModernizrTask_createDir.set(this, () => {
17
- return new Promise((resolve, reject) => {
18
- node.fs.mkdir(BalmJS.file.absPath(BalmJS.config.dest.js), { recursive: true }, (err) => {
25
+ };
26
+ #generateScript = (config) => {
27
+ return new Promise((resolve, reject) => {
28
+ build(config, (content) => {
29
+ node.fs.writeFile(this.output, content, (err) => {
19
30
  if (err)
20
31
  reject(err);
21
- resolve();
32
+ resolve(content);
22
33
  });
23
34
  });
24
35
  });
25
- _ModernizrTask_generateScript.set(this, (config) => {
26
- return new Promise((resolve, reject) => {
27
- build(config, (content) => {
28
- node.fs.writeFile(this.output, content, (err) => {
29
- if (err)
30
- reject(err);
31
- resolve(content);
32
- });
33
- });
36
+ };
37
+ fn = async (callback) => {
38
+ this.init();
39
+ if (node.fs.existsSync(this.input)) {
40
+ const [config] = await Promise.all([
41
+ this.#readConfig(),
42
+ this.#createDir()
43
+ ]);
44
+ await this.#generateScript(config);
45
+ }
46
+ else {
47
+ BalmJS.logger.warn(`${this.name} task`, `The '${this.input}' does not exist`, {
48
+ logLevel: BalmJS.LogLevel.Info
34
49
  });
35
- });
36
- this.fn = async (callback) => {
37
- this.init();
38
- if (node.fs.existsSync(this.input)) {
39
- const [config] = await Promise.all([
40
- __classPrivateFieldGet(this, _ModernizrTask_readConfig, "f").call(this),
41
- __classPrivateFieldGet(this, _ModernizrTask_createDir, "f").call(this)
42
- ]);
43
- await __classPrivateFieldGet(this, _ModernizrTask_generateScript, "f").call(this, config);
44
- }
45
- else {
46
- BalmJS.logger.warn(`${this.name} task`, `The '${this.input}' does not exist`, {
47
- logLevel: BalmJS.LogLevel.Info
48
- });
49
- }
50
- callback();
51
- };
52
- this.defaultInput = `${this.name}.json`;
53
- this.defaultOutput = node.path.join(BalmJS.config.dest.js, `${this.name}.js`);
54
- }
50
+ }
51
+ callback();
52
+ };
55
53
  }
56
- _ModernizrTask_readConfig = new WeakMap(), _ModernizrTask_createDir = new WeakMap(), _ModernizrTask_generateScript = new WeakMap();
57
54
  export default ModernizrTask;
@@ -2,17 +2,6 @@ import { deleteAsync } from 'del';
2
2
  class PwaCacheTask extends BalmJS.BalmTask {
3
3
  constructor() {
4
4
  super('pwa-cache');
5
- this.fn = () => {
6
- this.init();
7
- const newVersion = BalmJS.config.pwa.version || Date.now().toString();
8
- BalmJS.logger.info('pwa - version', newVersion);
9
- const stream = this.src
10
- .pipe(BalmJS.plugins.replace('{{ version }}', newVersion))
11
- .pipe($.if(BalmJS.config.env.isProd, BalmJS.plugins.jsmin(BalmJS.config.scripts.minifyOptions)))
12
- .pipe(gulp.dest(this.output));
13
- this.clear();
14
- return stream;
15
- };
16
5
  this.defaultOutput = BalmJS.config.dest.base;
17
6
  this.defaultInput = node.path.join(this.defaultOutput, BalmJS.config.pwa.swDestFilename);
18
7
  }
@@ -20,5 +9,16 @@ class PwaCacheTask extends BalmJS.BalmTask {
20
9
  const swOrigin = BalmJS.file.absPath(node.path.join(BalmJS.config.dest.base, BalmJS.config.pwa.swSrcFilename));
21
10
  deleteAsync(swOrigin, { force: true });
22
11
  }
12
+ fn = () => {
13
+ this.init();
14
+ const newVersion = BalmJS.config.pwa.version || Date.now().toString();
15
+ BalmJS.logger.info('pwa - version', newVersion);
16
+ const stream = this.src
17
+ .pipe(BalmJS.plugins.replace('{{ version }}', newVersion))
18
+ .pipe($.if(BalmJS.config.env.isProd, BalmJS.plugins.jsmin(BalmJS.config.scripts.minifyOptions)))
19
+ .pipe(gulp.dest(this.output));
20
+ this.clear();
21
+ return stream;
22
+ };
23
23
  }
24
24
  export default PwaCacheTask;
@@ -1,42 +1,8 @@
1
- var _SpriteTask_tasks, _SpriteTask_getParams;
2
- import { __classPrivateFieldGet } from "tslib";
3
1
  import mergeStream from '../../utilities/merge-stream.js';
4
2
  class SpriteTask extends BalmJS.BalmTask {
3
+ #tasks = [];
5
4
  constructor() {
6
5
  super('sprite');
7
- _SpriteTask_tasks.set(this, []);
8
- _SpriteTask_getParams.set(this, (spriteItem, spriteOptions) => {
9
- const stylesConfig = Object.assign(spriteOptions, BalmJS.config.styles);
10
- const spriteName = `${spriteItem.folderName}-${this.name}s`;
11
- const imageTarget = stylesConfig.imageTarget || BalmJS.config.paths.target.img;
12
- let defaultParams = Object.assign({
13
- padding: 1
14
- }, {
15
- imgName: `${spriteName}.png`,
16
- cssName: `_${spriteItem.folderName}.${stylesConfig.extname}`,
17
- imgPath: `${stylesConfig.imageBasePath}${imageTarget}/${spriteName}.png`,
18
- cssVarMap: (sprite) => {
19
- sprite.name = `${spriteItem.folderName}-${sprite.name}`;
20
- },
21
- cssSpritesheetName: `${spriteItem.folderName}-spritesheet`,
22
- cssOpts: {
23
- cssSelector: (sprite) => `.${sprite.name}`
24
- }
25
- });
26
- if (stylesConfig.spriteRetina) {
27
- defaultParams = Object.assign(defaultParams, {
28
- retinaSrcFilter: `${spriteItem.retinaSrc}`,
29
- retinaImgName: `${spriteName}@2x.png`,
30
- retinaImgPath: `${stylesConfig.imageBasePath}${imageTarget}/${spriteName}@2x.png`,
31
- cssVarMap: (sprite) => {
32
- sprite.name = `${spriteItem.folderName}-${sprite.name}`;
33
- },
34
- cssRetinaSpritesheetName: `${spriteItem.folderName}-spritesheet-2x`,
35
- cssRetinaGroupsName: `${spriteItem.folderName}-retina-groups`
36
- });
37
- }
38
- return Object.assign(defaultParams, stylesConfig.spriteParams);
39
- });
40
6
  this.defaultInput = BalmJS.config.styles.sprites;
41
7
  this.defaultOutput = BalmJS.config.dest.img;
42
8
  if (this.defaultInput.length) {
@@ -44,6 +10,38 @@ class SpriteTask extends BalmJS.BalmTask {
44
10
  this.collect();
45
11
  }
46
12
  }
13
+ #getParams = (spriteItem, spriteOptions) => {
14
+ const stylesConfig = Object.assign(spriteOptions, BalmJS.config.styles);
15
+ const spriteName = `${spriteItem.folderName}-${this.name}s`;
16
+ const imageTarget = stylesConfig.imageTarget || BalmJS.config.paths.target.img;
17
+ let defaultParams = Object.assign({
18
+ padding: 1
19
+ }, {
20
+ imgName: `${spriteName}.png`,
21
+ cssName: `_${spriteItem.folderName}.${stylesConfig.extname}`,
22
+ imgPath: `${stylesConfig.imageBasePath}${imageTarget}/${spriteName}.png`,
23
+ cssVarMap: (sprite) => {
24
+ sprite.name = `${spriteItem.folderName}-${sprite.name}`;
25
+ },
26
+ cssSpritesheetName: `${spriteItem.folderName}-spritesheet`,
27
+ cssOpts: {
28
+ cssSelector: (sprite) => `.${sprite.name}`
29
+ }
30
+ });
31
+ if (stylesConfig.spriteRetina) {
32
+ defaultParams = Object.assign(defaultParams, {
33
+ retinaSrcFilter: `${spriteItem.retinaSrc}`,
34
+ retinaImgName: `${spriteName}@2x.png`,
35
+ retinaImgPath: `${stylesConfig.imageBasePath}${imageTarget}/${spriteName}@2x.png`,
36
+ cssVarMap: (sprite) => {
37
+ sprite.name = `${spriteItem.folderName}-${sprite.name}`;
38
+ },
39
+ cssRetinaSpritesheetName: `${spriteItem.folderName}-spritesheet-2x`,
40
+ cssRetinaGroupsName: `${spriteItem.folderName}-retina-groups`
41
+ });
42
+ }
43
+ return Object.assign(defaultParams, stylesConfig.spriteParams);
44
+ };
47
45
  collect(spriteOptions = {}) {
48
46
  const spriteList = [];
49
47
  for (const spriteName of this.input) {
@@ -64,7 +62,7 @@ class SpriteTask extends BalmJS.BalmTask {
64
62
  BalmJS.logger.debug(`${this.name} task`, spriteConfig, {
65
63
  pre: true
66
64
  });
67
- spriteConfig.params = __classPrivateFieldGet(this, _SpriteTask_getParams, "f").call(this, spriteItem, spriteOptions);
65
+ spriteConfig.params = this.#getParams(spriteItem, spriteOptions);
68
66
  gulp.task(BalmJS.toNamespace(spriteTaskName), () => {
69
67
  const spriteData = gulp
70
68
  .src(spriteConfig.input, { encoding: false })
@@ -76,7 +74,7 @@ class SpriteTask extends BalmJS.BalmTask {
76
74
  const cssStream = spriteData.css.pipe(gulp.dest(spriteConfig.cssOutput));
77
75
  return mergeStream(imgStream, cssStream);
78
76
  });
79
- __classPrivateFieldGet(this, _SpriteTask_tasks, "f").push(spriteTaskName);
77
+ this.#tasks.push(spriteTaskName);
80
78
  }
81
79
  }
82
80
  recipe(input, output, spriteOptions = {}) {
@@ -89,8 +87,7 @@ class SpriteTask extends BalmJS.BalmTask {
89
87
  }
90
88
  }
91
89
  get deps() {
92
- return __classPrivateFieldGet(this, _SpriteTask_tasks, "f");
90
+ return this.#tasks;
93
91
  }
94
92
  }
95
- _SpriteTask_tasks = new WeakMap(), _SpriteTask_getParams = new WeakMap();
96
93
  export default SpriteTask;
@@ -1,13 +1,13 @@
1
1
  class StartTask extends BalmJS.BalmTask {
2
2
  constructor() {
3
3
  super('start');
4
- this.fn = async (callback) => {
5
- BalmJS.start = process.hrtime();
6
- if (BalmJS.utils.isFunction(BalmJS.beforeTask)) {
7
- await BalmJS.beforeTask();
8
- }
9
- callback();
10
- };
11
4
  }
5
+ fn = async (callback) => {
6
+ BalmJS.start = process.hrtime();
7
+ if (BalmJS.utils.isFunction(BalmJS.beforeTask)) {
8
+ await BalmJS.beforeTask();
9
+ }
10
+ callback();
11
+ };
12
12
  }
13
13
  export default StartTask;
@@ -1,15 +1,15 @@
1
1
  class WorkboxSwTask extends BalmJS.BalmTask {
2
2
  constructor() {
3
3
  super('workbox-sw');
4
- this.fn = () => {
5
- this.init();
6
- return this.src.pipe(gulp.dest(this.output));
7
- };
8
4
  this.defaultInput = [
9
5
  BalmJS.config.pwa.workboxSw,
10
6
  `${BalmJS.config.pwa.workboxSw}.map`
11
7
  ];
12
8
  this.defaultOutput = BalmJS.config.dest.base;
13
9
  }
10
+ fn = () => {
11
+ this.init();
12
+ return this.src.pipe(gulp.dest(this.output));
13
+ };
14
14
  }
15
15
  export default WorkboxSwTask;