@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.js CHANGED
@@ -1,409 +1,576 @@
1
- import { existsSync, mkdirSync, rmSync, readFileSync, writeFileSync, constants as constants$1, accessSync } from 'fs';
2
- import { mkdir, rm, readFile, writeFile, access, constants } from 'fs/promises';
3
- import { spawnSync, spawn } from 'child_process';
4
-
5
- // src/directory.ts
6
- async function exists(path) {
7
- try {
8
- await access(path, constants.F_OK);
9
- return true;
10
- } catch {
11
- return false;
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
- const { path, state } = options;
16
- const isPresent = await exists(path);
17
- if (state === "present") {
18
- if (!isPresent) {
19
- await mkdir(path, { recursive: true });
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
- const { path, state } = options;
27
- const isPresent = existsSync(path);
28
- if (state === "present") {
29
- if (!isPresent) {
30
- mkdirSync(path, { recursive: true });
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
- // src/ESLintConfig.ts
53
+ //#endregion
54
+ //#region src/ESLintConfig.ts
38
55
  function toArray(value) {
39
- if (value == null) {
40
- return [];
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
- return [...toArray(left), ...toArray(right)];
61
+ return [...toArray(left), ...toArray(right)];
49
62
  }
50
- var ESLintConfig;
51
- ((ESLintConfig2) => {
52
- function concat(...configs) {
53
- return configs.reduce(
54
- (returnValue, config) => ({
55
- ...returnValue,
56
- ...config,
57
- env: { ...returnValue.env, ...config.env },
58
- extends: concatArray(returnValue.extends, config.extends),
59
- globals: { ...returnValue.globals, ...config.globals },
60
- overrides: concatArray(returnValue.overrides, config.overrides),
61
- parserOptions: { ...returnValue.parserOptions, ...config.parserOptions },
62
- plugins: concatArray(returnValue.plugins, config.plugins),
63
- rules: { ...returnValue.rules, ...config.rules },
64
- settings: { ...returnValue.settings, ...config.settings }
65
- }),
66
- {
67
- env: {},
68
- extends: [],
69
- globals: {},
70
- overrides: [],
71
- parserOptions: {},
72
- plugins: [],
73
- rules: {},
74
- settings: {}
75
- }
76
- );
77
- }
78
- ESLintConfig2.concat = concat;
79
- function fixme(_status) {
80
- return "off";
81
- }
82
- ESLintConfig2.fixme = fixme;
83
- function renameRules(rules, map) {
84
- return Object.fromEntries(
85
- Object.entries(rules).map(([key, value]) => {
86
- for (const [from, to] of Object.entries(map)) {
87
- if (key.startsWith(`${from}/`)) return [to + key.slice(from.length), value];
88
- else if (from === "" && !key.includes("/") && to !== "") return [to + key, value];
89
- }
90
- return [key, value];
91
- })
92
- );
93
- }
94
- ESLintConfig2.renameRules = renameRules;
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
- async function exists2(path) {
97
- try {
98
- await access(path, constants$1.F_OK);
99
- return true;
100
- } catch {
101
- return false;
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 existsSync2(path) {
105
- try {
106
- accessSync(path, constants$1.F_OK);
107
- return true;
108
- } catch {
109
- return false;
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
- const { path, state, update, encoding = "utf8" } = options;
114
- if (state === "present") {
115
- const isPresent = await exists2(path);
116
- const previousContent = isPresent ? await readFile(path, encoding) : "";
117
- const newContent = update == null ? "" : update(previousContent);
118
- if (newContent != null) {
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
- const { path, state, update, encoding = "utf8" } = options;
127
- if (state === "present") {
128
- const isPresent = existsSync2(path);
129
- const previousContent = isPresent ? readFileSync(path, encoding) : "";
130
- const newContent = update == null ? "" : update(previousContent);
131
- if (newContent != null) {
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
- // src/block.ts
140
- var EOF = "EndOfFile";
141
- var BOF = "BeginningOfFile";
142
- var insertAt = (str, index, toInsert) => str.slice(0, index) + toInsert + str.slice(index);
143
- var matchLast = (string, regexp) => {
144
- const matcher = new RegExp(regexp.source, `${regexp.flags}g`);
145
- let firstIndex = -1;
146
- let lastIndex = -1;
147
- let matches;
148
- while (true) {
149
- matches = matcher.exec(string);
150
- if (matches == null) {
151
- break;
152
- }
153
- firstIndex = matches.index;
154
- lastIndex = matcher.lastIndex;
155
- }
156
- return { firstIndex, lastIndex };
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
- const {
160
- marker = (mark) => `# ${mark.toUpperCase()} MANAGED BLOCK`,
161
- path,
162
- block: blockName,
163
- insertPosition = ["after", EOF],
164
- state = "present"
165
- } = options;
166
- const EOL = "\n";
167
- const beginBlock = marker("Begin");
168
- const endBlock = marker("End");
169
- function findBlock(content) {
170
- const startIndex = content.indexOf(beginBlock);
171
- const endIndex = content.indexOf(endBlock) + endBlock.length;
172
- return {
173
- endIndex,
174
- exists: startIndex !== -1 && endIndex >= 0,
175
- startIndex
176
- };
177
- }
178
- function apply(fullContent, blockContent) {
179
- const found = findBlock(fullContent);
180
- const remove = state === "absent";
181
- const replaceBlock = remove ? "" : beginBlock + EOL + blockContent + EOL + endBlock;
182
- const [positionDirection, positionAnchor] = insertPosition;
183
- if (found.exists) {
184
- return fullContent.slice(0, found.startIndex) + replaceBlock + fullContent.slice(found.endIndex);
185
- }
186
- if (remove) {
187
- return fullContent;
188
- }
189
- switch (positionDirection) {
190
- case "before": {
191
- if (positionAnchor !== BOF) {
192
- const { firstIndex } = matchLast(fullContent, positionAnchor);
193
- if (firstIndex >= 0) {
194
- return insertAt(fullContent, firstIndex, replaceBlock + EOL);
195
- }
196
- }
197
- return replaceBlock + EOL + fullContent;
198
- }
199
- case "after": {
200
- if (positionAnchor !== EOF) {
201
- const { lastIndex } = matchLast(fullContent, positionAnchor);
202
- if (lastIndex >= 0) {
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
- return file(toFileOptions(options));
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
- return fileSync(toFileOptions(options));
268
+ return fileSync(toFileOptions(options));
224
269
  }
225
-
226
- // src/interopDefault.ts
227
- var getDefaultOrElse = (_) => _?.default ?? _;
270
+ //#endregion
271
+ //#region src/interopDefault.ts
272
+ const getDefaultOrElse = (_) => _?.default ?? _;
228
273
  function interopDefault(m) {
229
- return m != null && typeof m.then === "function" ? Promise.resolve(m).then(getDefaultOrElse) : getDefaultOrElse(m);
274
+ return m != null && typeof m.then === "function" ? Promise.resolve(m).then(getDefaultOrElse) : getDefaultOrElse(m);
230
275
  }
231
-
232
- // src/json.ts
276
+ //#endregion
277
+ //#region src/json.ts
233
278
  function toFileOption({ update, ...otherOptions }) {
234
- return {
235
- ...otherOptions,
236
- update: update == null ? update : (content) => {
237
- const jsonValue = content === "" ? void 0 : JSON.parse(content);
238
- return JSON.stringify(update(jsonValue));
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
- return file(toFileOption(options));
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
- return fileSync(toFileOption(options));
301
+ return fileSync(toFileOption(options));
247
302
  }
248
-
249
- // src/Project.ts
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
- return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
313
+ return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
252
314
  }
253
- var Project;
254
- ((Project2) => {
255
- function ecmaVersion() {
256
- return 2022;
257
- }
258
- Project2.ecmaVersion = ecmaVersion;
259
- const registry = {
260
- css: [".css"],
261
- graphql: [".gql", ".graphql"],
262
- javascript: [".js", ".cjs", ".mjs"],
263
- javascriptreact: [".jsx"],
264
- jpeg: [".jpg", ".jpeg"],
265
- json: [".json"],
266
- jsonc: [".jsonc"],
267
- less: [".less"],
268
- markdown: [".markdown", ".mdown", ".mkd", ".md"],
269
- sass: [".sass"],
270
- scss: [".scss"],
271
- typescript: [".ts", ".cts", ".mts"],
272
- typescriptreact: [".tsx"],
273
- vue: [".vue"],
274
- yaml: [".yaml", ".yml"]
275
- };
276
- function queryExtensions(languages) {
277
- return languages.reduce((previousValue, currentValue) => (
278
- // eslint-disable-next-line unicorn/prefer-spread
279
- previousValue.concat(registry[currentValue] ?? [])
280
- ), []).sort();
281
- }
282
- Project2.queryExtensions = queryExtensions;
283
- function sourceExtensions() {
284
- return queryExtensions(["javascript", "javascriptreact", "typescript", "typescriptreact"]);
285
- }
286
- Project2.sourceExtensions = sourceExtensions;
287
- const RESOURCE_EXTENSIONS = Object.freeze([
288
- ".gif",
289
- ".png",
290
- ".svg",
291
- ...queryExtensions(["css", "graphql", "jpeg", "less", "sass", "sass", "yaml"])
292
- ]);
293
- function resourceExtensions() {
294
- return RESOURCE_EXTENSIONS;
295
- }
296
- Project2.resourceExtensions = resourceExtensions;
297
- const IGNORED = Object.freeze([
298
- "node_modules/",
299
- "build/",
300
- "cjs/",
301
- "coverage/",
302
- "dist/",
303
- "dts/",
304
- "esm/",
305
- "lib/",
306
- "mjs/",
307
- "umd/"
308
- ]);
309
- function ignored() {
310
- return IGNORED;
311
- }
312
- Project2.ignored = ignored;
313
- function extensionsToMatcher(extensions) {
314
- return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
315
- }
316
- Project2.extensionsToMatcher = extensionsToMatcher;
317
- function extensionsToGlob(extensions) {
318
- return `*.+(${extensions.map((_) => _.replace(/^\./, "")).join("|")})`;
319
- }
320
- Project2.extensionsToGlob = extensionsToGlob;
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
- // src/ProjectScript.ts
324
- var ProjectScript = {
325
- Build: "build",
326
- Clean: "clean",
327
- CodeAnalysis: "code-analysis",
328
- Coverage: "coverage",
329
- Develop: "develop",
330
- Docs: "docs",
331
- Format: "format",
332
- Install: "install",
333
- Lint: "lint",
334
- Prepare: "prepare",
335
- Release: "release",
336
- Rescue: "rescue",
337
- Spellcheck: "spellcheck",
338
- Test: "test",
339
- Validate: "validate"
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
- const result = spawnSync(command, args, { ...options });
343
- const encoding = "utf8";
344
- return { stdout: result.stdout.toString(encoding), stderr: result.stderr.toString(encoding) };
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
- return new Promise((resolve, reject) => {
348
- const encoding = "utf8";
349
- const child = spawn(command, args, { ...options });
350
- let stdout = "";
351
- let stderr = "";
352
- if (child.stdout != null) {
353
- child.stdout.on("data", (data) => {
354
- stdout += data.toString(encoding);
355
- });
356
- }
357
- if (child.stderr != null) {
358
- child.stderr.on("data", (data) => {
359
- stderr += data.toString(encoding);
360
- });
361
- }
362
- child.on("close", (_code) => {
363
- resolve({ stdout, stderr });
364
- });
365
- child.on("error", reject);
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
- // src/yarnConfig.ts
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
- const { key, state, update } = options;
372
- if (state === "present") {
373
- const { stdout } = execSync("yarn", ["config", "get", String(key)]);
374
- execSync("yarn", ["config", "set", String(key), `${update == null ? "" : update(stdout)}`]);
375
- } else {
376
- execSync("yarn", ["config", "unset"]);
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
- const { key, state, update } = options;
381
- if (state === "present") {
382
- const { stdout } = await exec("yarn", ["config", "get", String(key)]);
383
- await exec("yarn", ["config", "set", String(key), `${update == null ? "" : update(stdout)}`]);
384
- } else {
385
- await exec("yarn", ["config", "unset"]);
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
- // src/yarnVersion.ts
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
- const { state, update } = options;
392
- if (state === "present") {
393
- execSync("yarn", ["set", "version", `${update == null ? "berry" : update()}`]);
394
- } else {
395
- throw new Error("Not implemented");
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
- const { state, update } = options;
400
- if (state === "present") {
401
- await exec("yarn", ["set", "version", `${update == null ? "berry" : update()}`]);
402
- } else {
403
- throw new Error("Not implemented");
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