js-build-tools 5.6.0 → 6.0.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 (65) hide show
  1. package/README.md +98 -3
  2. package/dist/build.js +65 -64
  3. package/dist/build.min.js +1 -1
  4. package/dist/bundle.js +40 -40
  5. package/dist/bundleMinify.js +18 -18
  6. package/dist/compileReadme.js +7 -7
  7. package/dist/copyFonts.js +10 -10
  8. package/dist/default.js +12 -12
  9. package/dist/dist.js +7 -7
  10. package/dist/distMinify.js +10 -10
  11. package/dist/images.js +7 -7
  12. package/dist/partials/addToReadme.js +14 -3
  13. package/dist/partials/imagesFor.js +42 -42
  14. package/dist/partials/loadPeer.js +70 -70
  15. package/dist/partials/neostandardLint.js +144 -0
  16. package/dist/partials/tsFor.js +70 -70
  17. package/dist/partials/typeDocsFor.js +202 -202
  18. package/dist/partials.js +136 -136
  19. package/dist/partials.min.js +1 -1
  20. package/dist/sass.js +7 -7
  21. package/dist/sourceLint.js +33 -0
  22. package/dist/sourceLint.min.js +1 -0
  23. package/dist/test-helpers/neostandardLintWithRealNeostandard.js +48 -0
  24. package/dist/test-helpers/setUp.js +5 -0
  25. package/dist/testFull.js +13 -13
  26. package/dist/testHelpers.js +8 -8
  27. package/dist/testQuick.js +13 -13
  28. package/dist/typeDocs.js +9 -9
  29. package/dist/typeScript.js +6 -6
  30. package/dist/utilities/convertMjsFilesForDocs.js +48 -0
  31. package/dist/utilities/esmNamedExportsToCjs.js +33 -0
  32. package/dist/utilities/getBundleConfigs.js +27 -27
  33. package/dist/watchFull.js +7 -7
  34. package/dist/watchTest.js +11 -11
  35. package/functions/build.mjs +9 -8
  36. package/functions/build.test.mjs +18 -25
  37. package/functions/partials/addToReadme.mjs +14 -5
  38. package/functions/partials/neostandardLint.mjs +118 -0
  39. package/functions/partials/neostandardLint.test.mjs +109 -0
  40. package/functions/partials.mjs +1 -1
  41. package/functions/sourceLint.mjs +24 -0
  42. package/functions/sourceLint.test.mjs +73 -0
  43. package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +38 -0
  44. package/functions/test-helpers/setUp.mjs +5 -0
  45. package/functions/utilities/convertMjsFilesForDocs.mjs +33 -0
  46. package/functions/utilities/convertMjsFilesForDocs.test.mjs +57 -0
  47. package/functions/utilities/esmNamedExportsToCjs.mjs +29 -0
  48. package/functions/utilities/esmNamedExportsToCjs.test.mjs +47 -0
  49. package/gulp.config.mjs +4 -0
  50. package/gulpfile.base.js +2 -4
  51. package/gulpfile.base.mjs +1 -2
  52. package/package.json +7 -6
  53. package/dist/bundleLint.js +0 -28
  54. package/dist/bundleLint.min.js +0 -1
  55. package/dist/distLint.js +0 -20
  56. package/dist/distLint.min.js +0 -1
  57. package/dist/partials/standardLint.js +0 -94
  58. package/dist/test-helpers/standardLintWithRealStandard.js +0 -28
  59. package/functions/bundleLint.mjs +0 -18
  60. package/functions/bundleLint.test.mjs +0 -85
  61. package/functions/distLint.mjs +0 -12
  62. package/functions/distLint.test.mjs +0 -62
  63. package/functions/partials/standardLint.mjs +0 -78
  64. package/functions/partials/standardLint.test.mjs +0 -99
  65. package/functions/test-helpers/standardLintWithRealStandard.mjs +0 -21
