@zokugun/artifact 0.5.2 → 0.6.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.
Files changed (216) hide show
  1. package/bin/artifact +1 -1
  2. package/lib/cli.d.ts +1 -0
  3. package/lib/cli.js +12 -4
  4. package/lib/commands/add.d.ts +6 -0
  5. package/lib/commands/add.js +47 -36
  6. package/lib/commands/index.d.ts +4 -0
  7. package/lib/commands/index.js +9 -7
  8. package/lib/commands/list.d.ts +1 -0
  9. package/lib/commands/list.js +13 -8
  10. package/lib/commands/remove.d.ts +6 -0
  11. package/lib/commands/remove.js +79 -0
  12. package/lib/commands/update.d.ts +5 -0
  13. package/lib/commands/update.js +43 -39
  14. package/lib/compositors/compose.d.ts +7 -0
  15. package/lib/compositors/compose.js +13 -13
  16. package/lib/compositors/fork.d.ts +3 -0
  17. package/lib/compositors/fork.js +4 -4
  18. package/lib/compositors/index.d.ts +6 -0
  19. package/lib/compositors/index.js +12 -12
  20. package/lib/compositors/json.d.ts +2 -0
  21. package/lib/compositors/json.js +14 -12
  22. package/lib/compositors/map-sort.d.ts +2 -0
  23. package/lib/compositors/map-sort.js +2 -2
  24. package/lib/compositors/rc.d.ts +2 -0
  25. package/lib/compositors/rc.js +13 -10
  26. package/lib/compositors/yaml.d.ts +2 -0
  27. package/lib/compositors/yaml.js +8 -11
  28. package/lib/configs/index.d.ts +3 -0
  29. package/lib/configs/index.js +3 -2
  30. package/lib/configs/install/index.d.ts +3 -0
  31. package/lib/configs/install/index.js +6 -6
  32. package/lib/configs/install/read-install-config.d.ts +6 -0
  33. package/lib/configs/install/read-install-config.js +123 -80
  34. package/lib/configs/install/update-install-config.d.ts +2 -0
  35. package/lib/configs/install/write-install-config.d.ts +5 -0
  36. package/lib/configs/install/write-install-config.js +17 -9
  37. package/lib/configs/package/index.d.ts +1 -0
  38. package/lib/configs/package/index.js +2 -2
  39. package/lib/configs/package/read-package-config.d.ts +3 -0
  40. package/lib/configs/package/read-package-config.js +159 -40
  41. package/lib/configs/uninstall/index.d.ts +1 -0
  42. package/lib/configs/uninstall/index.js +5 -0
  43. package/lib/configs/uninstall/update-uninstall-config.d.ts +2 -0
  44. package/lib/configs/uninstall/update-uninstall-config.js +6 -0
  45. package/lib/configs/utils/constants.d.ts +11 -0
  46. package/lib/configs/utils/constants.js +24 -0
  47. package/lib/configs/utils/is-transform.d.ts +2 -0
  48. package/lib/configs/utils/is-transform.js +16 -0
  49. package/lib/configs/utils/merge-upsert-property.d.ts +3 -0
  50. package/lib/configs/utils/merge-upsert-property.js +68 -0
  51. package/lib/configs/utils/normalize-file-always.d.ts +3 -0
  52. package/lib/configs/utils/normalize-file-always.js +28 -0
  53. package/lib/configs/utils/normalize-file-uninstall.d.ts +3 -0
  54. package/lib/configs/utils/normalize-file-uninstall.js +31 -0
  55. package/lib/configs/utils/normalize-file-upsert.d.ts +3 -0
  56. package/lib/configs/utils/normalize-file-upsert.js +54 -0
  57. package/lib/journeys/commitlint/index.d.ts +2 -0
  58. package/lib/journeys/commitlint/index.js +15 -15
  59. package/lib/journeys/config.ts/index.d.ts +2 -0
  60. package/lib/journeys/config.ts/index.js +5 -5
  61. package/lib/journeys/default/index.d.ts +2 -0
  62. package/lib/journeys/default/index.js +11 -14
  63. package/lib/journeys/fixpack/index.d.ts +2 -0
  64. package/lib/journeys/fixpack/index.js +13 -13
  65. package/lib/journeys/gitignore/index.d.ts +2 -0
  66. package/lib/journeys/gitignore/index.js +5 -5
  67. package/lib/journeys/ignore/index.d.ts +2 -0
  68. package/lib/journeys/ignore/index.js +5 -5
  69. package/lib/journeys/index.d.ts +2 -0
  70. package/lib/journeys/index.js +20 -20
  71. package/lib/journeys/npmignore/index.d.ts +2 -0
  72. package/lib/journeys/npmignore/index.js +5 -5
  73. package/lib/journeys/package/index.d.ts +2 -0
  74. package/lib/journeys/package/index.js +27 -30
  75. package/lib/journeys/rc/index.d.ts +2 -0
  76. package/lib/journeys/rc/index.js +12 -12
  77. package/lib/journeys/tsconfig/index.d.ts +2 -0
  78. package/lib/journeys/tsconfig/index.js +13 -16
  79. package/lib/parsers/json.d.ts +2 -0
  80. package/lib/parsers/jsonc/index.d.ts +2 -0
  81. package/lib/parsers/jsonc/index.js +4 -4
  82. package/lib/parsers/jsonc/parse.d.ts +5 -0
  83. package/lib/parsers/jsonc/parse.js +1 -13
  84. package/lib/parsers/jsonc/stringify.d.ts +2 -0
  85. package/lib/parsers/jsonc/stringify.js +2 -2
  86. package/lib/parsers/jsonc/transform.d.ts +10 -0
  87. package/lib/parsers/yaml.d.ts +2 -0
  88. package/lib/routes/command.d.ts +4 -0
  89. package/lib/routes/command.js +10 -10
  90. package/lib/routes/index.d.ts +8 -0
  91. package/lib/routes/index.js +17 -15
  92. package/lib/routes/lines-concat.d.ts +4 -0
  93. package/lib/routes/lines-concat.js +7 -7
  94. package/lib/routes/list-concat.d.ts +4 -0
  95. package/lib/routes/list-concat.js +3 -7
  96. package/lib/routes/list-sort-concat.d.ts +4 -0
  97. package/lib/routes/list-sort-concat.js +1 -1
  98. package/lib/routes/map-concat.d.ts +4 -0
  99. package/lib/routes/map-concat.js +1 -1
  100. package/lib/routes/map-delete.d.ts +4 -0
  101. package/lib/routes/map-delete.js +32 -0
  102. package/lib/routes/overwrite.d.ts +4 -0
  103. package/lib/routes/overwrite.js +2 -2
  104. package/lib/routes/primitive.d.ts +4 -0
  105. package/lib/routes/primitive.js +3 -3
  106. package/lib/steps/apply-formatting.d.ts +8 -0
  107. package/lib/steps/apply-formatting.js +19 -15
  108. package/lib/steps/configure-branches.d.ts +3 -0
  109. package/lib/steps/configure-branches.js +8 -5
  110. package/lib/steps/configure-install-file-actions.d.ts +3 -0
  111. package/lib/steps/configure-install-file-actions.js +41 -86
  112. package/lib/steps/configure-uninstall-file-actions.d.ts +3 -0
  113. package/lib/steps/configure-uninstall-file-actions.js +53 -0
  114. package/lib/steps/configure-update-file-actions.d.ts +3 -0
  115. package/lib/steps/configure-update-file-actions.js +64 -97
  116. package/lib/steps/copy-binary-files.d.ts +3 -0
  117. package/lib/steps/copy-binary-files.js +24 -11
  118. package/lib/steps/execute-first-block.d.ts +3 -0
  119. package/lib/steps/execute-first-block.js +35 -14
  120. package/lib/steps/execute-next-block.d.ts +3 -0
  121. package/lib/steps/execute-next-block.js +8 -3
  122. package/lib/steps/index.d.ts +54 -0
  123. package/lib/steps/index.js +76 -54
  124. package/lib/steps/insert-final-new-line.d.ts +6 -0
  125. package/lib/steps/insert-final-new-line.js +13 -1
  126. package/lib/steps/merge-text-files.d.ts +3 -0
  127. package/lib/steps/merge-text-files.js +41 -27
  128. package/lib/steps/read-editor-config.d.ts +3 -0
  129. package/lib/steps/read-editor-config.js +21 -26
  130. package/lib/steps/read-files.d.ts +3 -0
  131. package/lib/steps/read-files.js +19 -8
  132. package/lib/steps/read-incoming-config.d.ts +3 -0
  133. package/lib/steps/read-incoming-config.js +7 -5
  134. package/lib/steps/read-incoming-package.d.ts +3 -0
  135. package/lib/steps/read-incoming-package.js +12 -7
  136. package/lib/steps/remove-files.d.ts +3 -0
  137. package/lib/steps/remove-files.js +10 -4
  138. package/lib/steps/rename-files.d.ts +3 -0
  139. package/lib/steps/rename-files.js +25 -0
  140. package/lib/steps/replace-templates.d.ts +3 -0
  141. package/lib/steps/replace-templates.js +19 -5
  142. package/lib/steps/transform-untouched-files.d.ts +3 -0
  143. package/lib/steps/transform-untouched-files.js +73 -0
  144. package/lib/steps/unmerge-text-files.d.ts +3 -0
  145. package/lib/steps/unmerge-text-files.js +63 -0
  146. package/lib/steps/validate-newer-package.d.ts +3 -0
  147. package/lib/steps/validate-newer-package.js +4 -2
  148. package/lib/steps/validate-not-present-package.d.ts +3 -0
  149. package/lib/steps/validate-not-present-package.js +7 -4
  150. package/lib/steps/validate-present-package.d.ts +3 -0
  151. package/lib/steps/validate-present-package.js +24 -0
  152. package/lib/steps/write-text-files.d.ts +3 -0
  153. package/lib/steps/write-text-files.js +16 -7
  154. package/lib/types/binary-file.d.ts +4 -0
  155. package/lib/types/command.d.ts +5 -0
  156. package/lib/types/config.d.ts +58 -0
  157. package/lib/types/context.d.ts +56 -0
  158. package/lib/types/format.d.ts +10 -0
  159. package/lib/types/step.d.ts +3 -0
  160. package/lib/types/text-file.d.ts +7 -0
  161. package/lib/types/travel.d.ts +14 -0
  162. package/lib/utils/apply-transforms.d.ts +2 -0
  163. package/lib/utils/apply-transforms.js +48 -0
  164. package/lib/utils/build-journey-plan.d.ts +2 -0
  165. package/lib/utils/build-route.d.ts +3 -0
  166. package/lib/utils/build-route.js +92 -0
  167. package/lib/utils/build-travel-plan.d.ts +2 -0
  168. package/lib/utils/build-travel.d.ts +3 -0
  169. package/lib/utils/build-travel.js +32 -0
  170. package/lib/utils/command/dedupe-strings.d.ts +1 -0
  171. package/lib/utils/command/index.d.ts +8 -0
  172. package/lib/utils/command/index.js +14 -14
  173. package/lib/utils/command/join-command.d.ts +2 -0
  174. package/lib/utils/command/merge-and-chains.d.ts +1 -0
  175. package/lib/utils/command/merge-and-chains.js +21 -21
  176. package/lib/utils/command/merge-command-records.d.ts +2 -0
  177. package/lib/utils/command/merge-command-records.js +43 -22
  178. package/lib/utils/command/merge-flag-tokens.d.ts +1 -0
  179. package/lib/utils/command/merge-flag-tokens.js +1 -1
  180. package/lib/utils/command/merge-flags-as-string.d.ts +4 -0
  181. package/lib/utils/command/merge-flags-as-string.js +4 -4
  182. package/lib/utils/command/merge-or-segments.d.ts +1 -0
  183. package/lib/utils/command/merge-or-segments.js +28 -28
  184. package/lib/utils/command/merge-parts-by-prefix.d.ts +1 -0
  185. package/lib/utils/command/merge-parts-by-prefix.js +6 -6
  186. package/lib/utils/command/merge-semicolon-segments.d.ts +1 -0
  187. package/lib/utils/command/merge-semicolon-segments.js +35 -35
  188. package/lib/utils/command/merge-with-semicolon-mix.d.ts +1 -0
  189. package/lib/utils/command/merge-with-semicolon-mix.js +12 -12
  190. package/lib/utils/command/prefix-of-command.d.ts +1 -0
  191. package/lib/utils/command/prefix-of-command.js +2 -2
  192. package/lib/utils/command/split-chain.d.ts +1 -0
  193. package/lib/utils/command/split-command.d.ts +2 -0
  194. package/lib/utils/command/split-command.js +8 -8
  195. package/lib/utils/command/split-prefix-and-flags.d.ts +4 -0
  196. package/lib/utils/command/split-prefix-and-flags.js +5 -5
  197. package/lib/utils/command/split-segments.d.ts +1 -0
  198. package/lib/utils/detect-indent.d.ts +5 -0
  199. package/lib/utils/detect-indent.js +60 -0
  200. package/lib/utils/flow.d.ts +3 -0
  201. package/lib/utils/flow.js +12 -0
  202. package/lib/utils/get-format.d.ts +2 -0
  203. package/lib/utils/get-format.js +19 -0
  204. package/lib/utils/has-final-new-line.d.ts +1 -0
  205. package/lib/utils/has-final-new-line.js +7 -0
  206. package/lib/utils/read-buffer.d.ts +2 -0
  207. package/lib/utils/resolve-request.d.ts +3 -0
  208. package/lib/utils/resolve-request.js +4 -3
  209. package/lib/utils/template.d.ts +17 -0
  210. package/lib/utils/template.js +79 -57
  211. package/lib/utils/to-lines.d.ts +1 -0
  212. package/lib/utils/trim-final-newline.d.ts +1 -0
  213. package/lib/utils/try-json.d.ts +1 -0
  214. package/lib/utils/try-json.js +2 -2
  215. package/package.json +123 -101
  216. package/lib/utils/dev-null.js +0 -7
