js-build-tools 5.2.0 → 5.3.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.
Files changed (60) hide show
  1. package/README.md +75 -10
  2. package/dist/build.js +7 -2
  3. package/dist/build.min.js +1 -1
  4. package/dist/bundle.js +27 -27
  5. package/dist/bundleLint.js +16 -16
  6. package/dist/bundleMinify.js +13 -13
  7. package/dist/compileReadme.js +10 -10
  8. package/dist/copyFonts.js +13 -13
  9. package/dist/default.js +15 -15
  10. package/dist/dist.js +10 -10
  11. package/dist/distLint.js +16 -16
  12. package/dist/distMinify.js +13 -13
  13. package/dist/images.js +10 -10
  14. package/dist/partials/addToReadme.js +17 -17
  15. package/dist/partials/beginWatcher.js +12 -12
  16. package/dist/partials/clean.js +14 -14
  17. package/dist/partials/copyFor.js +12 -12
  18. package/dist/partials/distFor.js +21 -21
  19. package/dist/partials/distForSrc.js +11 -11
  20. package/dist/partials/distSeries.js +19 -19
  21. package/dist/partials/imagesFor.js +48 -48
  22. package/dist/partials/minifyFor.js +16 -16
  23. package/dist/partials/readmeTemplate.js +14 -14
  24. package/dist/partials/removeDirectory.js +29 -29
  25. package/dist/partials/runOnChange.js +28 -28
  26. package/dist/partials/sassFor.js +28 -28
  27. package/dist/partials/standardLint.js +75 -75
  28. package/dist/partials/tsFor.js +82 -82
  29. package/dist/partials/typeDocsFor.js +214 -0
  30. package/dist/partials.js +7 -0
  31. package/dist/partials.min.js +1 -1
  32. package/dist/sass.js +10 -10
  33. package/dist/test-helpers/setUp.js +89 -89
  34. package/dist/test-helpers/standardLintWithRealStandard.js +27 -27
  35. package/dist/testFull.js +20 -20
  36. package/dist/testHelpers.js +10 -10
  37. package/dist/testQuick.js +22 -22
  38. package/dist/typeDocs.js +14 -0
  39. package/dist/typeDocs.min.js +1 -0
  40. package/dist/typeScript.js +9 -9
  41. package/dist/utilities/dotGet.js +46 -46
  42. package/dist/utilities/dotNotate.js +46 -46
  43. package/dist/utilities/dotSet.js +37 -37
  44. package/dist/utilities/isObject.js +8 -8
  45. package/dist/utilities/strAfter.js +11 -11
  46. package/dist/utilities/strBefore.js +11 -11
  47. package/dist/watchFull.js +10 -10
  48. package/dist/watchTest.js +16 -16
  49. package/functions/build.mjs +7 -2
  50. package/functions/build.test.mjs +29 -0
  51. package/functions/partials/typeDocsFor.mjs +194 -0
  52. package/functions/partials/typeDocsFor.test.mjs +183 -0
  53. package/functions/partials.mjs +1 -0
  54. package/functions/partials.test.mjs +1 -1
  55. package/functions/typeDocs.mjs +9 -0
  56. package/functions/typeDocs.test.mjs +11 -0
  57. package/gulp.config.mjs +22 -0
  58. package/gulpfile.base.js +2 -0
  59. package/gulpfile.base.mjs +1 -0
  60. package/package.json +12 -7
