js-build-tools 6.0.0 → 6.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 +45 -2
- package/dist/build.js +63 -62
- package/dist/build.min.js +1 -1
- package/dist/bundle.js +40 -39
- package/dist/bundle.min.js +1 -1
- package/dist/bundleMinify.js +18 -17
- package/dist/bundleMinify.min.js +1 -1
- package/dist/copyFonts.js +13 -12
- package/dist/copyFonts.min.js +1 -1
- package/dist/default.js +15 -14
- package/dist/default.min.js +1 -1
- package/dist/distMinify.js +13 -12
- package/dist/distMinify.min.js +1 -1
- package/dist/partials/addToReadme.js +25 -24
- package/dist/partials/beginWatcher.js +13 -12
- package/dist/partials/clean.js +15 -14
- package/dist/partials/distFor.js +22 -21
- package/dist/partials/distForSrc.js +12 -11
- package/dist/partials/distSeries.js +20 -19
- package/dist/partials/imagesFor.js +43 -42
- package/dist/partials/neostandardLint.js +130 -111
- package/dist/partials/readmeTemplate.js +15 -14
- package/dist/partials/runOnChange.js +29 -28
- package/dist/partials/sassFor.js +29 -28
- package/dist/partials/tsFor.js +71 -70
- package/dist/partials/typeDocsFor.js +203 -202
- package/dist/sourceLint.js +26 -24
- package/dist/sourceLint.min.js +1 -1
- package/dist/test-helpers/neostandardLintWithRealNeostandard.js +49 -47
- package/dist/test-helpers/setUp.js +95 -94
- package/dist/testFull.js +20 -19
- package/dist/testFull.min.js +1 -1
- package/dist/testHelpers.js +11 -10
- package/dist/testHelpers.min.js +1 -1
- package/dist/testQuick.js +22 -21
- package/dist/testQuick.min.js +1 -1
- package/dist/utilities/dotNotate.js +48 -46
- package/dist/utilities/getBundleConfigs.js +28 -27
- package/dist/watchTest.js +16 -15
- package/dist/watchTest.min.js +1 -1
- package/functions/bundle.mjs +2 -2
- package/functions/partials/addToReadme.mjs +1 -1
- package/functions/partials/neostandardLint.mjs +19 -7
- package/functions/partials/neostandardLint.test.mjs +9 -1
- package/functions/sourceLint.mjs +1 -1
- package/functions/sourceLint.test.mjs +24 -0
- package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +7 -5
- package/functions/utilities/dotNotate.mjs +3 -1
- package/functions/utilities/dotNotate.test.mjs +34 -0
- package/functions/utilities/getBundleConfigs.mjs +1 -1
- package/gulp.config.mjs +14 -0
- package/package.json +1 -1
package/dist/partials/clean.js
CHANGED
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.clean = void 0;
|
|
8
|
-
require("core-js/modules/esnext.iterator.constructor.js");
|
|
9
|
-
require("core-js/modules/esnext.iterator.reduce.js");
|
|
10
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
11
|
-
var _removeDirectory = require("./removeDirectory.js");
|
|
12
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.clean = void 0;
|
|
8
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
9
|
+
require("core-js/modules/esnext.iterator.reduce.js");
|
|
10
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
11
|
+
var _removeDirectory = require("./removeDirectory.js");
|
|
12
|
+
var cache;
|
|
13
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
13
14
|
/**
|
|
14
15
|
* Deletes all the distribution and browser files (used before create a new build).
|
|
15
16
|
* Configure array of directories to remove with 'cleanPaths'.
|
|
16
17
|
* @memberOf module:partials
|
|
17
18
|
* @returns {Promise<string[]> | *}
|
|
18
|
-
*/
|
|
19
|
-
const clean = () => gulpConfig.get('cleanPaths').reduce((promise, path) => promise.then(() => (0, _removeDirectory.removeDirectory)(path)), Promise.resolve());
|
|
19
|
+
*/
|
|
20
|
+
const clean = () => gulpConfig.get('cleanPaths').reduce((promise, path) => promise.then(() => (0, _removeDirectory.removeDirectory)(path)), Promise.resolve());
|
|
20
21
|
exports.clean = clean;
|
package/dist/partials/distFor.js
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.distFor = void 0;
|
|
8
|
-
var _gulpBabel = _interopRequireDefault(require("gulp-babel"));
|
|
9
|
-
var _gulp = require("gulp");
|
|
10
|
-
var _distForSrc = require("./distForSrc.js");
|
|
11
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
12
|
-
var _through = _interopRequireDefault(require("through2"));
|
|
13
|
-
|
|
14
|
-
function
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.distFor = void 0;
|
|
8
|
+
var _gulpBabel = _interopRequireDefault(require("gulp-babel"));
|
|
9
|
+
var _gulp = require("gulp");
|
|
10
|
+
var _distForSrc = require("./distForSrc.js");
|
|
11
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
12
|
+
var _through = _interopRequireDefault(require("through2"));
|
|
13
|
+
var cache;
|
|
14
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
16
|
/**
|
|
16
17
|
* Build the distribution for a given source pattern.
|
|
17
18
|
* @memberOf module:partials
|
|
18
19
|
* @param {string|array} [srcPath='src/config/path/dist/for']
|
|
19
20
|
* @param {string} [destPath='dist/config/path']
|
|
20
21
|
* @returns {stream.Stream}
|
|
21
|
-
*/
|
|
22
|
-
const distFor = (srcPath = (0, _distForSrc.distForSrc)(), destPath = gulpConfig.get('dist.to')) => (0, _gulp.src)(srcPath).pipe((0, _gulpBabel.default)()).pipe(_through.default.obj(function (file, enc, callback) {
|
|
23
|
-
const regex = /\.mjs(['"]\s*\))/gi;
|
|
24
|
-
file.contents = Buffer.from(file.contents.toString().replaceAll(regex, '.js$1'));
|
|
25
|
-
this.push(file);
|
|
26
|
-
callback();
|
|
27
|
-
})).pipe((0, _gulp.dest)(destPath));
|
|
22
|
+
*/
|
|
23
|
+
const distFor = (srcPath = (0, _distForSrc.distForSrc)(), destPath = gulpConfig.get('dist.to')) => (0, _gulp.src)(srcPath).pipe((0, _gulpBabel.default)()).pipe(_through.default.obj(function (file, enc, callback) {
|
|
24
|
+
const regex = /\.mjs(['"]\s*\))/gi;
|
|
25
|
+
file.contents = Buffer.from(file.contents.toString().replaceAll(regex, '.js$1'));
|
|
26
|
+
this.push(file);
|
|
27
|
+
callback();
|
|
28
|
+
})).pipe((0, _gulp.dest)(destPath));
|
|
28
29
|
exports.distFor = distFor;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.distForSrc = void 0;
|
|
8
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.distForSrc = void 0;
|
|
8
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
9
|
+
var cache;
|
|
10
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
10
11
|
/**
|
|
11
12
|
* Retrieve the correct distFor search path based on TS Config.
|
|
12
13
|
* @memberOf module:partials
|
|
13
14
|
* @param {module:gulpConfig~FlagStringSetting} [useTs='config/for/ts']
|
|
14
15
|
* @returns {string}
|
|
15
|
-
*/
|
|
16
|
-
const distForSrc = (useTs = gulpConfig.get('typescript.enabled')) => useTs ? gulpConfig.get('browser.from') : gulpConfig.get('dist.from');
|
|
16
|
+
*/
|
|
17
|
+
const distForSrc = (useTs = gulpConfig.get('typescript.enabled')) => useTs ? gulpConfig.get('browser.from') : gulpConfig.get('dist.from');
|
|
17
18
|
exports.distForSrc = distForSrc;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.distSeries = void 0;
|
|
8
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
9
|
-
var _distFor = require("./distFor.js");
|
|
10
|
-
var _distForSrc = require("./distForSrc.js");
|
|
11
|
-
var _gulp = require("gulp");
|
|
12
|
-
var _tsFor = require("./tsFor.js");
|
|
13
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.distSeries = void 0;
|
|
8
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
9
|
+
var _distFor = require("./distFor.js");
|
|
10
|
+
var _distForSrc = require("./distForSrc.js");
|
|
11
|
+
var _gulp = require("gulp");
|
|
12
|
+
var _tsFor = require("./tsFor.js");
|
|
13
|
+
var cache;
|
|
14
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
14
15
|
/**
|
|
15
16
|
* When using TypeScript, ensure that we process the ts first then run babel (dist)
|
|
16
17
|
* @memberOf module:partials
|
|
@@ -18,10 +19,10 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
18
19
|
* @param {string} [distFinalPath='dist/config/path']
|
|
19
20
|
* @param {string} [tsSearch='ts/search/config/path']
|
|
20
21
|
* @returns {function(null=): stream.Stream}
|
|
21
|
-
*/
|
|
22
|
-
const distSeries = (srcPath = (0, _distForSrc.distForSrc)(), distFinalPath = gulpConfig.get('dist.to'), tsSearch = gulpConfig.get('typescript.from')) => {
|
|
23
|
-
const typescript = (0, _tsFor.tsFor)(tsSearch, distFinalPath);
|
|
24
|
-
const dist = () => (0, _distFor.distFor)(srcPath, distFinalPath);
|
|
25
|
-
return gulpConfig.get('typescript.enabled') ? (0, _gulp.series)(typescript, dist) : dist;
|
|
26
|
-
};
|
|
22
|
+
*/
|
|
23
|
+
const distSeries = (srcPath = (0, _distForSrc.distForSrc)(), distFinalPath = gulpConfig.get('dist.to'), tsSearch = gulpConfig.get('typescript.from')) => {
|
|
24
|
+
const typescript = (0, _tsFor.tsFor)(tsSearch, distFinalPath);
|
|
25
|
+
const dist = () => (0, _distFor.distFor)(srcPath, distFinalPath);
|
|
26
|
+
return gulpConfig.get('typescript.enabled') ? (0, _gulp.series)(typescript, dist) : dist;
|
|
27
|
+
};
|
|
27
28
|
exports.distSeries = distSeries;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.loadImagemin = exports.imagesFor = void 0;
|
|
8
|
-
var _gulpCache = _interopRequireDefault(require("gulp-cache"));
|
|
9
|
-
var _loadPeer = require("./loadPeer.js");
|
|
10
|
-
var _gulp = require("gulp");
|
|
11
|
-
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
12
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
13
|
-
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.loadImagemin = exports.imagesFor = void 0;
|
|
8
|
+
var _gulpCache = _interopRequireDefault(require("gulp-cache"));
|
|
9
|
+
var _loadPeer = require("./loadPeer.js");
|
|
10
|
+
var _gulp = require("gulp");
|
|
11
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
12
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
13
|
+
var cache;
|
|
14
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
15
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
const installHint = 'Add it to your project with: npm install --save-dev github:jheagle/gulp-imagemin#common-js-compatibility ' + '(the CommonJS-compatible fork - upstream gulp-imagemin is ESM-only and cannot be require()d by this package\'s CommonJS build).';
|
|
17
|
+
|
|
17
18
|
/**
|
|
18
19
|
* Load `gulp-imagemin`, an optional peer dependency: image optimization is off by default and its binary-download
|
|
19
20
|
* dependency chain is heavy, so it is only required once the images task actually runs, and it is resolved from the
|
|
@@ -22,36 +23,36 @@ const installHint = 'Add it to your project with: npm install --save-dev github:
|
|
|
22
23
|
* @param {string} [projectPath=process.cwd()] - The project directory to resolve `gulp-imagemin` from.
|
|
23
24
|
* @returns {Function} The gulp-imagemin plugin factory.
|
|
24
25
|
* @throws {Error} With install instructions when gulp-imagemin is missing or is the ESM-only upstream release.
|
|
25
|
-
*/
|
|
26
|
-
const loadImagemin = (projectPath = process.cwd()) => {
|
|
27
|
-
const loaded = (0, _loadPeer.requirePeer)('gulp-imagemin', {
|
|
28
|
-
task: 'images',
|
|
29
|
-
installHint,
|
|
30
|
-
esmOnlyMessage: `gulp-imagemin could not be loaded because it is ESM-only. ${installHint}`,
|
|
31
|
-
projectPath
|
|
32
|
-
});
|
|
33
|
-
return loaded && (loaded.__esModule || loaded.default) ? loaded.default : loaded;
|
|
34
|
-
};
|
|
35
|
-
|
|
26
|
+
*/
|
|
27
|
+
const loadImagemin = (projectPath = process.cwd()) => {
|
|
28
|
+
const loaded = (0, _loadPeer.requirePeer)('gulp-imagemin', {
|
|
29
|
+
task: 'images',
|
|
30
|
+
installHint,
|
|
31
|
+
esmOnlyMessage: `gulp-imagemin could not be loaded because it is ESM-only. ${installHint}`,
|
|
32
|
+
projectPath
|
|
33
|
+
});
|
|
34
|
+
return loaded && (loaded.__esModule || loaded.default) ? loaded.default : loaded;
|
|
35
|
+
};
|
|
36
|
+
|
|
36
37
|
/**
|
|
37
38
|
* Move and optimize images into the browser directory.
|
|
38
39
|
* @memberOf module:partials
|
|
39
40
|
* @param {string|array} [imageSrc=src/images/pattern]
|
|
40
41
|
* @param {string} [imageDest=dest/image/folder]
|
|
41
42
|
* @return {stream.Stream}
|
|
42
|
-
*/
|
|
43
|
-
exports.loadImagemin = loadImagemin;
|
|
44
|
-
const imagesFor = (imageSrc = gulpConfig.get('images.from'), imageDest = gulpConfig.get('images.to')) => {
|
|
45
|
-
const imagemin = loadImagemin();
|
|
46
|
-
// Gulp 5 reads files as utf8 text unless told otherwise, which corrupts binary images (and makes gulp-cache drop them).
|
|
47
|
-
return (0, _gulp.src)(imageSrc, {
|
|
48
|
-
encoding: false
|
|
49
|
-
}).pipe(
|
|
50
|
-
// Caching images that ran through imagemin
|
|
51
|
-
(0, _gulpCache.default)(imagemin({
|
|
52
|
-
interlaced: true,
|
|
53
|
-
silent: true,
|
|
54
|
-
verbose: false
|
|
55
|
-
}))).pipe((0, _gulp.dest)(imageDest));
|
|
56
|
-
};
|
|
43
|
+
*/
|
|
44
|
+
exports.loadImagemin = loadImagemin;
|
|
45
|
+
const imagesFor = (imageSrc = gulpConfig.get('images.from'), imageDest = gulpConfig.get('images.to')) => {
|
|
46
|
+
const imagemin = loadImagemin();
|
|
47
|
+
// Gulp 5 reads files as utf8 text unless told otherwise, which corrupts binary images (and makes gulp-cache drop them).
|
|
48
|
+
return (0, _gulp.src)(imageSrc, {
|
|
49
|
+
encoding: false
|
|
50
|
+
}).pipe(
|
|
51
|
+
// Caching images that ran through imagemin
|
|
52
|
+
(0, _gulpCache.default)(imagemin({
|
|
53
|
+
interlaced: true,
|
|
54
|
+
silent: true,
|
|
55
|
+
verbose: false
|
|
56
|
+
}))).pipe((0, _gulp.dest)(imageDest));
|
|
57
|
+
};
|
|
57
58
|
exports.imagesFor = imagesFor;
|
|
@@ -1,82 +1,97 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.neostandardLint = void 0;
|
|
7
|
-
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
-
require("core-js/modules/esnext.iterator.for-each.js");
|
|
9
|
-
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
10
|
-
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
11
|
-
var _through = _interopRequireDefault(require("through2"));
|
|
12
|
-
var _eslint = require("eslint");
|
|
13
|
-
var _loadPeer = require("./loadPeer.js");
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
// neostandard (js-build-tools' chosen style - a maintained, TypeScript-aware successor to `standard`, see
|
|
16
|
-
// https://github.com/neostandard/neostandard) ships ESM-only, see importModule for how it is imported.
|
|
17
|
-
const importNeostandard = () => (0, _loadPeer.importModule)('neostandard')
|
|
18
|
-
|
|
19
|
-
}) => neostandard);
|
|
20
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.neostandardLint = void 0;
|
|
7
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.for-each.js");
|
|
9
|
+
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
10
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
11
|
+
var _through = _interopRequireDefault(require("through2"));
|
|
12
|
+
var _eslint = require("eslint");
|
|
13
|
+
var _loadPeer = require("./loadPeer.js");
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
// neostandard (js-build-tools' chosen style - a maintained, TypeScript-aware successor to `standard`, see
|
|
16
|
+
// https://github.com/neostandard/neostandard) ships ESM-only, see importModule for how it is imported.
|
|
17
|
+
const importNeostandard = () => (0, _loadPeer.importModule)('neostandard');
|
|
18
|
+
|
|
21
19
|
/**
|
|
22
20
|
* Read the `env` a project already declared for Standard (the `standard` field in its package.json), so a project
|
|
23
21
|
* migrating from `standard` keeps its globals (jest, browser, ...) without touching package.json.
|
|
24
22
|
* @param {string} cwd
|
|
25
23
|
* @returns {Array<string>}
|
|
26
|
-
*/
|
|
27
|
-
const readEnv = cwd => {
|
|
28
|
-
try {
|
|
29
|
-
return JSON.parse(_nodeFs.default.readFileSync(_nodePath.default.join(cwd, 'package.json'), 'utf8')).standard?.env ?? [];
|
|
30
|
-
} catch {
|
|
31
|
-
return [];
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
24
|
+
*/
|
|
25
|
+
const readEnv = cwd => {
|
|
26
|
+
try {
|
|
27
|
+
return JSON.parse(_nodeFs.default.readFileSync(_nodePath.default.join(cwd, 'package.json'), 'utf8')).standard?.env ?? [];
|
|
28
|
+
} catch {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
35
33
|
/**
|
|
36
|
-
* Build an ESLint instance configured with neostandard, honoring the project's own package.json `standard.env
|
|
34
|
+
* Build an ESLint instance configured with neostandard, honoring the project's own package.json `standard.env`,
|
|
35
|
+
* plus an optional layer of rule overrides (see gulp.config.mjs's `lint.rules`) for a rule that is wrong for this
|
|
36
|
+
* project specifically rather than something to fix in its code - for example a test fixture whose content
|
|
37
|
+
* neostandard mistakes for a real syntax problem. Scoped to the same files neostandard itself lints (its own
|
|
38
|
+
* `defaultFilePatterns.all`), per neostandard's own guidance: an unscoped rule-tweak layer would otherwise apply
|
|
39
|
+
* to every lintable file, including ones from an unrelated plugin this project never defined.
|
|
37
40
|
* @param {Object} options
|
|
38
41
|
* @param {string} options.cwd
|
|
39
42
|
* @param {boolean} options.ts
|
|
40
43
|
* @param {boolean} options.fix
|
|
44
|
+
* @param {Object<string, *>} [options.rules={}]
|
|
41
45
|
* @returns {Promise<import('eslint').ESLint>}
|
|
42
|
-
*/
|
|
43
|
-
const buildEslint = async ({
|
|
44
|
-
cwd,
|
|
45
|
-
ts,
|
|
46
|
-
fix
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
46
|
+
*/
|
|
47
|
+
const buildEslint = async ({
|
|
48
|
+
cwd,
|
|
49
|
+
ts,
|
|
50
|
+
fix,
|
|
51
|
+
rules = {}
|
|
52
|
+
}) => {
|
|
53
|
+
const {
|
|
54
|
+
neostandard,
|
|
55
|
+
defaultFilePatterns
|
|
56
|
+
} = await importNeostandard();
|
|
57
|
+
const baseConfig = neostandard({
|
|
58
|
+
ts,
|
|
59
|
+
env: readEnv(cwd)
|
|
60
|
+
});
|
|
61
|
+
if (Object.keys(rules).length) {
|
|
62
|
+
baseConfig.push({
|
|
63
|
+
files: defaultFilePatterns.all,
|
|
64
|
+
rules
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return new _eslint.ESLint({
|
|
68
|
+
cwd,
|
|
69
|
+
fix,
|
|
70
|
+
overrideConfigFile: true,
|
|
71
|
+
baseConfig
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
60
75
|
/**
|
|
61
76
|
* Print a file's lint messages, if it has any.
|
|
62
77
|
* @memberOf module:partials
|
|
63
78
|
* @param {import('vinyl')} file
|
|
64
79
|
* @param {{messages: Array<{line: number, column: number, message: string}>, errorCount: number, warningCount: number}} result
|
|
65
80
|
* @returns {undefined}
|
|
66
|
-
*/
|
|
67
|
-
const printFileReport = (file, result) => {
|
|
68
|
-
if (!result.messages.length) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
console.log(_nodePath.default.relative(file.cwd, file.path));
|
|
72
|
-
result.messages.forEach(({
|
|
73
|
-
line,
|
|
74
|
-
column,
|
|
75
|
-
message
|
|
76
|
-
}) => console.log(`line ${line}:${column}\t${message}`));
|
|
77
|
-
console.log(`✖ ${result.errorCount} error\t⚠ ${result.warningCount} warning\n`);
|
|
78
|
-
};
|
|
79
|
-
|
|
81
|
+
*/
|
|
82
|
+
const printFileReport = (file, result) => {
|
|
83
|
+
if (!result.messages.length) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
console.log(_nodePath.default.relative(file.cwd, file.path));
|
|
87
|
+
result.messages.forEach(({
|
|
88
|
+
line,
|
|
89
|
+
column,
|
|
90
|
+
message
|
|
91
|
+
}) => console.log(`line ${line}:${column}\t${message}`));
|
|
92
|
+
console.log(`✖ ${result.errorCount} error\t⚠ ${result.warningCount} warning\n`);
|
|
93
|
+
};
|
|
94
|
+
|
|
80
95
|
/**
|
|
81
96
|
* Lint every file streaming through with neostandard and, unless `fix` is false, apply the automatic fixes to the
|
|
82
97
|
* file's contents so a following `dest()` writes the fixed version. Remaining problems are printed along with a
|
|
@@ -88,57 +103,61 @@ const printFileReport = (file, result) => {
|
|
|
88
103
|
* @param {Object} [options={}]
|
|
89
104
|
* @param {boolean} [options.fix=true] - Apply neostandard's automatic fixes to the file contents.
|
|
90
105
|
* @param {boolean} [options.ts=false] - Lint `.ts` files too, with type-aware rules (see neostandard's `ts` option).
|
|
106
|
+
* @param {Object<string, *>} [options.rules={}] - ESLint rule overrides layered on top of neostandard's own rules
|
|
107
|
+
* (see gulp.config.mjs's `lint.rules`).
|
|
91
108
|
* @param {function(Object): Promise<{lintText: Function}>} [loadEslint] - Resolves an ESLint-shaped linter. Real
|
|
92
109
|
* callers should never need to pass this - it exists so tests can supply a stand-in, since this project's
|
|
93
110
|
* CommonJS-transform-based Jest setup cannot execute a real dynamic import() of neostandard (ESM-only).
|
|
94
111
|
* @returns {import('stream').Transform}
|
|
95
|
-
*/
|
|
96
|
-
const neostandardLint = ({
|
|
97
|
-
fix = true,
|
|
98
|
-
ts = false
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
console.log(
|
|
140
|
-
console.log(
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
112
|
+
*/
|
|
113
|
+
const neostandardLint = ({
|
|
114
|
+
fix = true,
|
|
115
|
+
ts = false,
|
|
116
|
+
rules = {}
|
|
117
|
+
} = {}, loadEslint = buildEslint) => {
|
|
118
|
+
const totals = {
|
|
119
|
+
errors: 0,
|
|
120
|
+
warnings: 0
|
|
121
|
+
};
|
|
122
|
+
let eslintPromise = null;
|
|
123
|
+
return _through.default.obj(function (file, enc, callback) {
|
|
124
|
+
if (file.isNull()) {
|
|
125
|
+
callback(null, file);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (file.isStream()) {
|
|
129
|
+
callback(new Error('neostandardLint: streaming file contents are not supported.'));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
if (!eslintPromise) {
|
|
133
|
+
eslintPromise = loadEslint({
|
|
134
|
+
cwd: file.cwd,
|
|
135
|
+
ts,
|
|
136
|
+
fix,
|
|
137
|
+
rules
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
eslintPromise.then(eslint => eslint.lintText(file.contents.toString(), {
|
|
141
|
+
filePath: file.path
|
|
142
|
+
})).then(results => {
|
|
143
|
+
// No result at all means the file is ignored by the project's ESLint configuration.
|
|
144
|
+
const [result] = results;
|
|
145
|
+
if (result) {
|
|
146
|
+
if (typeof result.output === 'string') {
|
|
147
|
+
file.contents = Buffer.from(result.output);
|
|
148
|
+
}
|
|
149
|
+
totals.errors += result.errorCount;
|
|
150
|
+
totals.warnings += result.warningCount;
|
|
151
|
+
printFileReport(file, result);
|
|
152
|
+
}
|
|
153
|
+
callback(null, file);
|
|
154
|
+
}, callback);
|
|
155
|
+
}, function (callback) {
|
|
156
|
+
console.log('neostandard linter results');
|
|
157
|
+
console.log('======================================');
|
|
158
|
+
console.log(`✖ Errors total: ${totals.errors}`);
|
|
159
|
+
console.log(`⚠ Warnings total: ${totals.warnings}\n`);
|
|
160
|
+
callback();
|
|
161
|
+
});
|
|
162
|
+
};
|
|
144
163
|
exports.neostandardLint = neostandardLint;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.readmeTemplate = void 0;
|
|
8
|
-
var _gulp = require("gulp");
|
|
9
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
10
|
-
var _gulpRename = _interopRequireDefault(require("gulp-rename"));
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.readmeTemplate = void 0;
|
|
8
|
+
var _gulp = require("gulp");
|
|
9
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
10
|
+
var _gulpRename = _interopRequireDefault(require("gulp-rename"));
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
var cache;
|
|
13
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
13
14
|
/**
|
|
14
15
|
* Copy a readme template into the README.md file.
|
|
15
16
|
* @memberOf module:partials
|
|
16
17
|
* @returns {*}
|
|
17
|
-
*/
|
|
18
|
-
const readmeTemplate = () => (0, _gulp.src)(gulpConfig.get('readme.template')).pipe((0, _gulpRename.default)(gulpConfig.get('readme.file'))).pipe((0, _gulp.dest)(gulpConfig.get('readme.to')));
|
|
18
|
+
*/
|
|
19
|
+
const readmeTemplate = () => (0, _gulp.src)(gulpConfig.get('readme.template')).pipe((0, _gulpRename.default)(gulpConfig.get('readme.file'))).pipe((0, _gulp.dest)(gulpConfig.get('readme.to')));
|
|
19
20
|
exports.readmeTemplate = readmeTemplate;
|