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.
- package/README.md +1 -1
- package/index.d.ts +9 -0
- package/lib/config/globals.js +14 -1
- package/lib/plugins/htmlmin.js +4 -3
- package/lib/plugins/imagemin.js +15 -10
- 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 +3 -1
- package/lib/plugins/sass-legacy.js +131 -0
- package/lib/plugins/sass.js +66 -125
- package/lib/plugins/sftp.js +7 -5
- package/lib/tasks/foundation/balm.js +4 -4
- package/lib/tasks/foundation/balm_style.js +1 -2
- package/lib/tasks/private/cache.js +7 -4
- package/lib/tasks/private/image.js +2 -2
- package/lib/tasks/private/pwa-cache.js +10 -4
- package/lib/tasks/public/publish.js +9 -3
- package/lib/tasks/public/pwa.js +22 -7
- package/lib/tasks/public/sass.js +1 -2
- package/package.json +48 -49
- package/tslib/balm.js +5 -8
- package/tslib/config/globals.js +21 -1
- package/tslib/plugins/htmlmin.js +4 -3
- package/tslib/plugins/imagemin.js +15 -10
- 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/plugins/sftp.js +7 -4
- package/tslib/tasks/foundation/balm.js +12 -10
- package/tslib/tasks/foundation/balm_style.js +3 -2
- package/tslib/tasks/private/build.js +7 -7
- package/tslib/tasks/private/cache.js +14 -11
- 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 -16
- 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 +21 -13
- package/tslib/tasks/private/sprite.js +36 -39
- 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 +19 -16
- package/tslib/tasks/public/pwa.js +23 -6
- 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/README.md
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export * from './types/vendors';
|
|
2
|
+
export * from './types/globals';
|
|
3
|
+
export * from './types/webworker';
|
|
4
|
+
export * from './types/balm';
|
|
5
|
+
export * from './types/gulp';
|
|
6
|
+
export * from './types/node';
|
|
7
|
+
|
|
1
8
|
export interface LooseObject {
|
|
2
9
|
[key: string]: any;
|
|
3
10
|
}
|
|
@@ -182,6 +189,8 @@ export interface BalmFtpConfig {
|
|
|
182
189
|
username?: string;
|
|
183
190
|
password?: string;
|
|
184
191
|
remotePath?: string;
|
|
192
|
+
dirMode?: string;
|
|
193
|
+
fileMode?: string;
|
|
185
194
|
}
|
|
186
195
|
|
|
187
196
|
export interface BalmConfig {
|
package/lib/config/globals.js
CHANGED
|
@@ -4,10 +4,21 @@ import colors from 'ansi-colors';
|
|
|
4
4
|
import { create } from 'browser-sync';
|
|
5
5
|
import through2 from 'through2';
|
|
6
6
|
import PluginError from 'plugin-error';
|
|
7
|
+
import semver from 'semver';
|
|
7
8
|
|
|
8
9
|
// Set env var for ORIGINAL cwd before anything touches it
|
|
9
10
|
process.env.BALM_CWD = process.env.INIT_CWD || process.cwd();
|
|
10
11
|
const gulpModule = path.join(process.env.BALM_ROOT || process.env.BALM_CWD, 'node_modules', 'gulp', 'index.js');
|
|
12
|
+
const localSassModule = path.join(process.env.BALM_CWD, 'node_modules', 'sass');
|
|
13
|
+
let isLegacySass = false;
|
|
14
|
+
try {
|
|
15
|
+
const sassPkg = requireModule(path.join(localSassModule, 'package.json'));
|
|
16
|
+
isLegacySass = semver.lt(sassPkg.version, '1.40.0');
|
|
17
|
+
} catch (_) {}
|
|
18
|
+
const nodeLocalSassModule = path.join(localSassModule, 'sass.node.js');
|
|
19
|
+
const defaultLocalSassModule = path.join(localSassModule, 'sass.default.js'); // For `npm i -D sass <= 1.62.1`
|
|
20
|
+
const dartLocalSassModule = path.join(localSassModule, 'sass.dart.js'); // For `npm i -D sass <= 1.39.2`
|
|
21
|
+
const getSassModule = sass => fs.existsSync(nodeLocalSassModule) ? requireModule(nodeLocalSassModule) : fs.existsSync(defaultLocalSassModule) ? requireModule(defaultLocalSassModule) : fs.existsSync(dartLocalSassModule) ? requireModule(dartLocalSassModule) : sass;
|
|
11
22
|
if (fs.existsSync(gulpModule)) {
|
|
12
23
|
// Chdir before requiring balm config to make sure
|
|
13
24
|
// we let them chdir as needed
|
|
@@ -22,7 +33,9 @@ if (fs.existsSync(gulpModule)) {
|
|
|
22
33
|
}
|
|
23
34
|
global.node = {
|
|
24
35
|
path,
|
|
25
|
-
fs
|
|
36
|
+
fs,
|
|
37
|
+
isLegacySass,
|
|
38
|
+
getSassModule
|
|
26
39
|
};
|
|
27
40
|
global.server = create();
|
|
28
41
|
global.through2 = through2;
|
package/lib/plugins/htmlmin.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Reference `gulp-htmlmin@5.0.1`
|
|
2
2
|
|
|
3
|
-
import { minify } from 'html-minifier';
|
|
3
|
+
import { minify } from 'html-minifier-terser';
|
|
4
4
|
const PLUGIN_NAME = 'htmlmin';
|
|
5
5
|
function gulpHtmlmin(options) {
|
|
6
6
|
options = BalmJS.utils.deepMerge({}, options);
|
|
@@ -9,9 +9,10 @@ function gulpHtmlmin(options) {
|
|
|
9
9
|
callback(null, file);
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
function htmlMinify(buf, enc, cb) {
|
|
12
|
+
async function htmlMinify(buf, enc, cb) {
|
|
13
13
|
try {
|
|
14
|
-
const
|
|
14
|
+
const minified = await minify(buf.toString(), options);
|
|
15
|
+
const contents = Buffer.from(minified);
|
|
15
16
|
if (cb === callback) {
|
|
16
17
|
file.contents = contents;
|
|
17
18
|
cb(null, file);
|
package/lib/plugins/imagemin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Reference `gulp-imagemin@9.
|
|
1
|
+
// Reference `gulp-imagemin@9.1.0`
|
|
2
2
|
|
|
3
3
|
import imagemin from 'imagemin';
|
|
4
4
|
import prettyBytes from 'pretty-bytes';
|
|
@@ -6,11 +6,16 @@ import through2Concurrent from 'through2-concurrent';
|
|
|
6
6
|
const PLUGIN_NAME = 'imagemin';
|
|
7
7
|
const defaultPlugins = ['gifsicle', 'mozjpeg', 'optipng', 'svgo'];
|
|
8
8
|
const loadPlugin = (plugin, ...args) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
return async input => {
|
|
10
|
+
try {
|
|
11
|
+
const m = await import(`imagemin-${plugin}`);
|
|
12
|
+
const pluginFn = m.default(...args);
|
|
13
|
+
return pluginFn(input);
|
|
14
|
+
} catch (_) {
|
|
15
|
+
BalmJS.logger.error(PLUGIN_NAME, `Could not load default plugin \`${plugin}\``);
|
|
16
|
+
return input;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
14
19
|
};
|
|
15
20
|
const exposePlugin = plugin => (...args) => loadPlugin(plugin, ...args);
|
|
16
21
|
const getDefaultPlugins = () => defaultPlugins.flatMap(plugin => loadPlugin(plugin));
|
|
@@ -39,9 +44,9 @@ function gulpImagemin(customPlugins) {
|
|
|
39
44
|
const plugins = customPlugins ?? getDefaultPlugins();
|
|
40
45
|
(async () => {
|
|
41
46
|
try {
|
|
42
|
-
const data =
|
|
43
|
-
plugins
|
|
44
|
-
})
|
|
47
|
+
const data = await imagemin.buffer(file.contents, {
|
|
48
|
+
plugins: plugins
|
|
49
|
+
});
|
|
45
50
|
const originalSize = file.contents.length;
|
|
46
51
|
const optimizedSize = data.length;
|
|
47
52
|
const saved = originalSize - optimizedSize;
|
|
@@ -54,7 +59,7 @@ function gulpImagemin(customPlugins) {
|
|
|
54
59
|
totalFiles++;
|
|
55
60
|
}
|
|
56
61
|
BalmJS.logger.debug(PLUGIN_NAME, `${file.relative} (${message})`);
|
|
57
|
-
file.contents = data;
|
|
62
|
+
file.contents = Buffer.from(data);
|
|
58
63
|
callback(null, file);
|
|
59
64
|
} catch (error) {
|
|
60
65
|
callback(new PluginError(PLUGIN_NAME, error, {
|
package/lib/plugins/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import postcssPlugins from './postcss-plugins.js';
|
|
|
8
8
|
import rename from './rename.js';
|
|
9
9
|
import replace from './replace.js';
|
|
10
10
|
import sass from './sass.js';
|
|
11
|
+
import legacySass from './sass-legacy.js';
|
|
11
12
|
import sftp from './sftp.js';
|
|
12
13
|
const plugins = {
|
|
13
14
|
htmlmin,
|
|
@@ -20,6 +21,7 @@ const plugins = {
|
|
|
20
21
|
rename,
|
|
21
22
|
replace,
|
|
22
23
|
sass,
|
|
24
|
+
legacySass,
|
|
23
25
|
sftp
|
|
24
26
|
};
|
|
25
27
|
BalmJS.plugins = plugins;
|
package/lib/plugins/postcss.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Reference `gulp-postcss@
|
|
1
|
+
// Reference `gulp-postcss@10.0.0`
|
|
2
2
|
import { Transform } from 'node:stream';
|
|
3
3
|
import postcss from 'postcss';
|
|
4
4
|
import postcssLoadConfig from 'postcss-load-config';
|
|
@@ -28,7 +28,7 @@ function gulpPostcss(cb) {
|
|
|
28
28
|
}
|
|
29
29
|
const ctx = {
|
|
30
30
|
file,
|
|
31
|
-
options: contextOptions
|
|
31
|
+
options: contextOptions // @TODO: The options property is deprecated and should be removed
|
|
32
32
|
};
|
|
33
33
|
return postcssLoadConfig(ctx, configPath);
|
|
34
34
|
});
|
package/lib/plugins/rename.js
CHANGED
|
@@ -13,9 +13,7 @@ function gulpRename(obj, options = {}) {
|
|
|
13
13
|
};
|
|
14
14
|
};
|
|
15
15
|
stream._transform = (chunk, unused, callback) => {
|
|
16
|
-
const file = chunk.clone(
|
|
17
|
-
contents: false
|
|
18
|
-
});
|
|
16
|
+
const file = chunk.clone();
|
|
19
17
|
let parsedPath = parsePath(file.relative);
|
|
20
18
|
let _path;
|
|
21
19
|
const type = typeof obj;
|
package/lib/plugins/replace.js
CHANGED
|
@@ -5,8 +5,10 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
5
5
|
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); }
|
|
6
6
|
// Reference `gulp-replace@1.1.4`
|
|
7
7
|
import { Transform } from 'node:stream';
|
|
8
|
-
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import * as isTextModule from 'istextorbinary';
|
|
9
10
|
import rs from '../utilities/replacestream.js';
|
|
11
|
+
const isText = isTextModule.isText || isTextModule;
|
|
10
12
|
const defaultOptions = {
|
|
11
13
|
skipBinary: true
|
|
12
14
|
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Reference `gulp-sass@5.1.0`
|
|
2
|
+
import { Transform } from 'node:stream';
|
|
3
|
+
import * as sass from 'sass';
|
|
4
|
+
import replaceExtension from 'replace-ext';
|
|
5
|
+
import stripAnsi from 'strip-ansi';
|
|
6
|
+
import applySourceMap from 'vinyl-sourcemaps-apply';
|
|
7
|
+
import ansiColors from 'ansi-colors';
|
|
8
|
+
const sassModule = node.getSassModule(sass);
|
|
9
|
+
const PLUGIN_NAME = 'sass-legacy';
|
|
10
|
+
const transformObj = transform => new Transform({
|
|
11
|
+
transform,
|
|
12
|
+
objectMode: true
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Handles returning the file to the stream
|
|
17
|
+
*/
|
|
18
|
+
function filePush(file, sassObject, callback) {
|
|
19
|
+
// Build Source Maps!
|
|
20
|
+
if (sassObject.map) {
|
|
21
|
+
// Transform map into JSON
|
|
22
|
+
const sassMap = JSON.parse(sassObject.map.toString());
|
|
23
|
+
// Grab the stdout and transform it into stdin
|
|
24
|
+
const sassMapFile = sassMap.file.replace(/^stdout$/, 'stdin');
|
|
25
|
+
// Grab the base filename that's being worked on
|
|
26
|
+
const sassFileSrc = file.relative;
|
|
27
|
+
// Grab the path portion of the file that's being worked on
|
|
28
|
+
const sassFileSrcPath = node.path.dirname(sassFileSrc);
|
|
29
|
+
if (sassFileSrcPath) {
|
|
30
|
+
const sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
|
|
31
|
+
// Prepend the path to all files in the sources array except the file that's being worked on
|
|
32
|
+
sassMap.sources = sassMap.sources.map((source, index) => index === sourceFileIndex ? source : node.path.join(sassFileSrcPath, source));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Remove 'stdin' from sources and replace with filenames!
|
|
36
|
+
sassMap.sources = sassMap.sources.filter(src => src !== 'stdin' && src);
|
|
37
|
+
|
|
38
|
+
// Replace the map file with the original filename (but new extension)
|
|
39
|
+
sassMap.file = replaceExtension(sassFileSrc, '.css');
|
|
40
|
+
// Apply the map
|
|
41
|
+
applySourceMap(file, sassMap);
|
|
42
|
+
}
|
|
43
|
+
file.contents = sassObject.css;
|
|
44
|
+
file.path = replaceExtension(file.path, '.css');
|
|
45
|
+
if (file.stat) {
|
|
46
|
+
file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
|
|
47
|
+
}
|
|
48
|
+
callback(null, file);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Handles error message
|
|
53
|
+
*/
|
|
54
|
+
function handleError(error, file, callback) {
|
|
55
|
+
const filePath = (error.file === 'stdin' ? file.path : error.file) || file.path;
|
|
56
|
+
const relativePath = node.path.relative(process.cwd(), filePath);
|
|
57
|
+
const message = `${ansiColors.underline(relativePath)}\n${error.formatted}`;
|
|
58
|
+
error.messageFormatted = message;
|
|
59
|
+
error.messageOriginal = error.message;
|
|
60
|
+
error.message = stripAnsi(message);
|
|
61
|
+
error.relativePath = relativePath;
|
|
62
|
+
return callback(new PluginError(PLUGIN_NAME, error));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//////////////////////////////
|
|
66
|
+
// Main Gulp Sass function
|
|
67
|
+
//////////////////////////////
|
|
68
|
+
const gulpSass = (options, sync = false) => transformObj((file, encoding, callback) => {
|
|
69
|
+
if (file.isNull()) {
|
|
70
|
+
return callback(null, file);
|
|
71
|
+
}
|
|
72
|
+
if (file.isStream()) {
|
|
73
|
+
return callback(new PluginError(PLUGIN_NAME, 'Streaming not supported'));
|
|
74
|
+
}
|
|
75
|
+
if (node.path.basename(file.path).startsWith('_')) {
|
|
76
|
+
return callback();
|
|
77
|
+
}
|
|
78
|
+
if (!file.contents.length) {
|
|
79
|
+
file.path = replaceExtension(file.path, '.css');
|
|
80
|
+
return callback(null, file);
|
|
81
|
+
}
|
|
82
|
+
const opts = options || {};
|
|
83
|
+
opts.data = file.contents.toString();
|
|
84
|
+
|
|
85
|
+
// We set the file path here so that libsass can correctly resolve import paths
|
|
86
|
+
opts.file = file.path;
|
|
87
|
+
|
|
88
|
+
// Ensure `indentedSyntax` is true if a `.sass` file
|
|
89
|
+
if (node.path.extname(file.path) === '.sass') {
|
|
90
|
+
opts.indentedSyntax = true;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Ensure file's parent directory in the include path
|
|
94
|
+
if (opts.includePaths) {
|
|
95
|
+
if (typeof opts.includePaths === 'string') {
|
|
96
|
+
opts.includePaths = [opts.includePaths];
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
opts.includePaths = [];
|
|
100
|
+
}
|
|
101
|
+
opts.includePaths.unshift(node.path.dirname(file.path));
|
|
102
|
+
|
|
103
|
+
// Generate Source Maps if the source-map plugin is present
|
|
104
|
+
if (file.sourceMap) {
|
|
105
|
+
opts.sourceMap = file.path;
|
|
106
|
+
opts.omitSourceMapUrl = true;
|
|
107
|
+
opts.sourceMapContents = true;
|
|
108
|
+
}
|
|
109
|
+
if (sync !== true) {
|
|
110
|
+
/**
|
|
111
|
+
* Async Sass render
|
|
112
|
+
*/
|
|
113
|
+
sassModule.render(opts, (error, obj) => {
|
|
114
|
+
if (error) {
|
|
115
|
+
handleError(error, file, callback);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
filePush(file, obj, callback);
|
|
119
|
+
});
|
|
120
|
+
} else {
|
|
121
|
+
/**
|
|
122
|
+
* Sync Sass render
|
|
123
|
+
*/
|
|
124
|
+
try {
|
|
125
|
+
filePush(file, sassModule.renderSync(opts), callback);
|
|
126
|
+
} catch (error) {
|
|
127
|
+
handleError(error, file, callback);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
export default gulpSass;
|
package/lib/plugins/sass.js
CHANGED
|
@@ -1,24 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import { pathToFileURL } from 'node:url';
|
|
3
|
-
// Reference `gulp-sass@5.1.0`
|
|
1
|
+
// Reference `gulp-sass@6.0.1`
|
|
4
2
|
import { Transform } from 'node:stream';
|
|
5
|
-
import semver from 'semver';
|
|
6
3
|
import * as sass from 'sass';
|
|
7
4
|
import replaceExtension from 'replace-ext';
|
|
8
5
|
import stripAnsi from 'strip-ansi';
|
|
9
6
|
import applySourceMap from 'vinyl-sourcemaps-apply';
|
|
10
7
|
import ansiColors from 'ansi-colors';
|
|
11
|
-
|
|
12
|
-
const localSassModule = node.path.join(process.env.BALM_CWD, 'node_modules', 'sass');
|
|
13
|
-
let isLegacy = false;
|
|
14
|
-
try {
|
|
15
|
-
const sassPkg = requireModule(node.path.join(localSassModule, 'package.json'));
|
|
16
|
-
isLegacy = semver.lt(sassPkg.version, '1.40.0');
|
|
17
|
-
} catch (_) {}
|
|
18
|
-
const nodeLocalSassModule = node.path.join(localSassModule, 'sass.node.js');
|
|
19
|
-
const defaultLocalSassModule = node.path.join(localSassModule, 'sass.default.js'); // For `npm i -D sass <= 1.62.1`
|
|
20
|
-
const dartLocalSassModule = node.path.join(localSassModule, 'sass.dart.js'); // For `npm i -D sass <= 1.39.2`
|
|
21
|
-
const sassModule = fs.existsSync(nodeLocalSassModule) ? requireModule(nodeLocalSassModule) : fs.existsSync(defaultLocalSassModule) ? requireModule(defaultLocalSassModule) : fs.existsSync(dartLocalSassModule) ? requireModule(dartLocalSassModule) : sass;
|
|
8
|
+
const sassModule = node.getSassModule(sass);
|
|
22
9
|
const PLUGIN_NAME = 'sass';
|
|
23
10
|
const transformObj = transform => new Transform({
|
|
24
11
|
transform,
|
|
@@ -29,48 +16,44 @@ const transformObj = transform => new Transform({
|
|
|
29
16
|
* Handles returning the file to the stream
|
|
30
17
|
*/
|
|
31
18
|
function filePush(file, result, callback) {
|
|
32
|
-
// Build Source Maps!
|
|
33
|
-
if (result.sourceMap) {
|
|
34
|
-
const sassMap = result.sourceMap;
|
|
35
|
-
// Replace the map file with the original filename (but new extension)
|
|
36
|
-
sassMap.file = replaceExtension(file.relative, '.css');
|
|
37
|
-
// Apply the map
|
|
38
|
-
applySourceMap(file, sassMap);
|
|
39
|
-
}
|
|
40
19
|
file.contents = Buffer.from(result.css);
|
|
41
20
|
file.path = replaceExtension(file.path, '.css');
|
|
42
|
-
|
|
43
|
-
file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
|
|
44
|
-
}
|
|
45
|
-
callback(null, file);
|
|
46
|
-
}
|
|
47
|
-
function legacyFilePush(file, sassObject, callback) {
|
|
21
|
+
|
|
48
22
|
// Build Source Maps!
|
|
49
|
-
if (
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const sassFileSrcPath = node.path.dirname(sassFileSrc);
|
|
58
|
-
if (sassFileSrcPath) {
|
|
59
|
-
const sourceFileIndex = sassMap.sources.indexOf(sassMapFile);
|
|
60
|
-
// Prepend the path to all files in the sources array except the file that's being worked on
|
|
61
|
-
sassMap.sources = sassMap.sources.map((source, index) => index === sourceFileIndex ? source : node.path.join(sassFileSrcPath, source));
|
|
23
|
+
if (result.sourceMap) {
|
|
24
|
+
const proto = /^file:\/\/?/;
|
|
25
|
+
const leadingSlash = /^\//;
|
|
26
|
+
const sassMap = result.sourceMap;
|
|
27
|
+
const base = node.path.resolve(file.cwd, file.base);
|
|
28
|
+
if (!sassMap.file) {
|
|
29
|
+
// Convert from absolute path to relative as in gulp-sass 5.0.0
|
|
30
|
+
sassMap.file = file.history[0].replace(base + node.path.sep, '').replace(proto, '');
|
|
62
31
|
}
|
|
63
32
|
|
|
64
|
-
//
|
|
65
|
-
sassMap.sources = sassMap.sources.
|
|
33
|
+
// Transform to relative file paths as in gulp-sass 5.0.0
|
|
34
|
+
sassMap.sources = sassMap.sources.map(src => {
|
|
35
|
+
// file uses Windows-style path separators, source is a URL.
|
|
36
|
+
const baseUri = base.replace(/\\/g, '/');
|
|
37
|
+
// The current file and its content is included
|
|
38
|
+
// as data:<encoded file contents> in the new Sass JS API.
|
|
39
|
+
// Map it to the original file name (first history entry).
|
|
40
|
+
if (src.startsWith('data:')) {
|
|
41
|
+
return file.history[0].replace(/\\/g, '/').replace(`${baseUri}/`, '').replace(proto, '').replace(leadingSlash, '');
|
|
42
|
+
}
|
|
43
|
+
return src.replace(proto, '').replace(`${baseUri}/`, '').replace(leadingSlash, '');
|
|
44
|
+
});
|
|
66
45
|
|
|
46
|
+
// Grab the base filename that's being worked on
|
|
47
|
+
const sassFileSrc = file.relative;
|
|
67
48
|
// Replace the map file with the original filename (but new extension)
|
|
68
49
|
sassMap.file = replaceExtension(sassFileSrc, '.css');
|
|
50
|
+
if (file.sourceMap && file.sourceMap.sourcesContent && !sassMap.sourcesContent) {
|
|
51
|
+
sassMap.sourcesContent = file.sourceMap.sourcesContent;
|
|
52
|
+
}
|
|
53
|
+
|
|
69
54
|
// Apply the map
|
|
70
55
|
applySourceMap(file, sassMap);
|
|
71
56
|
}
|
|
72
|
-
file.contents = sassObject.css;
|
|
73
|
-
file.path = replaceExtension(file.path, '.css');
|
|
74
57
|
if (file.stat) {
|
|
75
58
|
file.stat.atime = file.stat.mtime = file.stat.ctime = new Date();
|
|
76
59
|
}
|
|
@@ -81,26 +64,17 @@ function legacyFilePush(file, sassObject, callback) {
|
|
|
81
64
|
* Handles error message
|
|
82
65
|
*/
|
|
83
66
|
function handleError(error, file, callback) {
|
|
84
|
-
const relativePath = node.path.relative(process.cwd(), file.path);
|
|
85
|
-
const message = `${ansiColors.underline(relativePath)}\n${error.message}`;
|
|
86
|
-
error.message = stripAnsi(message);
|
|
87
|
-
return callback(new PluginError(PLUGIN_NAME, error));
|
|
88
|
-
}
|
|
89
|
-
function legacyHandleError(error, file, callback) {
|
|
90
67
|
const filePath = (error.file === 'stdin' ? file.path : error.file) || file.path;
|
|
91
68
|
const relativePath = node.path.relative(process.cwd(), filePath);
|
|
92
|
-
const message = `${ansiColors.underline(relativePath)}\n${error.
|
|
93
|
-
error.messageFormatted = message;
|
|
94
|
-
error.messageOriginal = error.message;
|
|
69
|
+
const message = `${ansiColors.underline(relativePath)}\n${error.message}`;
|
|
95
70
|
error.message = stripAnsi(message);
|
|
96
|
-
error.relativePath = relativePath;
|
|
97
71
|
return callback(new PluginError(PLUGIN_NAME, error));
|
|
98
72
|
}
|
|
99
73
|
|
|
100
74
|
//////////////////////////////
|
|
101
75
|
// Main Gulp Sass function
|
|
102
76
|
//////////////////////////////
|
|
103
|
-
const gulpSass = options => transformObj((file, encoding, callback) => {
|
|
77
|
+
const gulpSass = (options, sync = false) => transformObj((file, encoding, callback) => {
|
|
104
78
|
if (file.isNull()) {
|
|
105
79
|
return callback(null, file);
|
|
106
80
|
}
|
|
@@ -115,79 +89,46 @@ const gulpSass = options => transformObj((file, encoding, callback) => {
|
|
|
115
89
|
return callback(null, file);
|
|
116
90
|
}
|
|
117
91
|
const opts = options || {};
|
|
118
|
-
if (isLegacy) {
|
|
119
|
-
opts.data = file.contents.toString();
|
|
120
|
-
|
|
121
|
-
// We set the file path here so that libsass can correctly resolve import paths
|
|
122
|
-
opts.file = file.path;
|
|
123
|
-
|
|
124
|
-
// Ensure `indentedSyntax` is true if a `.sass` file
|
|
125
|
-
if (node.path.extname(file.path) === '.sass') {
|
|
126
|
-
opts.indentedSyntax = true;
|
|
127
|
-
}
|
|
128
92
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
opts.includePaths = [];
|
|
136
|
-
}
|
|
137
|
-
opts.includePaths.unshift(node.path.dirname(file.path));
|
|
93
|
+
// Ensure `indented` if a `.sass` file
|
|
94
|
+
if (node.path.extname(file.path) === '.sass') {
|
|
95
|
+
opts.syntax = 'indented';
|
|
96
|
+
}
|
|
138
97
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
opts.
|
|
143
|
-
opts.sourceMapContents = true;
|
|
98
|
+
// Ensure file's parent directory in the include path
|
|
99
|
+
if (opts.loadPaths) {
|
|
100
|
+
if (typeof opts.loadPaths === 'string') {
|
|
101
|
+
opts.loadPaths = [opts.loadPaths];
|
|
144
102
|
}
|
|
103
|
+
} else {
|
|
104
|
+
opts.loadPaths = [];
|
|
105
|
+
}
|
|
106
|
+
opts.loadPaths.unshift(node.path.dirname(file.path));
|
|
145
107
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
};
|
|
162
|
-
}];
|
|
163
|
-
}
|
|
164
|
-
}
|
|
108
|
+
// Generate Source Maps if the source-map plugin is present
|
|
109
|
+
if (file.sourceMap) {
|
|
110
|
+
opts.sourceMap = true;
|
|
111
|
+
opts.sourceMapIncludeSources = true;
|
|
112
|
+
}
|
|
113
|
+
const fileContents = file.contents.toString();
|
|
114
|
+
if (sync !== true) {
|
|
115
|
+
/**
|
|
116
|
+
* Async Sass compile
|
|
117
|
+
*/
|
|
118
|
+
sassModule.compileStringAsync(fileContents, opts).then(compileResult => {
|
|
119
|
+
filePush(file, compileResult, callback);
|
|
120
|
+
}).catch(error => {
|
|
121
|
+
handleError(error, file, callback);
|
|
122
|
+
});
|
|
165
123
|
} else {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
let file = url;
|
|
174
|
-
const result = url.match(aliasKeyRegex);
|
|
175
|
-
const key = result ? result[1] : null;
|
|
176
|
-
if (key) {
|
|
177
|
-
file = url.replace(key, BalmJS.config.scripts.alias[key]);
|
|
178
|
-
BalmJS.logger.debug(`${PLUGIN_NAME} alias`, `${key} -> ${url} => ${file}`);
|
|
179
|
-
}
|
|
180
|
-
return pathToFileURL(file);
|
|
181
|
-
}
|
|
182
|
-
}];
|
|
183
|
-
}
|
|
124
|
+
/**
|
|
125
|
+
* Sync Sass compile
|
|
126
|
+
*/
|
|
127
|
+
try {
|
|
128
|
+
filePush(file, sassModule.compileString(fileContents, opts), callback);
|
|
129
|
+
} catch (error) {
|
|
130
|
+
handleError(error, file, callback);
|
|
184
131
|
}
|
|
185
132
|
}
|
|
186
|
-
try {
|
|
187
|
-
isLegacy ? legacyFilePush(file, sassModule.renderSync(opts), callback) : filePush(file, sassModule.compile(file.path, options), callback);
|
|
188
|
-
} catch (error) {
|
|
189
|
-
isLegacy ? legacyHandleError(error, file, callback) : handleError(error, file, callback);
|
|
190
|
-
}
|
|
191
133
|
});
|
|
192
|
-
export default gulpSass;
|
|
193
|
-
export { isLegacy };
|
|
134
|
+
export default gulpSass;
|
package/lib/plugins/sftp.js
CHANGED
|
@@ -65,7 +65,7 @@ function getKey(options) {
|
|
|
65
65
|
function gulpSftp(options) {
|
|
66
66
|
options = Object.assign({}, options); // Credit sindresorhus
|
|
67
67
|
|
|
68
|
-
if (options.host
|
|
68
|
+
if (!options.host) {
|
|
69
69
|
throw new PluginError(PLUGIN_NAME, '`host` required');
|
|
70
70
|
}
|
|
71
71
|
let fileCount = 0;
|
|
@@ -167,7 +167,8 @@ function gulpSftp(options) {
|
|
|
167
167
|
});
|
|
168
168
|
});
|
|
169
169
|
conn.on('error', err => {
|
|
170
|
-
|
|
170
|
+
const errorMsg = err && (err.message || err.toString()) || 'SFTP connection error';
|
|
171
|
+
this.emit('error', new PluginError(PLUGIN_NAME, errorMsg));
|
|
171
172
|
});
|
|
172
173
|
conn.on('end', () => {
|
|
173
174
|
BalmJS.logger.debug(PLUGIN_NAME, 'Client :: end');
|
|
@@ -216,7 +217,6 @@ function gulpSftp(options) {
|
|
|
216
217
|
cb => cb(null, fileDirs && fileDirs.length), cb => {
|
|
217
218
|
let d = fileDirs.pop();
|
|
218
219
|
mkDirCache[d] = true;
|
|
219
|
-
// Mdrake - TODO: use a default file permission instead of defaulting to 755
|
|
220
220
|
if (remotePlatform && remotePlatform.toLowerCase().indexOf('win') !== -1) {
|
|
221
221
|
d = d.replace('/', '\\');
|
|
222
222
|
}
|
|
@@ -224,8 +224,9 @@ function gulpSftp(options) {
|
|
|
224
224
|
if (exist) {
|
|
225
225
|
cb();
|
|
226
226
|
} else {
|
|
227
|
+
const dirMode = options.dirMode || '0755';
|
|
227
228
|
sftp.mkdir(d, {
|
|
228
|
-
mode:
|
|
229
|
+
mode: dirMode
|
|
229
230
|
}, err => {
|
|
230
231
|
// REMOTE PATH
|
|
231
232
|
if (err) {
|
|
@@ -239,10 +240,11 @@ function gulpSftp(options) {
|
|
|
239
240
|
}
|
|
240
241
|
});
|
|
241
242
|
}, () => {
|
|
243
|
+
const fileMode = options.fileMode || '0666';
|
|
242
244
|
const stream = sftp.createWriteStream(finalRemotePath, {
|
|
243
245
|
flags: 'w',
|
|
244
246
|
encoding: null,
|
|
245
|
-
mode:
|
|
247
|
+
mode: fileMode,
|
|
246
248
|
autoClose: true
|
|
247
249
|
});
|
|
248
250
|
|
|
@@ -31,8 +31,8 @@ class BalmTask {
|
|
|
31
31
|
}
|
|
32
32
|
get src() {
|
|
33
33
|
return gulp.src(this.input, Object.assign({
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
allowEmpty: true,
|
|
35
|
+
encoding: false
|
|
36
36
|
}, this.gulpSrcOptions)).pipe(BalmJS.plugins.plumber(error => {
|
|
37
37
|
BalmJS.logger.error(`${this.name} task`, error.message);
|
|
38
38
|
}));
|
|
@@ -49,8 +49,8 @@ class BalmTask {
|
|
|
49
49
|
default:
|
|
50
50
|
}
|
|
51
51
|
const useAbsPath = !['webpack', 'rollup', 'esbuild', 'sprite'].includes(key);
|
|
52
|
-
this.input = useAbsPath ? BalmJS.file.absPaths(input || this.defaultInput) : input || this.defaultInput;
|
|
53
|
-
this.output = useAbsPath ? BalmJS.file.absPath(output || this.defaultOutput) : output || this.defaultOutput;
|
|
52
|
+
this.input = useAbsPath && (input || this.defaultInput) ? BalmJS.file.absPaths(input || this.defaultInput) : input || this.defaultInput;
|
|
53
|
+
this.output = useAbsPath && typeof (output || this.defaultOutput) === 'string' ? BalmJS.file.absPath(output || this.defaultOutput) : output || this.defaultOutput;
|
|
54
54
|
this.customOptions = options[key] || {};
|
|
55
55
|
const obj = {
|
|
56
56
|
input: this.input,
|
|
@@ -32,7 +32,6 @@ class BalmStyleTask extends BalmTask {
|
|
|
32
32
|
const taskName = `${this.name} task`;
|
|
33
33
|
const shouldUseSourceMap = !(BalmJS.config.env.isProd || BalmJS.config.styles.minify);
|
|
34
34
|
let stream = gulp.src(this.input, Object.assign({
|
|
35
|
-
encoding: false,
|
|
36
35
|
sourcemaps: shouldUseSourceMap,
|
|
37
36
|
allowEmpty: true
|
|
38
37
|
}, this.gulpSrcOptions)).pipe(BalmJS.plugins.plumber(function (error) {
|
|
@@ -47,7 +46,7 @@ class BalmStyleTask extends BalmTask {
|
|
|
47
46
|
}));
|
|
48
47
|
switch (style) {
|
|
49
48
|
case 'sass':
|
|
50
|
-
stream = stream.pipe(BalmJS.plugins.sass(options));
|
|
49
|
+
stream = stream.pipe(node.isLegacySass ? BalmJS.plugins.legacySass(options) : BalmJS.plugins.sass(options));
|
|
51
50
|
break;
|
|
52
51
|
case 'less':
|
|
53
52
|
stream = stream.pipe(BalmJS.plugins.less(options));
|