balm-core 5.0.2 → 5.2.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 (57) hide show
  1. package/README.md +1 -1
  2. package/index.d.ts +9 -0
  3. package/lib/config/globals.js +14 -1
  4. package/lib/plugins/htmlmin.js +4 -3
  5. package/lib/plugins/imagemin.js +15 -10
  6. package/lib/plugins/index.js +2 -0
  7. package/lib/plugins/postcss.js +2 -2
  8. package/lib/plugins/rename.js +1 -3
  9. package/lib/plugins/replace.js +3 -1
  10. package/lib/plugins/sass-legacy.js +131 -0
  11. package/lib/plugins/sass.js +66 -125
  12. package/lib/plugins/sftp.js +7 -5
  13. package/lib/tasks/foundation/balm.js +4 -4
  14. package/lib/tasks/foundation/balm_style.js +1 -2
  15. package/lib/tasks/private/cache.js +7 -4
  16. package/lib/tasks/private/image.js +2 -2
  17. package/lib/tasks/private/pwa-cache.js +10 -4
  18. package/lib/tasks/public/publish.js +9 -3
  19. package/lib/tasks/public/pwa.js +22 -7
  20. package/lib/tasks/public/sass.js +1 -2
  21. package/package.json +48 -49
  22. package/tslib/balm.js +5 -8
  23. package/tslib/config/globals.js +21 -1
  24. package/tslib/plugins/htmlmin.js +4 -3
  25. package/tslib/plugins/imagemin.js +15 -10
  26. package/tslib/plugins/index.js +2 -0
  27. package/tslib/plugins/rename.js +1 -1
  28. package/tslib/plugins/replace.js +2 -1
  29. package/tslib/plugins/sass-legacy.js +95 -0
  30. package/tslib/plugins/sass.js +62 -124
  31. package/tslib/plugins/sftp.js +7 -4
  32. package/tslib/tasks/foundation/balm.js +12 -10
  33. package/tslib/tasks/foundation/balm_style.js +3 -2
  34. package/tslib/tasks/private/build.js +7 -7
  35. package/tslib/tasks/private/cache.js +14 -11
  36. package/tslib/tasks/private/clean.js +28 -31
  37. package/tslib/tasks/private/end.js +8 -8
  38. package/tslib/tasks/private/extra.js +7 -7
  39. package/tslib/tasks/private/font.js +4 -4
  40. package/tslib/tasks/private/image.js +16 -16
  41. package/tslib/tasks/private/lint.js +9 -9
  42. package/tslib/tasks/private/media.js +4 -4
  43. package/tslib/tasks/private/modernizr.js +40 -43
  44. package/tslib/tasks/private/pwa-cache.js +21 -13
  45. package/tslib/tasks/private/sprite.js +36 -39
  46. package/tslib/tasks/private/start.js +7 -7
  47. package/tslib/tasks/private/workbox-sw.js +4 -4
  48. package/tslib/tasks/public/html.js +23 -26
  49. package/tslib/tasks/public/publish.js +19 -16
  50. package/tslib/tasks/public/pwa.js +23 -6
  51. package/tslib/tasks/public/remove.js +8 -11
  52. package/tslib/tasks/public/sass.js +1 -2
  53. package/tslib/tasks/public/server.js +34 -37
  54. package/tslib/tasks/public/url.js +16 -19
  55. package/tslib/utilities/compiling.js +4 -9
  56. package/tslib/utilities/loading.js +8 -14
  57. package/tslib/utilities/logger.js +13 -18
@@ -1,86 +1,61 @@
1
- import fs from 'node:fs';
2
- import { pathToFileURL } from 'node:url';
3
1
  import { Transform } from 'node:stream';
4
- import semver from 'semver';
5
2
  import * as sass from 'sass';
6
3
  import replaceExtension from 'replace-ext';
7
4
  import stripAnsi from 'strip-ansi';
8
5
  import applySourceMap from 'vinyl-sourcemaps-apply';
9
6
  import ansiColors from 'ansi-colors';