@@ -1,40 +1,40 @@
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
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- // `standard` (17+) ships ESM-only, but this package also publishes a CommonJS build (dist/*.js) whose babel
13
- // transform would turn even a dynamic import() into a require() that cannot load an ES module. Hiding the import()
14
- // inside a Function constructor keeps it a genuine dynamic import that works from either build (same escape hatch
15
- // as tsFor.mjs uses for gulp-ts-compile).
16
- const importStandard = new Function('return import(\'standard\')');
17
-
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
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ // `standard` (17+) ships ESM-only, but this package also publishes a CommonJS build (dist/*.js) whose babel
13
+ // transform would turn even a dynamic import() into a require() that cannot load an ES module. Hiding the import()
14
+ // inside a Function constructor keeps it a genuine dynamic import that works from either build (same escape hatch
15
+ // as tsFor.mjs uses for gulp-ts-compile).
16
+ const importStandard = new Function('return import(\'standard\')');
17
+
18
18
  /**
19
19
  * Print a file's lint messages, if it has any.
20
20
  * @memberOf module:partials
21
21
  * @param {import('vinyl')} file
22
22
  * @param {{messages: Array<{line: number, column: number, message: string}>, errorCount: number, warningCount: number}} result
23
23
  * @returns {undefined}
24
- */
25
- const printFileReport = (file, result) => {
26
- if (!result.messages.length) {
27
- return;
28
- }
29
- console.log(_nodePath.default.relative(file.cwd, file.path));
30
- result.messages.forEach(({
31
- line,
32
- column,
33
- message
34
- }) => console.log(`line ${line}:${column}\t${message}`));
35
- console.log(`✖ ${result.errorCount} error\t⚠ ${result.warningCount} warning\n`);
36
- };
37
-
24
+ */
25
+ const printFileReport = (file, result) => {
26
+ if (!result.messages.length) {
27
+ return;
28
+ }
29
+ console.log(_nodePath.default.relative(file.cwd, file.path));
30
+ result.messages.forEach(({
31
+ line,
32
+ column,
33
+ message
34
+ }) => console.log(`line ${line}:${column}\t${message}`));
35
+ console.log(`✖ ${result.errorCount} error\t⚠ ${result.warningCount} warning\n`);
36
+ };
37
+
38
38
  /**
39
39
  * Lint every file streaming through with JavaScript Standard Style and, unless `fix` is false, apply the automatic
40
40
  * fixes to the file's contents so a following `dest()` writes the fixed version. Remaining problems are printed
@@ -49,48 +49,48 @@ const printFileReport = (file, result) => {
49
49
  * should never need to pass this - it exists so tests can supply a stand-in, since this project's
50
50
  * CommonJS-transform-based Jest setup cannot execute a real dynamic import() of an ES module.
51
51
  * @returns {import('stream').Transform}
52
- */
53
- const standardLint = ({
54
- fix = true
55
- } = {}, loadStandard = () => importStandard().then(({
56
- default: standard
57
- }) => standard)) => {
58
- const totals = {
59
- errors: 0,
60
- warnings: 0
61
- };
62
- return _through.default.obj(function (file, enc, callback) {
63
- if (file.isNull()) {
64
- callback(null, file);
65
- return;
66
- }
67
- if (file.isStream()) {
68
- callback(new Error('standardLint: streaming file contents are not supported.'));
69
- return;
70
- }
71
- loadStandard().then(standard => standard.lintText(file.contents.toString(), {
72
- filename: file.path,
73
- cwd: file.cwd,
74
- fix
75
- })).then(results => {
76
- // No result at all means the file is ignored by the project's Standard configuration.
77
- const [result] = results;
78
- if (result) {
79
- if (typeof result.output === 'string') {
80
- file.contents = Buffer.from(result.output);
81
- }
82
- totals.errors += result.errorCount;
83
- totals.warnings += result.warningCount;
84
- printFileReport(file, result);
85
- }
86
- callback(null, file);
87
- }, callback);
88
- }, function (callback) {
89
- console.log('Standard linter results');
90
- console.log('======================================');
91
- console.log(`✖ Errors total: ${totals.errors}`);
92
- console.log(`⚠ Warnings total: ${totals.warnings}\n`);
93
- callback();
94
- });
95
- };
52
+ */
53
+ const standardLint = ({
54
+ fix = true
55
+ } = {}, loadStandard = () => importStandard().then(({
56
+ default: standard
57
+ }) => standard)) => {
58
+ const totals = {
59
+ errors: 0,
60
+ warnings: 0
61
+ };
62
+ return _through.default.obj(function (file, enc, callback) {
63
+ if (file.isNull()) {
64
+ callback(null, file);
65
+ return;
66
+ }
67
+ if (file.isStream()) {
68
+ callback(new Error('standardLint: streaming file contents are not supported.'));
69
+ return;
70
+ }
71
+ loadStandard().then(standard => standard.lintText(file.contents.toString(), {
72
+ filename: file.path,
73
+ cwd: file.cwd,
74
+ fix
75
+ })).then(results => {
76
+ // No result at all means the file is ignored by the project's Standard configuration.
77
+ const [result] = results;
78
+ if (result) {
79
+ if (typeof result.output === 'string') {
80
+ file.contents = Buffer.from(result.output);
81
+ }
82
+ totals.errors += result.errorCount;
83
+ totals.warnings += result.warningCount;
84
+ printFileReport(file, result);
85
+ }
86
+ callback(null, file);
87
+ }, callback);
88
+ }, function (callback) {
89
+ console.log('Standard linter results');
90
+ console.log('======================================');
91
+ console.log(`✖ Errors total: ${totals.errors}`);
92
+ console.log(`⚠ Warnings total: ${totals.warnings}\n`);
93
+ callback();
94
+ });
95
+ };
96
96
  exports.standardLint = standardLint;