package/bin/artifact CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require('../lib/cli');
3
+ import '../lib/cli.js';
package/lib/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {};
package/lib/cli.js CHANGED
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const commander_1 = require("@zokugun/cli-utils/commander");
7
7
  const package_json_1 = __importDefault(require("../package.json"));
8
- const commands_1 = require("./commands");
8
+ const index_js_1 = require("./commands/index.js");
9
9
  const program = new commander_1.Command();
10
10
  program
11
11
  .version(package_json_1.default.version, '-V, --version')
@@ -16,17 +16,25 @@ program
16
16
  .option('-d, --dry-run', 'fake install')
17
17
  .option('-v, --verbose', 'output more details')
18
18
  .argument('<artifacts...>')
19
- .action(commands_1.add);
19
+ .action(index_js_1.add);
20
20
  program
21
21
  .command('update')
22
22
  .description('update the current project using the installed artifacts')
23
23
  .option('-d, --dry-run', 'fake update')
24
24
  .option('-v, --verbose', 'output more details')
25
25
  .alias('up')
26
- .action(commands_1.update);
26
+ .action(index_js_1.update);
27
+ program
28
+ .command('remove')
29
+ .description('remove an artifact from the current project')
30
+ .option('-d, --dry-run', 'fake uninstall')
31
+ .option('-v, --verbose', 'output more details')
32
+ .argument('<artifacts...>')
33
+ .alias('rm')
34
+ .action(index_js_1.remove);
27
35
  program