@@ -1,29 +1,29 @@
1
- "use strict";
2
-
3
- require("core-js/modules/esnext.weak-map.delete-all.js");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.writeDocEntries = exports.typeDocsFor = exports.loadTypeDoc = exports.describeFolder = exports.describeFile = 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.find.js");
12
- require("core-js/modules/esnext.iterator.flat-map.js");
13
- require("core-js/modules/esnext.iterator.for-each.js");
14
- require("core-js/modules/esnext.iterator.map.js");
15
- require("core-js/modules/esnext.iterator.some.js");
16
- var _nodeFs = _interopRequireDefault(require("node:fs"));
17
- var _nodeOs = _interopRequireDefault(require("node:os"));
18
- var _nodePath = _interopRequireDefault(require("node:path"));
19
- var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
20
- var _loadPeer = require("./loadPeer.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
- const installHint = 'Install it in your project with: npm install --save-dev typedoc';
26
-
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.describeFolder = exports.describeFile = 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.find.js");
12
+ require("core-js/modules/esnext.iterator.flat-map.js");
13
+ require("core-js/modules/esnext.iterator.for-each.js");
14
+ require("core-js/modules/esnext.iterator.map.js");
15
+ require("core-js/modules/esnext.iterator.some.js");
16
+ var _nodeFs = _interopRequireDefault(require("node:fs"));
17
+ var _nodeOs = _interopRequireDefault(require("node:os"));
18
+ var _nodePath = _interopRequireDefault(require("node:path"));
19
+ var gulpConfig = _interopRequireWildcard(require("../../gulp.config.js"));
20
+ var _loadPeer = require("./loadPeer.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
+ const installHint = 'Install it in your project with: npm install --save-dev typedoc';
26
+
27
27
  /**
28
28
  * Find the TypeDoc of the project being built (an optional peer dependency, only needed when the docs task is
29
29
  * enabled) and load it, so projects which do not document TypeScript never need it installed.
@@ -31,80 +31,80 @@ const installHint = 'Install it in your project with: npm install --save-dev typ
31
31
  * @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
32
32
  * @returns {Promise<Object>} The TypeDoc module.
33
33
  * @throws {Error} With install instructions when typedoc is not installed.
34
- */
35
- const loadTypeDoc = (projectPath = process.cwd()) => (0, _loadPeer.importPeer)('typedoc', {
36
- task: 'docs',
37
- installHint,
38
- projectPath
39
- });
40
- exports.loadTypeDoc = loadTypeDoc;
41
- const isSource = fileName => /\.(ts|tsx|mts|cts)$/.test(fileName) && !/\.d\.[cm]?ts$/.test(fileName) && !/\.(test|spec)\./.test(fileName);
42
- const listSources = dirPath => _nodeFs.default.readdirSync(dirPath, {
43
- withFileTypes: true
44
- }).flatMap(entry => {
45
- const entryPath = _nodePath.default.join(dirPath, entry.name);
46
- if (entry.isDirectory()) {
47
- return entry.name === 'node_modules' ? [] : listSources(entryPath);
48
- }
49
- return isSource(entry.name) ? [entryPath] : [];
50
- });
51
- const toIdentifier = fileName => fileName.replace(/[^\w$]+(\w)?/g, (match, letter) => (letter || '').toUpperCase()).replace(/^(\d)/, '_$1');
52
- const toModulePath = filePath => filePath.replace(/\.[cm]?tsx?$/, '').split(_nodePath.default.sep).join('/');
53
-
34
+ */
35
+ const loadTypeDoc = (projectPath = process.cwd()) => (0, _loadPeer.importPeer)('typedoc', {
36
+ task: 'docs',
37
+ installHint,
38
+ projectPath
39
+ });
40
+ exports.loadTypeDoc = loadTypeDoc;
41
+ const isSource = fileName => /\.(ts|tsx|mts|cts)$/.test(fileName) && !/\.d\.[cm]?ts$/.test(fileName) && !/\.(test|spec)\./.test(fileName);
42
+ const listSources = dirPath => _nodeFs.default.readdirSync(dirPath, {
43
+ withFileTypes: true
44
+ }).flatMap(entry => {
45
+ const entryPath = _nodePath.default.join(dirPath, entry.name);
46
+ if (entry.isDirectory()) {
47
+ return entry.name === 'node_modules' ? [] : listSources(entryPath);
48
+ }
49
+ return isSource(entry.name) ? [entryPath] : [];
50
+ });
51
+ const toIdentifier = fileName => fileName.replace(/[^\w$]+(\w)?/g, (match, letter) => (letter || '').toUpperCase()).replace(/^(\d)/, '_$1');
52
+ const toModulePath = filePath => filePath.replace(/\.[cm]?tsx?$/, '').split(_nodePath.default.sep).join('/');
53
+
54
54
  /**
55
55
  * Describe what a source file exports: whether it has a default export, and whether it has any named exports.
56
56
  * @memberOf module:partials
57
57
  * @param {Object} ts - The TypeScript compiler API.
58
58
  * @param {string} filePath
59
59
  * @returns {{hasDefault: boolean, hasNamed: boolean}}
60
- */
61
- const describeExports = (ts, filePath) => {
62
- const source = ts.createSourceFile(filePath, _nodeFs.default.readFileSync(filePath, 'utf8'), ts.ScriptTarget.Latest);
63
- let hasDefault = false;
64
- let hasNamed = false;
65
- source.statements.forEach(statement => {
66
- if (ts.isExportAssignment(statement)) {
67
- hasDefault = hasDefault || !statement.isExportEquals;
68
- return;
69
- }
70
- if (ts.isExportDeclaration(statement)) {
71
- const names = statement.exportClause && ts.isNamedExports(statement.exportClause) ? statement.exportClause.elements : null;
72
- if (names && names.some(element => element.name.text === 'default')) {
73
- hasDefault = true;
74
- }
75
- if (!names || names.some(element => element.name.text !== 'default')) {
76
- hasNamed = true;
77
- }
78
- return;
79
- }
80
- const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) || [] : [];
81
- if (modifiers.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword)) {
82
- if (modifiers.some(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword)) {
83
- hasDefault = true;
84
- } else {
85
- hasNamed = true;
86
- }
87
- }
88
- });
89
- return {
90
- hasDefault,
91
- hasNamed
92
- };
93
- };
94
-
60
+ */
61
+ const describeExports = (ts, filePath) => {
62
+ const source = ts.createSourceFile(filePath, _nodeFs.default.readFileSync(filePath, 'utf8'), ts.ScriptTarget.Latest);
63
+ let hasDefault = false;
64
+ let hasNamed = false;
65
+ source.statements.forEach(statement => {
66
+ if (ts.isExportAssignment(statement)) {
67
+ hasDefault = hasDefault || !statement.isExportEquals;
68
+ return;
69
+ }
70
+ if (ts.isExportDeclaration(statement)) {
71
+ const names = statement.exportClause && ts.isNamedExports(statement.exportClause) ? statement.exportClause.elements : null;
72
+ if (names && names.some(element => element.name.text === 'default')) {
73
+ hasDefault = true;
74
+ }
75
+ if (!names || names.some(element => element.name.text !== 'default')) {
76
+ hasNamed = true;
77
+ }
78
+ return;
79
+ }
80
+ const modifiers = ts.canHaveModifiers(statement) ? ts.getModifiers(statement) || [] : [];
81
+ if (modifiers.some(modifier => modifier.kind === ts.SyntaxKind.ExportKeyword)) {
82
+ if (modifiers.some(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword)) {
83
+ hasDefault = true;
84
+ } else {
85
+ hasNamed = true;
86
+ }
87
+ }
88
+ });
89
+ return {
90
+ hasDefault,
91
+ hasNamed
92
+ };
93
+ };
94
+
95
95
  /**
96
96
  * The description of a folder for its module: the first doc comment of the folder's index file, without its tags
97
97
  * (@module, @file, ...), or an empty string when there is none.
98
98
  * @memberOf module:partials
99
99
  * @param {string} folderPath
100
100
  * @returns {string}
101
- */
102
- exports.describeExports = describeExports;
103
- const describeFolder = folderPath => {
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
- return indexFile ? describeFile(indexFile) : '';
106
- };
107
-
101
+ */
102
+ exports.describeExports = describeExports;
103
+ const describeFolder = folderPath => {
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
+ return indexFile ? describeFile(indexFile) : '';
106
+ };
107
+
108
108
  /**
109
109
  * The description of a source file for its module: its first doc comment without the tags (@module, @file, ...), when
110
110
  * that comment is a header (it is followed by an import or export, so it does not document a declaration itself), or
@@ -112,18 +112,18 @@ const describeFolder = folderPath => {
112
112
  * @memberOf module:partials
113
113
  * @param {string} filePath
114
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)|$)/);
119
- if (!comment) {
120
- return '';
121
- }
122
- const lines = comment[1].split('\n').map(line => line.replace(/^\s*\* ?/, '').trimEnd());
123
- const tagAt = lines.findIndex(line => /^@\w+/.test(line));
124
- return (tagAt === -1 ? lines : lines.slice(0, tagAt)).join('\n').trim();
125
- };
126
-
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)|$)/);
119
+ if (!comment) {
120
+ return '';
121
+ }
122
+ const lines = comment[1].split('\n').map(line => line.replace(/^\s*\* ?/, '').trimEnd());
123
+ const tagAt = lines.findIndex(line => /^@\w+/.test(line));
124
+ return (tagAt === -1 ? lines : lines.slice(0, tagAt)).join('\n').trim();
125
+ };
126
+
127
127
  /**
128
128
  * Write one entry file per folder of the source directory into the entry directory. TypeDoc makes a module of every
129
129
  * entry file, so the modules of the documentation mirror the folders. The default export of each source file is
@@ -137,61 +137,61 @@ const describeFile = filePath => {
137
137
  * @param {string} srcDir - The directory holding the TypeScript source.
138
138
  * @param {string} entryDir - The directory to write the entry files into.
139
139
  * @returns {Array<string>} The paths of the entry files.
140
- */
141
- exports.describeFile = describeFile;
142
- const writeDocEntries = (ts, srcDir, entryDir) => {
143
- const absoluteSrc = _nodePath.default.resolve(srcDir);
144
- _nodeFs.default.mkdirSync(entryDir, {
145
- recursive: true
146
- });
147
- const folders = _nodeFs.default.readdirSync(absoluteSrc, {
148
- withFileTypes: true
149
- }).filter(entry => entry.isDirectory() && entry.name !== 'node_modules').map(entry => ({
150
- name: entry.name,
151
- path: _nodePath.default.join(absoluteSrc, entry.name),
152
- files: listSources(_nodePath.default.join(absoluteSrc, entry.name))
153
- })).filter(folder => folder.files.length);
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))] : [{
164
- name: 'index',
165
- path: absoluteSrc,
166
- files: rootFiles
167
- }];
168
- return groups.map(group => {
169
- const lines = group.files.filter(file => !/^index\./.test(_nodePath.default.basename(file))).sort().flatMap(file => {
170
- const modulePath = toModulePath(file);
171
- const {
172
- hasDefault,
173
- hasNamed
174
- } = describeExports(ts, file);
175
- const fileName = _nodePath.default.basename(file).replace(/\.[cm]?tsx?$/, '');
176
- return [...(hasDefault ? [`export { default as ${toIdentifier(fileName)} } from '${modulePath}'`] : []), ...(hasNamed ? [`export * from '${modulePath}'`] : [])];
177
- });
178
- const description = group.description ?? (group.path ? describeFolder(group.path) : '');
179
- // TypeDoc takes the first comment of an entry file which has the @module tag as the description of the module
180
- const moduleComment = description ? `/**\n${description.split('\n').map(line => ` * ${line}`.trimEnd()).join('\n')}\n * @module\n */\n\n` : '';
181
- const entryPath = _nodePath.default.join(entryDir, `${group.name}.ts`);
182
- _nodeFs.default.writeFileSync(entryPath, moduleComment + lines.join('\n') + '\n');
183
- return entryPath;
184
- });
185
- };
186
- exports.writeDocEntries = writeDocEntries;
187
- const projectName = () => {
188
- try {
189
- return JSON.parse(_nodeFs.default.readFileSync(_nodePath.default.join(process.cwd(), 'package.json'), 'utf8')).name;
190
- } catch (error) {
191
- return _nodePath.default.basename(process.cwd());
192
- }
193
- };
194
-
140
+ */
141
+ exports.describeFile = describeFile;
142
+ const writeDocEntries = (ts, srcDir, entryDir) => {
143
+ const absoluteSrc = _nodePath.default.resolve(srcDir);
144
+ _nodeFs.default.mkdirSync(entryDir, {
145
+ recursive: true
146
+ });
147
+ const folders = _nodeFs.default.readdirSync(absoluteSrc, {
148
+ withFileTypes: true
149
+ }).filter(entry => entry.isDirectory() && entry.name !== 'node_modules').map(entry => ({
150
+ name: entry.name,
151
+ path: _nodePath.default.join(absoluteSrc, entry.name),
152
+ files: listSources(_nodePath.default.join(absoluteSrc, entry.name))
153
+ })).filter(folder => folder.files.length);
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))] : [{
164
+ name: 'index',
165
+ path: absoluteSrc,
166
+ files: rootFiles
167
+ }];
168
+ return groups.map(group => {
169
+ const lines = group.files.filter(file => !/^index\./.test(_nodePath.default.basename(file))).sort().flatMap(file => {
170
+ const modulePath = toModulePath(file);
171
+ const {
172
+ hasDefault,
173
+ hasNamed
174
+ } = describeExports(ts, file);
175
+ const fileName = _nodePath.default.basename(file).replace(/\.[cm]?tsx?$/, '');
176
+ return [...(hasDefault ? [`export { default as ${toIdentifier(fileName)} } from '${modulePath}'`] : []), ...(hasNamed ? [`export * from '${modulePath}'`] : [])];
177
+ });
178
+ const description = group.description ?? (group.path ? describeFolder(group.path) : '');
179
+ // TypeDoc takes the first comment of an entry file which has the @module tag as the description of the module
180
+ const moduleComment = description ? `/**\n${description.split('\n').map(line => ` * ${line}`.trimEnd()).join('\n')}\n * @module\n */\n\n` : '';
181
+ const entryPath = _nodePath.default.join(entryDir, `${group.name}.ts`);
182
+ _nodeFs.default.writeFileSync(entryPath, moduleComment + lines.join('\n') + '\n');
183
+ return entryPath;
184
+ });
185
+ };
186
+ exports.writeDocEntries = writeDocEntries;
187
+ const projectName = () => {
188
+ try {
189
+ return JSON.parse(_nodeFs.default.readFileSync(_nodePath.default.join(process.cwd(), 'package.json'), 'utf8')).name;
190
+ } catch (error) {
191
+ return _nodePath.default.basename(process.cwd());
192
+ }
193
+ };
194
+
195
195
  /**
196
196
  * Generate the HTML documentation of a TypeScript project with TypeDoc, straight from the TypeScript source, so the
197
197
  * types (and the comments on them) are documented from where they are defined. The modules mirror the folders of the
@@ -202,51 +202,51 @@ const projectName = () => {
202
202
  * @param {string} [outPath=gulpConfig.get('docs.to')] - The directory the documentation is generated into (cleared first).
203
203
  * @param {function(string): Promise<Object>} [loadDocs] - Resolves the TypeDoc module, tests can inject a stand-in.
204
204
  * @returns {Function} A gulp task, it accepts an optional callback and returns a promise.
205
- */
206
- const typeDocsFor = (srcPath = gulpConfig.get('docs.from'), outPath = gulpConfig.get('docs.to'), loadDocs = loadTypeDoc) => {
207
- if (gulpConfig.get('docs.enabled') === false) {
208
- return () => {};
209
- }
210
- return done => {
211
- const generate = async () => {
212
- const ts = (0, _tsFor.loadTypescript)();
213
- const {
214
- Application
215
- } = await loadDocs();
216
- const workDir = _nodeFs.default.mkdtempSync(_nodePath.default.join(_nodeOs.default.tmpdir(), 'typedocs-'));
217
- try {
218
- const entryPoints = writeDocEntries(ts, srcPath, _nodePath.default.join(workDir, 'entries'));
219
- // The entry files live outside the project, so the tsconfig which is used for the documentation extends the
220
- // one of the project and adds the entries to the files it includes.
221
- const projectConfig = gulpConfig.get('docs.tsconfig') || gulpConfig.get('typescript.config');
222
- const tsconfig = _nodePath.default.join(workDir, 'tsconfig.json');
223
- _nodeFs.default.writeFileSync(tsconfig, JSON.stringify({
224
- ...(projectConfig ? {
225
- extends: _nodePath.default.resolve(projectConfig)
226
- } : {}),
227
- include: [_nodePath.default.join(workDir, 'entries', '*.ts').split(_nodePath.default.sep).join('/'), _nodePath.default.resolve(srcPath).split(_nodePath.default.sep).join('/') + '/**/*.ts'],
228
- exclude: [_nodePath.default.resolve(srcPath).split(_nodePath.default.sep).join('/') + '/**/*.test.*']
229
- }));
230
- const indexFile = gulpConfig.get('docs.index');
231
- await (0, _removeDirectory.removeDirectory)(outPath);
232
- const app = await Application.bootstrap({
233
- entryPoints,
234
- tsconfig,
235
- name: gulpConfig.get('docs.title') || projectName(),
236
- readme: indexFile && _nodeFs.default.existsSync(indexFile) ? indexFile : 'none',
237
- logLevel: gulpConfig.get('docs.logLevel') || 'Warn',
238
- skipErrorChecking: true
239
- });
240
- const project = await app.convert();
241
- if (!project) {
242
- throw new Error('TypeDoc could not read the TypeScript source, see the errors above.');
243
- }
244
- await app.generateDocs(project, outPath);
245
- } finally {
246
- await (0, _removeDirectory.removeDirectory)(workDir);
247
- }
248
- };
249
- return typeof done === 'function' ? generate().then(() => done(), done) : generate();
250
- };
251
- };
205
+ */
206
+ const typeDocsFor = (srcPath = gulpConfig.get('docs.from'), outPath = gulpConfig.get('docs.to'), loadDocs = loadTypeDoc) => {
207
+ if (gulpConfig.get('docs.enabled') === false) {
208
+ return () => {};
209
+ }
210
+ return done => {
211
+ const generate = async () => {
212
+ const ts = (0, _tsFor.loadTypescript)();
213
+ const {
214
+ Application
215
+ } = await loadDocs();
216
+ const workDir = _nodeFs.default.mkdtempSync(_nodePath.default.join(_nodeOs.default.tmpdir(), 'typedocs-'));
217
+ try {
218
+ const entryPoints = writeDocEntries(ts, srcPath, _nodePath.default.join(workDir, 'entries'));
219
+ // The entry files live outside the project, so the tsconfig which is used for the documentation extends the
220
+ // one of the project and adds the entries to the files it includes.
221
+ const projectConfig = gulpConfig.get('docs.tsconfig') || gulpConfig.get('typescript.config');
222
+ const tsconfig = _nodePath.default.join(workDir, 'tsconfig.json');
223
+ _nodeFs.default.writeFileSync(tsconfig, JSON.stringify({
224
+ ...(projectConfig ? {
225
+ extends: _nodePath.default.resolve(projectConfig)
226
+ } : {}),
227
+ include: [_nodePath.default.join(workDir, 'entries', '*.ts').split(_nodePath.default.sep).join('/'), _nodePath.default.resolve(srcPath).split(_nodePath.default.sep).join('/') + '/**/*.ts'],
228
+ exclude: [_nodePath.default.resolve(srcPath).split(_nodePath.default.sep).join('/') + '/**/*.test.*']
229
+ }));
230
+ const indexFile = gulpConfig.get('docs.index');
231
+ await (0, _removeDirectory.removeDirectory)(outPath);
232
+ const app = await Application.bootstrap({
233
+ entryPoints,
234
+ tsconfig,
235
+ name: gulpConfig.get('docs.title') || projectName(),
236
+ readme: indexFile && _nodeFs.default.existsSync(indexFile) ? indexFile : 'none',
237
+ logLevel: gulpConfig.get('docs.logLevel') || 'Warn',
238
+ skipErrorChecking: true
239
+ });
240
+ const project = await app.convert();
241
+ if (!project) {
242
+ throw new Error('TypeDoc could not read the TypeScript source, see the errors above.');
243
+ }
244
+ await app.generateDocs(project, outPath);
245
+ } finally {
246
+ await (0, _removeDirectory.removeDirectory)(workDir);
247
+ }
248
+ };
249
+ return typeof done === 'function' ? generate().then(() => done(), done) : generate();
250
+ };
251
+ };
252
252
  exports.typeDocsFor = typeDocsFor;