@w5s/configurator-core 1.0.0-alpha.8 → 1.0.0-alpha.9

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 CHANGED
@@ -1,6 +1,30 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
2
24
  let node_fs = require("node:fs");
3
25
  let node_fs_promises = require("node:fs/promises");
26
+ let yaml = require("yaml");
27
+ yaml = __toESM(yaml, 1);
4
28
  let node_child_process = require("node:child_process");
5
29
  //#region src/__exists.ts
6
30
  async function __exists(path) {
@@ -12,14 +36,6 @@ async function __exists(path) {
12
36
  }
13
37
  }
14
38
  //#endregion
15
- //#region src/__toMode.ts
16
- function toModeFlag(permissionSet, read, write, execute) {
17
- return (permissionSet?.read === true ? read : 0) | (permissionSet?.write === true ? write : 0) | (permissionSet?.execute === true ? execute : 0);
18
- }
19
- function __toMode(mode) {
20
- return mode == null ? mode : toModeFlag(mode.owner, 256, 128, 64) | toModeFlag(mode.group, 32, 16, 8) | toModeFlag(mode.other, 4, 2, 1);
21
- }
22
- //#endregion
23
39
  //#region src/__existsSync.ts
24
40
  function __existsSync(path) {
25
41
  try {
@@ -30,66 +46,12 @@ function __existsSync(path) {
30
46
  }
31
47
  }
32
48
  //#endregion
33
- //#region src/directory.ts
34
- /**
35
- * Ensure directory is present/absent
36
- *
37
- * @example
38
- * ```ts
39
- * await directory({
40
- * path: 'foo/bar',
41
- * state: 'present',
42
- * mode: {
43
- * owner: { read: true, write: true, execute: true },
44
- * group: { read: true, write: true, execute: true },
45
- * other: { read: true, write: true, execute: true },
46
- * },
47
- * })
48
- * ```
49
- *
50
- * @param options
51
- */
52
- async function directory(options) {
53
- const { path, state, mode } = options;
54
- const isPresent = await __exists(path);
55
- if (state === "present") {
56
- const newMode = __toMode(mode);
57
- if (!isPresent) await (0, node_fs_promises.mkdir)(path, {
58
- recursive: true,
59
- mode: newMode
60
- });
61
- if (newMode != null && isPresent) await (0, node_fs_promises.chmod)(path, newMode);
62
- } else if (isPresent) await (0, node_fs_promises.rm)(path, { recursive: true });
49
+ //#region src/__toMode.ts
50
+ function __toMode(mode) {
51
+ return mode == null ? mode : toModeFlag(mode.owner, 256, 128, 64) | toModeFlag(mode.group, 32, 16, 8) | toModeFlag(mode.other, 4, 2, 1);
63
52
  }
64
- /**
65
- * Ensure directory is present/absent
66
- *
67
- * @example
68
- * ```ts
69
- * directorySync({
70
- * path: 'foo/bar',
71
- * state: 'present',
72
- * mode: {
73
- * owner: { read: true, write: true, execute: true },
74
- * group: { read: true, write: true, execute: true },
75
- * other: { read: true, write: true, execute: true },
76
- * },
77
- * })
78
- * ```
79
- *
80
- * @param options
81
- */
82
- function directorySync(options) {
83
- const { path, state, mode } = options;
84
- const isPresent = __existsSync(path);
85
- if (state === "present") {
86
- const newMode = __toMode(mode);
87
- if (!isPresent) (0, node_fs.mkdirSync)(path, {
88
- recursive: true,
89
- mode: newMode
90
- });
91
- if (newMode != null && isPresent) (0, node_fs.chmodSync)(path, newMode);
92
- } else if (isPresent) (0, node_fs.rmSync)(path, { recursive: true });
53
+ function toModeFlag(permissionSet, read, write, execute) {
54
+ return (permissionSet?.read === true ? read : 0) | (permissionSet?.write === true ? write : 0) | (permissionSet?.execute === true ? execute : 0);
93
55
  }
94
56
  //#endregion
95
57
  //#region src/file.ts
@@ -113,7 +75,7 @@ function directorySync(options) {
113
75
  * @param options
114
76
  */
115
77
  async function file(options) {
116
- const { path, state, update, encoding = "utf8", mode } = options;
78
+ const { encoding = "utf8", mode, path, state, update } = options;
117
79
  if (state === "present") {
118
80
  const isPresent = await __exists(path);
119
81
  const previousContent = isPresent ? await (0, node_fs_promises.readFile)(path, encoding) : "";
@@ -146,7 +108,7 @@ async function file(options) {
146
108
  * @param options
147
109
  */
148
110
  function fileSync(options) {
149
- const { path, state, update, encoding = "utf8", mode } = options;
111
+ const { encoding = "utf8", mode, path, state, update } = options;
150
112
  if (state === "present") {
151
113
  const isPresent = __existsSync(path);
152
114
  const previousContent = isPresent ? (0, node_fs.readFileSync)(path, encoding) : "";
@@ -180,8 +142,32 @@ const matchLast = (string, regexp) => {
180
142
  lastIndex
181
143
  };
182
144
  };
145
+ /**
146
+ * Replace asynchronously a block in file that follows pattern :
147
+ *
148
+ * marker(markerBegin)
149
+ * ...
150
+ * marker(markerEnd)
151
+ *
152
+ * @param options
153
+ */
154
+ function block(options) {
155
+ return file(toFileOptions(options));
156
+ }
157
+ /**
158
+ * Replace synchronously a block in file that follows pattern :
159
+ *
160
+ * marker(markerBegin)
161
+ * ...
162
+ * marker(markerEnd)
163
+ *
164
+ * @param options
165
+ */
166
+ function blockSync(options) {
167
+ return fileSync(toFileOptions(options));
168
+ }
183
169
  function toFileOptions(options) {
184
- const { marker = (mark) => `# ${mark.toUpperCase()} MANAGED BLOCK`, path, block: blockName, insertPosition = ["after", EOF], state = "present" } = options;
170
+ const { block: blockName, insertPosition = ["after", EOF], marker = (mark) => `# ${mark.toUpperCase()} MANAGED BLOCK`, path, state = "present" } = options;
185
171
  const EOL = "\n";
186
172
  const beginBlock = marker("Begin");
187
173
  const endBlock = marker("End");
@@ -205,18 +191,18 @@ function toFileOptions(options) {
205
191
  if (found.exists) return fullContent.slice(0, found.startIndex) + replaceBlock + fullContent.slice(found.endIndex);
206
192
  if (remove) return fullContent;
207
193
  switch (positionDirection) {
208
- case "before":
209
- if (positionAnchor !== BOF) {
210
- const { firstIndex } = matchLast(fullContent, positionAnchor);
211
- if (firstIndex >= 0) return insertAt(fullContent, firstIndex, replaceBlock + EOL);
212
- }
213
- return replaceBlock + EOL + fullContent;
214
194
  case "after":
215
195
  if (positionAnchor !== EOF) {
216
196
  const { lastIndex } = matchLast(fullContent, positionAnchor);
217
197
  if (lastIndex >= 0) return insertAt(fullContent, lastIndex, EOL + replaceBlock);
218
198
  }
219
199
  return fullContent + EOL + replaceBlock;
200
+ case "before":
201
+ if (positionAnchor !== BOF) {
202
+ const { firstIndex } = matchLast(fullContent, positionAnchor);
203
+ if (firstIndex >= 0) return insertAt(fullContent, firstIndex, replaceBlock + EOL);
204
+ }
205
+ return replaceBlock + EOL + fullContent;
220
206
  default: throw new Error(`Unsupported position ${String(positionDirection)}`);
221
207
  }
222
208
  }
@@ -226,42 +212,70 @@ function toFileOptions(options) {
226
212
  update: (sourceContent) => apply(sourceContent, blockName)
227
213
  };
228
214
  }
215
+ //#endregion
216
+ //#region src/directory.ts
229
217
  /**
230
- * Replace asynchronously a block in file that follows pattern :
218
+ * Ensure directory is present/absent
231
219
  *
232
- * marker(markerBegin)
233
- * ...
234
- * marker(markerEnd)
220
+ * @example
221
+ * ```ts
222
+ * await directory({
223
+ * path: 'foo/bar',
224
+ * state: 'present',
225
+ * mode: {
226
+ * owner: { read: true, write: true, execute: true },
227
+ * group: { read: true, write: true, execute: true },
228
+ * other: { read: true, write: true, execute: true },
229
+ * },
230
+ * })
231
+ * ```
235
232
  *
236
233
  * @param options
237
234
  */
238
- function block(options) {
239
- return file(toFileOptions(options));
235
+ async function directory(options) {
236
+ const { mode, path, state } = options;
237
+ const isPresent = await __exists(path);
238
+ if (state === "present") {
239
+ const newMode = __toMode(mode);
240
+ if (!isPresent) await (0, node_fs_promises.mkdir)(path, {
241
+ mode: newMode,
242
+ recursive: true
243
+ });
244
+ if (newMode != null && isPresent) await (0, node_fs_promises.chmod)(path, newMode);
245
+ } else if (isPresent) await (0, node_fs_promises.rm)(path, { recursive: true });
240
246
  }
241
247
  /**
242
- * Replace synchronously a block in file that follows pattern :
248
+ * Ensure directory is present/absent
243
249
  *
244
- * marker(markerBegin)
245
- * ...
246
- * marker(markerEnd)
250
+ * @example
251
+ * ```ts
252
+ * directorySync({
253
+ * path: 'foo/bar',
254
+ * state: 'present',
255
+ * mode: {
256
+ * owner: { read: true, write: true, execute: true },
257
+ * group: { read: true, write: true, execute: true },
258
+ * other: { read: true, write: true, execute: true },
259
+ * },
260
+ * })
261
+ * ```
247
262
  *
248
263
  * @param options
249
264
  */
250
- function blockSync(options) {
251
- return fileSync(toFileOptions(options));
265
+ function directorySync(options) {
266
+ const { mode, path, state } = options;
267
+ const isPresent = __existsSync(path);
268
+ if (state === "present") {
269
+ const newMode = __toMode(mode);
270
+ if (!isPresent) (0, node_fs.mkdirSync)(path, {
271
+ mode: newMode,
272
+ recursive: true
273
+ });
274
+ if (newMode != null && isPresent) (0, node_fs.chmodSync)(path, newMode);
275
+ } else if (isPresent) (0, node_fs.rmSync)(path, { recursive: true });
252
276
  }
253
277
  //#endregion
254
278
  //#region src/ignoreFile.ts
255
- function toFileOption$1({ update, ...otherOptions }) {
256
- return {
257
- ...otherOptions,
258
- update: update == null ? update : (content) => {
259
- const eol = content.includes("\r\n") ? "\r\n" : "\n";
260
- const updatedLines = update(content === "" ? void 0 : content.split(eol));
261
- return updatedLines == null ? void 0 : updatedLines.join(eol);
262
- }
263
- };
264
- }
265
279
  /**
266
280
  * Ensure file is present/absent asynchronously with content initialized or modified by line.
267
281
  *
@@ -275,7 +289,7 @@ function toFileOption$1({ update, ...otherOptions }) {
275
289
  * @param options File target options.
276
290
  */
277
291
  async function ignoreFile(options) {
278
- return file(toFileOption$1(options));
292
+ return file(toFileOption$2(options));
279
293
  }
280
294
  /**
281
295
  * Ensure file is present/absent synchronously with content initialized or modified by line.
@@ -290,26 +304,27 @@ async function ignoreFile(options) {
290
304
  * @param options File target options.
291
305
  */
292
306
  function ignoreFileSync(options) {
293
- return fileSync(toFileOption$1(options));
307
+ return fileSync(toFileOption$2(options));
294
308
  }
295
- //#endregion
296
- //#region src/json.ts
297
- function toFileOption({ update, ...otherOptions }) {
309
+ function toFileOption$2({ update, ...otherOptions }) {
298
310
  return {
299
311
  ...otherOptions,
300
312
  update: update == null ? update : (content) => {
301
- const jsonValue = content === "" ? void 0 : JSON.parse(content);
302
- return JSON.stringify(update(jsonValue));
313
+ const eol = content.includes("\r\n") ? "\r\n" : "\n";
314
+ const updatedLines = update(content === "" ? void 0 : content.split(eol));
315
+ return updatedLines == null ? void 0 : updatedLines.join(eol);
303
316
  }
304
317
  };
305
318
  }
319
+ //#endregion
320
+ //#region src/json.ts
306
321
  /**
307
322
  * Ensure file is present/absent asynchronously with content value initialized or modified with `update`
308
323
  *
309
324
  * @param options
310
325
  */
311
326
  async function json(options) {
312
- return file(toFileOption(options));
327
+ return file(toFileOption$1(options));
313
328
  }
314
329
  /**
315
330
  * Ensure file is present/absent synchronously with content value initialized or modified with `update`
@@ -317,34 +332,53 @@ async function json(options) {
317
332
  * @param options
318
333
  */
319
334
  function jsonSync(options) {
320
- return fileSync(toFileOption(options));
335
+ return fileSync(toFileOption$1(options));
336
+ }
337
+ function toFileOption$1({ update, ...otherOptions }) {
338
+ return {
339
+ ...otherOptions,
340
+ update: update == null ? update : (content) => {
341
+ const jsonValue = content === "" ? void 0 : JSON.parse(content);
342
+ return JSON.stringify(update(jsonValue));
343
+ }
344
+ };
321
345
  }
322
346
  //#endregion
323
347
  //#region src/meta.ts
324
348
  const meta = Object.freeze({
349
+ buildNumber: 1,
325
350
  name: "@w5s/configurator-core",
326
- version: "1.0.0-alpha.8",
327
- buildNumber: 1
351
+ version: "1.0.0-alpha.9"
328
352
  });
329
353
  //#endregion
330
- //#region src/exec.ts
354
+ //#region src/yaml.ts
331
355
  /**
332
- * Runs a command in a shell and returns a promise that resolves with an object
333
- * containing the stdout and stderr strings.
356
+ * Ensure file is present/absent asynchronously with content value initialized or modified with `update`
334
357
  *
335
- * @param command The command to run
336
- * @param args The arguments to pass to the command
337
358
  * @param options
338
- * @returns A promise that resolves with an object like `{ stdout: string, stderr: string }`
339
359
  */
340
- function execSync(command, args, options) {
341
- const result = (0, node_child_process.spawnSync)(command, args, { ...options });
342
- const encoding = "utf8";
360
+ async function yaml$1(options) {
361
+ return file(toFileOption(options));
362
+ }
363
+ /**
364
+ * Ensure file is present/absent synchronously with content value initialized or modified with `update`
365
+ *
366
+ * @param options
367
+ */
368
+ function yamlSync(options) {
369
+ return fileSync(toFileOption(options));
370
+ }
371
+ function toFileOption({ update, ...otherOptions }) {
343
372
  return {
344
- stdout: result.stdout.toString(encoding),
345
- stderr: result.stderr.toString(encoding)
373
+ ...otherOptions,
374
+ update: update == null ? update : (content) => {
375
+ const yamlValue = content === "" ? void 0 : yaml.default.parse(content);
376
+ return yaml.default.stringify(update(yamlValue));
377
+ }
346
378
  };
347
379
  }
380
+ //#endregion
381
+ //#region src/exec.ts
348
382
  /**
349
383
  * Runs a command in a shell and returns a promise that resolves with an object
350
384
  * containing the stdout and stderr strings.
@@ -367,84 +401,101 @@ async function exec(command, args, options) {
367
401
  });
368
402
  child.on("close", (_code) => {
369
403
  resolve({
370
- stdout,
371
- stderr
404
+ stderr,
405
+ stdout
372
406
  });
373
407
  });
374
408
  child.on("error", reject);
375
409
  });
376
410
  }
411
+ /**
412
+ * Runs a command in a shell and returns a promise that resolves with an object
413
+ * containing the stdout and stderr strings.
414
+ *
415
+ * @param command The command to run
416
+ * @param args The arguments to pass to the command
417
+ * @param options
418
+ * @returns A promise that resolves with an object like `{ stdout: string, stderr: string }`
419
+ */
420
+ function execSync(command, args, options) {
421
+ const result = (0, node_child_process.spawnSync)(command, args, { ...options });
422
+ const encoding = "utf8";
423
+ return {
424
+ stderr: result.stderr.toString(encoding),
425
+ stdout: result.stdout.toString(encoding)
426
+ };
427
+ }
377
428
  //#endregion
378
429
  //#region src/yarnConfig.ts
379
430
  /**
380
- * Synchronous version of {@link yarnConfig}
431
+ * Set/Unset yarn configuration value
381
432
  *
382
433
  * @param options
383
434
  * @example
384
- * yarnConfigSync({
435
+ * await yarnConfig({
385
436
  * key: 'nodeLinker',
386
437
  * state: 'present',
387
438
  * update: (content) => content.replace('node-modules', 'hoisted'),
388
439
  * })
389
440
  */
390
- function yarnConfigSync(options) {
441
+ async function yarnConfig(options) {
391
442
  const { key, state, update } = options;
392
443
  if (state === "present") {
393
- const { stdout } = execSync("yarn", [
444
+ const { stdout } = await exec("yarn", [
394
445
  "config",
395
446
  "get",
396
447
  String(key)
397
448
  ]);
398
- execSync("yarn", [
449
+ await exec("yarn", [
399
450
  "config",
400
451
  "set",
401
452
  String(key),
402
453
  String(update == null ? "" : update(stdout))
403
454
  ]);
404
- } else execSync("yarn", ["config", "unset"]);
455
+ } else await exec("yarn", ["config", "unset"]);
405
456
  }
406
457
  /**
407
- * Set/Unset yarn configuration value
458
+ * Synchronous version of {@link yarnConfig}
408
459
  *
409
460
  * @param options
410
461
  * @example
411
- * await yarnConfig({
462
+ * yarnConfigSync({
412
463
  * key: 'nodeLinker',
413
464
  * state: 'present',
414
465
  * update: (content) => content.replace('node-modules', 'hoisted'),
415
466
  * })
416
467
  */
417
- async function yarnConfig(options) {
468
+ function yarnConfigSync(options) {
418
469
  const { key, state, update } = options;
419
470
  if (state === "present") {
420
- const { stdout } = await exec("yarn", [
471
+ const { stdout } = execSync("yarn", [
421
472
  "config",
422
473
  "get",
423
474
  String(key)
424
475
  ]);
425
- await exec("yarn", [
476
+ execSync("yarn", [
426
477
  "config",
427
478
  "set",
428
479
  String(key),
429
480
  String(update == null ? "" : update(stdout))
430
481
  ]);
431
- } else await exec("yarn", ["config", "unset"]);
482
+ } else execSync("yarn", ["config", "unset"]);
432
483
  }
433
484
  //#endregion
434
485
  //#region src/yarnVersion.ts
435
486
  /**
436
- * Synchronous version of {@link yarnVersion}
487
+ * Set/Unset yarn configuration value
437
488
  *
438
489
  * @param options
439
490
  * @example
440
- * yarnVersionSync({
491
+ * await yarnVersion({
441
492
  * state: 'present',
442
493
  * update: () => 'berry', // or 'classic'
443
494
  * })
444
495
  */
445
- function yarnVersionSync(options) {
496
+ async function yarnVersion(options) {
446
497
  const { state, update } = options;
447
- if (state === "present") execSync("yarn", [
498
+ if (state === "present") await exec("yarn", [
448
499
  "set",
449
500
  "version",
450
501
  String(update == null ? "berry" : update())
@@ -452,18 +503,18 @@ function yarnVersionSync(options) {
452
503
  else throw new Error("Not implemented");
453
504
  }
454
505
  /**
455
- * Set/Unset yarn configuration value
506
+ * Synchronous version of {@link yarnVersion}
456
507
  *
457
508
  * @param options
458
509
  * @example
459
- * await yarnVersion({
510
+ * yarnVersionSync({
460
511
  * state: 'present',
461
512
  * update: () => 'berry', // or 'classic'
462
513
  * })
463
514
  */
464
- async function yarnVersion(options) {
515
+ function yarnVersionSync(options) {
465
516
  const { state, update } = options;
466
- if (state === "present") await exec("yarn", [
517
+ if (state === "present") execSync("yarn", [
467
518
  "set",
468
519
  "version",
469
520
  String(update == null ? "berry" : update())
@@ -482,6 +533,8 @@ exports.ignoreFileSync = ignoreFileSync;
482
533
  exports.json = json;
483
534
  exports.jsonSync = jsonSync;
484
535
  exports.meta = meta;
536
+ exports.yaml = yaml$1;
537
+ exports.yamlSync = yamlSync;
485
538
  exports.yarnConfig = yarnConfig;
486
539
  exports.yarnConfigSync = yarnConfigSync;
487
540
  exports.yarnVersion = yarnVersion;