@w5s/dev 3.1.3 → 3.2.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/dist/index.cjs +543 -364
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +249 -239
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +249 -239
- package/dist/index.js +527 -360
- package/dist/index.js.map +1 -1
- package/package.json +3 -26
- package/src/ESLintConfig.ts +2 -3
- package/src/block.ts +4 -0
- package/src/directory.ts +1 -0
- package/src/exec.ts +5 -5
- package/src/file.ts +3 -1
- package/src/index.ts +1 -0
- package/src/interopDefault.ts +2 -2
- package/src/json.ts +3 -2
- package/src/meta.ts +8 -0
- package/src/yarnConfig.ts +0 -1
- package/src/yarnVersion.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -1,409 +1,576 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
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
|
+
}
|
|
13
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
|
+
*/
|
|
14
26
|
async function directory(options) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
} else if (isPresent) {
|
|
22
|
-
await rm(path, { recursive: true });
|
|
23
|
-
}
|
|
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 });
|
|
24
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
|
+
*/
|
|
25
46
|
function directorySync(options) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
} else if (isPresent) {
|
|
33
|
-
rmSync(path, { recursive: true });
|
|
34
|
-
}
|
|
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 });
|
|
35
52
|
}
|
|
36
|
-
|
|
37
|
-
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/ESLintConfig.ts
|
|
38
55
|
function toArray(value) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (Array.isArray(value)) {
|
|
43
|
-
return value;
|
|
44
|
-
}
|
|
45
|
-
return [value];
|
|
56
|
+
if (value == null) return [];
|
|
57
|
+
if (Array.isArray(value)) return value;
|
|
58
|
+
return [value];
|
|
46
59
|
}
|
|
47
60
|
function concatArray(left, right) {
|
|
48
|
-
|
|
61
|
+
return [...toArray(left), ...toArray(right)];
|
|
49
62
|
}
|
|
50
|
-
|
|
51
|
-
((
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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;
|
|
95
116
|
})(ESLintConfig || (ESLintConfig = {}));
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
+
}
|
|
103
126
|
}
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
127
|
+
function existsSync$1(path) {
|
|
128
|
+
try {
|
|
129
|
+
accessSync(path, constants.F_OK);
|
|
130
|
+
return true;
|
|
131
|
+
} catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
111
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Ensure file is present/absent with content initialized or modified with `update
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
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
|
|
148
|
+
*/
|
|
112
149
|
async function file(options) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
await writeFile(path, newContent, encoding);
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
await rm(path, { force: true });
|
|
123
|
-
}
|
|
150
|
+
const { path, state, update, encoding = "utf8" } = options;
|
|
151
|
+
if (state === "present") {
|
|
152
|
+
const previousContent = await exists(path) ? await readFile(path, encoding) : "";
|
|
153
|
+
const newContent = update == null ? "" : update(previousContent);
|
|
154
|
+
if (newContent != null) await writeFile(path, newContent, encoding);
|
|
155
|
+
} else await rm(path, { force: true });
|
|
124
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Ensure file is present/absent with content initialized or modified with `update
|
|
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
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @param options
|
|
170
|
+
*/
|
|
125
171
|
function fileSync(options) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
writeFileSync(path, newContent, encoding);
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
rmSync(path, { force: true });
|
|
136
|
-
}
|
|
172
|
+
const { path, state, update, encoding = "utf8" } = options;
|
|
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 });
|
|
137
178
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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
|
+
};
|
|
157
199
|
};
|
|
158
200
|
function toFileOptions(options) {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return insertAt(fullContent, lastIndex, EOL + replaceBlock);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
return fullContent + EOL + replaceBlock;
|
|
207
|
-
}
|
|
208
|
-
default: {
|
|
209
|
-
throw new Error(`Unsupported position ${String(positionDirection)}`);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
path,
|
|
215
|
-
state: "present",
|
|
216
|
-
update: (sourceContent) => apply(sourceContent, blockName)
|
|
217
|
-
};
|
|
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
|
+
};
|
|
218
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Replace asynchronously a block in file that follows pattern :
|
|
248
|
+
*
|
|
249
|
+
* marker(markerBegin)
|
|
250
|
+
* ...
|
|
251
|
+
* marker(markerEnd)
|
|
252
|
+
*
|
|
253
|
+
* @param options
|
|
254
|
+
*/
|
|
219
255
|
function block(options) {
|
|
220
|
-
|
|
256
|
+
return file(toFileOptions(options));
|
|
221
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Replace synchronously a block in file that follows pattern :
|
|
260
|
+
*
|
|
261
|
+
* marker(markerBegin)
|
|
262
|
+
* ...
|
|
263
|
+
* marker(markerEnd)
|
|
264
|
+
*
|
|
265
|
+
* @param options
|
|
266
|
+
*/
|
|
222
267
|
function blockSync(options) {
|
|
223
|
-
|
|
268
|
+
return fileSync(toFileOptions(options));
|
|
224
269
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
270
|
+
//#endregion
|
|
271
|
+
//#region src/interopDefault.ts
|
|
272
|
+
const getDefaultOrElse = (_) => _?.default ?? _;
|
|
228
273
|
function interopDefault(m) {
|
|
229
|
-
|
|
274
|
+
return m != null && typeof m.then === "function" ? Promise.resolve(m).then(getDefaultOrElse) : getDefaultOrElse(m);
|
|
230
275
|
}
|
|
231
|
-
|
|
232
|
-
|
|
276
|
+
//#endregion
|
|
277
|
+
//#region src/json.ts
|
|
233
278
|
function toFileOption({ update, ...otherOptions }) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
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
|
+
};
|
|
241
286
|
}
|
|
287
|
+
/**
|
|
288
|
+
* Ensure file is present/absent asynchronously with content value initialized or modified with `update`
|
|
289
|
+
*
|
|
290
|
+
* @param options
|
|
291
|
+
*/
|
|
242
292
|
async function json(options) {
|
|
243
|
-
|
|
293
|
+
return file(toFileOption(options));
|
|
244
294
|
}
|
|
295
|
+
/**
|
|
296
|
+
* Ensure file is present/absent synchronously with content value initialized or modified with `update`
|
|
297
|
+
*
|
|
298
|
+
* @param options
|
|
299
|
+
*/
|
|
245
300
|
function jsonSync(options) {
|
|
246
|
-
|
|
301
|
+
return fileSync(toFileOption(options));
|
|
247
302
|
}
|
|
248
|
-
|
|
249
|
-
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region src/meta.ts
|
|
305
|
+
const meta = Object.freeze({
|
|
306
|
+
name: "@w5s/dev",
|
|
307
|
+
version: "3.2.0",
|
|
308
|
+
buildNumber: 1
|
|
309
|
+
});
|
|
310
|
+
//#endregion
|
|
311
|
+
//#region src/Project.ts
|
|
250
312
|
function escapeRegExp(value) {
|
|
251
|
-
|
|
313
|
+
return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
|
|
252
314
|
}
|
|
253
|
-
|
|
254
|
-
((
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
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;
|
|
321
406
|
})(Project || (Project = {}));
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
407
|
+
//#endregion
|
|
408
|
+
//#region src/ProjectScript.ts
|
|
409
|
+
/**
|
|
410
|
+
* Project common scripts
|
|
411
|
+
*/
|
|
412
|
+
const ProjectScript = {
|
|
413
|
+
Build: "build",
|
|
414
|
+
Clean: "clean",
|
|
415
|
+
CodeAnalysis: "code-analysis",
|
|
416
|
+
Coverage: "coverage",
|
|
417
|
+
Develop: "develop",
|
|
418
|
+
Docs: "docs",
|
|
419
|
+
Format: "format",
|
|
420
|
+
Install: "install",
|
|
421
|
+
Lint: "lint",
|
|
422
|
+
Prepare: "prepare",
|
|
423
|
+
Release: "release",
|
|
424
|
+
Rescue: "rescue",
|
|
425
|
+
Spellcheck: "spellcheck",
|
|
426
|
+
Test: "test",
|
|
427
|
+
Validate: "validate"
|
|
340
428
|
};
|
|
429
|
+
//#endregion
|
|
430
|
+
//#region src/exec.ts
|
|
431
|
+
/**
|
|
432
|
+
* Runs a command in a shell and returns a promise that resolves with an object
|
|
433
|
+
* containing the stdout and stderr strings.
|
|
434
|
+
*
|
|
435
|
+
* @param command The command to run
|
|
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 }`
|
|
439
|
+
*/
|
|
341
440
|
function execSync(command, args, options) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
441
|
+
const result = spawnSync(command, args, { ...options });
|
|
442
|
+
const encoding = "utf8";
|
|
443
|
+
return {
|
|
444
|
+
stdout: result.stdout.toString(encoding),
|
|
445
|
+
stderr: result.stderr.toString(encoding)
|
|
446
|
+
};
|
|
345
447
|
}
|
|
448
|
+
/**
|
|
449
|
+
* Runs a command in a shell and returns a promise that resolves with an object
|
|
450
|
+
* containing the stdout and stderr strings.
|
|
451
|
+
*
|
|
452
|
+
* @param command The command to run
|
|
453
|
+
* @param args The arguments to pass to the command
|
|
454
|
+
* @param options
|
|
455
|
+
*/
|
|
346
456
|
async function exec(command, args, options) {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
});
|
|
457
|
+
return new Promise((resolve, reject) => {
|
|
458
|
+
const encoding = "utf8";
|
|
459
|
+
const child = spawn(command, args, { ...options });
|
|
460
|
+
let stdout = "";
|
|
461
|
+
let stderr = "";
|
|
462
|
+
if (child.stdout != null) child.stdout.on("data", (data) => {
|
|
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
|
+
});
|
|
367
476
|
}
|
|
368
|
-
|
|
369
|
-
|
|
477
|
+
//#endregion
|
|
478
|
+
//#region src/yarnConfig.ts
|
|
479
|
+
/**
|
|
480
|
+
* Synchronous version of {@link yarnConfig}
|
|
481
|
+
*
|
|
482
|
+
* @param options
|
|
483
|
+
* @example
|
|
484
|
+
* yarnConfigSync({
|
|
485
|
+
* key: 'nodeLinker',
|
|
486
|
+
* state: 'present',
|
|
487
|
+
* update: (content) => content.replace('node-modules', 'hoisted'),
|
|
488
|
+
* })
|
|
489
|
+
*/
|
|
370
490
|
function yarnConfigSync(options) {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
491
|
+
const { key, state, update } = options;
|
|
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"]);
|
|
378
505
|
}
|
|
506
|
+
/**
|
|
507
|
+
* Set/Unset yarn configuration value
|
|
508
|
+
*
|
|
509
|
+
* @param options
|
|
510
|
+
* @example
|
|
511
|
+
* await yarnConfig({
|
|
512
|
+
* key: 'nodeLinker',
|
|
513
|
+
* state: 'present',
|
|
514
|
+
* update: (content) => content.replace('node-modules', 'hoisted'),
|
|
515
|
+
* })
|
|
516
|
+
*/
|
|
379
517
|
async function yarnConfig(options) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
518
|
+
const { key, state, update } = options;
|
|
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"]);
|
|
387
532
|
}
|
|
388
|
-
|
|
389
|
-
|
|
533
|
+
//#endregion
|
|
534
|
+
//#region src/yarnVersion.ts
|
|
535
|
+
/**
|
|
536
|
+
* Synchronous version of {@link yarnVersion}
|
|
537
|
+
*
|
|
538
|
+
* @param options
|
|
539
|
+
* @example
|
|
540
|
+
* yarnVersionSync({
|
|
541
|
+
* state: 'present',
|
|
542
|
+
* update: () => 'berry', // or 'classic'
|
|
543
|
+
* })
|
|
544
|
+
*/
|
|
390
545
|
function yarnVersionSync(options) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
546
|
+
const { state, update } = options;
|
|
547
|
+
if (state === "present") execSync("yarn", [
|
|
548
|
+
"set",
|
|
549
|
+
"version",
|
|
550
|
+
`${update == null ? "berry" : update()}`
|
|
551
|
+
]);
|
|
552
|
+
else throw new Error("Not implemented");
|
|
397
553
|
}
|
|
554
|
+
/**
|
|
555
|
+
* Set/Unset yarn configuration value
|
|
556
|
+
*
|
|
557
|
+
* @param options
|
|
558
|
+
* @example
|
|
559
|
+
* await yarnVersion({
|
|
560
|
+
* state: 'present',
|
|
561
|
+
* update: () => 'berry', // or 'classic'
|
|
562
|
+
* })
|
|
563
|
+
*/
|
|
398
564
|
async function yarnVersion(options) {
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
565
|
+
const { state, update } = options;
|
|
566
|
+
if (state === "present") await exec("yarn", [
|
|
567
|
+
"set",
|
|
568
|
+
"version",
|
|
569
|
+
`${update == null ? "berry" : update()}`
|
|
570
|
+
]);
|
|
571
|
+
else throw new Error("Not implemented");
|
|
405
572
|
}
|
|
573
|
+
//#endregion
|
|
574
|
+
export { ESLintConfig, Project, ProjectScript, block, blockSync, directory, directorySync, file, fileSync, interopDefault, json, jsonSync, meta, yarnConfig, yarnConfigSync, yarnVersion, yarnVersionSync };
|
|
406
575
|
|
|
407
|
-
export { ESLintConfig, Project, ProjectScript, block, blockSync, directory, directorySync, file, fileSync, interopDefault, json, jsonSync, yarnConfig, yarnConfigSync, yarnVersion, yarnVersionSync };
|
|
408
|
-
//# sourceMappingURL=index.js.map
|
|
409
576
|
//# sourceMappingURL=index.js.map
|