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