10
- process.env.BALM_CWD = process.env.INIT_CWD || process.cwd();
11
- const localSassModule = node.path.join(process.env.BALM_CWD, 'node_modules', 'sass');
12
- let isLegacy = false;
13
- try {
14
- const sassPkg = requireModule(node.path.join(localSassModule, 'package.json'));
15
- isLegacy = semver.lt(sassPkg.version, '1.40.0');
16
- }
17
- catch (_) { }
18
- const nodeLocalSassModule = node.path.join(localSassModule, 'sass.node.js');
19
- const defaultLocalSassModule = node.path.join(localSassModule, 'sass.default.js');
20
- const dartLocalSassModule = node.path.join(localSassModule, 'sass.dart.js');
21
- const sassModule = fs.existsSync(nodeLocalSassModule)
22
- ? requireModule(nodeLocalSassModule)
23
- : fs.existsSync(defaultLocalSassModule)
24
- ? requireModule(defaultLocalSassModule)
25
- : fs.existsSync(dartLocalSassModule)
26
- ? requireModule(dartLocalSassModule)
27
- : sass;
7
+ const sassModule = node.getSassModule(sass);
28
8
  const PLUGIN_NAME = 'sass';
29
9
  const transformObj = (transform) => new Transform({ transform, objectMode: true });
