js-build-tools 6.3.1 → 6.4.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 +10 -3
- package/dist/lint.js +17 -0
- package/dist/lint.min.js +1 -0
- package/dist/partials/imagesFor.js +42 -43
- package/dist/partials/jsdocDocsFor.js +128 -128
- package/dist/partials/lintSource.js +41 -0
- package/dist/partials/loadPeer.js +71 -70
- package/dist/partials/minifyFor.js +16 -16
- package/dist/partials/neostandardLint.js +130 -122
- package/dist/partials.js +176 -169
- package/dist/partials.min.js +1 -1
- package/dist/sourceLint.js +11 -27
- package/dist/sourceLint.min.js +1 -1
- package/dist/test-helpers/isolateGulpCache.js +25 -0
- package/dist/utilities/dotGet.js +46 -46
- package/dist/utilities/dotNotate.js +48 -48
- package/dist/utilities/dotSet.js +37 -37
- package/functions/build.test.mjs +17 -7
- package/functions/bundle.test.mjs +0 -1
- package/functions/images.test.mjs +4 -1
- package/functions/lint.mjs +9 -0
- package/functions/partials/addToReadme.test.mjs +2 -1
- package/functions/partials/imagesFor.mjs +0 -1
- package/functions/partials/imagesFor.test.mjs +5 -2
- package/functions/partials/lintSource.mjs +27 -0
- package/functions/partials/loadPeer.mjs +1 -0
- package/functions/partials/loadPlaywright.test.mjs +1 -2
- package/functions/partials/minifyFor.mjs +1 -1
- package/functions/partials/neostandardLint.mjs +9 -2
- package/functions/partials/neostandardLint.test.mjs +14 -0
- package/functions/partials/runOnChange.test.mjs +5 -4
- package/functions/partials/tsFor.test.mjs +1 -0
- package/functions/partials.mjs +1 -0
- package/functions/partials.test.mjs +1 -1
- package/functions/sourceLint.mjs +4 -15
- package/functions/sourceLint.test.mjs +49 -0
- package/functions/test-helpers/isolateGulpCache.mjs +16 -0
- package/functions/test-helpers/setUp.mjs +7 -7
- package/functions/testFull.test.mjs +1 -1
- package/functions/testQuick.test.mjs +1 -1
- package/functions/utilities/convertMjsFilesForDocs.test.mjs +1 -0
- package/functions/utilities/dotGet.mjs +2 -2
- package/functions/utilities/dotNotate.mjs +2 -2
- package/functions/utilities/dotNotate.test.mjs +7 -0
- package/functions/utilities/dotSet.mjs +1 -1
- package/gulpfile.base.mjs +1 -0
- package/package.json +12 -2
package/README.md
CHANGED
|
@@ -592,8 +592,8 @@ using `<script type="module">`, which no DOM-simulation library executes at all)
|
|
|
592
592
|
`playwright` is an optional peer dependency, install it in your project with `npm install --save-dev playwright`,
|
|
593
593
|
then fetch a real browser binary once per machine (not per project) with `npx playwright install chromium` - if
|
|
594
594
|
that fails with "Playwright does not support chromium on <your distro>", your OS is too old for the current
|
|
595
|
-
release; either upgrade it or pin an older `playwright` version known to still support it (confirmed: `1.
|
|
596
|
-
still installs and runs real headless Chromium on Ubuntu 20.04
|
|
595
|
+
release; either upgrade it or pin an older `playwright` version known to still support it (confirmed: `1.62.1`
|
|
596
|
+
is the newest release that still installs and runs real headless Chromium on Ubuntu 20.04).
|
|
597
597
|
|
|
598
598
|
```js
|
|
599
599
|
const { launchBrowser, serveStatic } = require('js-build-tools').partials
|
|
@@ -689,6 +689,7 @@ Export these functions to your own project to customize your build pipeline.
|
|
|
689
689
|
* [.testQuick()](#module_js-build-tools.testQuick) ⇒ <code>Promise.<\*></code>
|
|
690
690
|
* [.testFull()](#module_js-build-tools.testFull) ⇒ <code>Promise.<\*></code>
|
|
691
691
|
* [.sourceLint()](#module_js-build-tools.sourceLint) ⇒ <code>\*</code>
|
|
692
|
+
* [.lint()](#module_js-build-tools.lint) ⇒ <code>\*</code>
|
|
692
693
|
* [.images()](#module_js-build-tools.images) ⇒ <code>stream.Stream</code>
|
|
693
694
|
* [.docs([done])](#module_js-build-tools.docs) ⇒ <code>\*</code>
|
|
694
695
|
* [.distMinify()](#module_js-build-tools.distMinify) ⇒ <code>\*</code>
|
|
@@ -751,7 +752,13 @@ Run all tests with jest.
|
|
|
751
752
|
<a name="module_js-build-tools.sourceLint"></a>
|
|
752
753
|
|
|
753
754
|
### js-build-tools.sourceLint() ⇒ <code>\*</code>
|
|
754
|
-
Applies neostandard linting (js-build-tools' chosen style) to the real, hand-written source - not the compiled
|
|
755
|
+
Applies neostandard linting (js-build-tools' chosen style) to the real, hand-written source - not the compiled
|
|
756
|
+
|
|
757
|
+
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
758
|
+
<a name="module_js-build-tools.lint"></a>
|
|
759
|
+
|
|
760
|
+
### js-build-tools.lint() ⇒ <code>\*</code>
|
|
761
|
+
The standalone lint command (`gulp lint`, or `npm run lint`): the same linting and fixing as sourceLint, but it
|
|
755
762
|
|
|
756
763
|
**Kind**: static method of [<code>js-build-tools</code>](#module_js-build-tools)
|
|
757
764
|
<a name="module_js-build-tools.images"></a>
|
package/dist/lint.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.lint = void 0;
|
|
7
|
+
var _lintSource = require("./partials/lintSource.js");
|
|
8
|
+
/**
|
|
9
|
+
* The standalone lint command (`gulp lint`, or `npm run lint`): the same linting and fixing as sourceLint, but it
|
|
10
|
+
* fails (exits non-zero) when any errors remain that neostandard could not fix automatically.
|
|
11
|
+
* @memberOf module:js-build-tools
|
|
12
|
+
* @returns {*}
|
|
13
|
+
*/
|
|
14
|
+
const lint = () => (0, _lintSource.lintSource)({
|
|
15
|
+
failOnError: true
|
|
16
|
+
});
|
|
17
|
+
exports.lint = lint;
|
package/dist/lint.min.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.lint=void 0;var _lintSource=require("./partials/lintSource.js");const lint=()=>(0,_lintSource.lintSource)({failOnError:!0});exports.lint=lint;
|
|
@@ -1,20 +1,19 @@
|
|
|
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
|
|
12
|
-
var
|
|
13
|
-
var cache;
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
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.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 gulpConfig = _interopRequireWildcard(require("../../gulp.config.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; }
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
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).';
|
|
16
|
+
|
|
18
17
|
/**
|
|
19
18
|
* Load `gulp-imagemin`, an optional peer dependency: image optimization is off by default and its binary-download
|
|
20
19
|
* dependency chain is heavy, so it is only required once the images task actually runs, and it is resolved from the
|
|
@@ -23,36 +22,36 @@ const installHint = 'Add it to your project with: npm install --save-dev github:
|
|
|
23
22
|
* @param {string} [projectPath=process.cwd()] - The project directory to resolve `gulp-imagemin` from.
|
|
24
23
|
* @returns {Function} The gulp-imagemin plugin factory.
|
|
25
24
|
* @throws {Error} With install instructions when gulp-imagemin is missing or is the ESM-only upstream release.
|
|
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
|
-
|
|
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
|
+
|
|
37
36
|
/**
|
|
38
37
|
* Move and optimize images into the browser directory.
|
|
39
38
|
* @memberOf module:partials
|
|
40
39
|
* @param {string|array} [imageSrc=src/images/pattern]
|
|
41
40
|
* @param {string} [imageDest=dest/image/folder]
|
|
42
41
|
* @return {stream.Stream}
|
|
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
|
-
};
|
|
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
|
+
};
|
|
58
57
|
exports.imagesFor = imagesFor;
|
|
@@ -1,36 +1,36 @@
|
|
|
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.resolveJsdocTheme = exports.resolveJsdocBin = exports.jsdocDocsFor = void 0;
|
|
8
|
-
require("core-js/modules/es.json.stringify.js");
|
|
9
|
-
require("core-js/modules/esnext.iterator.constructor.js");
|
|
10
|
-
require("core-js/modules/esnext.iterator.find.js");
|
|
11
|
-
require("core-js/modules/esnext.iterator.map.js");
|
|
12
|
-
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
13
|
-
var _nodeOs = _interopRequireDefault(require("node:os"));
|
|
14
|
-
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
15
|
-
var _nodeModule = require("node:module");
|
|
16
|
-
var _nodeChild_process = require("node:child_process");
|
|
17
|
-
var _nodeUtil = require("node:util");
|
|
18
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
19
|
-
var _removeDirectory = require("./removeDirectory.js");
|
|
20
|
-
var _jsdocBase = _interopRequireDefault(require("../../jsdoc.base.js"));
|
|
21
|
-
var cache;
|
|
22
|
-
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; }
|
|
23
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
24
|
-
// jsdoc.base.js is CommonJS (it's also required directly by consuming projects' own .jsdoc.conf.js) - Node's ESM
|
|
25
|
-
// loader imports a CJS module's module.exports as the default export directly, no createRequire/import.meta needed
|
|
26
|
-
// (import.meta.url tripped up this project's own Babel CJS transform, which Jest relies on to run .mjs test files -
|
|
27
|
-
// confirmed by removing it and nothing else changing).
|
|
28
|
-
|
|
29
|
-
const execFileAsync = (0, _nodeUtil.promisify)(_nodeChild_process.execFile);
|
|
30
|
-
const escapeHtml = text => String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
31
|
-
const jsdocInstallHint = 'Install it in your project with: npm install --save-dev jsdoc';
|
|
32
|
-
const themeInstallHint = name => `Install it in your project with: npm install --save-dev ${name}`;
|
|
33
|
-
|
|
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.resolveJsdocTheme = exports.resolveJsdocBin = exports.jsdocDocsFor = void 0;
|
|
8
|
+
require("core-js/modules/es.json.stringify.js");
|
|
9
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
10
|
+
require("core-js/modules/esnext.iterator.find.js");
|
|
11
|
+
require("core-js/modules/esnext.iterator.map.js");
|
|
12
|
+
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
13
|
+
var _nodeOs = _interopRequireDefault(require("node:os"));
|
|
14
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
15
|
+
var _nodeModule = require("node:module");
|
|
16
|
+
var _nodeChild_process = require("node:child_process");
|
|
17
|
+
var _nodeUtil = require("node:util");
|
|
18
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
19
|
+
var _removeDirectory = require("./removeDirectory.js");
|
|
20
|
+
var _jsdocBase = _interopRequireDefault(require("../../jsdoc.base.js"));
|
|
21
|
+
var cache;
|
|
22
|
+
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; }
|
|
23
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
24
|
+
// jsdoc.base.js is CommonJS (it's also required directly by consuming projects' own .jsdoc.conf.js) - Node's ESM
|
|
25
|
+
// loader imports a CJS module's module.exports as the default export directly, no createRequire/import.meta needed
|
|
26
|
+
// (import.meta.url tripped up this project's own Babel CJS transform, which Jest relies on to run .mjs test files -
|
|
27
|
+
// confirmed by removing it and nothing else changing).
|
|
28
|
+
|
|
29
|
+
const execFileAsync = (0, _nodeUtil.promisify)(_nodeChild_process.execFile);
|
|
30
|
+
const escapeHtml = text => String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
31
|
+
const jsdocInstallHint = 'Install it in your project with: npm install --save-dev jsdoc';
|
|
32
|
+
const themeInstallHint = name => `Install it in your project with: npm install --save-dev ${name}`;
|
|
33
|
+
|
|
34
34
|
/**
|
|
35
35
|
* Resolve the installed directory of an optional peer dependency, from the project being built rather than from
|
|
36
36
|
* this package. Deliberately not requirePeer/importPeer's own `require(name + '/package.json')` approach - that
|
|
@@ -48,20 +48,20 @@ const themeInstallHint = name => `Install it in your project with: npm install -
|
|
|
48
48
|
* @param {string} [options.projectPath=process.cwd()]
|
|
49
49
|
* @returns {string}
|
|
50
50
|
* @throws {Error} With install instructions when the package is not installed.
|
|
51
|
-
*/
|
|
52
|
-
const resolvePeerDir = (name, {
|
|
53
|
-
task,
|
|
54
|
-
installHint,
|
|
55
|
-
projectPath = process.cwd()
|
|
56
|
-
}) => {
|
|
57
|
-
const req = (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json'));
|
|
58
|
-
const found = (req.resolve.paths(name) || []).map(dir => _nodePath.default.join(dir, name)).find(dir => _nodeFs.default.existsSync(_nodePath.default.join(dir, 'package.json')));
|
|
59
|
-
if (!found) {
|
|
60
|
-
throw new Error(`The ${task} task needs the optional peer dependency ${name}, which is not installed. ${installHint}`);
|
|
61
|
-
}
|
|
62
|
-
return found;
|
|
63
|
-
};
|
|
64
|
-
|
|
51
|
+
*/
|
|
52
|
+
const resolvePeerDir = (name, {
|
|
53
|
+
task,
|
|
54
|
+
installHint,
|
|
55
|
+
projectPath = process.cwd()
|
|
56
|
+
}) => {
|
|
57
|
+
const req = (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json'));
|
|
58
|
+
const found = (req.resolve.paths(name) || []).map(dir => _nodePath.default.join(dir, name)).find(dir => _nodeFs.default.existsSync(_nodePath.default.join(dir, 'package.json')));
|
|
59
|
+
if (!found) {
|
|
60
|
+
throw new Error(`The ${task} task needs the optional peer dependency ${name}, which is not installed. ${installHint}`);
|
|
61
|
+
}
|
|
62
|
+
return found;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
65
|
/**
|
|
66
66
|
* Resolve jsdoc's own CLI entry point. jsdoc has no stable programmatic Node API for generating HTML docs (unlike
|
|
67
67
|
* TypeDoc's Application.bootstrap()/convert()/generateDocs()) - gulp-jsdoc3, the established gulp wrapper, is
|
|
@@ -71,13 +71,13 @@ const resolvePeerDir = (name, {
|
|
|
71
71
|
* @memberOf module:partials
|
|
72
72
|
* @param {string} [projectPath=process.cwd()]
|
|
73
73
|
* @returns {string}
|
|
74
|
-
*/
|
|
75
|
-
const resolveJsdocBin = (projectPath = process.cwd()) => _nodePath.default.join(resolvePeerDir('jsdoc', {
|
|
76
|
-
task: 'docs',
|
|
77
|
-
installHint: jsdocInstallHint,
|
|
78
|
-
projectPath
|
|
79
|
-
}), 'jsdoc.js');
|
|
80
|
-
|
|
74
|
+
*/
|
|
75
|
+
const resolveJsdocBin = (projectPath = process.cwd()) => _nodePath.default.join(resolvePeerDir('jsdoc', {
|
|
76
|
+
task: 'docs',
|
|
77
|
+
installHint: jsdocInstallHint,
|
|
78
|
+
projectPath
|
|
79
|
+
}), 'jsdoc.js');
|
|
80
|
+
|
|
81
81
|
/**
|
|
82
82
|
* Resolve a jsdoc theme package's own template directory, for jsdoc's own opts.template config key: the folder
|
|
83
83
|
* holding its publish.js. That is the package root for a classic jsdoc template (clean-jsdoc-theme 4.x included),
|
|
@@ -86,18 +86,18 @@ const resolveJsdocBin = (projectPath = process.cwd()) => _nodePath.default.join(
|
|
|
86
86
|
* @param {string} name
|
|
87
87
|
* @param {string} [projectPath=process.cwd()]
|
|
88
88
|
* @returns {string}
|
|
89
|
-
*/
|
|
90
|
-
exports.resolveJsdocBin = resolveJsdocBin;
|
|
91
|
-
const resolveJsdocTheme = (name, projectPath = process.cwd()) => {
|
|
92
|
-
const packageDir = resolvePeerDir(name, {
|
|
93
|
-
task: 'docs',
|
|
94
|
-
installHint: themeInstallHint(name),
|
|
95
|
-
projectPath
|
|
96
|
-
});
|
|
97
|
-
const distDir = _nodePath.default.join(packageDir, 'dist');
|
|
98
|
-
return _nodeFs.default.existsSync(_nodePath.default.join(distDir, 'publish.js')) ? distDir : packageDir;
|
|
99
|
-
};
|
|
100
|
-
|
|
89
|
+
*/
|
|
90
|
+
exports.resolveJsdocBin = resolveJsdocBin;
|
|
91
|
+
const resolveJsdocTheme = (name, projectPath = process.cwd()) => {
|
|
92
|
+
const packageDir = resolvePeerDir(name, {
|
|
93
|
+
task: 'docs',
|
|
94
|
+
installHint: themeInstallHint(name),
|
|
95
|
+
projectPath
|
|
96
|
+
});
|
|
97
|
+
const distDir = _nodePath.default.join(packageDir, 'dist');
|
|
98
|
+
return _nodeFs.default.existsSync(_nodePath.default.join(distDir, 'publish.js')) ? distDir : packageDir;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
101
|
/**
|
|
102
102
|
* Generate the HTML documentation of a plain-JavaScript project with jsdoc, using jsdoc.base.js's own shared
|
|
103
103
|
* config (plugins, includePattern/excludePattern) as the starting point rather than a parallel one - the same
|
|
@@ -110,66 +110,66 @@ const resolveJsdocTheme = (name, projectPath = process.cwd()) => {
|
|
|
110
110
|
* @param {string} [outPath=gulpConfig.get('docs.to')] - The directory the documentation is generated into (cleared first).
|
|
111
111
|
* @param {function(string, Array<string>): Promise<Object>} [runJsdoc] - Runs the jsdoc CLI, tests can inject a stand-in.
|
|
112
112
|
* @returns {Function} A gulp task, it accepts an optional callback and returns a promise.
|
|
113
|
-
*/
|
|
114
|
-
exports.resolveJsdocTheme = resolveJsdocTheme;
|
|
115
|
-
const jsdocDocsFor = (srcPath = gulpConfig.get('docs.from'), outPath = gulpConfig.get('docs.to'), runJsdoc = (bin, args) => execFileAsync(process.execPath, [bin, ...args])) => {
|
|
116
|
-
if (gulpConfig.get('docs.enabled') === false) {
|
|
117
|
-
return () => {};
|
|
118
|
-
}
|
|
119
|
-
return done => {
|
|
120
|
-
const generate = async () => {
|
|
121
|
-
const theme = gulpConfig.get('docs.theme') || 'clean-jsdoc-theme';
|
|
122
|
-
const themeDir = resolveJsdocTheme(theme);
|
|
123
|
-
const indexFile = gulpConfig.get('docs.index');
|
|
124
|
-
const title = gulpConfig.get('docs.title');
|
|
125
|
-
await (0, _removeDirectory.removeDirectory)(outPath);
|
|
126
|
-
const config = {
|
|
127
|
-
..._jsdocBase.default,
|
|
128
|
-
source: {
|
|
129
|
-
..._jsdocBase.default.source,
|
|
130
|
-
include: [].concat(srcPath).map(includePath => _nodePath.default.resolve(includePath))
|
|
131
|
-
},
|
|
132
|
-
opts: {
|
|
133
|
-
destination: _nodePath.default.resolve(outPath),
|
|
134
|
-
// jsdoc does not recurse into source.include's own subdirectories by default - without this, only
|
|
135
|
-
// the top level of docs.from would ever be scanned. Confirmed from clean-jsdoc-theme's own README
|
|
136
|
-
// quick-start example, which sets this explicitly, not assumed from jsdoc's own classic defaults.
|
|
137
|
-
recurse: true,
|
|
138
|
-
template: themeDir,
|
|
139
|
-
// clean-jsdoc-theme's own options for the name in its header and the home page's <title> (otherwise "Home").
|
|
140
|
-
// The header is given as a link: a plain-text title links to the site root ("/"), while every page is in one
|
|
141
|
-
// folder, so index.html is the home page wherever they are served. Both are printed unescaped by the theme.
|
|
142
|
-
...(title ? {
|
|
143
|
-
theme_opts: {
|
|
144
|
-
title: `<a href="index.html" class="sidebar-title sidebar-title-anchor">${escapeHtml(title)}</a>`,
|
|
145
|
-
homepageTitle: escapeHtml(title)
|
|
146
|
-
}
|
|
147
|
-
} : {}),
|
|
148
|
-
...(indexFile && _nodeFs.default.existsSync(indexFile) ? {
|
|
149
|
-
readme: _nodePath.default.resolve(indexFile)
|
|
150
|
-
} : {})
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
const workDir = _nodeFs.default.mkdtempSync(_nodePath.default.join(_nodeOs.default.tmpdir(), 'jsdocdocs-'));
|
|
154
|
-
try {
|
|
155
|
-
const configPath = _nodePath.default.join(workDir, 'jsdoc.conf.json');
|
|
156
|
-
_nodeFs.default.writeFileSync(configPath, JSON.stringify(config));
|
|
157
|
-
const bin = resolveJsdocBin();
|
|
158
|
-
// Pass on what jsdoc and the theme report (warnings such as a page which failed to render), which would
|
|
159
|
-
// otherwise be lost with the captured output
|
|
160
|
-
const {
|
|
161
|
-
stdout = '',
|
|
162
|
-
stderr = ''
|
|
163
|
-
} = (await runJsdoc(bin, ['-c', configPath])) || {};
|
|
164
|
-
const report = `${stdout}${stderr}`.trim();
|
|
165
|
-
if (report) {
|
|
166
|
-
console.warn(report);
|
|
167
|
-
}
|
|
168
|
-
} finally {
|
|
169
|
-
await (0, _removeDirectory.removeDirectory)(workDir);
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
return typeof done === 'function' ? generate().then(() => done(), done) : generate();
|
|
173
|
-
};
|
|
174
|
-
};
|
|
113
|
+
*/
|
|
114
|
+
exports.resolveJsdocTheme = resolveJsdocTheme;
|
|
115
|
+
const jsdocDocsFor = (srcPath = gulpConfig.get('docs.from'), outPath = gulpConfig.get('docs.to'), runJsdoc = (bin, args) => execFileAsync(process.execPath, [bin, ...args])) => {
|
|
116
|
+
if (gulpConfig.get('docs.enabled') === false) {
|
|
117
|
+
return () => {};
|
|
118
|
+
}
|
|
119
|
+
return done => {
|
|
120
|
+
const generate = async () => {
|
|
121
|
+
const theme = gulpConfig.get('docs.theme') || 'clean-jsdoc-theme';
|
|
122
|
+
const themeDir = resolveJsdocTheme(theme);
|
|
123
|
+
const indexFile = gulpConfig.get('docs.index');
|
|
124
|
+
const title = gulpConfig.get('docs.title');
|
|
125
|
+
await (0, _removeDirectory.removeDirectory)(outPath);
|
|
126
|
+
const config = {
|
|
127
|
+
..._jsdocBase.default,
|
|
128
|
+
source: {
|
|
129
|
+
..._jsdocBase.default.source,
|
|
130
|
+
include: [].concat(srcPath).map(includePath => _nodePath.default.resolve(includePath))
|
|
131
|
+
},
|
|
132
|
+
opts: {
|
|
133
|
+
destination: _nodePath.default.resolve(outPath),
|
|
134
|
+
// jsdoc does not recurse into source.include's own subdirectories by default - without this, only
|
|
135
|
+
// the top level of docs.from would ever be scanned. Confirmed from clean-jsdoc-theme's own README
|
|
136
|
+
// quick-start example, which sets this explicitly, not assumed from jsdoc's own classic defaults.
|
|
137
|
+
recurse: true,
|
|
138
|
+
template: themeDir,
|
|
139
|
+
// clean-jsdoc-theme's own options for the name in its header and the home page's <title> (otherwise "Home").
|
|
140
|
+
// The header is given as a link: a plain-text title links to the site root ("/"), while every page is in one
|
|
141
|
+
// folder, so index.html is the home page wherever they are served. Both are printed unescaped by the theme.
|
|
142
|
+
...(title ? {
|
|
143
|
+
theme_opts: {
|
|
144
|
+
title: `<a href="index.html" class="sidebar-title sidebar-title-anchor">${escapeHtml(title)}</a>`,
|
|
145
|
+
homepageTitle: escapeHtml(title)
|
|
146
|
+
}
|
|
147
|
+
} : {}),
|
|
148
|
+
...(indexFile && _nodeFs.default.existsSync(indexFile) ? {
|
|
149
|
+
readme: _nodePath.default.resolve(indexFile)
|
|
150
|
+
} : {})
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const workDir = _nodeFs.default.mkdtempSync(_nodePath.default.join(_nodeOs.default.tmpdir(), 'jsdocdocs-'));
|
|
154
|
+
try {
|
|
155
|
+
const configPath = _nodePath.default.join(workDir, 'jsdoc.conf.json');
|
|
156
|
+
_nodeFs.default.writeFileSync(configPath, JSON.stringify(config));
|
|
157
|
+
const bin = resolveJsdocBin();
|
|
158
|
+
// Pass on what jsdoc and the theme report (warnings such as a page which failed to render), which would
|
|
159
|
+
// otherwise be lost with the captured output
|
|
160
|
+
const {
|
|
161
|
+
stdout = '',
|
|
162
|
+
stderr = ''
|
|
163
|
+
} = (await runJsdoc(bin, ['-c', configPath])) || {};
|
|
164
|
+
const report = `${stdout}${stderr}`.trim();
|
|
165
|
+
if (report) {
|
|
166
|
+
console.warn(report);
|
|
167
|
+
}
|
|
168
|
+
} finally {
|
|
169
|
+
await (0, _removeDirectory.removeDirectory)(workDir);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
return typeof done === 'function' ? generate().then(() => done(), done) : generate();
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
175
|
exports.jsdocDocsFor = jsdocDocsFor;
|
|
@@ -0,0 +1,41 @@
|
|
|
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.lintSource = void 0;
|
|
8
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
9
|
+
var _gulp = require("gulp");
|
|
10
|
+
var _neostandardLint = require("./neostandardLint.js");
|
|
11
|
+
var cache;
|
|
12
|
+
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
|
+
* Lint the project's source (srcPath: .js, .mjs and .cjs, plus .ts when typescript.enabled) with neostandard and
|
|
15
|
+
* write the automatic fixes back in place. Shared by the sourceLint (build) and lint (standalone) tasks.
|
|
16
|
+
* @memberOf module:partials
|
|
17
|
+
* @param {Object} [options={}]
|
|
18
|
+
* @param {boolean} [options.failOnError=false] - Fail once linting finishes if any errors could not be fixed.
|
|
19
|
+
* @returns {stream.Stream}
|
|
20
|
+
*/
|
|
21
|
+
const lintSource = ({
|
|
22
|
+
failOnError = false
|
|
23
|
+
} = {}) => {
|
|
24
|
+
const srcPath = gulpConfig.get('srcPath');
|
|
25
|
+
const ts = gulpConfig.get('typescript.enabled');
|
|
26
|
+
const patterns = [`${srcPath}/**/*.{js,mjs,cjs}`];
|
|
27
|
+
if (ts) {
|
|
28
|
+
patterns.push(`${srcPath}/**/*.ts`);
|
|
29
|
+
}
|
|
30
|
+
const linter = (0, _neostandardLint.neostandardLint)({
|
|
31
|
+
fix: true,
|
|
32
|
+
ts,
|
|
33
|
+
rules: gulpConfig.get('lint.rules'),
|
|
34
|
+
failOnError
|
|
35
|
+
});
|
|
36
|
+
const written = (0, _gulp.src)(patterns).pipe(linter).pipe((0, _gulp.dest)(srcPath));
|
|
37
|
+
// pipe() does not forward errors, and gulp only watches the returned stream, so pass the linter's failure along.
|
|
38
|
+
linter.on('error', error => written.emit('error', error));
|
|
39
|
+
return written;
|
|
40
|
+
};
|
|
41
|
+
exports.lintSource = lintSource;
|
|
@@ -1,34 +1,35 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.requirePeer = exports.importPeer = exports.importModule = void 0;
|
|
7
|
-
require("core-js/modules/es.array.includes.js");
|
|
8
|
-
var _nodeModule = require("node:module");
|
|
9
|
-
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
-
var _nodeUrl = require("node:url");
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
// Several dependencies ship ESM-only (standard, gulp-ts-compile, typedoc), but this package also publishes a CommonJS
|
|
13
|
-
// build (dist/*.js) whose babel transform would turn even a dynamic import() into a require() that cannot load an ES
|
|
14
|
-
// module. Hiding the import() inside a Function constructor keeps it a genuine dynamic import that works from either
|
|
15
|
-
// build, because babel cannot see (and so cannot rewrite) an import expression which only exists as a runtime string.
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.requirePeer = exports.importPeer = exports.importModule = void 0;
|
|
7
|
+
require("core-js/modules/es.array.includes.js");
|
|
8
|
+
var _nodeModule = require("node:module");
|
|
9
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
+
var _nodeUrl = require("node:url");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
// Several dependencies ship ESM-only (standard, gulp-ts-compile, typedoc), but this package also publishes a CommonJS
|
|
13
|
+
// build (dist/*.js) whose babel transform would turn even a dynamic import() into a require() that cannot load an ES
|
|
14
|
+
// module. Hiding the import() inside a Function constructor keeps it a genuine dynamic import that works from either
|
|
15
|
+
// build, because babel cannot see (and so cannot rewrite) an import expression which only exists as a runtime string.
|
|
16
|
+
// eslint-disable-next-line no-new-func -- deliberate, see above
|
|
17
|
+
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
18
|
+
|
|
18
19
|
/**
|
|
19
20
|
* Import an ES module (or any module) with a real dynamic import(), whichever build (ESM or CommonJS) this runs from.
|
|
20
21
|
* @memberOf module:partials
|
|
21
22
|
* @param {string} specifier - The package name, or the URL of a file.
|
|
22
23
|
* @returns {Promise<Object>} The module namespace.
|
|
23
|
-
*/
|
|
24
|
-
const importModule = specifier => dynamicImport(specifier);
|
|
25
|
-
exports.importModule = importModule;
|
|
26
|
-
const isMissing = (error, name) => error.code === 'MODULE_NOT_FOUND' && error.message.includes(`'${name}'`);
|
|
27
|
-
const notInstalled = (name, {
|
|
28
|
-
task,
|
|
29
|
-
installHint
|
|
30
|
-
}) => new Error(`The ${task} task needs the optional peer dependency ${name}, which is not installed. ${installHint}`);
|
|
31
|
-
|
|
24
|
+
*/
|
|
25
|
+
const importModule = specifier => dynamicImport(specifier);
|
|
26
|
+
exports.importModule = importModule;
|
|
27
|
+
const isMissing = (error, name) => error.code === 'MODULE_NOT_FOUND' && error.message.includes(`'${name}'`);
|
|
28
|
+
const notInstalled = (name, {
|
|
29
|
+
task,
|
|
30
|
+
installHint
|
|
31
|
+
}) => new Error(`The ${task} task needs the optional peer dependency ${name}, which is not installed. ${installHint}`);
|
|
32
|
+
|
|
32
33
|
/**
|
|
33
34
|
* Load an optional peer dependency (one which is only needed once a task runs, so projects which never use that task
|
|
34
35
|
* do not have to install it) with require(), from the project being built rather than from this package. When it is
|
|
@@ -42,29 +43,29 @@ const notInstalled = (name, {
|
|
|
42
43
|
* @param {string} [options.projectPath=process.cwd()] - The folder of the project (which has the package.json) being built.
|
|
43
44
|
* @returns {*} Whatever the package exports.
|
|
44
45
|
* @throws {Error} With install instructions when the package is not installed.
|
|
45
|
-
*/
|
|
46
|
-
const requirePeer = (name, {
|
|
47
|
-
task,
|
|
48
|
-
installHint,
|
|
49
|
-
esmOnlyMessage,
|
|
50
|
-
projectPath = process.cwd()
|
|
51
|
-
}) => {
|
|
52
|
-
try {
|
|
53
|
-
return (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json'))(name);
|
|
54
|
-
} catch (error) {
|
|
55
|
-
if (isMissing(error, name)) {
|
|
56
|
-
throw notInstalled(name, {
|
|
57
|
-
task,
|
|
58
|
-
installHint
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
if (error.code === 'ERR_REQUIRE_ESM' && esmOnlyMessage) {
|
|
62
|
-
throw new Error(esmOnlyMessage);
|
|
63
|
-
}
|
|
64
|
-
throw error;
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
46
|
+
*/
|
|
47
|
+
const requirePeer = (name, {
|
|
48
|
+
task,
|
|
49
|
+
installHint,
|
|
50
|
+
esmOnlyMessage,
|
|
51
|
+
projectPath = process.cwd()
|
|
52
|
+
}) => {
|
|
53
|
+
try {
|
|
54
|
+
return (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json'))(name);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
if (isMissing(error, name)) {
|
|
57
|
+
throw notInstalled(name, {
|
|
58
|
+
task,
|
|
59
|
+
installHint
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (error.code === 'ERR_REQUIRE_ESM' && esmOnlyMessage) {
|
|
63
|
+
throw new Error(esmOnlyMessage);
|
|
64
|
+
}
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
68
69
|
/**
|
|
69
70
|
* Import an optional peer dependency which ships ESM-only, from the project being built. See {@link requirePeer}.
|
|
70
71
|
* @memberOf module:partials
|
|
@@ -75,25 +76,25 @@ const requirePeer = (name, {
|
|
|
75
76
|
* @param {string} [options.projectPath=process.cwd()] - The folder of the project (which has the package.json) being built.
|
|
76
77
|
* @returns {Promise<Object>} The module namespace.
|
|
77
78
|
* @throws {Error} With install instructions when the package is not installed.
|
|
78
|
-
*/
|
|
79
|
-
exports.requirePeer = requirePeer;
|
|
80
|
-
const importPeer = async (name, {
|
|
81
|
-
task,
|
|
82
|
-
installHint,
|
|
83
|
-
projectPath = process.cwd()
|
|
84
|
-
}) => {
|
|
85
|
-
let resolved;
|
|
86
|
-
try {
|
|
87
|
-
resolved = (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json')).resolve(name);
|
|
88
|
-
} catch (error) {
|
|
89
|
-
if (isMissing(error, name)) {
|
|
90
|
-
throw notInstalled(name, {
|
|
91
|
-
task,
|
|
92
|
-
installHint
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
return importModule((0, _nodeUrl.pathToFileURL)(resolved).href);
|
|
98
|
-
};
|
|
79
|
+
*/
|
|
80
|
+
exports.requirePeer = requirePeer;
|
|
81
|
+
const importPeer = async (name, {
|
|
82
|
+
task,
|
|
83
|
+
installHint,
|
|
84
|
+
projectPath = process.cwd()
|
|
85
|
+
}) => {
|
|
86
|
+
let resolved;
|
|
87
|
+
try {
|
|
88
|
+
resolved = (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json')).resolve(name);
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (isMissing(error, name)) {
|
|
91
|
+
throw notInstalled(name, {
|
|
92
|
+
task,
|
|
93
|
+
installHint
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
return importModule((0, _nodeUrl.pathToFileURL)(resolved).href);
|
|
99
|
+
};
|
|
99
100
|
exports.importPeer = importPeer;
|