28
36
  .command('list')
29
37
  .description('list the installed artifacts in the project')
30
38
  .alias('l')
31
- .action(commands_1.list);
39
+ .action(index_js_1.list);
32
40
  program.parse();
@@ -0,0 +1,6 @@
1
+ export declare function add(specs: string[], inputOptions?: {
2
+ force?: boolean;
3
+ skip?: boolean;
4
+ verbose?: boolean;
5
+ dryRun?: boolean;
6
+ }): Promise<void>;
@@ -5,69 +5,80 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.add = add;
7
7
  const process_1 = __importDefault(require("process"));
8
- const ansi_colors_1 = require("ansi-colors");
9
- const npm_1 = __importDefault(require("npm"));
10
- const ora_1 = __importDefault(require("ora"));
8
+ const cli_utils_1 = require("@zokugun/cli-utils");
11
9
  const pacote_1 = __importDefault(require("pacote"));
12
10
  const tempy_1 = __importDefault(require("tempy"));
13
- const configs_1 = require("../configs");
14
- const steps_1 = require("../steps");
15
- const resolve_request_1 = require("../utils/resolve-request");
16
- const { mainFlow } = (0, steps_1.composeSteps)([
17
- steps_1.steps.readIncomingPackage,
18
- steps_1.steps.validateNotPresentPackage,
19
- steps_1.steps.readIncomingConfig,
20
- steps_1.steps.executeFirstBlock,
11
+ const index_js_1 = require("../configs/index.js");
12
+ const index_js_2 = require("../steps/index.js");
13
+ const resolve_request_js_1 = require("../utils/resolve-request.js");
14
+ const { mainFlow } = (0, index_js_2.composeSteps)([
15
+ index_js_2.steps.readIncomingPackage,
16
+ index_js_2.steps.validateNotPresentPackage,
17
+ index_js_2.steps.readIncomingConfig,
18
+ index_js_2.steps.executeFirstBlock,
21
19
  ], [
22
- steps_1.steps.readIncomingConfig,
23
- steps_1.steps.configureBranches,
24
- steps_1.steps.configureInstallFileActions,
25
- steps_1.steps.readFiles,
26
- steps_1.steps.readEditorConfig,
27
- steps_1.steps.replaceTemplates,
28
- steps_1.steps.mergeTextFiles,
29
- steps_1.steps.insertFinalNewLine,
30
- steps_1.steps.applyFormatting,
31
- steps_1.steps.copyBinaryFiles,
32
- steps_1.steps.writeTextFiles,
33
- steps_1.steps.removeFiles,
34
- steps_1.steps.executeNextBlock,
20
+ index_js_2.steps.readIncomingConfig,
21
+ index_js_2.steps.configureBranches,
22
+ index_js_2.steps.configureInstallFileActions,
23
+ index_js_2.steps.renameFiles,
24
+ index_js_2.steps.readFiles,
25
+ index_js_2.steps.readEditorConfig,
26
+ index_js_2.steps.replaceTemplates,
27
+ index_js_2.steps.mergeTextFiles,
28
+ index_js_2.steps.transformUntouchedFiles,
29
+ index_js_2.steps.insertFinalNewLine,
30
+ index_js_2.steps.applyFormatting,
31
+ index_js_2.steps.copyBinaryFiles,
32
+ index_js_2.steps.writeTextFiles,
33
+ index_js_2.steps.removeFiles,
34
+ index_js_2.steps.executeNextBlock,
35
35
  ]);
36
36
  async function add(specs, inputOptions) {
37
- await npm_1.default.load();
38
- const registry = npm_1.default.config.get('registry');
39
- const targetPath = process_1.default.env.INIT_CWD;
37
+ cli_utils_1.logger.beginTimer();
38
+ const targetPath = process_1.default.cwd();
40
39
  const options = {
41
40
  force: inputOptions?.force ?? false,
42
41
  skip: inputOptions?.skip ?? false,
43
42
  verbose: inputOptions?.verbose ?? false,
44
43
  dryRun: inputOptions?.dryRun ?? false,
45
44
  };
46
- const { config, configStats } = await (0, configs_1.readInstallConfig)(targetPath);
45
+ const configResult = await (0, index_js_1.readInstallConfig)(targetPath);
46
+ if (configResult.fails) {
47
+ cli_utils_1.logger.fatal(configResult.error);
48
+ }
49
+ const { config, configStats } = configResult.value;
47
50
  for (const spec of specs) {
48
- const request = (0, resolve_request_1.resolveRequest)(spec);
49
- const spinner = (0, ora_1.default)(`${ansi_colors_1.cyan.bold(request.name)}`).start();
51
+ const requestResult = (0, resolve_request_js_1.resolveRequest)(spec);
52
+ if (requestResult.fails) {
53
+ cli_utils_1.logger.fatal(requestResult.error);
54
+ }
55
+ const request = requestResult.value;
56
+ const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(request.name)}`);
50
57
  const dir = tempy_1.default.directory();
51
- const pkgResult = await pacote_1.default.extract(request.name, dir, { registry });
58
+ const pkgResult = await pacote_1.default.extract(request.name, dir);
52
59
  if (!pkgResult.resolved) {
53
60
  if (options.force || options.skip) {
54
61
  spinner.fail();
55
62
  if (options.verbose) {
56
- console.log(`The artifact '${spec}' couldn't be found, skipping...`);
63
+ cli_utils_1.logger.warn(`The artifact '${spec}' couldn't be found, skipping...`);
57
64
  }
58
65
  continue;
59
66
  }
60
67
  else {
61
- throw new Error(pkgResult.from);
68
+ cli_utils_1.logger.fatal(pkgResult.from);
62
69
  }
63
70
  }
