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