30
10
  function filePush(file, result, callback) {
31
- if (result.sourceMap) {
32
- const sassMap = result.sourceMap;
33
- sassMap.file = replaceExtension(file.relative, '.css');
34
- applySourceMap(file, sassMap);
35
- }
36
11
  file.contents = Buffer.from(result.css);
37
12
  file.path = replaceExtension(file.path, '.css');
38
- if (file.stat) {
39
- file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
40
- }
41
- callback(null, file);
42
- }
43
- function legacyFilePush(file, sassObject, callback) {
44
- if (sassObject.map) {
45
- const sassMap = JSON.parse(sassObject.map.toString());
46
- const sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin');
47
- const sassFileSrc = file.relative;
48
- const sassFileSrcPath = node.path.dirname(sassFileSrc);
49
- if (sassFileSrcPath) {
50
- const sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
51
- sassMap.sources = sassMap.sources.map((source, index) => index === sourceFileIndex
52
- ? source
53
- : node.path.join(sassFileSrcPath, source));
13
+ if (result.sourceMap) {
14
+ const proto = /^file:\/\/?/;
15
+ const leadingSlash = /^\//;
16
+ const sassMap = result.sourceMap;
17
+ const base = node.path.resolve(file.cwd, file.base);
18
+ if (!sassMap.file) {
19
+ sassMap.file = file.history[0]
20
+ .replace(base + node.path.sep, '')
21
+ .replace(proto, '');
54
22
  }
55
- sassMap.sources = sassMap.sources.filter((src) => src !== 'stdin' && src);
23
+ sassMap.sources = sassMap.sources.map((src) => {
24
+ const baseUri = base.replace(/\\/g, '/');
25
+ if (src.startsWith('data:')) {
26
+ return file.history[0]
27
+ .replace(/\\/g, '/')
28
+ .replace(`${baseUri}/`, '')
29
+ .replace(proto, '')
30
+ .replace(leadingSlash, '');
31
+ }
32
+ return src
33
+ .replace(proto, '')
34
+ .replace(`${baseUri}/`, '')
35
+ .replace(leadingSlash, '');
36
+ });
37
+ const sassFileSrc = file.relative;
56
38
  sassMap.file = replaceExtension(sassFileSrc, '.css');
39
+ if (file.sourceMap &&
40
+ file.sourceMap.sourcesContent &&
41
+ !sassMap.sourcesContent) {
42
+ sassMap.sourcesContent = file.sourceMap.sourcesContent;
43
+ }
57
44
  applySourceMap(file, sassMap);
58
45
  }
59
- file.contents = sassObject.css;
60
- file.path = replaceExtension(file.path, '.css');
61
46
  if (file.stat) {
62
47
  file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
63
48
  }
64
49
  callback(null, file);
65
50
  }
66
51
  function handleError(error, file, callback) {
67
- const relativePath = node.path.relative(process.cwd(), file.path);
68
- const message = `${ansiColors.underline(relativePath)}\n${error.message}`;
69
- error.message = stripAnsi(message);
70
- return callback(new PluginError(PLUGIN_NAME, error));
71
- }
72
- function legacyHandleError(error, file, callback) {
73
- const filePath = ((error.file === 'stdin' ? file.path : error.file) ||
74
- file.path);
52
+ const filePath = (error.file === 'stdin' ? file.path : error.file) || file.path;
75
53
  const relativePath = node.path.relative(process.cwd(), filePath);
76
- const message = `${ansiColors.underline(relativePath)}\n${error.formatted}`;
77
- error.messageFormatted = message;
78
- error.messageOriginal = error.message;
54
+ const message = `${ansiColors.underline(relativePath)}\n${error.message}`;
79
55
  error.message = stripAnsi(message);
80
- error.relativePath = relativePath;
81
56
  return callback(new PluginError(PLUGIN_NAME, error));
82
57
  }
83
- const gulpSass = (options) => transformObj((file, encoding, callback) => {
58
+ const gulpSass = (options, sync = false) => transformObj((file, encoding, callback) => {
84
59
  if (file.isNull()) {
85
60
  return callback(null, file);
86
61
  }
@@ -95,77 +70,40 @@ const gulpSass = (options) => transformObj((file, encoding, callback) => {
95
70
  return callback(null, file);
96
71
  }
97
72
  const opts = (options || {});
98
- if (isLegacy) {
99
- opts.data = file.contents.toString();
100
- opts.file = file.path;
101
- if (node.path.extname(file.path) === '.sass') {
102
- opts.indentedSyntax = true;
103
- }
104
- if (opts.includePaths) {
105
- if (typeof opts.includePaths === 'string') {
106
- opts.includePaths = [opts.includePaths];
107
- }
108
- }
109
- else {
110
- opts.includePaths = [];
111
- }
112
- opts.includePaths.unshift(node.path.dirname(file.path));
113
- if (file.sourceMap) {
114
- opts.sourceMap = file.path;
115
- opts.omitSourceMapUrl = true;
116
- opts.sourceMapContents = true;
117
- }
118
- if (!opts.importer) {
119
- const aliasKeys = Object.keys(BalmJS.config.scripts.alias).filter((key) => /^@[a-z0-9-]{1,213}/.test(key));
120
- if (aliasKeys.length) {
121
- const aliasKeyRegex = new RegExp(`^(${aliasKeys.join('|')})/`);
122
- opts.importer = [
123
- function (url) {
124
- let file = url;
125
- const result = url.match(aliasKeyRegex);
126
- const key = result ? result[1] : null;
127
- if (key) {
128
- file = url.replace(key, BalmJS.config.scripts.alias[key]);
129
- BalmJS.logger.debug(`${PLUGIN_NAME} alias`, `${key} -> ${url} => ${file}`);
130
- }
131
- return { file };
132
- }
133
- ];
134
- }
73
+ if (node.path.extname(file.path) === '.sass') {
74
+ opts.syntax = 'indented';
75
+ }
76
+ if (opts.loadPaths) {
77
+ if (typeof opts.loadPaths === 'string') {
78
+ opts.loadPaths = [opts.loadPaths];
135
79
  }
136
80
  }
137
81
  else {
138
- if (!options.importers) {
139
- const aliasKeys = Object.keys(BalmJS.config.scripts.alias).filter((key) => /^@[a-z0-9-]{1,213}/.test(key));
140
- if (aliasKeys.length) {
141
- const aliasKeyRegex = new RegExp(`^(${aliasKeys.join('|')})/`);
142
- options.importers = [
143
- {
144
- findFileUrl(url) {
145
- let file = url;
146
- const result = url.match(aliasKeyRegex);
147
- const key = result ? result[1] : null;
148
- if (key) {
149
- file = url.replace(key, BalmJS.config.scripts.alias[key]);
150
- BalmJS.logger.debug(`${PLUGIN_NAME} alias`, `${key} -> ${url} => ${file}`);
151
- }
152
- return pathToFileURL(file);
153
- }
154
- }
155
- ];
156
- }
157
- }
82
+ opts.loadPaths = [];
158
83
  }
159
- try {
160
- isLegacy
161
- ? legacyFilePush(file, sassModule.renderSync(opts), callback)
162
- : filePush(file, sassModule.compile(file.path, options), callback);
84
+ opts.loadPaths.unshift(node.path.dirname(file.path));
85
+ if (file.sourceMap) {
86
+ opts.sourceMap = true;
87
+ opts.sourceMapIncludeSources = true;
163
88
  }
164
- catch (error) {
165
- isLegacy
166
- ? legacyHandleError(error, file, callback)
167
- : handleError(error, file, callback);
89
+ const fileContents = file.contents.toString();
90
+ if (sync !== true) {
91
+ sassModule
92
+ .compileStringAsync(fileContents, opts)
93
+ .then((compileResult) => {
94
+ filePush(file, compileResult, callback);
95
+ })
96
+ .catch((error) => {
97
+ handleError(error, file, callback);
98
+ });
99
+ }
100
+ else {
101
+ try {
102
+ filePush(file, sassModule.compileString(fileContents, opts), callback);
103
+ }
104
+ catch (error) {
105
+ handleError(error, file, callback);
106
+ }
168
107
  }
169
108
  });
170
109
  export default gulpSass;
171
- export { isLegacy };
@@ -71,7 +71,7 @@ function getKey(options) {
71
71
  }
72
72
  function gulpSftp(options) {
73
73
  options = Object.assign({}, options);
74
- if (options.host === undefined) {
74
+ if (!options.host) {
75
75
  throw new PluginError(PLUGIN_NAME, '`host` required');
76
76
  }
77
77
  let fileCount = 0;
@@ -154,7 +154,8 @@ function gulpSftp(options) {
154
154
  });
155
155
  });
156
156
  conn.on('error', (err) => {
157
- this.emit('error', new PluginError(PLUGIN_NAME, err));
157
+ const errorMsg = (err && (err.message || err.toString())) || 'SFTP connection error';
158
+ this.emit('error', new PluginError(PLUGIN_NAME, errorMsg));
158
159
  });
159
160
  conn.on('end', () => {
160
161
  BalmJS.logger.debug(PLUGIN_NAME, 'Client :: end');
@@ -195,7 +196,8 @@ function gulpSftp(options) {
195
196
  cb();
196
197
  }
197
198
  else {
198
- sftp.mkdir(d, { mode: '0755' }, (err) => {
199
+ const dirMode = options.dirMode || '0755';
200
+ sftp.mkdir(d, { mode: dirMode }, (err) => {
199
201
  if (err) {
200
202
  BalmJS.logger.warn(PLUGIN_NAME, `Error or directory exists: ${err} ${d}`);
201
203
  }
@@ -207,10 +209,11 @@ function gulpSftp(options) {
207
209
  }
208
210
  });
209
211
  }, () => {
212
+ const fileMode = options.fileMode || '0666';
210
213
  const stream = sftp.createWriteStream(finalRemotePath, {
211
214
  flags: 'w',
212
215
  encoding: null,
213
- mode: '0666',
216
+ mode: fileMode,
214
217
  autoClose: true
215
218
  });
216
219
  if (file.isStream()) {
@@ -1,11 +1,13 @@
1
1
  class BalmTask {
2
+ name;
3
+ taskName;
4
+ defaultInput = '';
5
+ defaultOutput = '';
6
+ input = '';
7
+ output = '';
8
+ customOptions = {};
9
+ gulpSrcOptions = {};
2
10
  constructor(name) {
3
- this.defaultInput = '';
4
- this.defaultOutput = '';
5
- this.input = '';
6
- this.output = '';
7
- this.customOptions = {};
8
- this.gulpSrcOptions = {};
9
11
  this.name = name;
10
12
  this.taskName = BalmJS.toNamespace(name);
11
13
  }
@@ -27,8 +29,8 @@ class BalmTask {
27
29
  get src() {
28
30
  return gulp
29
31
  .src(this.input, Object.assign({
30
- encoding: false,
31
- allowEmpty: true
32
+ allowEmpty: true,
33
+ encoding: false
32
34
  }, this.gulpSrcOptions))
33
35
  .pipe(BalmJS.plugins.plumber((error) => {
34
36
  BalmJS.logger.error(`${this.name} task`, error.message);
@@ -46,10 +48,10 @@ class BalmTask {
46
48
  default:
47
49
  }
48
50
  const useAbsPath = !['webpack', 'rollup', 'esbuild', 'sprite'].includes(key);
49
- this.input = useAbsPath
51
+ this.input = useAbsPath && (input || this.defaultInput)
50
52
  ? BalmJS.file.absPaths(input || this.defaultInput)
51
53
  : input || this.defaultInput;
52
- this.output = useAbsPath
54
+ this.output = useAbsPath && typeof (output || this.defaultOutput) === 'string'
53
55
  ? BalmJS.file.absPath(output || this.defaultOutput)
54
56
  : output || this.defaultOutput;
55
57
  this.customOptions = options[key] || {};
@@ -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]));
@@ -38,8 +28,21 @@ class CacheTask extends BalmJS.BalmTask {
38
28
  ? BalmJS.config.dest.base
39
29
  : BalmJS.config.dest.static;
40
30
  this.gulpSrcOptions = {
41
- base: BalmJS.config.dest.base
31
+ base: this.defaultOutput
42
32
  };
43
33
  }
34
+ fn = () => {
35
+ this.init();
36
+ this.gulpSrcOptions = {
37
+ base: this.output
38
+ };
39
+ return this.src
40
+ .pipe(revAll.revision(BalmJS.config.assets.options))
41
+ .pipe($.if(/\.html$/, BalmJS.file.setPublicPath()))
42
+ .pipe(gulp.dest(this.output))
43
+ .pipe($.revDeleteOriginal({ exclude: /\.html$/ }))
44
+ .pipe(revAll.manifestFile())
45
+ .pipe(gulp.dest(this.output));
46
+ };
44
47
  }
45
48
  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;