64
71
  const flowResult = await mainFlow(targetPath, dir, request, config, options);
65
- if (!flowResult || !flowResult.result) {
72
+ if (flowResult.fails) {
73
+ cli_utils_1.logger.fatal(flowResult.error);
74
+ }
75
+ if (!flowResult.value?.result) {
66
76
  spinner.succeed();
67
77
  continue;
68
78
  }
69
- (0, configs_1.updateInstallConfig)(config, flowResult.result);
70
- await (0, configs_1.writeInstallConfig)(config, configStats, flowResult.formats, targetPath, options);
79
+ (0, index_js_1.updateInstallConfig)(config, flowResult.value.result);
80
+ await (0, index_js_1.writeInstallConfig)(config, configStats, flowResult.value.formats, targetPath, options);
71
81
  spinner.succeed();
72
82
  }
83
+ cli_utils_1.logger.finishTimer();
73
84
  }
@@ -0,0 +1,4 @@
1
+ export { add } from './add.js';
2
+ export { list } from './list.js';
3
+ export { remove } from './remove.js';
4
+ export { update } from './update.js';
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.update = exports.list = exports.add = void 0;
4
- var add_1 = require("./add");
5
- Object.defineProperty(exports, "add", { enumerable: true, get: function () { return add_1.add; } });
6
- var list_1 = require("./list");
7
- Object.defineProperty(exports, "list", { enumerable: true, get: function () { return list_1.list; } });
8
- var update_1 = require("./update");
9
- Object.defineProperty(exports, "update", { enumerable: true, get: function () { return update_1.update; } });
3
+ exports.update = exports.remove = exports.list = exports.add = void 0;
4
+ var add_js_1 = require("./add.js");
5
+ Object.defineProperty(exports, "add", { enumerable: true, get: function () { return add_js_1.add; } });
6
+ var list_js_1 = require("./list.js");
7
+ Object.defineProperty(exports, "list", { enumerable: true, get: function () { return list_js_1.list; } });
8
+ var remove_js_1 = require("./remove.js");
9
+ Object.defineProperty(exports, "remove", { enumerable: true, get: function () { return remove_js_1.remove; } });
10
+ var update_js_1 = require("./update.js");
11
+ Object.defineProperty(exports, "update", { enumerable: true, get: function () { return update_js_1.update; } });
@@ -0,0 +1 @@
1
+ export declare function list(): Promise<void>;
@@ -5,10 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.list = list;
7
7
  const process_1 = __importDefault(require("process"));