@@ -1,34 +1,34 @@
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 _nodeModule = require("node:module");
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) since it's meant to be consumed by
15
- // gulpfiles running under a real ESM loader, same as this project's own gulpfile.mjs does. This project also
16
- // compiles itself to a CommonJS build (dist/*.js, this file's own compiled counterpart) for consumers using
17
- // require() though, and even a dynamic `import()` gets downleveled by babel's CommonJS transform into a
18
- // require() call - which can't load a real ES module. Hiding the import() call inside a Function constructor is
19
- // the standard escape hatch: babel can't see (and so can't rewrite) an import expression that only exists as a
20
- // runtime-evaluated string, so it survives as a genuine dynamic import, capable of loading gulp-ts-compile from
21
- // either build.
22
- const importGulpTsCompile = new Function('return import(\'gulp-ts-compile\')');
23
-
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 _nodeModule = require("node:module");
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) since it's meant to be consumed by
15
+ // gulpfiles running under a real ESM loader, same as this project's own gulpfile.mjs does. This project also
16
+ // compiles itself to a CommonJS build (dist/*.js, this file's own compiled counterpart) for consumers using
17
+ // require() though, and even a dynamic `import()` gets downleveled by babel's CommonJS transform into a
18
+ // require() call - which can't load a real ES module. Hiding the import() call inside a Function constructor is
19
+ // the standard escape hatch: babel can't see (and so can't rewrite) an import expression that only exists as a
20
+ // runtime-evaluated string, so it survives as a genuine dynamic import, capable of loading gulp-ts-compile from
21
+ // either build.
22
+ const importGulpTsCompile = new Function('return import(\'gulp-ts-compile\')');
23
+
24
24
  /**
25
25
  * Wrap a stream in a promise that resolves once it finishes writing.
26
26
  * @memberOf module:partials
27
27
  * @param {import('node:stream').Stream} stream
28
28
  * @returns {Promise<void>}
29
- */
30
- const installHint = 'Install it in your project with: npm install --save-dev typescript';
31
-
29
+ */
30
+ const installHint = 'Install it in your project with: npm install --save-dev typescript';
31
+
32
32
  /**
33
33
  * Load the project's own copy of TypeScript (an optional peer dependency, only needed when the typescript task is
34
34
  * enabled) from the project being built, so projects which do not use TypeScript never need it installed.
@@ -36,23 +36,23 @@ const installHint = 'Install it in your project with: npm install --save-dev typ
36
36
  * @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
37
37
  * @returns {Object} The TypeScript compiler API module.
38
38
  * @throws {Error} With install instructions when typescript is not installed.
39
- */
40
- const loadTypescript = (projectPath = process.cwd()) => {
41
- try {
42
- return (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json'))('typescript');
43
- } catch (error) {
44
- if (error.code === 'MODULE_NOT_FOUND' && /Cannot find module 'typescript'/.test(error.message)) {
45
- throw new Error(`The typescript task needs the optional peer dependency typescript, which is not installed. ${installHint}`);
46
- }
47
- throw error;
48
- }
49
- };
50
- exports.loadTypescript = loadTypescript;
51
- const streamToPromise = stream => new Promise((resolve, reject) => {
52
- stream.on('finish', resolve);
53
- stream.on('error', reject);
54
- });
55
-
39
+ */
40
+ const loadTypescript = (projectPath = process.cwd()) => {
41
+ try {
42
+ return (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json'))('typescript');
43
+ } catch (error) {
44
+ if (error.code === 'MODULE_NOT_FOUND' && /Cannot find module 'typescript'/.test(error.message)) {
45
+ throw new Error(`The typescript task needs the optional peer dependency typescript, which is not installed. ${installHint}`);
46
+ }
47
+ throw error;
48
+ }
49
+ };
50
+ exports.loadTypescript = loadTypescript;
51
+ const streamToPromise = stream => new Promise((resolve, reject) => {
52
+ stream.on('finish', resolve);
53
+ stream.on('error', reject);
54
+ });
55
+
56
56
  /**
57
57
  * Read a tsconfig.json file into real typescript.CompilerOptions values, using only TypeScript's stable, current,
58
58
  * public config-reading API (the same one `tsc --project` itself uses internally) - never
@@ -61,13 +61,13 @@ const streamToPromise = stream => new Promise((resolve, reject) => {
61
61
  * @memberOf module:partials
62
62
  * @param {string} configPath - Path to a tsconfig.json file.
63
63
  * @returns {import('typescript').CompilerOptions}
64
- */
65
- const readCompilerOptions = (ts, configPath) => {
66
- const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
67
- const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, _nodePath.default.dirname(configPath));
68
- return parsedConfig.options;
69
- };
70
-
64
+ */
65
+ const readCompilerOptions = (ts, configPath) => {
66
+ const configFile = ts.readConfigFile(configPath, ts.sys.readFile);
67
+ const parsedConfig = ts.parseJsonConfigFileContent(configFile.config, ts.sys, _nodePath.default.dirname(configPath));
68
+ return parsedConfig.options;
69
+ };
70
+
71
71
  /**
72
72
  * Starting at the source directory, find all the ts files and convert them into the distribution directory.
73
73
  * @memberOf module:partials
@@ -80,36 +80,36 @@ const readCompilerOptions = (ts, configPath) => {
80
80
  * suite already covers real TypeScript-compile correctness - this function's own tests only need to verify its
81
81
  * config resolution and stream wiring.
82
82
  * @returns {Function}
83
- */
84
- const tsFor = (srcPath = gulpConfig.get('typescript.from'), distPath = gulpConfig.get('typescript.to'), loadTsCompile = () => importGulpTsCompile().then(({
85
- default: tsCompile
86
- }) => tsCompile)) => {
87
- if (gulpConfig.get('typescript.enabled') === false) {
88
- return () => {};
89
- }
90
- const ts = loadTypescript();
91
- const configPath = gulpConfig.get('typescript.config');
92
- // When no tsconfig.json is configured, target/module are pinned explicitly rather than left for TypeScript's
93
- // own compiler defaults - those defaults have already shifted once across a TypeScript version bump in this
94
- // project's own history (silently changing whether output keeps `const`/`let` or downlevels to `var`), and
95
- // pinning them keeps this task's output stable across future TypeScript upgrades too. ES5/CommonJS matches
96
- // what the downstream babel/browserify bundling pipeline has always assumed it receives.
97
- const compilerOptions = configPath ? readCompilerOptions(ts, configPath) : {
98
- declaration: true,
99
- target: ts.ScriptTarget.ES5,
100
- module: ts.ModuleKind.CommonJS,
101
- esModuleInterop: false
102
- };
103
- // Accepts gulp's own callback-style task convention (an optional `done`, called once finished) rather than
104
- // just returning a Promise, since callers may invoke the returned function directly with a callback instead
105
- // of relying on gulp's own runner to observe a returned Promise.
106
- return done => {
107
- const compile = async () => {
108
- const tsCompile = await loadTsCompile();
109
- const tsResult = (0, _gulp.src)(srcPath).pipe(tsCompile(compilerOptions));
110
- await Promise.all([streamToPromise(tsResult.dts.pipe((0, _gulp.dest)(distPath))), streamToPromise(tsResult.js.pipe((0, _gulp.dest)(distPath)))]);
111
- };
112
- return typeof done === 'function' ? compile().then(() => done(), done) : compile();
113
- };
114
- };
83
+ */
84
+ const tsFor = (srcPath = gulpConfig.get('typescript.from'), distPath = gulpConfig.get('typescript.to'), loadTsCompile = () => importGulpTsCompile().then(({
85
+ default: tsCompile
86
+ }) => tsCompile)) => {
87
+ if (gulpConfig.get('typescript.enabled') === false) {
88
+ return () => {};
89
+ }
90
+ const ts = loadTypescript();
91
+ const configPath = gulpConfig.get('typescript.config');
92
+ // When no tsconfig.json is configured, target/module are pinned explicitly rather than left for TypeScript's
93
+ // own compiler defaults - those defaults have already shifted once across a TypeScript version bump in this
94
+ // project's own history (silently changing whether output keeps `const`/`let` or downlevels to `var`), and
95
+ // pinning them keeps this task's output stable across future TypeScript upgrades too. ES5/CommonJS matches
96
+ // what the downstream babel/browserify bundling pipeline has always assumed it receives.
97
+ const compilerOptions = configPath ? readCompilerOptions(ts, configPath) : {
98
+ declaration: true,
99
+ target: ts.ScriptTarget.ES5,
100
+ module: ts.ModuleKind.CommonJS,
101
+ esModuleInterop: false
102
+ };
103
+ // Accepts gulp's own callback-style task convention (an optional `done`, called once finished) rather than
104
+ // just returning a Promise, since callers may invoke the returned function directly with a callback instead
105
+ // of relying on gulp's own runner to observe a returned Promise.
106
+ return done => {
107
+ const compile = async () => {
108
+ const tsCompile = await loadTsCompile();
109
+ const tsResult = (0, _gulp.src)(srcPath).pipe(tsCompile(compilerOptions));
110
+ await Promise.all([streamToPromise(tsResult.dts.pipe((0, _gulp.dest)(distPath))), streamToPromise(tsResult.js.pipe((0, _gulp.dest)(distPath)))]);
111
+ };
112
+ return typeof done === 'function' ? compile().then(() => done(), done) : compile();
113
+ };
114
+ };
115
115
  exports.tsFor = tsFor;
@@ -0,0 +1,214 @@
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.writeDocEntries = exports.typeDocsFor = exports.loadTypeDoc = exports.describeExports = 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.filter.js");
11
+ require("core-js/modules/esnext.iterator.flat-map.js");
12
+ require("core-js/modules/esnext.iterator.for-each.js");
13
+ require("core-js/modules/esnext.iterator.map.js");
14
+ require("core-js/modules/esnext.iterator.some.js");
15
+ var _nodeFs = _interopRequireDefault(require("node:fs"));
16
+ var _nodeOs = _interopRequireDefault(require("node:os"));
17
+ var _nodePath = _interopRequireDefault(require("node:path"));
18
+ var _nodeModule = require("node:module");
19
+ var _nodeUrl = require("node:url");
20
+ var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
21
+ var _tsFor = require("./tsFor.js");
22
+ var _removeDirectory = require("./removeDirectory.js");
23
+ 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); }
24
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
25
+ // TypeDoc ships ESM-only, and this project also compiles itself to a CommonJS build (see tsFor.mjs, which hides its
26
+ // own import of gulp-ts-compile the same way), so the import() is hidden from babel's CommonJS transform.
27
+ const importModule = new Function('specifier', 'return import(specifier)');
28
+ const installHint = 'Install it in your project with: npm install --save-dev typedoc';
29
+
30
+ /**
31
+ * Find the TypeDoc of the project being built (an optional peer dependency, only needed when the docs task is
32
+ * enabled) and load it, so projects which do not document TypeScript never need it installed.
33
+ * @memberOf module:partials
34
+ * @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
35
+ * @returns {Promise<Object>} The TypeDoc module.
36
+ * @throws {Error} With install instructions when typedoc is not installed.
37
+ */
38
+ const loadTypeDoc = async (projectPath = process.cwd()) => {
39
+ let typeDocPath;
40
+ try {
41
+ typeDocPath = (0, _nodeModule.createRequire)(_nodePath.default.join(projectPath, 'package.json')).resolve('typedoc');
42
+ } catch (error) {
43
+ if (error.code === 'MODULE_NOT_FOUND') {
44
+ throw new Error(`The docs task needs the optional peer dependency typedoc, which is not installed. ${installHint}`);
45
+ }
46
+ throw error;
47
+ }
48
+ return importModule((0, _nodeUrl.pathToFileURL)(typeDocPath).href);
49
+ };
50
+ exports.loadTypeDoc = loadTypeDoc;
51
+ const isSource = fileName => /\.(ts|tsx|mts|cts)$/.test(fileName) && !/\.d\.[cm]?ts$/.test(fileName) && !/\.(test|spec)\./.test(fileName);
52
+ const listSources = dirPath => _nodeFs.default.readdirSync(dirPath, {
53
+ withFileTypes: true
54
+ }).flatMap(entry => {
55
+ const entryPath = _nodePath.default.join(dirPath, entry.name);
56
+ if (entry.isDirectory()) {
57
+ return entry.name === 'node_modules' ? [] : listSources(entryPath);
58
+ }
59
+ return isSource(entry.name) ? [entryPath] : [];
60
+ });
61
+ const toIdentifier = fileName => fileName.replace(/[^\w$]+(\w)?/g, (match, letter) => (letter || '').toUpperCase()).replace(/^(\d)/, '_$1');
62
+ const toModulePath = filePath => filePath.replace(/\.[cm]?tsx?$/, '').split(_nodePath.default.sep).join('/');
63
+
64
+ /**
65
+ * Describe what a source file exports: whether it has a default export, and whether it has any named exports.
66
+ * @memberOf module:partials
67
+ * @param {Object} ts - The TypeScript compiler API.
68
+ * @param {string} filePath
69
+ * @returns {{hasDefault: boolean, hasNamed: boolean}}
70
+ */
71
+ const describeExports = (ts, filePath) => {
72
+ const source = ts.createSourceFile(filePath, _nodeFs.default.readFileSync(filePath, 'utf8'), ts.ScriptTarget.Latest);
73
+ let hasDefault = false;
74
+ let hasNamed = false;
75
+ source.statements.forEach(statement => {
76
+ if (ts.isExportAssignment(statement)) {
77
+ hasDefault = hasDefault || !statement.isExportEquals;
78
+ return;
79
+ }
80
+ if (ts.isExportDeclaration(statement)) {
81
+ const names = statement.exportClause && ts.isNamedExports(statement.exportClause) ? statement.exportClause.elements : null;
82
+ if (names && names.some(element => element.name.text === 'default')) {
83
+ hasDefault = true;
84
+ }
85
+ if (!names || names.some(element => element.name.text !== 'default')) {
86
+ hasNamed = true;
87
+ }
88
+ return;
89
+ }
90
+ const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) || [] : [];
91
+ if (modifiers.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword)) {
92
+ if (modifiers.some(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword)) {
93
+ hasDefault = true;
94
+ } else {
95
+ hasNamed = true;
96
+ }
97
+ }
98
+ });
99
+ return {
100
+ hasDefault,
101
+ hasNamed
102
+ };
103
+ };
104
+
105
+ /**
106
+ * Write one entry file per folder of the source directory into the entry directory. TypeDoc makes a module of every
107
+ * entry file, so the modules of the documentation mirror the folders. The default export of each source file is
108
+ * re-exported under the name of the file (the source files hold one function each), and anything else a file exports
109
+ * is re-exported as it is (that is where the types.ts files go). Index files (the barrels), tests and declaration
110
+ * files are left out. A source directory with no folders gets a single entry called index.
111
+ * @memberOf module:partials
112
+ * @param {Object} ts - The TypeScript compiler API.
113
+ * @param {string} srcDir - The directory holding the TypeScript source.
114
+ * @param {string} entryDir - The directory to write the entry files into.
115
+ * @returns {Array<string>} The paths of the entry files.
116
+ */
117
+ exports.describeExports = describeExports;
118
+ const writeDocEntries = (ts, srcDir, entryDir) => {
119
+ const absoluteSrc = _nodePath.default.resolve(srcDir);
120
+ _nodeFs.default.mkdirSync(entryDir, {
121
+ recursive: true
122
+ });
123
+ const folders = _nodeFs.default.readdirSync(absoluteSrc, {
124
+ withFileTypes: true
125
+ }).filter(entry => entry.isDirectory() && entry.name !== 'node_modules').map(entry => ({
126
+ name: entry.name,
127
+ files: listSources(_nodePath.default.join(absoluteSrc, entry.name))
128
+ })).filter(folder => folder.files.length);
129
+ const groups = folders.length ? folders : [{
130
+ name: 'index',
131
+ files: listSources(absoluteSrc).filter(file => !/^(index|main)\./.test(_nodePath.default.basename(file)))
132
+ }];
133
+ return groups.map(group => {
134
+ const lines = group.files.filter(file => !/^index\./.test(_nodePath.default.basename(file))).sort().flatMap(file => {
135
+ const modulePath = toModulePath(file);
136
+ const {
137
+ hasDefault,
138
+ hasNamed
139
+ } = describeExports(ts, file);
140
+ const fileName = _nodePath.default.basename(file).replace(/\.[cm]?tsx?$/, '');
141
+ return [...(hasDefault ? [`export { default as ${toIdentifier(fileName)} } from '${modulePath}'`] : []), ...(hasNamed ? [`export * from '${modulePath}'`] : [])];
142
+ });
143
+ const entryPath = _nodePath.default.join(entryDir, `${group.name}.ts`);
144
+ _nodeFs.default.writeFileSync(entryPath, lines.join('\n') + '\n');
145
+ return entryPath;
146
+ });
147
+ };
148
+ exports.writeDocEntries = writeDocEntries;
149
+ const projectName = () => {
150
+ try {
151
+ return JSON.parse(_nodeFs.default.readFileSync(_nodePath.default.join(process.cwd(), 'package.json'), 'utf8')).name;
152
+ } catch (error) {
153
+ return _nodePath.default.basename(process.cwd());
154
+ }
155
+ };
156
+
157
+ /**
158
+ * Generate the HTML documentation of a TypeScript project with TypeDoc, straight from the TypeScript source, so the
159
+ * types (and the comments on them) are documented from where they are defined. The modules mirror the folders of the
160
+ * source, see {@link writeDocEntries}. Configure this with 'docs.from', 'docs.to', 'docs.index', 'docs.title',
161
+ * 'docs.tsconfig' and 'docs.logLevel'.
162
+ * @memberOf module:partials
163
+ * @param {string} [srcPath=gulpConfig.get('docs.from')] - The directory holding the TypeScript source.
164
+ * @param {string} [outPath=gulpConfig.get('docs.to')] - The directory the documentation is generated into (cleared first).
165
+ * @param {function(string): Promise<Object>} [loadDocs] - Resolves the TypeDoc module, tests can inject a stand-in.
166
+ * @returns {Function} A gulp task, it accepts an optional callback and returns a promise.
167
+ */
168
+ const typeDocsFor = (srcPath = gulpConfig.get('docs.from'), outPath = gulpConfig.get('docs.to'), loadDocs = loadTypeDoc) => {
169
+ if (gulpConfig.get('docs.enabled') === false) {
170
+ return () => {};
171
+ }
172
+ return done => {
173
+ const generate = async () => {
174
+ const ts = (0, _tsFor.loadTypescript)();
175
+ const {
176
+ Application
177
+ } = await loadDocs();
178
+ const workDir = _nodeFs.default.mkdtempSync(_nodePath.default.join(_nodeOs.default.tmpdir(), 'typedocs-'));
179
+ try {
180
+ const entryPoints = writeDocEntries(ts, srcPath, _nodePath.default.join(workDir, 'entries'));
181
+ // The entry files live outside the project, so the tsconfig which is used for the documentation extends the
182
+ // one of the project and adds the entries to the files it includes.
183
+ const projectConfig = gulpConfig.get('docs.tsconfig') || gulpConfig.get('typescript.config');
184
+ const tsconfig = _nodePath.default.join(workDir, 'tsconfig.json');
185
+ _nodeFs.default.writeFileSync(tsconfig, JSON.stringify({
186
+ ...(projectConfig ? {
187
+ extends: _nodePath.default.resolve(projectConfig)
188
+ } : {}),
189
+ include: [_nodePath.default.join(workDir, 'entries', '*.ts').split(_nodePath.default.sep).join('/'), _nodePath.default.resolve(srcPath).split(_nodePath.default.sep).join('/') + '/**/*.ts'],
190
+ exclude: [_nodePath.default.resolve(srcPath).split(_nodePath.default.sep).join('/') + '/**/*.test.*']
191
+ }));
192
+ const indexFile = gulpConfig.get('docs.index');
193
+ await (0, _removeDirectory.removeDirectory)(outPath);
194
+ const app = await Application.bootstrap({
195
+ entryPoints,
196
+ tsconfig,
197
+ name: gulpConfig.get('docs.title') || projectName(),
198
+ readme: indexFile && _nodeFs.default.existsSync(indexFile) ? indexFile : 'none',
199
+ logLevel: gulpConfig.get('docs.logLevel') || 'Warn',
200
+ skipErrorChecking: true
201
+ });
202
+ const project = await app.convert();
203
+ if (!project) {
204
+ throw new Error('TypeDoc could not read the TypeScript source, see the errors above.');
205
+ }
206
+ await app.generateDocs(project, outPath);
207
+ } finally {
208
+ await (0, _removeDirectory.removeDirectory)(workDir);
209
+ }
210
+ };
211
+ return typeof done === 'function' ? generate().then(() => done(), done) : generate();
212
+ };
213
+ };
214
+ exports.typeDocsFor = typeDocsFor;
package/dist/partials.js CHANGED
@@ -93,6 +93,12 @@ Object.defineProperty(exports, 'tsFor', {
93
93
  return _tsFor.tsFor
94
94
  }
95
95
  })
