js-build-tools 5.3.1 → 5.3.2
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 +3 -1
- package/dist/partials/imagesFor.js +42 -42
- package/dist/partials/loadPeer.js +70 -70
- package/dist/partials/standardLint.js +73 -73
- package/dist/partials/tsFor.js +70 -70
- package/dist/partials/typeDocsFor.js +31 -7
- package/dist/partials.js +136 -136
- package/functions/partials/typeDocsFor.mjs +29 -5
- package/functions/partials/typeDocsFor.test.mjs +26 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -444,7 +444,9 @@ module.exports = babelConfig
|
|
|
444
444
|
the readme it generates. Instead, this can generate HTML documentation straight from the TypeScript source with
|
|
445
445
|
[TypeDoc](https://typedoc.org/). Every folder in your source directory becomes a module of the documentation, the default
|
|
446
446
|
export of each file (one function per file) is listed under the name of the file, and everything else a file exports (for
|
|
447
|
-
example the types in a `types.ts`) is listed as it is. Index files, tests and declaration files are left out.
|
|
447
|
+
example the types in a `types.ts`) is listed as it is. Index files, tests and declaration files are left out. A file
|
|
448
|
+
which sits directly in the source directory, beside the folders, is a module of its own (unless it is `index` or
|
|
449
|
+
`main`). The first comment of a folder's `index.ts` (or the header comment of such a file) describes its module. The
|
|
448
450
|
comments on your code are the documentation, and the types come from the code itself, so `@module`, `@memberOf`,
|
|
449
451
|
`@typedef` and the `{Type}` of `@param` are not needed.
|
|
450
452
|
|
|
@@ -1,19 +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 _nodePath = _interopRequireDefault(require("node:path"));
|
|
12
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
13
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
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
|
-
|
|
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
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
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
|
+
|
|
17
17
|
/**
|
|
18
18
|
* Load `gulp-imagemin`, an optional peer dependency: image optimization is off by default and its binary-download
|
|
19
19
|
* dependency chain is heavy, so it is only required once the images task actually runs, and it is resolved from the
|
|
@@ -22,36 +22,36 @@ const installHint = 'Add it to your project with: npm install --save-dev github:
|
|
|
22
22
|
* @param {string} [projectPath=process.cwd()] - The project directory to resolve `gulp-imagemin` from.
|
|
23
23
|
* @returns {Function} The gulp-imagemin plugin factory.
|
|
24
24
|
* @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
|
-
|
|
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
|
+
|
|
36
36
|
/**
|
|
37
37
|
* Move and optimize images into the browser directory.
|
|
38
38
|
* @memberOf module:partials
|
|
39
39
|
* @param {string|array} [imageSrc=src/images/pattern]
|
|
40
40
|
* @param {string} [imageDest=dest/image/folder]
|
|
41
41
|
* @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
|
-
};
|
|
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
|
+
};
|
|
57
57
|
exports.imagesFor = imagesFor;
|
|
@@ -1,34 +1,34 @@
|
|
|
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
|
-
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
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
|
+
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
17
|
+
|
|
18
18
|
/**
|
|
19
19
|
* Import an ES module (or any module) with a real dynamic import(), whichever build (ESM or CommonJS) this runs from.
|
|
20
20
|
* @memberOf module:partials
|
|
21
21
|
* @param {string} specifier - The package name, or the URL of a file.
|
|
22
22
|
* @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
|
-
|
|
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
|
+
|
|
32
32
|
/**
|
|
33
33
|
* Load an optional peer dependency (one which is only needed once a task runs, so projects which never use that task
|
|
34
34
|
* do not have to install it) with require(), from the project being built rather than from this package. When it is
|
|
@@ -42,29 +42,29 @@ const notInstalled = (name, {
|
|
|
42
42
|
* @param {string} [options.projectPath=process.cwd()] - The folder of the project (which has the package.json) being built.
|
|
43
43
|
* @returns {*} Whatever the package exports.
|
|
44
44
|
* @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
|
-
|
|
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
|
+
|
|
68
68
|
/**
|
|
69
69
|
* Import an optional peer dependency which ships ESM-only, from the project being built. See {@link requirePeer}.
|
|
70
70
|
* @memberOf module:partials
|
|
@@ -75,25 +75,25 @@ const requirePeer = (name, {
|
|
|
75
75
|
* @param {string} [options.projectPath=process.cwd()] - The folder of the project (which has the package.json) being built.
|
|
76
76
|
* @returns {Promise<Object>} The module namespace.
|
|
77
77
|
* @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
|
-
};
|
|
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
|
+
};
|
|
99
99
|
exports.importPeer = importPeer;
|
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.standardLint = void 0;
|
|
7
|
-
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
-
require("core-js/modules/esnext.iterator.for-each.js");
|
|
9
|
-
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
-
var _through = _interopRequireDefault(require("through2"));
|
|
11
|
-
var _loadPeer = require("./loadPeer.js");
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
// `standard` (17+) ships ESM-only, see importModule for how it is imported.
|
|
14
|
-
const importStandard = () => (0, _loadPeer.importModule)('standard');
|
|
15
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.standardLint = void 0;
|
|
7
|
+
require("core-js/modules/esnext.iterator.constructor.js");
|
|
8
|
+
require("core-js/modules/esnext.iterator.for-each.js");
|
|
9
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
+
var _through = _interopRequireDefault(require("through2"));
|
|
11
|
+
var _loadPeer = require("./loadPeer.js");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
// `standard` (17+) ships ESM-only, see importModule for how it is imported.
|
|
14
|
+
const importStandard = () => (0, _loadPeer.importModule)('standard');
|
|
15
|
+
|
|
16
16
|
/**
|
|
17
17
|
* Print a file's lint messages, if it has any.
|
|
18
18
|
* @memberOf module:partials
|
|
19
19
|
* @param {import('vinyl')} file
|
|
20
20
|
* @param {{messages: Array<{line: number, column: number, message: string}>, errorCount: number, warningCount: number}} result
|
|
21
21
|
* @returns {undefined}
|
|
22
|
-
*/
|
|
23
|
-
const printFileReport = (file, result) => {
|
|
24
|
-
if (!result.messages.length) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
console.log(_nodePath.default.relative(file.cwd, file.path));
|
|
28
|
-
result.messages.forEach(({
|
|
29
|
-
line,
|
|
30
|
-
column,
|
|
31
|
-
message
|
|
32
|
-
}) => console.log(`line ${line}:${column}\t${message}`));
|
|
33
|
-
console.log(`✖ ${result.errorCount} error\t⚠ ${result.warningCount} warning\n`);
|
|
34
|
-
};
|
|
35
|
-
|
|
22
|
+
*/
|
|
23
|
+
const printFileReport = (file, result) => {
|
|
24
|
+
if (!result.messages.length) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
console.log(_nodePath.default.relative(file.cwd, file.path));
|
|
28
|
+
result.messages.forEach(({
|
|
29
|
+
line,
|
|
30
|
+
column,
|
|
31
|
+
message
|
|
32
|
+
}) => console.log(`line ${line}:${column}\t${message}`));
|
|
33
|
+
console.log(`✖ ${result.errorCount} error\t⚠ ${result.warningCount} warning\n`);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
36
|
/**
|
|
37
37
|
* Lint every file streaming through with JavaScript Standard Style and, unless `fix` is false, apply the automatic
|
|
38
38
|
* fixes to the file's contents so a following `dest()` writes the fixed version. Remaining problems are printed
|
|
@@ -47,48 +47,48 @@ const printFileReport = (file, result) => {
|
|
|
47
47
|
* should never need to pass this - it exists so tests can supply a stand-in, since this project's
|
|
48
48
|
* CommonJS-transform-based Jest setup cannot execute a real dynamic import() of an ES module.
|
|
49
49
|
* @returns {import('stream').Transform}
|
|
50
|
-
*/
|
|
51
|
-
const standardLint = ({
|
|
52
|
-
fix = true
|
|
53
|
-
} = {}, loadStandard = () => importStandard().then(({
|
|
54
|
-
default: standard
|
|
55
|
-
}) => standard)) => {
|
|
56
|
-
const totals = {
|
|
57
|
-
errors: 0,
|
|
58
|
-
warnings: 0
|
|
59
|
-
};
|
|
60
|
-
return _through.default.obj(function (file, enc, callback) {
|
|
61
|
-
if (file.isNull()) {
|
|
62
|
-
callback(null, file);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
if (file.isStream()) {
|
|
66
|
-
callback(new Error('standardLint: streaming file contents are not supported.'));
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
loadStandard().then(standard => standard.lintText(file.contents.toString(), {
|
|
70
|
-
filename: file.path,
|
|
71
|
-
cwd: file.cwd,
|
|
72
|
-
fix
|
|
73
|
-
})).then(results => {
|
|
74
|
-
// No result at all means the file is ignored by the project's Standard configuration.
|
|
75
|
-
const [result] = results;
|
|
76
|
-
if (result) {
|
|
77
|
-
if (typeof result.output === 'string') {
|
|
78
|
-
file.contents = Buffer.from(result.output);
|
|
79
|
-
}
|
|
80
|
-
totals.errors += result.errorCount;
|
|
81
|
-
totals.warnings += result.warningCount;
|
|
82
|
-
printFileReport(file, result);
|
|
83
|
-
}
|
|
84
|
-
callback(null, file);
|
|
85
|
-
}, callback);
|
|
86
|
-
}, function (callback) {
|
|
87
|
-
console.log('Standard linter results');
|
|
88
|
-
console.log('======================================');
|
|
89
|
-
console.log(`✖ Errors total: ${totals.errors}`);
|
|
90
|
-
console.log(`⚠ Warnings total: ${totals.warnings}\n`);
|
|
91
|
-
callback();
|
|
92
|
-
});
|
|
93
|
-
};
|
|
50
|
+
*/
|
|
51
|
+
const standardLint = ({
|
|
52
|
+
fix = true
|
|
53
|
+
} = {}, loadStandard = () => importStandard().then(({
|
|
54
|
+
default: standard
|
|
55
|
+
}) => standard)) => {
|
|
56
|
+
const totals = {
|
|
57
|
+
errors: 0,
|
|
58
|
+
warnings: 0
|
|
59
|
+
};
|
|
60
|
+
return _through.default.obj(function (file, enc, callback) {
|
|
61
|
+
if (file.isNull()) {
|
|
62
|
+
callback(null, file);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (file.isStream()) {
|
|
66
|
+
callback(new Error('standardLint: streaming file contents are not supported.'));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
loadStandard().then(standard => standard.lintText(file.contents.toString(), {
|
|
70
|
+
filename: file.path,
|
|
71
|
+
cwd: file.cwd,
|
|
72
|
+
fix
|
|
73
|
+
})).then(results => {
|
|
74
|
+
// No result at all means the file is ignored by the project's Standard configuration.
|
|
75
|
+
const [result] = results;
|
|
76
|
+
if (result) {
|
|
77
|
+
if (typeof result.output === 'string') {
|
|
78
|
+
file.contents = Buffer.from(result.output);
|
|
79
|
+
}
|
|
80
|
+
totals.errors += result.errorCount;
|
|
81
|
+
totals.warnings += result.warningCount;
|
|
82
|
+
printFileReport(file, result);
|
|
83
|
+
}
|
|
84
|
+
callback(null, file);
|
|
85
|
+
}, callback);
|
|
86
|
+
}, function (callback) {
|
|
87
|
+
console.log('Standard linter results');
|
|
88
|
+
console.log('======================================');
|
|
89
|
+
console.log(`✖ Errors total: ${totals.errors}`);
|
|
90
|
+
console.log(`⚠ Warnings total: ${totals.warnings}\n`);
|
|
91
|
+
callback();
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
94
|
exports.standardLint = standardLint;
|
package/dist/partials/tsFor.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
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.tsFor = exports.loadTypescript = void 0;
|
|
8
|
-
var _gulp = require("gulp");
|
|
9
|
-
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
-
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
11
|
-
var _loadPeer = require("./loadPeer.js");
|
|
12
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
-
// gulp-ts-compile ships ESM-only (no CJS build - see its own package.json), see importModule for how it is imported.
|
|
15
|
-
const importGulpTsCompile = () => (0, _loadPeer.importModule)('gulp-ts-compile');
|
|
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.tsFor = exports.loadTypescript = void 0;
|
|
8
|
+
var _gulp = require("gulp");
|
|
9
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
10
|
+
var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
|
|
11
|
+
var _loadPeer = require("./loadPeer.js");
|
|
12
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
// gulp-ts-compile ships ESM-only (no CJS build - see its own package.json), see importModule for how it is imported.
|
|
15
|
+
const importGulpTsCompile = () => (0, _loadPeer.importModule)('gulp-ts-compile');
|
|
16
|
+
|
|
17
17
|
/**
|
|
18
18
|
* Wrap a stream in a promise that resolves once it finishes writing.
|
|
19
19
|
* @memberOf module:partials
|
|
20
20
|
* @param {import('node:stream').Stream} stream
|
|
21
21
|
* @returns {Promise<void>}
|
|
22
|
-
*/
|
|
23
|
-
const installHint = 'Install it in your project with: npm install --save-dev typescript';
|
|
24
|
-
|
|
22
|
+
*/
|
|
23
|
+
const installHint = 'Install it in your project with: npm install --save-dev typescript';
|
|
24
|
+
|
|
25
25
|
/**
|
|
26
26
|
* Load the project's own copy of TypeScript (an optional peer dependency, only needed when the typescript task is
|
|
27
27
|
* enabled) from the project being built, so projects which do not use TypeScript never need it installed.
|
|
@@ -29,18 +29,18 @@ const installHint = 'Install it in your project with: npm install --save-dev typ
|
|
|
29
29
|
* @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
|
|
30
30
|
* @returns {Object} The TypeScript compiler API module.
|
|
31
31
|
* @throws {Error} With install instructions when typescript is not installed.
|
|
32
|
-
*/
|
|
33
|
-
const loadTypescript = (projectPath = process.cwd()) => (0, _loadPeer.requirePeer)('typescript', {
|
|
34
|
-
task: 'typescript',
|
|
35
|
-
installHint,
|
|
36
|
-
projectPath
|
|
37
|
-
});
|
|
38
|
-
exports.loadTypescript = loadTypescript;
|
|
39
|
-
const streamToPromise = stream => new Promise((resolve, reject) => {
|
|
40
|
-
stream.on('finish', resolve);
|
|
41
|
-
stream.on('error', reject);
|
|
42
|
-
});
|
|
43
|
-
|
|
32
|
+
*/
|
|
33
|
+
const loadTypescript = (projectPath = process.cwd()) => (0, _loadPeer.requirePeer)('typescript', {
|
|
34
|
+
task: 'typescript',
|
|
35
|
+
installHint,
|
|
36
|
+
projectPath
|
|
37
|
+
});
|
|
38
|
+
exports.loadTypescript = loadTypescript;
|
|
39
|
+
const streamToPromise = stream => new Promise((resolve, reject) => {
|
|
40
|
+
stream.on('finish', resolve);
|
|
41
|
+
stream.on('error', reject);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
44
|
/**
|
|
45
45
|
* Read a tsconfig.json file into real typescript.CompilerOptions values, using only TypeScript's stable, current,
|
|
46
46
|
* public config-reading API (the same one `tsc --project` itself uses internally) - never
|
|
@@ -49,13 +49,13 @@ const streamToPromise = stream => new Promise((resolve, reject) => {
|
|
|
49
49
|
* @memberOf module:partials
|
|
50
50
|
* @param {string} configPath - Path to a tsconfig.json file.
|
|
51
51
|
* @returns {import('typescript').CompilerOptions}
|
|
52
|
-
*/
|
|
53
|
-
const readCompilerOptions = (ts, configPath) => {
|
|
54
|
-
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
55
|
-
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, _nodePath.default.dirname(configPath));
|
|
56
|
-
return parsedConfig.options;
|
|
57
|
-
};
|
|
58
|
-
|
|
52
|
+
*/
|
|
53
|
+
const readCompilerOptions = (ts, configPath) => {
|
|
54
|
+
const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
55
|
+
const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, _nodePath.default.dirname(configPath));
|
|
56
|
+
return parsedConfig.options;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
59
|
/**
|
|
60
60
|
* Starting at the source directory, find all the ts files and convert them into the distribution directory.
|
|
61
61
|
* @memberOf module:partials
|
|
@@ -68,36 +68,36 @@ const readCompilerOptions = (ts, configPath) => {
|
|
|
68
68
|
* suite already covers real TypeScript-compile correctness - this function's own tests only need to verify its
|
|
69
69
|
* config resolution and stream wiring.
|
|
70
70
|
* @returns {Function}
|
|
71
|
-
*/
|
|
72
|
-
const tsFor = (srcPath = gulpConfig.get('typescript.from'), distPath = gulpConfig.get('typescript.to'), loadTsCompile = () => importGulpTsCompile().then(({
|
|
73
|
-
default: tsCompile
|
|
74
|
-
}) => tsCompile)) => {
|
|
75
|
-
if (gulpConfig.get('typescript.enabled') === false) {
|
|
76
|
-
return () => {};
|
|
77
|
-
}
|
|
78
|
-
const ts = loadTypescript();
|
|
79
|
-
const configPath = gulpConfig.get('typescript.config');
|
|
80
|
-
// When no tsconfig.json is configured, target/module are pinned explicitly rather than left for TypeScript's
|
|
81
|
-
// own compiler defaults - those defaults have already shifted once across a TypeScript version bump in this
|
|
82
|
-
// project's own history (silently changing whether output keeps `const`/`let` or downlevels to `var`), and
|
|
83
|
-
// pinning them keeps this task's output stable across future TypeScript upgrades too. ES5/CommonJS matches
|
|
84
|
-
// what the downstream babel/browserify bundling pipeline has always assumed it receives.
|
|
85
|
-
const compilerOptions = configPath ? readCompilerOptions(ts, configPath) : {
|
|
86
|
-
declaration: true,
|
|
87
|
-
target: ts.ScriptTarget.ES5,
|
|
88
|
-
module: ts.ModuleKind.CommonJS,
|
|
89
|
-
esModuleInterop: false
|
|
90
|
-
};
|
|
91
|
-
// Accepts gulp's own callback-style task convention (an optional `done`, called once finished) rather than
|
|
92
|
-
// just returning a Promise, since callers may invoke the returned function directly with a callback instead
|
|
93
|
-
// of relying on gulp's own runner to observe a returned Promise.
|
|
94
|
-
return done => {
|
|
95
|
-
const compile = async () => {
|
|
96
|
-
const tsCompile = await loadTsCompile();
|
|
97
|
-
const tsResult = (0, _gulp.src)(srcPath).pipe(tsCompile(compilerOptions));
|
|
98
|
-
await Promise.all([streamToPromise(tsResult.dts.pipe((0, _gulp.dest)(distPath))), streamToPromise(tsResult.js.pipe((0, _gulp.dest)(distPath)))]);
|
|
99
|
-
};
|
|
100
|
-
return typeof done === 'function' ? compile().then(() => done(), done) : compile();
|
|
101
|
-
};
|
|
102
|
-
};
|
|
71
|
+
*/
|
|
72
|
+
const tsFor = (srcPath = gulpConfig.get('typescript.from'), distPath = gulpConfig.get('typescript.to'), loadTsCompile = () => importGulpTsCompile().then(({
|
|
73
|
+
default: tsCompile
|
|
74
|
+
}) => tsCompile)) => {
|
|
75
|
+
if (gulpConfig.get('typescript.enabled') === false) {
|
|
76
|
+
return () => {};
|
|
77
|
+
}
|
|
78
|
+
const ts = loadTypescript();
|
|
79
|
+
const configPath = gulpConfig.get('typescript.config');
|
|
80
|
+
// When no tsconfig.json is configured, target/module are pinned explicitly rather than left for TypeScript's
|
|
81
|
+
// own compiler defaults - those defaults have already shifted once across a TypeScript version bump in this
|
|
82
|
+
// project's own history (silently changing whether output keeps `const`/`let` or downlevels to `var`), and
|
|
83
|
+
// pinning them keeps this task's output stable across future TypeScript upgrades too. ES5/CommonJS matches
|
|
84
|
+
// what the downstream babel/browserify bundling pipeline has always assumed it receives.
|
|
85
|
+
const compilerOptions = configPath ? readCompilerOptions(ts, configPath) : {
|
|
86
|
+
declaration: true,
|
|
87
|
+
target: ts.ScriptTarget.ES5,
|
|
88
|
+
module: ts.ModuleKind.CommonJS,
|
|
89
|
+
esModuleInterop: false
|
|
90
|
+
};
|
|
91
|
+
// Accepts gulp's own callback-style task convention (an optional `done`, called once finished) rather than
|
|
92
|
+
// just returning a Promise, since callers may invoke the returned function directly with a callback instead
|
|
93
|
+
// of relying on gulp's own runner to observe a returned Promise.
|
|
94
|
+
return done => {
|
|
95
|
+
const compile = async () => {
|
|
96
|
+
const tsCompile = await loadTsCompile();
|
|
97
|
+
const tsResult = (0, _gulp.src)(srcPath).pipe(tsCompile(compilerOptions));
|
|
98
|
+
await Promise.all([streamToPromise(tsResult.dts.pipe((0, _gulp.dest)(distPath))), streamToPromise(tsResult.js.pipe((0, _gulp.dest)(distPath)))]);
|
|
99
|
+
};
|
|
100
|
+
return typeof done === 'function' ? compile().then(() => done(), done) : compile();
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
103
|
exports.tsFor = tsFor;
|
|
@@ -4,7 +4,7 @@ require("core-js/modules/esnext.weak-map.delete-all.js");
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.writeDocEntries = exports.typeDocsFor = exports.loadTypeDoc = exports.describeFolder = exports.describeExports = void 0;
|
|
7
|
+
exports.writeDocEntries = exports.typeDocsFor = exports.loadTypeDoc = exports.describeFolder = exports.describeFile = exports.describeExports = void 0;
|
|
8
8
|
require("core-js/modules/es.json.stringify.js");
|
|
9
9
|
require("core-js/modules/esnext.iterator.constructor.js");
|
|
10
10
|
require("core-js/modules/esnext.iterator.filter.js");
|
|
@@ -102,7 +102,20 @@ const describeExports = (ts, filePath) => {
|
|
|
102
102
|
exports.describeExports = describeExports;
|
|
103
103
|
const describeFolder = folderPath => {
|
|
104
104
|
const indexFile = ['index.ts', 'index.tsx', 'index.mts', 'index.cts'].map(name => _nodePath.default.join(folderPath, name)).find(file => _nodeFs.default.existsSync(file));
|
|
105
|
-
|
|
105
|
+
return indexFile ? describeFile(indexFile) : '';
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The description of a source file for its module: its first doc comment without the tags (@module, @file, ...), when
|
|
110
|
+
* that comment is a header (it is followed by an import or export, so it does not document a declaration itself), or
|
|
111
|
+
* an empty string.
|
|
112
|
+
* @memberOf module:partials
|
|
113
|
+
* @param {string} filePath
|
|
114
|
+
* @returns {string}
|
|
115
|
+
*/
|
|
116
|
+
exports.describeFolder = describeFolder;
|
|
117
|
+
const describeFile = filePath => {
|
|
118
|
+
const comment = _nodeFs.default.readFileSync(filePath, 'utf8').match(/^\s*\/\*\*([\s\S]*?)\*\/\s*(import\b|export\s+(\*|\{[^}]*\}\s+from)|$)/);
|
|
106
119
|
if (!comment) {
|
|
107
120
|
return '';
|
|
108
121
|
}
|
|
@@ -116,14 +129,16 @@ const describeFolder = folderPath => {
|
|
|
116
129
|
* entry file, so the modules of the documentation mirror the folders. The default export of each source file is
|
|
117
130
|
* re-exported under the name of the file (the source files hold one function each), and anything else a file exports
|
|
118
131
|
* is re-exported as it is (that is where the types.ts files go). Index files (the barrels), tests and declaration
|
|
119
|
-
* files are left out, but the first doc comment of a folder's index file becomes the description of its module.
|
|
132
|
+
* files are left out, but the first doc comment of a folder's index file becomes the description of its module.
|
|
133
|
+
* A file which sits beside the folders (not an index or main file) is a module of its own, described by its header
|
|
134
|
+
* comment. A source directory with no folders gets a single entry called index.
|
|
120
135
|
* @memberOf module:partials
|
|
121
136
|
* @param {Object} ts - The TypeScript compiler API.
|
|
122
137
|
* @param {string} srcDir - The directory holding the TypeScript source.
|
|
123
138
|
* @param {string} entryDir - The directory to write the entry files into.
|
|
124
139
|
* @returns {Array<string>} The paths of the entry files.
|
|
125
140
|
*/
|
|
126
|
-
exports.
|
|
141
|
+
exports.describeFile = describeFile;
|
|
127
142
|
const writeDocEntries = (ts, srcDir, entryDir) => {
|
|
128
143
|
const absoluteSrc = _nodePath.default.resolve(srcDir);
|
|
129
144
|
_nodeFs.default.mkdirSync(entryDir, {
|
|
@@ -136,10 +151,19 @@ const writeDocEntries = (ts, srcDir, entryDir) => {
|
|
|
136
151
|
path: _nodePath.default.join(absoluteSrc, entry.name),
|
|
137
152
|
files: listSources(_nodePath.default.join(absoluteSrc, entry.name))
|
|
138
153
|
})).filter(folder => folder.files.length);
|
|
139
|
-
const
|
|
154
|
+
const rootFiles = _nodeFs.default.readdirSync(absoluteSrc, {
|
|
155
|
+
withFileTypes: true
|
|
156
|
+
}).filter(entry => entry.isFile() && isSource(entry.name) && !/^(index|main)\./.test(entry.name)).map(entry => _nodePath.default.join(absoluteSrc, entry.name));
|
|
157
|
+
// Folders make modules, and so do the files which sit beside them (except the barrel: index and main). A source
|
|
158
|
+
// directory with no folders gets a single module called index which holds its files.
|
|
159
|
+
const groups = folders.length ? [...folders, ...rootFiles.map(file => ({
|
|
160
|
+
name: toIdentifier(_nodePath.default.basename(file).replace(/\.[cm]?tsx?$/, '')),
|
|
161
|
+
files: [file],
|
|
162
|
+
description: describeFile(file)
|
|
163
|
+
})).filter(group => !folders.some(folder => folder.name === group.name))] : [{
|
|
140
164
|
name: 'index',
|
|
141
165
|
path: absoluteSrc,
|
|
142
|
-
files:
|
|
166
|
+
files: rootFiles
|
|
143
167
|
}];
|
|
144
168
|
return groups.map(group => {
|
|
145
169
|
const lines = group.files.filter(file => !/^index\./.test(_nodePath.default.basename(file))).sort().flatMap(file => {
|
|
@@ -151,7 +175,7 @@ const writeDocEntries = (ts, srcDir, entryDir) => {
|
|
|
151
175
|
const fileName = _nodePath.default.basename(file).replace(/\.[cm]?tsx?$/, '');
|
|
152
176
|
return [...(hasDefault ? [`export { default as ${toIdentifier(fileName)} } from '${modulePath}'`] : []), ...(hasNamed ? [`export * from '${modulePath}'`] : [])];
|
|
153
177
|
});
|
|
154
|
-
const description = group.path ? describeFolder(group.path) : '';
|
|
178
|
+
const description = group.description ?? (group.path ? describeFolder(group.path) : '');
|
|
155
179
|
// TypeDoc takes the first comment of an entry file which has the @module tag as the description of the module
|
|
156
180
|
const moduleComment = description ? `/**\n${description.split('\n').map(line => ` * ${line}`.trimEnd()).join('\n')}\n * @module\n */\n\n` : '';
|
|
157
181
|
const entryPath = _nodePath.default.join(entryDir, `${group.name}.ts`);
|
package/dist/partials.js
CHANGED
|
@@ -1,136 +1,136 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', {
|
|
4
|
-
value: true
|
|
5
|
-
})
|
|
6
|
-
Object.defineProperty(exports, 'addToReadme', {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _addToReadme.addToReadme
|
|
10
|
-
}
|
|
11
|
-
})
|
|
12
|
-
Object.defineProperty(exports, 'beginWatcher', {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _beginWatcher.beginWatcher
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
Object.defineProperty(exports, 'clean', {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _clean.clean
|
|
22
|
-
}
|
|
23
|
-
})
|
|
24
|
-
Object.defineProperty(exports, 'copyFor', {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _copyFor.copyFor
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
Object.defineProperty(exports, 'distFor', {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () {
|
|
33
|
-
return _distFor.distFor
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
Object.defineProperty(exports, 'distForSrc', {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () {
|
|
39
|
-
return _distForSrc.distForSrc
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
Object.defineProperty(exports, 'distSeries', {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function () {
|
|
45
|
-
return _distSeries.distSeries
|
|
46
|
-
}
|
|
47
|
-
})
|
|
48
|
-
Object.defineProperty(exports, 'imagesFor', {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: function () {
|
|
51
|
-
return _imagesFor.imagesFor
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
Object.defineProperty(exports, 'importModule', {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _loadPeer.importModule
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
Object.defineProperty(exports, 'importPeer', {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
get: function () {
|
|
63
|
-
return _loadPeer.importPeer
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
Object.defineProperty(exports, 'minifyFor', {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
get: function () {
|
|
69
|
-
return _minifyFor.minifyFor
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
Object.defineProperty(exports, 'readmeTemplate', {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
get: function () {
|
|
75
|
-
return _readmeTemplate.readmeTemplate
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
Object.defineProperty(exports, 'removeDirectory', {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
get: function () {
|
|
81
|
-
return _removeDirectory.removeDirectory
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
Object.defineProperty(exports, 'requirePeer', {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
get: function () {
|
|
87
|
-
return _loadPeer.requirePeer
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
Object.defineProperty(exports, 'runOnChange', {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
get: function () {
|
|
93
|
-
return _runOnChange.runOnChange
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
Object.defineProperty(exports, 'sassFor', {
|
|
97
|
-
enumerable: true,
|
|
98
|
-
get: function () {
|
|
99
|
-
return _sassFor.sassFor
|
|
100
|
-
}
|
|
101
|
-
})
|
|
102
|
-
Object.defineProperty(exports, 'standardLint', {
|
|
103
|
-
enumerable: true,
|
|
104
|
-
get: function () {
|
|
105
|
-
return _standardLint.standardLint
|
|
106
|
-
}
|
|
107
|
-
})
|
|
108
|
-
Object.defineProperty(exports, 'tsFor', {
|
|
109
|
-
enumerable: true,
|
|
110
|
-
get: function () {
|
|
111
|
-
return _tsFor.tsFor
|
|
112
|
-
}
|
|
113
|
-
})
|
|
114
|
-
Object.defineProperty(exports, 'typeDocsFor', {
|
|
115
|
-
enumerable: true,
|
|
116
|
-
get: function () {
|
|
117
|
-
return _typeDocsFor.typeDocsFor
|
|
118
|
-
}
|
|
119
|
-
})
|
|
120
|
-
var _addToReadme = require('./partials/addToReadme.js')
|
|
121
|
-
var _beginWatcher = require('./partials/beginWatcher.js')
|
|
122
|
-
var _clean = require('./partials/clean.js')
|
|
123
|
-
var _copyFor = require('./partials/copyFor.js')
|
|
124
|
-
var _distFor = require('./partials/distFor.js')
|
|
125
|
-
var _distForSrc = require('./partials/distForSrc.js')
|
|
126
|
-
var _distSeries = require('./partials/distSeries.js')
|
|
127
|
-
var _imagesFor = require('./partials/imagesFor.js')
|
|
128
|
-
var _loadPeer = require('./partials/loadPeer.js')
|
|
129
|
-
var _minifyFor = require('./partials/minifyFor.js')
|
|
130
|
-
var _readmeTemplate = require('./partials/readmeTemplate.js')
|
|
131
|
-
var _removeDirectory = require('./partials/removeDirectory.js')
|
|
132
|
-
var _runOnChange = require('./partials/runOnChange.js')
|
|
133
|
-
var _sassFor = require('./partials/sassFor.js')
|
|
134
|
-
var _standardLint = require('./partials/standardLint.js')
|
|
135
|
-
var _tsFor = require('./partials/tsFor.js')
|
|
136
|
-
var _typeDocsFor = require('./partials/typeDocsFor.js')
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', {
|
|
4
|
+
value: true
|
|
5
|
+
})
|
|
6
|
+
Object.defineProperty(exports, 'addToReadme', {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _addToReadme.addToReadme
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
Object.defineProperty(exports, 'beginWatcher', {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _beginWatcher.beginWatcher
|
|
16
|
+
}
|
|
17
|
+
})
|
|
18
|
+
Object.defineProperty(exports, 'clean', {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _clean.clean
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
Object.defineProperty(exports, 'copyFor', {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _copyFor.copyFor
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
Object.defineProperty(exports, 'distFor', {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _distFor.distFor
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
Object.defineProperty(exports, 'distForSrc', {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _distForSrc.distForSrc
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
Object.defineProperty(exports, 'distSeries', {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _distSeries.distSeries
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
Object.defineProperty(exports, 'imagesFor', {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _imagesFor.imagesFor
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
Object.defineProperty(exports, 'importModule', {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _loadPeer.importModule
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
Object.defineProperty(exports, 'importPeer', {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _loadPeer.importPeer
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
Object.defineProperty(exports, 'minifyFor', {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _minifyFor.minifyFor
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
Object.defineProperty(exports, 'readmeTemplate', {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () {
|
|
75
|
+
return _readmeTemplate.readmeTemplate
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
Object.defineProperty(exports, 'removeDirectory', {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function () {
|
|
81
|
+
return _removeDirectory.removeDirectory
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
Object.defineProperty(exports, 'requirePeer', {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return _loadPeer.requirePeer
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
Object.defineProperty(exports, 'runOnChange', {
|
|
91
|
+
enumerable: true,
|
|
92
|
+
get: function () {
|
|
93
|
+
return _runOnChange.runOnChange
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
Object.defineProperty(exports, 'sassFor', {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get: function () {
|
|
99
|
+
return _sassFor.sassFor
|
|
100
|
+
}
|
|
101
|
+
})
|
|
102
|
+
Object.defineProperty(exports, 'standardLint', {
|
|
103
|
+
enumerable: true,
|
|
104
|
+
get: function () {
|
|
105
|
+
return _standardLint.standardLint
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
Object.defineProperty(exports, 'tsFor', {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
get: function () {
|
|
111
|
+
return _tsFor.tsFor
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
Object.defineProperty(exports, 'typeDocsFor', {
|
|
115
|
+
enumerable: true,
|
|
116
|
+
get: function () {
|
|
117
|
+
return _typeDocsFor.typeDocsFor
|
|
118
|
+
}
|
|
119
|
+
})
|
|
120
|
+
var _addToReadme = require('./partials/addToReadme.js')
|
|
121
|
+
var _beginWatcher = require('./partials/beginWatcher.js')
|
|
122
|
+
var _clean = require('./partials/clean.js')
|
|
123
|
+
var _copyFor = require('./partials/copyFor.js')
|
|
124
|
+
var _distFor = require('./partials/distFor.js')
|
|
125
|
+
var _distForSrc = require('./partials/distForSrc.js')
|
|
126
|
+
var _distSeries = require('./partials/distSeries.js')
|
|
127
|
+
var _imagesFor = require('./partials/imagesFor.js')
|
|
128
|
+
var _loadPeer = require('./partials/loadPeer.js')
|
|
129
|
+
var _minifyFor = require('./partials/minifyFor.js')
|
|
130
|
+
var _readmeTemplate = require('./partials/readmeTemplate.js')
|
|
131
|
+
var _removeDirectory = require('./partials/removeDirectory.js')
|
|
132
|
+
var _runOnChange = require('./partials/runOnChange.js')
|
|
133
|
+
var _sassFor = require('./partials/sassFor.js')
|
|
134
|
+
var _standardLint = require('./partials/standardLint.js')
|
|
135
|
+
var _tsFor = require('./partials/tsFor.js')
|
|
136
|
+
var _typeDocsFor = require('./partials/typeDocsFor.js')
|
|
@@ -79,7 +79,19 @@ export const describeExports = (ts, filePath) => {
|
|
|
79
79
|
*/
|
|
80
80
|
export const describeFolder = folderPath => {
|
|
81
81
|
const indexFile = ['index.ts', 'index.tsx', 'index.mts', 'index.cts'].map(name => path.join(folderPath, name)).find(file => fs.existsSync(file))
|
|
82
|
-
|
|
82
|
+
return indexFile ? describeFile(indexFile) : ''
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The description of a source file for its module: its first doc comment without the tags (@module, @file, ...), when
|
|
87
|
+
* that comment is a header (it is followed by an import or export, so it does not document a declaration itself), or
|
|
88
|
+
* an empty string.
|
|
89
|
+
* @memberOf module:partials
|
|
90
|
+
* @param {string} filePath
|
|
91
|
+
* @returns {string}
|
|
92
|
+
*/
|
|
93
|
+
export const describeFile = filePath => {
|
|
94
|
+
const comment = fs.readFileSync(filePath, 'utf8').match(/^\s*\/\*\*([\s\S]*?)\*\/\s*(import\b|export\s+(\*|\{[^}]*\}\s+from)|$)/)
|
|
83
95
|
if (!comment) {
|
|
84
96
|
return ''
|
|
85
97
|
}
|
|
@@ -93,7 +105,9 @@ export const describeFolder = folderPath => {
|
|
|
93
105
|
* entry file, so the modules of the documentation mirror the folders. The default export of each source file is
|
|
94
106
|
* re-exported under the name of the file (the source files hold one function each), and anything else a file exports
|
|
95
107
|
* is re-exported as it is (that is where the types.ts files go). Index files (the barrels), tests and declaration
|
|
96
|
-
* files are left out, but the first doc comment of a folder's index file becomes the description of its module.
|
|
108
|
+
* files are left out, but the first doc comment of a folder's index file becomes the description of its module.
|
|
109
|
+
* A file which sits beside the folders (not an index or main file) is a module of its own, described by its header
|
|
110
|
+
* comment. A source directory with no folders gets a single entry called index.
|
|
97
111
|
* @memberOf module:partials
|
|
98
112
|
* @param {Object} ts - The TypeScript compiler API.
|
|
99
113
|
* @param {string} srcDir - The directory holding the TypeScript source.
|
|
@@ -107,9 +121,19 @@ export const writeDocEntries = (ts, srcDir, entryDir) => {
|
|
|
107
121
|
.filter(entry => entry.isDirectory() && entry.name !== 'node_modules')
|
|
108
122
|
.map(entry => ({ name: entry.name, path: path.join(absoluteSrc, entry.name), files: listSources(path.join(absoluteSrc, entry.name)) }))
|
|
109
123
|
.filter(folder => folder.files.length)
|
|
124
|
+
const rootFiles = fs.readdirSync(absoluteSrc, { withFileTypes: true })
|
|
125
|
+
.filter(entry => entry.isFile() && isSource(entry.name) && !/^(index|main)\./.test(entry.name))
|
|
126
|
+
.map(entry => path.join(absoluteSrc, entry.name))
|
|
127
|
+
// Folders make modules, and so do the files which sit beside them (except the barrel: index and main). A source
|
|
128
|
+
// directory with no folders gets a single module called index which holds its files.
|
|
110
129
|
const groups = folders.length
|
|
111
|
-
?
|
|
112
|
-
|
|
130
|
+
? [
|
|
131
|
+
...folders,
|
|
132
|
+
...rootFiles
|
|
133
|
+
.map(file => ({ name: toIdentifier(path.basename(file).replace(/\.[cm]?tsx?$/, '')), files: [file], description: describeFile(file) }))
|
|
134
|
+
.filter(group => !folders.some(folder => folder.name === group.name))
|
|
135
|
+
]
|
|
136
|
+
: [{ name: 'index', path: absoluteSrc, files: rootFiles }]
|
|
113
137
|
return groups.map(group => {
|
|
114
138
|
const lines = group.files
|
|
115
139
|
.filter(file => !/^index\./.test(path.basename(file)))
|
|
@@ -123,7 +147,7 @@ export const writeDocEntries = (ts, srcDir, entryDir) => {
|
|
|
123
147
|
...(hasNamed ? [`export * from '${modulePath}'`] : [])
|
|
124
148
|
]
|
|
125
149
|
})
|
|
126
|
-
const description = group.path ? describeFolder(group.path) : ''
|
|
150
|
+
const description = group.description ?? (group.path ? describeFolder(group.path) : '')
|
|
127
151
|
// TypeDoc takes the first comment of an entry file which has the @module tag as the description of the module
|
|
128
152
|
const moduleComment = description ? `/**\n${description.split('\n').map(line => ` * ${line}`.trimEnd()).join('\n')}\n * @module\n */\n\n` : ''
|
|
129
153
|
const entryPath = path.join(entryDir, `${group.name}.ts`)
|
|
@@ -2,7 +2,7 @@ import fs from 'fs'
|
|
|
2
2
|
import path from 'node:path'
|
|
3
3
|
import ts from 'typescript'
|
|
4
4
|
import * as setUp from '../test-helpers/setUp.mjs'
|
|
5
|
-
import { describeExports, describeFolder, loadTypeDoc, typeDocsFor, writeDocEntries } from './typeDocsFor.mjs'
|
|
5
|
+
import { describeExports, describeFile, describeFolder, loadTypeDoc, typeDocsFor, writeDocEntries } from './typeDocsFor.mjs'
|
|
6
6
|
|
|
7
7
|
setUp.setDefaults('test-type-docs-for')
|
|
8
8
|
const gulpConfig = setUp.gulpConfig
|
|
@@ -66,6 +66,18 @@ describe('describeFolder', () => {
|
|
|
66
66
|
})
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
+
describe('describeFile', () => {
|
|
70
|
+
test('is the header comment of a file, without its tags', () => {
|
|
71
|
+
write(`${gulpConfig.get('srcPath')}/header.ts`, "/**\n * Simulate what a user does.\n * @module simulate\n */\nimport a from './a'\nexport default a\n")
|
|
72
|
+
expect(describeFile(`${gulpConfig.get('srcPath')}/header.ts`)).toBe('Simulate what a user does.')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('is empty when the first comment documents a declaration', () => {
|
|
76
|
+
write(`${gulpConfig.get('srcPath')}/declaration.ts`, '/**\n * Add two numbers.\n */\nconst add = (a: number, b: number) => a + b\nexport default add\n')
|
|
77
|
+
expect(describeFile(`${gulpConfig.get('srcPath')}/declaration.ts`)).toBe('')
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
69
81
|
describe('writeDocEntries', () => {
|
|
70
82
|
test('writes one entry file for each folder which has source', () => {
|
|
71
83
|
const entryDir = `${gulpConfig.get('srcPath')}/../entries`
|
|
@@ -104,6 +116,19 @@ describe('writeDocEntries', () => {
|
|
|
104
116
|
expect(fs.readFileSync(`${entryDir}/line.ts`, 'utf8').startsWith('export')).toBe(true)
|
|
105
117
|
})
|
|
106
118
|
|
|
119
|
+
test('makes a module of a file which sits beside the folders, but not of the barrel files', () => {
|
|
120
|
+
const srcPath = gulpConfig.get('srcPath')
|
|
121
|
+
write(`${srcPath}/simulate.ts`, "/**\n * Simulate what a user does.\n */\nimport add from './point/add'\nexport const click = () => add(1, 2)\nexport default { click }\n")
|
|
122
|
+
write(`${srcPath}/simulate.test.ts`, "test('x', () => {})\n")
|
|
123
|
+
const entryDir = `${srcPath}/../entries`
|
|
124
|
+
const entries = writeDocEntries(ts, srcPath, entryDir)
|
|
125
|
+
expect(entries.map(entry => path.basename(entry)).sort()).toEqual(['line.ts', 'point.ts', 'simulate.ts'])
|
|
126
|
+
const absoluteSrc = path.resolve(srcPath).split(path.sep).join('/')
|
|
127
|
+
expect(fs.readFileSync(`${entryDir}/simulate.ts`, 'utf8')).toBe(
|
|
128
|
+
`/**\n * Simulate what a user does.\n * @module\n */\n\nexport { default as simulate } from '${absoluteSrc}/simulate'\nexport * from '${absoluteSrc}/simulate'\n`
|
|
129
|
+
)
|
|
130
|
+
})
|
|
131
|
+
|
|
107
132
|
test('makes one entry called index when the source has no folders', () => {
|
|
108
133
|
const flat = `${gulpConfig.get('srcPath')}/../flat`
|
|
109
134
|
write(`${flat}/one.ts`, 'export default 1\n')
|