8
- const lodash_1 = require("lodash");
9
- const configs_1 = require("../configs");
8
+ const cli_utils_1 = require("@zokugun/cli-utils");
9
+ const lodash_es_1 = require("lodash-es");
10
+ const index_js_1 = require("../configs/index.js");
10
11
  function formatVariant(artifact) {
11
- const variant = Array.isArray(artifact.requires) ? (0, lodash_1.last)(artifact.requires) ?? '' : '';
12
+ const variant = Array.isArray(artifact.requires) ? (0, lodash_es_1.last)(artifact.requires) ?? '' : '';
12
13
  if (variant.length > 0) {
13
14
  return `:${variant}`;
14
15
  }
@@ -18,17 +19,21 @@ function formatVariant(artifact) {
18
19
  }
19
20
  async function list() {
20
21
  const targetPath = process_1.default.env.INIT_CWD;
21
- const { config, configStats } = await (0, configs_1.readInstallConfig)(targetPath);
22
+ const configResult = await (0, index_js_1.readInstallConfig)(targetPath);
23
+ if (configResult.fails) {
24
+ cli_utils_1.logger.fatal(configResult.error);
25
+ }
26
+ const { config, configStats } = configResult.value;
22
27
  const artifacts = Object.entries(config.artifacts);
23
28
  if (artifacts.length === 0) {
24
- console.log('No artifacts have been installed.');
29
+ cli_utils_1.logger.info('No artifacts have been installed.');
25
30
  }
26
31
  else {
27
- console.log(`List of installed artifacts (${configStats.name}):\n`);
32
+ cli_utils_1.logger.info(`List of installed artifacts (${configStats.name}):\n`);
28
33
  for (const [name, artifact] of artifacts) {
29
34
  const version = artifact.version ? `@${artifact.version}` : '';
30
- console.log(`- ${name}${version}${formatVariant(artifact)}`);
35
+ cli_utils_1.logger.info(`- ${name}${version}${formatVariant(artifact)}`);
31
36
  }
32
37
  }
33
- console.log();
38
+ cli_utils_1.logger.newLine();
34
39
  }
@@ -0,0 +1,6 @@
1
+ export declare function remove(specs: string[], inputOptions?: {
2
+ force?: boolean;
3
+ skip?: boolean;
4
+ verbose?: boolean;
5
+ dryRun?: boolean;
6
+ }): Promise<void>;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.remove = remove;
7
+ const process_1 = __importDefault(require("process"));
8
+ const cli_utils_1 = require("@zokugun/cli-utils");
9
+ const pacote_1 = __importDefault(require("pacote"));
10
+ const tempy_1 = __importDefault(require("tempy"));
11
+ const index_js_1 = require("../configs/index.js");
12
+ const index_js_2 = require("../steps/index.js");
13
+ const resolve_request_js_1 = require("../utils/resolve-request.js");
14
+ const { mainFlow } = (0, index_js_2.composeSteps)([
15
+ index_js_2.steps.readIncomingPackage,
16
+ index_js_2.steps.validatePresentPackage,
17
+ index_js_2.steps.readIncomingConfig,
18
+ index_js_2.steps.executeFirstBlock,
19
+ ], [
20
+ index_js_2.steps.readIncomingConfig,
21
+ index_js_2.steps.configureBranches,
22
+ index_js_2.steps.configureUninstallFileActions,
23
+ index_js_2.steps.unmergeTextFiles,
24
+ index_js_2.steps.transformUntouchedFiles,
25
+ index_js_2.steps.insertFinalNewLine,
26
+ index_js_2.steps.applyFormatting,
27
+ index_js_2.steps.writeTextFiles,
28
+ index_js_2.steps.removeFiles,
29
+ index_js_2.steps.executeNextBlock,
30
+ ]);
31
+ async function remove(specs, inputOptions) {
32
+ cli_utils_1.logger.beginTimer();
33
+ const targetPath = process_1.default.cwd();
34
+ const options = {
35
+ force: inputOptions?.force ?? false,
36
+ skip: inputOptions?.skip ?? false,
37
+ verbose: inputOptions?.verbose ?? false,
38
+ dryRun: inputOptions?.dryRun ?? false,
39
+ };
40
+ const configResult = await (0, index_js_1.readInstallConfig)(targetPath);
41
+ if (configResult.fails) {
42
+ cli_utils_1.logger.fatal(configResult.error);
43
+ }
44
+ const { config, configStats } = configResult.value;
45
+ for (const spec of specs) {
46
+ const requestResult = (0, resolve_request_js_1.resolveRequest)(spec);
47
+ if (requestResult.fails) {
48
+ cli_utils_1.logger.fatal(requestResult.error);
49
+ }
50
+ const request = requestResult.value;
51
+ const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(request.name)}`);
52
+ const dir = tempy_1.default.directory();
53
+ const pkgResult = await pacote_1.default.extract(request.name, dir);
54
+ if (!pkgResult.resolved) {
55
+ if (options.force || options.skip) {
56
+ spinner.fail();
57
+ if (options.verbose) {
58
+ cli_utils_1.logger.debug(`The artifact '${spec}' couldn't be found, skipping...`);
59
+ }
60
+ continue;
61
+ }
62
+ else {
63
+ cli_utils_1.logger.fatal(pkgResult.from);
64
+ }
65
+ }
66
+ const flowResult = await mainFlow(targetPath, dir, request, config, options);
67
+ if (flowResult.fails) {
68
+ cli_utils_1.logger.fatal(flowResult.error);
69
+ }
70
+ if (!flowResult.value?.result) {
71
+ spinner.succeed();
72
+ continue;
73
+ }
74
+ (0, index_js_1.updateUninstallConfig)(config, flowResult.value.result);
75
+ await (0, index_js_1.writeInstallConfig)(config, configStats, flowResult.value.formats, targetPath, options);
76
+ spinner.succeed();
77
+ }
78
+ cli_utils_1.logger.finishTimer();
79
+ }
@@ -0,0 +1,5 @@
1
+ export declare function update(inputOptions?: {
2
+ force?: boolean;
3
+ verbose?: boolean;
4
+ dryRun?: boolean;
5
+ }): Promise<void>;
@@ -5,72 +5,76 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.update = update;
7
7
  const process_1 = __importDefault(require("process"));
