@w5s/dev 3.2.3 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +207 -524
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +105 -340
- package/dist/index.d.ts +105 -340
- package/dist/index.js +206 -501
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/ESLintConfig.ts +67 -60
- package/src/Project.ts +141 -133
- package/src/ProjectScript.ts +1 -0
- package/src/index.ts +0 -6
- package/dist/index.d.cts.map +0 -1
- package/src/block.ts +0 -153
- package/src/directory.ts +0 -73
- package/src/exec.ts +0 -73
- package/src/file.ts +0 -99
- package/src/json.ts +0 -58
- package/src/yarnConfig.ts +0 -61
- package/src/yarnVersion.ts +0 -56
package/dist/index.js
CHANGED
|
@@ -1,56 +1,3 @@
|
|
|
1
|
-
import { accessSync, constants, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { access, constants as constants$1, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
-
import { spawn, spawnSync } from "node:child_process";
|
|
4
|
-
//#region src/directory.ts
|
|
5
|
-
async function exists$1(path) {
|
|
6
|
-
try {
|
|
7
|
-
await access(path, constants$1.F_OK);
|
|
8
|
-
return true;
|
|
9
|
-
} catch {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Ensure directory is present/absent
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* await directory({
|
|
19
|
-
* path: 'foo/bar',
|
|
20
|
-
* state: 'present',
|
|
21
|
-
* })
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @param options
|
|
25
|
-
*/
|
|
26
|
-
async function directory(options) {
|
|
27
|
-
const { path, state } = options;
|
|
28
|
-
const isPresent = await exists$1(path);
|
|
29
|
-
if (state === "present") {
|
|
30
|
-
if (!isPresent) await mkdir(path, { recursive: true });
|
|
31
|
-
} else if (isPresent) await rm(path, { recursive: true });
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Ensure directory is present/absent
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```ts
|
|
38
|
-
* await directorySync({
|
|
39
|
-
* path: 'foo/bar',
|
|
40
|
-
* state: 'present',
|
|
41
|
-
* })
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* @param options
|
|
45
|
-
*/
|
|
46
|
-
function directorySync(options) {
|
|
47
|
-
const { path, state } = options;
|
|
48
|
-
const isPresent = existsSync(path);
|
|
49
|
-
if (state === "present") {
|
|
50
|
-
if (!isPresent) mkdirSync(path, { recursive: true });
|
|
51
|
-
} else if (isPresent) rmSync(path, { recursive: true });
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
54
1
|
//#region src/ESLintConfig.ts
|
|
55
2
|
function toArray(value) {
|
|
56
3
|
if (value == null) return [];
|
|
@@ -60,213 +7,81 @@ function toArray(value) {
|
|
|
60
7
|
function concatArray(left, right) {
|
|
61
8
|
return [...toArray(left), ...toArray(right)];
|
|
62
9
|
}
|
|
63
|
-
let ESLintConfig;
|
|
64
|
-
(function(_ESLintConfig) {
|
|
65
|
-
function concat(...configs) {
|
|
66
|
-
return configs.reduce((returnValue, config) => ({
|
|
67
|
-
...returnValue,
|
|
68
|
-
...config,
|
|
69
|
-
env: {
|
|
70
|
-
...returnValue.env,
|
|
71
|
-
...config.env
|
|
72
|
-
},
|
|
73
|
-
extends: concatArray(returnValue.extends, config.extends),
|
|
74
|
-
globals: {
|
|
75
|
-
...returnValue.globals,
|
|
76
|
-
...config.globals
|
|
77
|
-
},
|
|
78
|
-
overrides: concatArray(returnValue.overrides, config.overrides),
|
|
79
|
-
parserOptions: {
|
|
80
|
-
...returnValue.parserOptions,
|
|
81
|
-
...config.parserOptions
|
|
82
|
-
},
|
|
83
|
-
plugins: concatArray(returnValue.plugins, config.plugins),
|
|
84
|
-
rules: {
|
|
85
|
-
...returnValue.rules,
|
|
86
|
-
...config.rules
|
|
87
|
-
},
|
|
88
|
-
settings: {
|
|
89
|
-
...returnValue.settings,
|
|
90
|
-
...config.settings
|
|
91
|
-
}
|
|
92
|
-
}), {
|
|
93
|
-
env: {},
|
|
94
|
-
extends: [],
|
|
95
|
-
globals: {},
|
|
96
|
-
overrides: [],
|
|
97
|
-
parserOptions: {},
|
|
98
|
-
plugins: [],
|
|
99
|
-
rules: {},
|
|
100
|
-
settings: {}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
_ESLintConfig.concat = concat;
|
|
104
|
-
function fixme(_status) {
|
|
105
|
-
return "off";
|
|
106
|
-
}
|
|
107
|
-
_ESLintConfig.fixme = fixme;
|
|
108
|
-
function renameRules(rules, map) {
|
|
109
|
-
return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
|
|
110
|
-
for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
|
|
111
|
-
else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
|
|
112
|
-
return [key, value];
|
|
113
|
-
}));
|
|
114
|
-
}
|
|
115
|
-
_ESLintConfig.renameRules = renameRules;
|
|
116
|
-
})(ESLintConfig || (ESLintConfig = {}));
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region src/file.ts
|
|
119
|
-
async function exists(path) {
|
|
120
|
-
try {
|
|
121
|
-
await access(path, constants.F_OK);
|
|
122
|
-
return true;
|
|
123
|
-
} catch {
|
|
124
|
-
return false;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
function existsSync$1(path) {
|
|
128
|
-
try {
|
|
129
|
-
accessSync(path, constants.F_OK);
|
|
130
|
-
return true;
|
|
131
|
-
} catch {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
10
|
/**
|
|
136
|
-
* Ensure file is present/absent with content initialized or modified with `update
|
|
137
11
|
*
|
|
138
|
-
* @
|
|
139
|
-
* ```ts
|
|
140
|
-
* await file({
|
|
141
|
-
* path: 'foo/bar',
|
|
142
|
-
* state: 'present',
|
|
143
|
-
* update: (content) => content + '_test', // This will append '_test' after current content
|
|
144
|
-
* })
|
|
145
|
-
* ```
|
|
146
|
-
*
|
|
147
|
-
* @param options
|
|
12
|
+
* @param configs
|
|
148
13
|
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
14
|
+
function concat(...configs) {
|
|
15
|
+
return configs.reduce((returnValue, config) => ({
|
|
16
|
+
...returnValue,
|
|
17
|
+
...config,
|
|
18
|
+
env: {
|
|
19
|
+
...returnValue.env,
|
|
20
|
+
...config.env
|
|
21
|
+
},
|
|
22
|
+
extends: concatArray(returnValue.extends, config.extends),
|
|
23
|
+
globals: {
|
|
24
|
+
...returnValue.globals,
|
|
25
|
+
...config.globals
|
|
26
|
+
},
|
|
27
|
+
overrides: concatArray(returnValue.overrides, config.overrides),
|
|
28
|
+
parserOptions: {
|
|
29
|
+
...returnValue.parserOptions,
|
|
30
|
+
...config.parserOptions
|
|
31
|
+
},
|
|
32
|
+
plugins: concatArray(returnValue.plugins, config.plugins),
|
|
33
|
+
rules: {
|
|
34
|
+
...returnValue.rules,
|
|
35
|
+
...config.rules
|
|
36
|
+
},
|
|
37
|
+
settings: {
|
|
38
|
+
...returnValue.settings,
|
|
39
|
+
...config.settings
|
|
40
|
+
}
|
|
41
|
+
}), {
|
|
42
|
+
env: {},
|
|
43
|
+
extends: [],
|
|
44
|
+
globals: {},
|
|
45
|
+
overrides: [],
|
|
46
|
+
parserOptions: {},
|
|
47
|
+
plugins: [],
|
|
48
|
+
rules: {},
|
|
49
|
+
settings: {}
|
|
50
|
+
});
|
|
156
51
|
}
|
|
157
52
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* @example
|
|
161
|
-
* ```ts
|
|
162
|
-
* fileSync({
|
|
163
|
-
* path: 'foo/bar',
|
|
164
|
-
* state: 'present',
|
|
165
|
-
* update: (content) => content + '_test', // This will append '_test' after current content
|
|
166
|
-
* })
|
|
167
|
-
* ```
|
|
53
|
+
* Always return 'off'. `_status` is the previous rule value.
|
|
168
54
|
*
|
|
169
|
-
* @param
|
|
55
|
+
* @param _status
|
|
170
56
|
*/
|
|
171
|
-
function
|
|
172
|
-
|
|
173
|
-
if (state === "present") {
|
|
174
|
-
const previousContent = existsSync$1(path) ? readFileSync(path, encoding) : "";
|
|
175
|
-
const newContent = update == null ? "" : update(previousContent);
|
|
176
|
-
if (newContent != null) writeFileSync(path, newContent, encoding);
|
|
177
|
-
} else rmSync(path, { force: true });
|
|
178
|
-
}
|
|
179
|
-
//#endregion
|
|
180
|
-
//#region src/block.ts
|
|
181
|
-
const EOF = "EndOfFile";
|
|
182
|
-
const BOF = "BeginningOfFile";
|
|
183
|
-
const insertAt = (str, index, toInsert) => str.slice(0, index) + toInsert + str.slice(index);
|
|
184
|
-
const matchLast = (string, regexp) => {
|
|
185
|
-
const matcher = new RegExp(regexp.source, `${regexp.flags}g`);
|
|
186
|
-
let firstIndex = -1;
|
|
187
|
-
let lastIndex = -1;
|
|
188
|
-
let matches;
|
|
189
|
-
while (true) {
|
|
190
|
-
matches = matcher.exec(string);
|
|
191
|
-
if (matches == null) break;
|
|
192
|
-
firstIndex = matches.index;
|
|
193
|
-
lastIndex = matcher.lastIndex;
|
|
194
|
-
}
|
|
195
|
-
return {
|
|
196
|
-
firstIndex,
|
|
197
|
-
lastIndex
|
|
198
|
-
};
|
|
199
|
-
};
|
|
200
|
-
function toFileOptions(options) {
|
|
201
|
-
const { marker = (mark) => `# ${mark.toUpperCase()} MANAGED BLOCK`, path, block: blockName, insertPosition = ["after", EOF], state = "present" } = options;
|
|
202
|
-
const EOL = "\n";
|
|
203
|
-
const beginBlock = marker("Begin");
|
|
204
|
-
const endBlock = marker("End");
|
|
205
|
-
/**
|
|
206
|
-
* @param content
|
|
207
|
-
*/
|
|
208
|
-
function findBlock(content) {
|
|
209
|
-
const startIndex = content.indexOf(beginBlock);
|
|
210
|
-
const endIndex = content.indexOf(endBlock) + endBlock.length;
|
|
211
|
-
return {
|
|
212
|
-
endIndex,
|
|
213
|
-
exists: startIndex !== -1 && endIndex >= 0,
|
|
214
|
-
startIndex
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
function apply(fullContent, blockContent) {
|
|
218
|
-
const found = findBlock(fullContent);
|
|
219
|
-
const remove = state === "absent";
|
|
220
|
-
const replaceBlock = remove ? "" : beginBlock + EOL + blockContent + EOL + endBlock;
|
|
221
|
-
const [positionDirection, positionAnchor] = insertPosition;
|
|
222
|
-
if (found.exists) return fullContent.slice(0, found.startIndex) + replaceBlock + fullContent.slice(found.endIndex);
|
|
223
|
-
if (remove) return fullContent;
|
|
224
|
-
switch (positionDirection) {
|
|
225
|
-
case "before":
|
|
226
|
-
if (positionAnchor !== BOF) {
|
|
227
|
-
const { firstIndex } = matchLast(fullContent, positionAnchor);
|
|
228
|
-
if (firstIndex >= 0) return insertAt(fullContent, firstIndex, replaceBlock + EOL);
|
|
229
|
-
}
|
|
230
|
-
return replaceBlock + EOL + fullContent;
|
|
231
|
-
case "after":
|
|
232
|
-
if (positionAnchor !== EOF) {
|
|
233
|
-
const { lastIndex } = matchLast(fullContent, positionAnchor);
|
|
234
|
-
if (lastIndex >= 0) return insertAt(fullContent, lastIndex, EOL + replaceBlock);
|
|
235
|
-
}
|
|
236
|
-
return fullContent + EOL + replaceBlock;
|
|
237
|
-
default: throw new Error(`Unsupported position ${String(positionDirection)}`);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return {
|
|
241
|
-
path,
|
|
242
|
-
state: "present",
|
|
243
|
-
update: (sourceContent) => apply(sourceContent, blockName)
|
|
244
|
-
};
|
|
57
|
+
function fixme(_status) {
|
|
58
|
+
return "off";
|
|
245
59
|
}
|
|
246
60
|
/**
|
|
247
|
-
*
|
|
61
|
+
* Renames rules in the given object according to the given map.
|
|
248
62
|
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
63
|
+
* Given a map `{ 'old-prefix': 'new-prefix' }`, and a rule object
|
|
64
|
+
* `{ 'old-prefix/rule-name': 'error' }`, this function will return
|
|
65
|
+
* `{ 'new-prefix/rule-name': 'error' }`.
|
|
252
66
|
*
|
|
253
|
-
* @param
|
|
67
|
+
* @param rules The object containing the rules to rename.
|
|
68
|
+
* @param map The object containing the rename map.
|
|
254
69
|
*/
|
|
255
|
-
function
|
|
256
|
-
return
|
|
70
|
+
function renameRules(rules, map) {
|
|
71
|
+
return Object.fromEntries(Object.entries(rules).map(([key, value]) => {
|
|
72
|
+
for (const [from, to] of Object.entries(map)) if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
|
|
73
|
+
else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
|
|
74
|
+
return [key, value];
|
|
75
|
+
}));
|
|
257
76
|
}
|
|
258
77
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
* marker(markerBegin)
|
|
262
|
-
* ...
|
|
263
|
-
* marker(markerEnd)
|
|
264
|
-
*
|
|
265
|
-
* @param options
|
|
78
|
+
* @namespace
|
|
266
79
|
*/
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
80
|
+
const ESLintConfig = Object.freeze({
|
|
81
|
+
concat,
|
|
82
|
+
fixme,
|
|
83
|
+
renameRules
|
|
84
|
+
});
|
|
270
85
|
//#endregion
|
|
271
86
|
//#region src/interopDefault.ts
|
|
272
87
|
const getDefaultOrElse = (_) => _?.default ?? _;
|
|
@@ -274,37 +89,10 @@ function interopDefault(m) {
|
|
|
274
89
|
return m != null && typeof m.then === "function" ? Promise.resolve(m).then(getDefaultOrElse) : getDefaultOrElse(m);
|
|
275
90
|
}
|
|
276
91
|
//#endregion
|
|
277
|
-
//#region src/json.ts
|
|
278
|
-
function toFileOption({ update, ...otherOptions }) {
|
|
279
|
-
return {
|
|
280
|
-
...otherOptions,
|
|
281
|
-
update: update == null ? update : (content) => {
|
|
282
|
-
const jsonValue = content === "" ? void 0 : JSON.parse(content);
|
|
283
|
-
return JSON.stringify(update(jsonValue));
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Ensure file is present/absent asynchronously with content value initialized or modified with `update`
|
|
289
|
-
*
|
|
290
|
-
* @param options
|
|
291
|
-
*/
|
|
292
|
-
async function json(options) {
|
|
293
|
-
return file(toFileOption(options));
|
|
294
|
-
}
|
|
295
|
-
/**
|
|
296
|
-
* Ensure file is present/absent synchronously with content value initialized or modified with `update`
|
|
297
|
-
*
|
|
298
|
-
* @param options
|
|
299
|
-
*/
|
|
300
|
-
function jsonSync(options) {
|
|
301
|
-
return fileSync(toFileOption(options));
|
|
302
|
-
}
|
|
303
|
-
//#endregion
|
|
304
92
|
//#region src/meta.ts
|
|
305
93
|
const meta = Object.freeze({
|
|
306
94
|
name: "@w5s/dev",
|
|
307
|
-
version: "3.2
|
|
95
|
+
version: "3.3.2",
|
|
308
96
|
buildNumber: 1
|
|
309
97
|
});
|
|
310
98
|
//#endregion
|
|
@@ -312,265 +100,182 @@ const meta = Object.freeze({
|
|
|
312
100
|
function escapeRegExp(value) {
|
|
313
101
|
return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
|
|
314
102
|
}
|
|
315
|
-
let Project;
|
|
316
|
-
(function(_Project) {
|
|
317
|
-
function ecmaVersion() {
|
|
318
|
-
return 2022;
|
|
319
|
-
}
|
|
320
|
-
_Project.ecmaVersion = ecmaVersion;
|
|
321
|
-
const registry = {
|
|
322
|
-
css: [".css"],
|
|
323
|
-
graphql: [".gql", ".graphql"],
|
|
324
|
-
javascript: [
|
|
325
|
-
".js",
|
|
326
|
-
".cjs",
|
|
327
|
-
".mjs"
|
|
328
|
-
],
|
|
329
|
-
javascriptreact: [".jsx"],
|
|
330
|
-
jpeg: [".jpg", ".jpeg"],
|
|
331
|
-
json: [".json"],
|
|
332
|
-
jsonc: [".jsonc"],
|
|
333
|
-
less: [".less"],
|
|
334
|
-
markdown: [
|
|
335
|
-
".markdown",
|
|
336
|
-
".mdown",
|
|
337
|
-
".mkd",
|
|
338
|
-
".md"
|
|
339
|
-
],
|
|
340
|
-
sass: [".sass"],
|
|
341
|
-
scss: [".scss"],
|
|
342
|
-
typescript: [
|
|
343
|
-
".ts",
|
|
344
|
-
".cts",
|
|
345
|
-
".mts"
|
|
346
|
-
],
|
|
347
|
-
typescriptreact: [".tsx"],
|
|
348
|
-
vue: [".vue"],
|
|
349
|
-
yaml: [".yaml", ".yml"]
|
|
350
|
-
};
|
|
351
|
-
function queryExtensions(languages) {
|
|
352
|
-
return languages.reduce((previousValue, currentValue) => previousValue.concat(registry[currentValue] ?? []), []).sort();
|
|
353
|
-
}
|
|
354
|
-
_Project.queryExtensions = queryExtensions;
|
|
355
|
-
function sourceExtensions() {
|
|
356
|
-
return queryExtensions([
|
|
357
|
-
"javascript",
|
|
358
|
-
"javascriptreact",
|
|
359
|
-
"typescript",
|
|
360
|
-
"typescriptreact"
|
|
361
|
-
]);
|
|
362
|
-
}
|
|
363
|
-
_Project.sourceExtensions = sourceExtensions;
|
|
364
|
-
const RESOURCE_EXTENSIONS = Object.freeze([
|
|
365
|
-
".gif",
|
|
366
|
-
".png",
|
|
367
|
-
".svg",
|
|
368
|
-
...queryExtensions([
|
|
369
|
-
"css",
|
|
370
|
-
"graphql",
|
|
371
|
-
"jpeg",
|
|
372
|
-
"less",
|
|
373
|
-
"sass",
|
|
374
|
-
"sass",
|
|
375
|
-
"yaml"
|
|
376
|
-
])
|
|
377
|
-
]);
|
|
378
|
-
function resourceExtensions() {
|
|
379
|
-
return RESOURCE_EXTENSIONS;
|
|
380
|
-
}
|
|
381
|
-
_Project.resourceExtensions = resourceExtensions;
|
|
382
|
-
const IGNORED = Object.freeze([
|
|
383
|
-
"node_modules/",
|
|
384
|
-
"build/",
|
|
385
|
-
"cjs/",
|
|
386
|
-
"coverage/",
|
|
387
|
-
"dist/",
|
|
388
|
-
"dts/",
|
|
389
|
-
"esm/",
|
|
390
|
-
"lib/",
|
|
391
|
-
"mjs/",
|
|
392
|
-
"umd/"
|
|
393
|
-
]);
|
|
394
|
-
function ignored() {
|
|
395
|
-
return IGNORED;
|
|
396
|
-
}
|
|
397
|
-
_Project.ignored = ignored;
|
|
398
|
-
function extensionsToMatcher(extensions) {
|
|
399
|
-
return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
|
|
400
|
-
}
|
|
401
|
-
_Project.extensionsToMatcher = extensionsToMatcher;
|
|
402
|
-
function extensionsToGlob(extensions) {
|
|
403
|
-
return `*.+(${extensions.map((_) => _.replace(/^\./, "")).join("|")})`;
|
|
404
|
-
}
|
|
405
|
-
_Project.extensionsToGlob = extensionsToGlob;
|
|
406
|
-
})(Project || (Project = {}));
|
|
407
|
-
//#endregion
|
|
408
|
-
//#region src/ProjectScript.ts
|
|
409
103
|
/**
|
|
410
|
-
*
|
|
104
|
+
* Supported ECMA version
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* Project.ecmaVersion() // 2022
|
|
109
|
+
* ```
|
|
411
110
|
*/
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
111
|
+
function ecmaVersion() {
|
|
112
|
+
return 2022;
|
|
113
|
+
}
|
|
114
|
+
const registry = {
|
|
115
|
+
css: [".css"],
|
|
116
|
+
graphql: [".gql", ".graphql"],
|
|
117
|
+
javascript: [
|
|
118
|
+
".js",
|
|
119
|
+
".cjs",
|
|
120
|
+
".mjs"
|
|
121
|
+
],
|
|
122
|
+
javascriptreact: [".jsx"],
|
|
123
|
+
jpeg: [".jpg", ".jpeg"],
|
|
124
|
+
json: [".json"],
|
|
125
|
+
jsonc: [".jsonc"],
|
|
126
|
+
less: [".less"],
|
|
127
|
+
markdown: [
|
|
128
|
+
".markdown",
|
|
129
|
+
".mdown",
|
|
130
|
+
".mkd",
|
|
131
|
+
".md"
|
|
132
|
+
],
|
|
133
|
+
sass: [".sass"],
|
|
134
|
+
scss: [".scss"],
|
|
135
|
+
typescript: [
|
|
136
|
+
".ts",
|
|
137
|
+
".cts",
|
|
138
|
+
".mts"
|
|
139
|
+
],
|
|
140
|
+
typescriptreact: [".tsx"],
|
|
141
|
+
vue: [".vue"],
|
|
142
|
+
yaml: [".yaml", ".yml"]
|
|
428
143
|
};
|
|
429
|
-
//#endregion
|
|
430
|
-
//#region src/exec.ts
|
|
431
144
|
/**
|
|
432
|
-
*
|
|
433
|
-
*
|
|
145
|
+
* Return a list of extensions
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```ts
|
|
149
|
+
* Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]
|
|
150
|
+
* Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']
|
|
151
|
+
* ```
|
|
434
152
|
*
|
|
435
|
-
* @param
|
|
436
|
-
* @param args The arguments to pass to the command
|
|
437
|
-
* @param options
|
|
438
|
-
* @returns A promise that resolves with an object like `{ stdout: string, stderr: string }`
|
|
153
|
+
* @param languages
|
|
439
154
|
*/
|
|
440
|
-
function
|
|
441
|
-
|
|
442
|
-
const encoding = "utf8";
|
|
443
|
-
return {
|
|
444
|
-
stdout: result.stdout.toString(encoding),
|
|
445
|
-
stderr: result.stderr.toString(encoding)
|
|
446
|
-
};
|
|
155
|
+
function queryExtensions(languages) {
|
|
156
|
+
return languages.reduce((previousValue, currentValue) => previousValue.concat(registry[currentValue] ?? []), []).sort();
|
|
447
157
|
}
|
|
448
158
|
/**
|
|
449
|
-
*
|
|
450
|
-
* containing the stdout and stderr strings.
|
|
159
|
+
* Supported file extensions
|
|
451
160
|
*
|
|
452
|
-
* @
|
|
453
|
-
*
|
|
454
|
-
*
|
|
161
|
+
* @example
|
|
162
|
+
* ```ts
|
|
163
|
+
* Project.sourceExtensions() // ['.ts', '.js', ...]
|
|
164
|
+
* ```
|
|
455
165
|
*/
|
|
456
|
-
|
|
457
|
-
return
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
stdout += data.toString(encoding);
|
|
464
|
-
});
|
|
465
|
-
if (child.stderr != null) child.stderr.on("data", (data) => {
|
|
466
|
-
stderr += data.toString(encoding);
|
|
467
|
-
});
|
|
468
|
-
child.on("close", (_code) => {
|
|
469
|
-
resolve({
|
|
470
|
-
stdout,
|
|
471
|
-
stderr
|
|
472
|
-
});
|
|
473
|
-
});
|
|
474
|
-
child.on("error", reject);
|
|
475
|
-
});
|
|
166
|
+
function sourceExtensions() {
|
|
167
|
+
return queryExtensions([
|
|
168
|
+
"javascript",
|
|
169
|
+
"javascriptreact",
|
|
170
|
+
"typescript",
|
|
171
|
+
"typescriptreact"
|
|
172
|
+
]);
|
|
476
173
|
}
|
|
477
|
-
|
|
478
|
-
|
|
174
|
+
const RESOURCE_EXTENSIONS = Object.freeze([
|
|
175
|
+
".gif",
|
|
176
|
+
".png",
|
|
177
|
+
".svg",
|
|
178
|
+
...queryExtensions([
|
|
179
|
+
"css",
|
|
180
|
+
"graphql",
|
|
181
|
+
"jpeg",
|
|
182
|
+
"less",
|
|
183
|
+
"sass",
|
|
184
|
+
"sass",
|
|
185
|
+
"yaml"
|
|
186
|
+
])
|
|
187
|
+
]);
|
|
479
188
|
/**
|
|
480
|
-
*
|
|
189
|
+
* Resource file extensions
|
|
481
190
|
*
|
|
482
|
-
* @param options
|
|
483
191
|
* @example
|
|
484
|
-
*
|
|
485
|
-
*
|
|
486
|
-
*
|
|
487
|
-
* update: (content) => content.replace('node-modules', 'hoisted'),
|
|
488
|
-
* })
|
|
192
|
+
* ```ts
|
|
193
|
+
* Project.resourceExtensions() // ['.css', '.sass', ...]
|
|
194
|
+
* ```
|
|
489
195
|
*/
|
|
490
|
-
function
|
|
491
|
-
|
|
492
|
-
if (state === "present") {
|
|
493
|
-
const { stdout } = execSync("yarn", [
|
|
494
|
-
"config",
|
|
495
|
-
"get",
|
|
496
|
-
String(key)
|
|
497
|
-
]);
|
|
498
|
-
execSync("yarn", [
|
|
499
|
-
"config",
|
|
500
|
-
"set",
|
|
501
|
-
String(key),
|
|
502
|
-
`${update == null ? "" : update(stdout)}`
|
|
503
|
-
]);
|
|
504
|
-
} else execSync("yarn", ["config", "unset"]);
|
|
196
|
+
function resourceExtensions() {
|
|
197
|
+
return RESOURCE_EXTENSIONS;
|
|
505
198
|
}
|
|
199
|
+
const IGNORED = Object.freeze([
|
|
200
|
+
"node_modules/",
|
|
201
|
+
"build/",
|
|
202
|
+
"cjs/",
|
|
203
|
+
"coverage/",
|
|
204
|
+
"dist/",
|
|
205
|
+
"dts/",
|
|
206
|
+
"esm/",
|
|
207
|
+
"lib/",
|
|
208
|
+
"mjs/",
|
|
209
|
+
"umd/"
|
|
210
|
+
]);
|
|
506
211
|
/**
|
|
507
|
-
*
|
|
212
|
+
* Files and folders to always ignore
|
|
508
213
|
*
|
|
509
|
-
* @param options
|
|
510
214
|
* @example
|
|
511
|
-
*
|
|
512
|
-
*
|
|
513
|
-
*
|
|
514
|
-
* update: (content) => content.replace('node-modules', 'hoisted'),
|
|
515
|
-
* })
|
|
215
|
+
* ```ts
|
|
216
|
+
* IGNORED // ['node_modules/', 'build/', ...]
|
|
217
|
+
* ```
|
|
516
218
|
*/
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
if (state === "present") {
|
|
520
|
-
const { stdout } = await exec("yarn", [
|
|
521
|
-
"config",
|
|
522
|
-
"get",
|
|
523
|
-
String(key)
|
|
524
|
-
]);
|
|
525
|
-
await exec("yarn", [
|
|
526
|
-
"config",
|
|
527
|
-
"set",
|
|
528
|
-
String(key),
|
|
529
|
-
`${update == null ? "" : update(stdout)}`
|
|
530
|
-
]);
|
|
531
|
-
} else await exec("yarn", ["config", "unset"]);
|
|
219
|
+
function ignored() {
|
|
220
|
+
return IGNORED;
|
|
532
221
|
}
|
|
533
|
-
//#endregion
|
|
534
|
-
//#region src/yarnVersion.ts
|
|
535
222
|
/**
|
|
536
|
-
*
|
|
223
|
+
* Return a RegExp that will match any list of extensions
|
|
537
224
|
*
|
|
538
|
-
* @param
|
|
225
|
+
* @param extensions
|
|
539
226
|
* @example
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
* })
|
|
227
|
+
* ```ts
|
|
228
|
+
* Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
|
|
229
|
+
* ```
|
|
544
230
|
*/
|
|
545
|
-
function
|
|
546
|
-
|
|
547
|
-
if (state === "present") execSync("yarn", [
|
|
548
|
-
"set",
|
|
549
|
-
"version",
|
|
550
|
-
`${update == null ? "berry" : update()}`
|
|
551
|
-
]);
|
|
552
|
-
else throw new Error("Not implemented");
|
|
231
|
+
function extensionsToMatcher(extensions) {
|
|
232
|
+
return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
|
|
553
233
|
}
|
|
554
234
|
/**
|
|
555
|
-
*
|
|
235
|
+
* Return a glob matcher that will match any list of extensions
|
|
556
236
|
*
|
|
557
|
-
* @param
|
|
237
|
+
* @param extensions
|
|
558
238
|
* @example
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
* })
|
|
239
|
+
* ```ts
|
|
240
|
+
* Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'
|
|
241
|
+
* ```
|
|
563
242
|
*/
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
if (state === "present") await exec("yarn", [
|
|
567
|
-
"set",
|
|
568
|
-
"version",
|
|
569
|
-
`${update == null ? "berry" : update()}`
|
|
570
|
-
]);
|
|
571
|
-
else throw new Error("Not implemented");
|
|
243
|
+
function extensionsToGlob(extensions) {
|
|
244
|
+
return `*.+(${extensions.map((_) => _.replace(/^\./, "")).join("|")})`;
|
|
572
245
|
}
|
|
246
|
+
const Project = Object.freeze({
|
|
247
|
+
ecmaVersion,
|
|
248
|
+
extensionsToGlob,
|
|
249
|
+
extensionsToMatcher,
|
|
250
|
+
ignored,
|
|
251
|
+
queryExtensions,
|
|
252
|
+
resourceExtensions,
|
|
253
|
+
sourceExtensions
|
|
254
|
+
});
|
|
255
|
+
//#endregion
|
|
256
|
+
//#region src/ProjectScript.ts
|
|
257
|
+
/**
|
|
258
|
+
* Project common scripts
|
|
259
|
+
*/
|
|
260
|
+
const ProjectScript = {
|
|
261
|
+
Build: "build",
|
|
262
|
+
Clean: "clean",
|
|
263
|
+
CodeAnalysis: "code-analysis",
|
|
264
|
+
Coverage: "coverage",
|
|
265
|
+
Develop: "develop",
|
|
266
|
+
Docs: "docs",
|
|
267
|
+
Format: "format",
|
|
268
|
+
Install: "install",
|
|
269
|
+
Lint: "lint",
|
|
270
|
+
Prepare: "prepare",
|
|
271
|
+
Release: "release",
|
|
272
|
+
Rescue: "rescue",
|
|
273
|
+
Spellcheck: "spellcheck",
|
|
274
|
+
Test: "test",
|
|
275
|
+
Typecheck: "typecheck",
|
|
276
|
+
Validate: "validate"
|
|
277
|
+
};
|
|
573
278
|
//#endregion
|
|
574
|
-
export { ESLintConfig, Project, ProjectScript,
|
|
279
|
+
export { ESLintConfig, Project, ProjectScript, interopDefault, meta };
|
|
575
280
|
|
|
576
281
|
//# sourceMappingURL=index.js.map
|