js-build-tools 6.0.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -2
- package/dist/build.js +63 -62
- package/dist/build.min.js +1 -1
- package/dist/bundle.js +40 -39
- package/dist/bundle.min.js +1 -1
- package/dist/bundleMinify.js +18 -17
- package/dist/bundleMinify.min.js +1 -1
- package/dist/copyFonts.js +13 -12
- package/dist/copyFonts.min.js +1 -1
- package/dist/default.js +15 -14
- package/dist/default.min.js +1 -1
- package/dist/distMinify.js +13 -12
- package/dist/distMinify.min.js +1 -1
- package/dist/partials/addToReadme.js +25 -24
- package/dist/partials/beginWatcher.js +13 -12
- package/dist/partials/clean.js +15 -14
- package/dist/partials/distFor.js +22 -21
- package/dist/partials/distForSrc.js +12 -11
- package/dist/partials/distSeries.js +20 -19
- package/dist/partials/imagesFor.js +43 -42
- package/dist/partials/neostandardLint.js +130 -111
- package/dist/partials/readmeTemplate.js +15 -14
- package/dist/partials/runOnChange.js +29 -28
- package/dist/partials/sassFor.js +29 -28
- package/dist/partials/tsFor.js +71 -70
- package/dist/partials/typeDocsFor.js +203 -202
- package/dist/sourceLint.js +26 -24
- package/dist/sourceLint.min.js +1 -1
- package/dist/test-helpers/neostandardLintWithRealNeostandard.js +49 -47
- package/dist/test-helpers/setUp.js +95 -94
- package/dist/testFull.js +20 -19
- package/dist/testFull.min.js +1 -1
- package/dist/testHelpers.js +11 -10
- package/dist/testHelpers.min.js +1 -1
- package/dist/testQuick.js +22 -21
- package/dist/testQuick.min.js +1 -1
- package/dist/utilities/dotNotate.js +48 -46
- package/dist/utilities/getBundleConfigs.js +28 -27
- package/dist/watchTest.js +16 -15
- package/dist/watchTest.min.js +1 -1
- package/functions/bundle.mjs +2 -2
- package/functions/partials/addToReadme.mjs +1 -1
- package/functions/partials/neostandardLint.mjs +19 -7
- package/functions/partials/neostandardLint.test.mjs +9 -1
- package/functions/sourceLint.mjs +1 -1
- package/functions/sourceLint.test.mjs +24 -0
- package/functions/test-helpers/neostandardLintWithRealNeostandard.mjs +7 -5
- package/functions/utilities/dotNotate.mjs +3 -1
- package/functions/utilities/dotNotate.test.mjs +34 -0
- package/functions/utilities/getBundleConfigs.mjs +1 -1
- package/gulp.config.mjs +14 -0
- package/package.json +1 -1
|
@@ -1,29 +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
|
-
|
|
24
|
-
function
|
|
25
|
-
|
|
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
|
+
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
|
+
|
|
27
28
|
/**
|
|
28
29
|
* Find the TypeDoc of the project being built (an optional peer dependency, only needed when the docs task is
|
|
29
30
|
* enabled) and load it, so projects which do not document TypeScript never need it installed.
|
|
@@ -31,80 +32,80 @@ const installHint = 'Install it in your project with: npm install --save-dev typ
|
|
|
31
32
|
* @param {string} [projectPath=process.cwd()] The folder of the project (which has the package.json) being built.
|
|
32
33
|
* @returns {Promise<Object>} The TypeDoc module.
|
|
33
34
|
* @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
|
-
|
|
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
|
+
|
|
54
55
|
/**
|
|
55
56
|
* Describe what a source file exports: whether it has a default export, and whether it has any named exports.
|
|
56
57
|
* @memberOf module:partials
|
|
57
58
|
* @param {Object} ts - The TypeScript compiler API.
|
|
58
59
|
* @param {string} filePath
|
|
59
60
|
* @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
|
-
|
|
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
|
+
|
|
95
96
|
/**
|
|
96
97
|
* The description of a folder for its module: the first doc comment of the folder's index file, without its tags
|
|
97
98
|
* (@module, @file, ...), or an empty string when there is none.
|
|
98
99
|
* @memberOf module:partials
|
|
99
100
|
* @param {string} folderPath
|
|
100
101
|
* @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
|
-
|
|
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
|
+
|
|
108
109
|
/**
|
|
109
110
|
* The description of a source file for its module: its first doc comment without the tags (@module, @file, ...), when
|
|
110
111
|
* that comment is a header (it is followed by an import or export, so it does not document a declaration itself), or
|
|
@@ -112,18 +113,18 @@ const describeFolder = folderPath => {
|
|
|
112
113
|
* @memberOf module:partials
|
|
113
114
|
* @param {string} filePath
|
|
114
115
|
* @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
|
-
|
|
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
|
+
|
|
127
128
|
/**
|
|
128
129
|
* Write one entry file per folder of the source directory into the entry directory. TypeDoc makes a module of every
|
|
129
130
|
* entry file, so the modules of the documentation mirror the folders. The default export of each source file is
|
|
@@ -137,61 +138,61 @@ const describeFile = filePath => {
|
|
|
137
138
|
* @param {string} srcDir - The directory holding the TypeScript source.
|
|
138
139
|
* @param {string} entryDir - The directory to write the entry files into.
|
|
139
140
|
* @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
|
-
|
|
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
|
+
|
|
195
196
|
/**
|
|
196
197
|
* Generate the HTML documentation of a TypeScript project with TypeDoc, straight from the TypeScript source, so the
|
|
197
198
|
* types (and the comments on them) are documented from where they are defined. The modules mirror the folders of the
|
|
@@ -202,51 +203,51 @@ const projectName = () => {
|
|
|
202
203
|
* @param {string} [outPath=gulpConfig.get('docs.to')] - The directory the documentation is generated into (cleared first).
|
|
203
204
|
* @param {function(string): Promise<Object>} [loadDocs] - Resolves the TypeDoc module, tests can inject a stand-in.
|
|
204
205
|
* @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
|
-
};
|
|
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
|
+
};
|
|
252
253
|
exports.typeDocsFor = typeDocsFor;
|
package/dist/sourceLint.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
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.sourceLint = void 0;
|
|
8
|
-
var gulpConfig = _interopRequireWildcard(require("../gulp.config.js"));
|
|
9
|
-
var _gulp = require("gulp");
|
|
10
|
-
var _neostandardLint = require("./partials/neostandardLint.js");
|
|
11
|
-
|
|
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.sourceLint = void 0;
|
|
8
|
+
var gulpConfig = _interopRequireWildcard(require("../gulp.config.js"));
|
|
9
|
+
var _gulp = require("gulp");
|
|
10
|
+
var _neostandardLint = require("./partials/neostandardLint.js");
|
|
11
|
+
var cache;
|
|
12
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
12
13
|
/**
|
|
13
14
|
* Applies neostandard linting (js-build-tools' chosen style) to the real, hand-written source - not the compiled
|
|
14
15
|
* dist/browser output, which is generated and so was never going to pass a hand-authored-code style check (every
|
|
@@ -17,17 +18,18 @@ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r
|
|
|
17
18
|
* source. When typescript.enabled, the real TypeScript source is linted too, with type-aware rules.
|
|
18
19
|
* @memberOf module:js-build-tools
|
|
19
20
|
* @returns {*}
|
|
20
|
-
*/
|
|
21
|
-
const sourceLint = () => {
|
|
22
|
-
const srcPath = gulpConfig.get('srcPath');
|
|
23
|
-
const ts = gulpConfig.get('typescript.enabled');
|
|
24
|
-
const patterns = [`${srcPath}/**/*.js`];
|
|
25
|
-
if (ts) {
|
|
26
|
-
patterns.push(`${srcPath}/**/*.ts`);
|
|
27
|
-
}
|
|
28
|
-
return (0, _gulp.src)(patterns).pipe((0, _neostandardLint.neostandardLint)({
|
|
29
|
-
fix: true,
|
|
30
|
-
ts
|
|
31
|
-
|
|
32
|
-
};
|
|
21
|
+
*/
|
|
22
|
+
const sourceLint = () => {
|
|
23
|
+
const srcPath = gulpConfig.get('srcPath');
|
|
24
|
+
const ts = gulpConfig.get('typescript.enabled');
|
|
25
|
+
const patterns = [`${srcPath}/**/*.js`];
|
|
26
|
+
if (ts) {
|
|
27
|
+
patterns.push(`${srcPath}/**/*.ts`);
|
|
28
|
+
}
|
|
29
|
+
return (0, _gulp.src)(patterns).pipe((0, _neostandardLint.neostandardLint)({
|
|
30
|
+
fix: true,
|
|
31
|
+
ts,
|
|
32
|
+
rules: gulpConfig.get('lint.rules')
|
|
33
|
+
})).pipe((0, _gulp.dest)(srcPath));
|
|
34
|
+
};
|
|
33
35
|
exports.sourceLint = sourceLint;
|
package/dist/sourceLint.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.sourceLint=void 0;var gulpConfig=_interopRequireWildcard(require("../gulp.config.js")),_gulp=require("gulp"),_neostandardLint=require("./partials/neostandardLint.js");function _interopRequireWildcard(e,t){if(
|
|
1
|
+
"use strict";require("core-js/modules/esnext.weak-map.delete-all.js"),Object.defineProperty(exports,"__esModule",{value:!0}),exports.sourceLint=void 0;var cache,gulpConfig=_interopRequireWildcard(require("../gulp.config.js")),_gulp=require("gulp"),_neostandardLint=require("./partials/neostandardLint.js");function _interopRequireWildcard(e,t){if(!t&&e&&e.__esModule)return e;var r,n,i=Object.defineProperty,s={__proto__:null,default:e};if(Object(e)!==e)return s;if(cache||"function"!=typeof WeakMap||(cache=new WeakMap),cache){if(cache.has(e))return cache.get(e);cache.set(e,s)}for(n in e)"default"!==n&&{}.hasOwnProperty.call(e,n)&&((r=i&&Object.getOwnPropertyDescriptor(e,n))&&(r.get||r.set)?i(s,n,r):s[n]=e[n]);return s}const sourceLint=()=>{const e=gulpConfig.get("srcPath"),t=gulpConfig.get("typescript.enabled"),r=[`${e}/**/*.js`];return t&&r.push(`${e}/**/*.ts`),(0,_gulp.src)(r).pipe((0,_neostandardLint.neostandardLint)({fix:!0,ts:t,rules:gulpConfig.get("lint.rules")})).pipe((0,_gulp.dest)(e))};exports.sourceLint=sourceLint;
|
|
@@ -1,48 +1,50 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.neostandardLint = exports.loadEslintViaSubprocess = void 0;
|
|
7
|
-
require("core-js/modules/es.json.stringify.js");
|
|
8
|
-
var _nodeChild_process = require("node:child_process");
|
|
9
|
-
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
10
|
-
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
-
// Jest's CommonJS transform cannot load `neostandard` (ESM-only) or run a real dynamic import(), so tests that need
|
|
13
|
-
// genuine neostandard behavior run the actual package in a plain Node subprocess instead of faking it.
|
|
14
|
-
const script = 'import { readFileSync } from \'node:fs\'\n' + 'import { ESLint } from \'eslint\'\n' + 'import { neostandard } from \'neostandard\'\n' + 'const { text, filePath, cwd, fix, ts, env } = JSON.parse(readFileSync(0, \'utf8\'))\n' + 'const eslint = new ESLint({ cwd, fix, overrideConfigFile: true, baseConfig
|
|
15
|
-
const readEnv = cwd => {
|
|
16
|
-
try {
|
|
17
|
-
return JSON.parse(_nodeFs.default.readFileSync(_nodePath.default.join(cwd, 'package.json'), 'utf8')).standard?.env ?? [];
|
|
18
|
-
} catch {
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const loadEslintViaSubprocess = ({
|
|
23
|
-
cwd,
|
|
24
|
-
ts,
|
|
25
|
-
fix
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.neostandardLint = exports.loadEslintViaSubprocess = void 0;
|
|
7
|
+
require("core-js/modules/es.json.stringify.js");
|
|
8
|
+
var _nodeChild_process = require("node:child_process");
|
|
9
|
+
var _nodeFs = _interopRequireDefault(require("node:fs"));
|
|
10
|
+
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
// Jest's CommonJS transform cannot load `neostandard` (ESM-only) or run a real dynamic import(), so tests that need
|
|
13
|
+
// genuine neostandard behavior run the actual package in a plain Node subprocess instead of faking it.
|
|
14
|
+
const script = 'import { readFileSync } from \'node:fs\'\n' + 'import { ESLint } from \'eslint\'\n' + 'import { neostandard, defaultFilePatterns } from \'neostandard\'\n' + 'const { text, filePath, cwd, fix, ts, env, rules } = JSON.parse(readFileSync(0, \'utf8\'))\n' + 'const baseConfig = neostandard({ ts, env })\n' + 'if (Object.keys(rules).length) { baseConfig.push({ files: defaultFilePatterns.all, rules }) }\n' + 'const eslint = new ESLint({ cwd, fix, overrideConfigFile: true, baseConfig })\n' + 'process.stdout.write(JSON.stringify(await eslint.lintText(text, { filePath })))\n';
|
|
15
|
+
const readEnv = cwd => {
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(_nodeFs.default.readFileSync(_nodePath.default.join(cwd, 'package.json'), 'utf8')).standard?.env ?? [];
|
|
18
|
+
} catch {
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const loadEslintViaSubprocess = ({
|
|
23
|
+
cwd,
|
|
24
|
+
ts,
|
|
25
|
+
fix,
|
|
26
|
+
rules = {}
|
|
27
|
+
}) => Promise.resolve({
|
|
28
|
+
lintText: (text, {
|
|
29
|
+
filePath
|
|
30
|
+
}) => Promise.resolve().then(() => JSON.parse((0, _nodeChild_process.execFileSync)(process.execPath, ['--input-type=module', '--eval', script], {
|
|
31
|
+
input: JSON.stringify({
|
|
32
|
+
text,
|
|
33
|
+
filePath,
|
|
34
|
+
cwd,
|
|
35
|
+
fix,
|
|
36
|
+
ts,
|
|
37
|
+
env: readEnv(cwd),
|
|
38
|
+
rules
|
|
39
|
+
}),
|
|
40
|
+
encoding: 'utf8',
|
|
41
|
+
cwd,
|
|
42
|
+
maxBuffer: 256 * 1024 * 1024
|
|
43
|
+
})))
|
|
44
|
+
});
|
|
45
|
+
exports.loadEslintViaSubprocess = loadEslintViaSubprocess;
|
|
46
|
+
const actual = jest.requireActual('../partials/neostandardLint.js');
|
|
47
|
+
|
|
48
|
+
// Drop-in replacement for the partial module (see jest.mock in the lint/build tests): same API, real neostandard.
|
|
49
|
+
const neostandardLint = options => actual.neostandardLint(options, loadEslintViaSubprocess);
|
|
48
50
|
exports.neostandardLint = neostandardLint;
|