8
- const ansi_colors_1 = require("ansi-colors");
9
- const lodash_1 = require("lodash");
10
- const npm_1 = __importDefault(require("npm"));
11
- const ora_1 = __importDefault(require("ora"));
8
+ const cli_utils_1 = require("@zokugun/cli-utils");
9
+ const lodash_es_1 = require("lodash-es");
12
10
  const pacote_1 = __importDefault(require("pacote"));
13
11
  const tempy_1 = __importDefault(require("tempy"));
14
- const configs_1 = require("../configs");
15
- const steps_1 = require("../steps");
16
- const dev_null_1 = require("../utils/dev-null");
17
- const { mainFlow } = (0, steps_1.composeSteps)([
18
- steps_1.steps.readIncomingPackage,
19
- steps_1.steps.validateNewerPackage,
20
- steps_1.steps.readIncomingConfig,
21
- steps_1.steps.executeFirstBlock,
12
+ const index_js_1 = require("../configs/index.js");
13
+ const index_js_2 = require("../steps/index.js");
14
+ const { mainFlow } = (0, index_js_2.composeSteps)([
15
+ index_js_2.steps.readIncomingPackage,
16
+ index_js_2.steps.validateNewerPackage,
17
+ index_js_2.steps.readIncomingConfig,
18
+ index_js_2.steps.executeFirstBlock,
22
19
  ], [
23
- steps_1.steps.readIncomingConfig,
24
- steps_1.steps.configureBranches,
25
- steps_1.steps.configureUpdateFileActions,
26
- steps_1.steps.readFiles,
27
- steps_1.steps.readEditorConfig,
28
- steps_1.steps.replaceTemplates,
29
- steps_1.steps.mergeTextFiles,
30
- steps_1.steps.insertFinalNewLine,
31
- steps_1.steps.applyFormatting,
32
- steps_1.steps.copyBinaryFiles,
33
- steps_1.steps.writeTextFiles,
34
- steps_1.steps.removeFiles,
35
- steps_1.steps.executeNextBlock,
20
+ index_js_2.steps.readIncomingConfig,
21
+ index_js_2.steps.configureBranches,
22
+ index_js_2.steps.configureUpdateFileActions,
23
+ index_js_2.steps.renameFiles,
24
+ index_js_2.steps.readFiles,
25
+ index_js_2.steps.readEditorConfig,
26
+ index_js_2.steps.replaceTemplates,
27
+ index_js_2.steps.mergeTextFiles,
28
+ index_js_2.steps.transformUntouchedFiles,
29
+ index_js_2.steps.insertFinalNewLine,
30
+ index_js_2.steps.applyFormatting,
31
+ index_js_2.steps.copyBinaryFiles,
32
+ index_js_2.steps.writeTextFiles,
33
+ index_js_2.steps.removeFiles,
34
+ index_js_2.steps.executeNextBlock,
36
35
  ]);
37
36
  async function update(inputOptions) {
38
- // @ts-expect-error log property isn't exposed
39
- npm_1.default.log.stream = (0, dev_null_1.createDevNull)();
40
- await npm_1.default.load();
41
- const registry = npm_1.default.config.get('registry');
42
- const targetPath = process_1.default.env.INIT_CWD;
37
+ cli_utils_1.logger.beginTimer();
38
+ const targetPath = process_1.default.cwd();
43
39
  const options = {
44
40
  force: inputOptions?.force ?? false,
45
41
  skip: false,
46
42
  verbose: inputOptions?.verbose ?? false,
47
43
  dryRun: inputOptions?.dryRun ?? false,
48
44
  };
49
- const { config, configStats } = await (0, configs_1.readInstallConfig)(targetPath);
45
+ const configResult = await (0, index_js_1.readInstallConfig)(targetPath);
46
+ if (configResult.fails) {
47
+ cli_utils_1.logger.fatal(configResult.error);
48
+ }
49
+ const { config, configStats } = configResult.value;
50
50
  for (const [name, artifact] of Object.entries(config.artifacts)) {
51
- const spinner = (0, ora_1.default)(`${ansi_colors_1.cyan.bold(name)}`).start();
51
+ const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(name)}`);
52
52
  const dir = tempy_1.default.directory();
53
- const pkgResult = await pacote_1.default.extract(name, dir, { registry });
53
+ const pkgResult = await pacote_1.default.extract(name, dir);
54
54
  if (!pkgResult.resolved) {
55
55
  if (options.force) {
56
56
  spinner.fail();
57
57
  if (options.verbose) {
58
- console.log(`The artifact '${name}' couldn't be found, skipping...`);
58
+ cli_utils_1.logger.debug(`The artifact '${name}' couldn't be found, skipping...`);
59
59
  }
60
60
  continue;
61
61
  }
62
62
  else {
63
- throw new Error(pkgResult.from);
63
+ cli_utils_1.logger.fatal(pkgResult.from);
64
64
  }
65
65
  }
