balm-core 5.0.1 → 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.
- package/README.md +1 -1
- package/index.d.ts +7 -0
- package/lib/balm.js +2 -2
- package/lib/bundler/webpack/config/env.js +1 -1
- package/lib/config/globals.js +14 -1
- package/lib/plugins/imagemin.js +13 -8
- package/lib/plugins/index.js +2 -0
- package/lib/plugins/postcss.js +2 -2
- package/lib/plugins/rename.js +1 -3
- package/lib/plugins/replace.js +4 -2
- package/lib/plugins/sass-legacy.js +131 -0
- package/lib/plugins/sass.js +66 -125
- package/lib/tasks/foundation/balm.js +3 -2
- package/lib/tasks/foundation/balm_style.js +1 -1
- package/lib/tasks/private/build.js +1 -1
- package/lib/tasks/private/cache.js +1 -1
- package/lib/tasks/private/clean.js +3 -3
- package/lib/tasks/private/end.js +1 -1
- package/lib/tasks/private/extra.js +1 -1
- package/lib/tasks/private/font.js +1 -1
- package/lib/tasks/private/image.js +3 -2
- package/lib/tasks/private/lint.js +1 -1
- package/lib/tasks/private/media.js +1 -1
- package/lib/tasks/private/modernizr.js +3 -3
- package/lib/tasks/private/pwa-cache.js +1 -1
- package/lib/tasks/private/sprite.js +5 -3
- package/lib/tasks/private/start.js +1 -1
- package/lib/tasks/private/workbox-sw.js +1 -1
- package/lib/tasks/public/html.js +2 -2
- package/lib/tasks/public/publish.js +2 -2
- package/lib/tasks/public/remove.js +2 -2
- package/lib/tasks/public/sass.js +1 -2
- package/lib/tasks/public/server.js +2 -2
- package/lib/tasks/public/url.js +2 -2
- package/lib/utilities/compiling.js +2 -2
- package/lib/utilities/loading.js +2 -2
- package/lib/utilities/logger.js +2 -2
- package/package.json +53 -52
- package/tslib/balm.js +5 -8
- package/tslib/config/globals.js +21 -1
- package/tslib/plugins/imagemin.js +13 -8
- package/tslib/plugins/index.js +2 -0
- package/tslib/plugins/rename.js +1 -1
- package/tslib/plugins/replace.js +2 -1
- package/tslib/plugins/sass-legacy.js +95 -0
- package/tslib/plugins/sass.js +62 -124
- package/tslib/tasks/foundation/balm.js +10 -7
- package/tslib/tasks/foundation/balm_style.js +3 -1
- package/tslib/tasks/private/build.js +7 -7
- package/tslib/tasks/private/cache.js +10 -10
- package/tslib/tasks/private/clean.js +28 -31
- package/tslib/tasks/private/end.js +8 -8
- package/tslib/tasks/private/extra.js +7 -7
- package/tslib/tasks/private/font.js +4 -4
- package/tslib/tasks/private/image.js +16 -15
- package/tslib/tasks/private/lint.js +9 -9
- package/tslib/tasks/private/media.js +4 -4
- package/tslib/tasks/private/modernizr.js +40 -43
- package/tslib/tasks/private/pwa-cache.js +11 -11
- package/tslib/tasks/private/sprite.js +37 -40
- package/tslib/tasks/private/start.js +7 -7
- package/tslib/tasks/private/workbox-sw.js +4 -4
- package/tslib/tasks/public/html.js +23 -26
- package/tslib/tasks/public/publish.js +13 -16
- package/tslib/tasks/public/remove.js +8 -11
- package/tslib/tasks/public/sass.js +1 -2
- package/tslib/tasks/public/server.js +34 -37
- package/tslib/tasks/public/url.js +16 -19
- package/tslib/utilities/compiling.js +4 -9
- package/tslib/utilities/loading.js +8 -14
- package/tslib/utilities/logger.js +13 -18
package/tslib/plugins/sass.js
CHANGED
|
@@ -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
|
-
|
|
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 (
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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.
|
|
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
|
|
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.
|
|
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 (
|
|
99
|
-
opts.
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
84
|
+
opts.loadPaths.unshift(node.path.dirname(file.path));
|
|
85
|
+
if (file.sourceMap) {
|
|
86
|
+
opts.sourceMap = true;
|
|
87
|
+
opts.sourceMapIncludeSources = true;
|
|
163
88
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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 };
|
|
@@ -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,7 +29,8 @@ class BalmTask {
|
|
|
27
29
|
get src() {
|
|
28
30
|
return gulp
|
|
29
31
|
.src(this.input, Object.assign({
|
|
30
|
-
allowEmpty: true
|
|
32
|
+
allowEmpty: true,
|
|
33
|
+
encoding: false
|
|
31
34
|
}, this.gulpSrcOptions))
|
|
32
35
|
.pipe(BalmJS.plugins.plumber((error) => {
|
|
33
36
|
BalmJS.logger.error(`${this.name} task`, error.message);
|
|
@@ -47,7 +47,9 @@ class BalmStyleTask extends BalmTask {
|
|
|
47
47
|
}));
|
|
48
48
|
switch (style) {
|
|
49
49
|
case 'sass':
|
|
50
|
-
stream = stream.pipe(
|
|
50
|
+
stream = stream.pipe(node.isLegacySass
|
|
51
|
+
? BalmJS.plugins.legacySass(options)
|
|
52
|
+
: BalmJS.plugins.sass(options));
|
|
51
53
|
break;
|
|
52
54
|
case 'less':
|
|
53
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,5 +28,15 @@ class CacheTask extends BalmJS.BalmTask {
|
|
|
38
28
|
? BalmJS.config.dest.base
|
|
39
29
|
: BalmJS.config.dest.static;
|
|
40
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
|
+
};
|
|
41
41
|
}
|
|
42
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
|
-
:
|
|
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, ...
|
|
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,21 +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
|
-
since: gulp.lastRun(balmImage)
|
|
11
|
-
})
|
|
12
|
-
.pipe(BalmJS.plugins.plumber((error) => {
|
|
13
|
-
BalmJS.logger.error(`${this.name} task`, error);
|
|
14
|
-
}))
|
|
15
|
-
.pipe(BalmJS.plugins.imagemin(this.plugins))
|
|
16
|
-
.pipe(gulp.dest(this.output));
|
|
17
|
-
};
|
|
18
|
-
return balmImage();
|
|
19
|
-
};
|
|
20
5
|
const excludeGlobs = [];
|
|
21
6
|
for (const imageFolder of BalmJS.config.styles.sprites) {
|
|
22
7
|
excludeGlobs.push(node.path.join(`!${BalmJS.config.src.img}`, imageFolder));
|
|
@@ -37,5 +22,21 @@ class ImageTask extends BalmJS.BalmTask {
|
|
|
37
22
|
BalmJS.logger.debug(`${this.name} task - plugins`, enablePlugins);
|
|
38
23
|
}
|
|
39
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
|
+
};
|
|
40
41
|
}
|
|
41
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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;
|