96
+ Object.defineProperty(exports, 'typeDocsFor', {
97
+ enumerable: true,
98
+ get: function () {
99
+ return _typeDocsFor.typeDocsFor
100
+ }
101
+ })
96
102
  var _addToReadme = require('./partials/addToReadme.js')
97
103
  var _beginWatcher = require('./partials/beginWatcher.js')
98
104
  var _clean = require('./partials/clean.js')
@@ -108,3 +114,4 @@ var _runOnChange = require('./partials/runOnChange.js')
108
114
  var _sassFor = require('./partials/sassFor.js')
109
115
  var _standardLint = require('./partials/standardLint.js')
110
116
  var _tsFor = require('./partials/tsFor.js')
117
+ var _typeDocsFor = require('./partials/typeDocsFor.js')
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"addToReadme",{enumerable:!0,get:function(){return _addToReadme.addToReadme}}),Object.defineProperty(exports,"beginWatcher",{enumerable:!0,get:function(){return _beginWatcher.beginWatcher}}),Object.defineProperty(exports,"clean",{enumerable:!0,get:function(){return _clean.clean}}),Object.defineProperty(exports,"copyFor",{enumerable:!0,get:function(){return _copyFor.copyFor}}),Object.defineProperty(exports,"distFor",{enumerable:!0,get:function(){return _distFor.distFor}}),Object.defineProperty(exports,"distForSrc",{enumerable:!0,get:function(){return _distForSrc.distForSrc}}),Object.defineProperty(exports,"distSeries",{enumerable:!0,get:function(){return _distSeries.distSeries}}),Object.defineProperty(exports,"imagesFor",{enumerable:!0,get:function(){return _imagesFor.imagesFor}}),Object.defineProperty(exports,"minifyFor",{enumerable:!0,get:function(){return _minifyFor.minifyFor}}),Object.defineProperty(exports,"readmeTemplate",{enumerable:!0,get:function(){return _readmeTemplate.readmeTemplate}}),Object.defineProperty(exports,"removeDirectory",{enumerable:!0,get:function(){return _removeDirectory.removeDirectory}}),Object.defineProperty(exports,"runOnChange",{enumerable:!0,get:function(){return _runOnChange.runOnChange}}),Object.defineProperty(exports,"sassFor",{enumerable:!0,get:function(){return _sassFor.sassFor}}),Object.defineProperty(exports,"standardLint",{enumerable:!0,get:function(){return _standardLint.standardLint}}),Object.defineProperty(exports,"tsFor",{enumerable:!0,get:function(){return _tsFor.tsFor}});var _addToReadme=require("./partials/addToReadme.js"),_beginWatcher=require("./partials/beginWatcher.js"),_clean=require("./partials/clean.js"),_copyFor=require("./partials/copyFor.js"),_distFor=require("./partials/distFor.js"),_distForSrc=require("./partials/distForSrc.js"),_distSeries=require("./partials/distSeries.js"),_imagesFor=require("./partials/imagesFor.js"),_minifyFor=require("./partials/minifyFor.js"),_readmeTemplate=require("./partials/readmeTemplate.js"),_removeDirectory=require("./partials/removeDirectory.js"),_runOnChange=require("./partials/runOnChange.js"),_sassFor=require("./partials/sassFor.js"),_standardLint=require("./partials/standardLint.js"),_tsFor=require("./partials/tsFor.js");
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"addToReadme",{enumerable:!0,get:function(){return _addToReadme.addToReadme}}),Object.defineProperty(exports,"beginWatcher",{enumerable:!0,get:function(){return _beginWatcher.beginWatcher}}),Object.defineProperty(exports,"clean",{enumerable:!0,get:function(){return _clean.clean}}),Object.defineProperty(exports,"copyFor",{enumerable:!0,get:function(){return _copyFor.copyFor}}),Object.defineProperty(exports,"distFor",{enumerable:!0,get:function(){return _distFor.distFor}}),Object.defineProperty(exports,"distForSrc",{enumerable:!0,get:function(){return _distForSrc.distForSrc}}),Object.defineProperty(exports,"distSeries",{enumerable:!0,get:function(){return _distSeries.distSeries}}),Object.defineProperty(exports,"imagesFor",{enumerable:!0,get:function(){return _imagesFor.imagesFor}}),Object.defineProperty(exports,"minifyFor",{enumerable:!0,get:function(){return _minifyFor.minifyFor}}),Object.defineProperty(exports,"readmeTemplate",{enumerable:!0,get:function(){return _readmeTemplate.readmeTemplate}}),Object.defineProperty(exports,"removeDirectory",{enumerable:!0,get:function(){return _removeDirectory.removeDirectory}}),Object.defineProperty(exports,"runOnChange",{enumerable:!0,get:function(){return _runOnChange.runOnChange}}),Object.defineProperty(exports,"sassFor",{enumerable:!0,get:function(){return _sassFor.sassFor}}),Object.defineProperty(exports,"standardLint",{enumerable:!0,get:function(){return _standardLint.standardLint}}),Object.defineProperty(exports,"tsFor",{enumerable:!0,get:function(){return _tsFor.tsFor}}),Object.defineProperty(exports,"typeDocsFor",{enumerable:!0,get:function(){return _typeDocsFor.typeDocsFor}});var _addToReadme=require("./partials/addToReadme.js"),_beginWatcher=require("./partials/beginWatcher.js"),_clean=require("./partials/clean.js"),_copyFor=require("./partials/copyFor.js"),_distFor=require("./partials/distFor.js"),_distForSrc=require("./partials/distForSrc.js"),_distSeries=require("./partials/distSeries.js"),_imagesFor=require("./partials/imagesFor.js"),_minifyFor=require("./partials/minifyFor.js"),_readmeTemplate=require("./partials/readmeTemplate.js"),_removeDirectory=require("./partials/removeDirectory.js"),_runOnChange=require("./partials/runOnChange.js"),_sassFor=require("./partials/sassFor.js"),_standardLint=require("./partials/standardLint.js"),_tsFor=require("./partials/tsFor.js"),_typeDocsFor=require("./partials/typeDocsFor.js");
package/dist/sass.js CHANGED
@@ -1,10 +1,10 @@
1
- 'use strict'
2
-
3
- Object.defineProperty(exports, '__esModule', {
4
- value: true
5
- })
6
- exports.sass = void 0
7
- const _sassFor = require('./partials/sassFor.js')
8
- // Compile sass into CSS & auto-inject into browsers
9
- const sass = () => (0, _sassFor.sassFor)()
10
- exports.sass = sass
1
+ 'use strict'
2
+
3
+ Object.defineProperty(exports, '__esModule', {
4
+ value: true
5
+ })
6
+ exports.sass = void 0
7
+ const _sassFor = require('./partials/sassFor.js')
8
+ // Compile sass into CSS & auto-inject into browsers
9
+ const sass = () => (0, _sassFor.sassFor)()
10
+ exports.sass = sass