66
- const request = artifact.requires ? { name, variant: (0, lodash_1.last)(artifact.requires) } : { name };
66
+ const request = artifact.requires ? { name, variant: (0, lodash_es_1.last)(artifact.requires) } : { name };
67
67
  const flowResult = await mainFlow(targetPath, dir, request, config, options);
68
- if (!flowResult || !flowResult.result) {
68
+ if (flowResult.fails) {
69
+ cli_utils_1.logger.fatal(flowResult.error);
70
+ }
71
+ if (!flowResult.value?.result) {
69
72
  spinner.succeed();
70
73
  continue;
71
74
  }
72
- (0, configs_1.updateInstallConfig)(config, flowResult.result);
73
- await (0, configs_1.writeInstallConfig)(config, configStats, flowResult.formats, targetPath, options);
75
+ (0, index_js_1.updateInstallConfig)(config, flowResult.value.result);
76
+ await (0, index_js_1.writeInstallConfig)(config, configStats, flowResult.value.formats, targetPath, options);
74
77
  spinner.succeed();
75
78
  }
79
+ cli_utils_1.logger.finishTimer();
76
80
  }
@@ -0,0 +1,7 @@
1
+ import { type Route } from '../types/travel.js';
2
+ type ComposeMap = {
3
+ [key: string]: Route<any> | string[] | undefined;
4
+ $$ignore?: string[];
5
+ };
6
+ export declare function compose(map: ComposeMap): Route<Record<string, any>>;
7
+ export {};
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.compose = compose;
4
- const lodash_1 = require("lodash");
5
- function apply(map, keys, current, incoming, result) {
4
+ const lodash_es_1 = require("lodash-es");
5
+ async function apply(map, keys, current, incoming, result) {
6
6
  if (keys.length === 0) {
7
7
  return;
8
8
  }
@@ -10,14 +10,14 @@ function apply(map, keys, current, incoming, result) {
10
10
  for (const key of keys) {
11
11
  const currentValue = current[key];
12
12
  const transform = map[key] ?? map.$$default;
13
- if (!transform || !(0, lodash_1.has)(incoming, key) || ignores.includes(key)) {
14
- if (!(0, lodash_1.isNil)(currentValue)) {
13
+ if (!transform || !(0, lodash_es_1.has)(incoming, key) || ignores.includes(key)) {
14
+ if (!(0, lodash_es_1.isNil)(currentValue)) {
15
15
  result[key] = currentValue;
16
16
  }
17
17
  continue;
18
18
  }
19
19
  const incomingValue = incoming[key];
20
- result[key] = transform({
20
+ result[key] = await transform({
21
21
  current: currentValue,
22
22
  incoming: incomingValue,
23
23
  ignores: map.$$ignore,
@@ -25,26 +25,26 @@ function apply(map, keys, current, incoming, result) {
25
25
  }
26
26
  }
27
27
  function compose(map) {
28
- return ({ current, incoming, filters }) => {
29
- if ((0, lodash_1.isNil)(incoming)) {
28
+ return async ({ current, incoming, filters }) => {
29
+ if ((0, lodash_es_1.isNil)(incoming)) {
30
30
  return current ?? {};
31
31
  }
32
- if ((0, lodash_1.isNil)(current) || typeof current !== typeof incoming) {
32
+ if ((0, lodash_es_1.isNil)(current) || typeof current !== typeof incoming) {
33
33
  return incoming;
34
34
  }
35
35
  const currentKeys = Object.keys(current);
36
36
  const incomingKeys = Object.keys(incoming);
37
- const newKeys = (0, lodash_1.without)(incomingKeys, ...currentKeys);
37
+ const newKeys = (0, lodash_es_1.without)(incomingKeys, ...currentKeys);
38
38
  if (filters) {
39
39
  const result = { ...current };
40
- apply(map, filters, current, incoming, result);
41
- apply(map, newKeys, current, incoming, result);
40
+ await apply(map, filters, current, incoming, result);
41
+ await apply(map, newKeys, current, incoming, result);
42
42
  return result;
43
43
  }
44
44
  else {
45
45
  const result = {};
46
- apply(map, currentKeys, current, incoming, result);
47
- apply(map, newKeys, current, incoming, result);
46
+ await apply(map, currentKeys, current, incoming, result);
47
+ await apply(map, newKeys, current, incoming, result);
48
48
  return result;
49
49
  }
50
50
  };
@@ -0,0 +1,3 @@
1
+ import { type Route } from '../types/travel.js';
2
+ export type ForkParameter = [(value: any) => boolean, Route<any>] | Route<any>;
3
+ export declare function fork<T>(...cases: ForkParameter[]): Route<T>;
@@ -2,13 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fork = fork;
4
4
  function fork(...cases) {
5
- return ({ current, incoming }) => {
5
+ return async ({ current, incoming }) => {
6
6
  const targetCase = cases.find((c) => {
7
- if (!Array.isArray(c)) {
8
- return c;
7
+ if (Array.isArray(c)) {
8
+ return c[0](current ?? incoming);
9
9
  }
10
10
  else {
11
- return c[0](current ?? incoming);
11
+ return c;
12
12
  }
13
13
  });
14
14
  if (!targetCase) {
@@ -0,0 +1,6 @@
1
+ export { compose } from './compose.js';
2
+ export { fork } from './fork.js';
3
+ export { json } from './json.js';
4
+ export { mapSort } from './map-sort.js';
5
+ export { rc } from './rc.js';
6
+ export { yaml } from './yaml.js';
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.yaml = exports.rc = exports.mapSort = exports.json = exports.fork = exports.compose = void 0;
4
- var compose_1 = require("./compose");
5
- Object.defineProperty(exports, "compose", { enumerable: true, get: function () { return compose_1.compose; } });
6
- var fork_1 = require("./fork");
7
- Object.defineProperty(exports, "fork", { enumerable: true, get: function () { return fork_1.fork; } });
8
- var json_1 = require("./json");
9
- Object.defineProperty(exports, "json", { enumerable: true, get: function () { return json_1.json; } });
10
- var map_sort_1 = require("./map-sort");
11
- Object.defineProperty(exports, "mapSort", { enumerable: true, get: function () { return map_sort_1.mapSort; } });
12
- var rc_1 = require("./rc");
13
- Object.defineProperty(exports, "rc", { enumerable: true, get: function () { return rc_1.rc; } });
14
- var yaml_1 = require("./yaml");
15
- Object.defineProperty(exports, "yaml", { enumerable: true, get: function () { return yaml_1.yaml; } });
4
+ var compose_js_1 = require("./compose.js");
5
+ Object.defineProperty(exports, "compose", { enumerable: true, get: function () { return compose_js_1.compose; } });
6
+ var fork_js_1 = require("./fork.js");
7
+ Object.defineProperty(exports, "fork", { enumerable: true, get: function () { return fork_js_1.fork; } });
8
+ var json_js_1 = require("./json.js");
9
+ Object.defineProperty(exports, "json", { enumerable: true, get: function () { return json_js_1.json; } });
10
+ var map_sort_js_1 = require("./map-sort.js");
11
+ Object.defineProperty(exports, "mapSort", { enumerable: true, get: function () { return map_sort_js_1.mapSort; } });
12
+ var rc_js_1 = require("./rc.js");
13
+ Object.defineProperty(exports, "rc", { enumerable: true, get: function () { return rc_js_1.rc; } });
14
+ var yaml_js_1 = require("./yaml.js");
15
+ Object.defineProperty(exports, "yaml", { enumerable: true, get: function () { return yaml_js_1.yaml; } });
@@ -0,0 +1,2 @@
1
+ import { type Route } from '../types/travel.js';
2
+ export declare function json(...routes: Array<Route<Record<string, any>>>): Route<string>;