@zokugun/artifact 0.7.0 → 0.9.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 (107) hide show
  1. package/README.md +22 -2
  2. package/lib/cli.js +16 -11
  3. package/lib/commands/add.js +95 -22
  4. package/lib/commands/index.d.ts +1 -0
  5. package/lib/commands/index.js +3 -1
  6. package/lib/commands/list.js +25 -7
  7. package/lib/commands/outdated.d.ts +1 -0
  8. package/lib/commands/outdated.js +73 -0
  9. package/lib/commands/remove.js +39 -18
  10. package/lib/commands/update.js +36 -21
  11. package/lib/compositors/codec.d.ts +3 -0
  12. package/lib/compositors/codec.js +46 -0
  13. package/lib/compositors/compose.d.ts +1 -0
  14. package/lib/compositors/compose.js +4 -0
  15. package/lib/compositors/index.d.ts +1 -0
  16. package/lib/compositors/index.js +3 -1
  17. package/lib/compositors/json.js +3 -66
  18. package/lib/compositors/rc.js +3 -56
  19. package/lib/compositors/yaml.js +24 -3
  20. package/lib/configs/install/read-install-config.d.ts +2 -5
  21. package/lib/configs/install/read-install-config.js +20 -18
  22. package/lib/configs/install/write-install-config.d.ts +2 -2
  23. package/lib/configs/install/write-install-config.js +2 -1
  24. package/lib/configs/package/read-listing-config.d.ts +7 -0
  25. package/lib/configs/package/read-listing-config.js +71 -0
  26. package/lib/configs/package/read-package-config.d.ts +2 -1
  27. package/lib/configs/package/read-package-config.js +96 -10
  28. package/lib/configs/utils/constants.d.ts +2 -2
  29. package/lib/configs/utils/constants.js +2 -2
  30. package/lib/configs/utils/merge-upsert-property.js +0 -8
  31. package/lib/configs/utils/normalize-file-always.js +5 -0
  32. package/lib/configs/utils/normalize-file-upsert.d.ts +2 -1
  33. package/lib/configs/utils/normalize-file-upsert.js +12 -5
  34. package/lib/journeys/commitlint/index.d.ts +1 -1
  35. package/lib/journeys/config.ts/index.d.ts +1 -1
  36. package/lib/journeys/config.ts/index.js +2 -6
  37. package/lib/journeys/default/index.d.ts +1 -1
  38. package/lib/journeys/gitignore/index.d.ts +1 -1
  39. package/lib/journeys/ignore/index.d.ts +1 -1
  40. package/lib/journeys/index.d.ts +2 -2
  41. package/lib/journeys/index.js +9 -11
  42. package/lib/journeys/npmignore/index.d.ts +1 -1
  43. package/lib/journeys/package/index.d.ts +1 -1
  44. package/lib/journeys/rc/index.d.ts +1 -1
  45. package/lib/journeys/tsconfig/index.d.ts +1 -1
  46. package/lib/parsers/index.d.ts +4 -0
  47. package/lib/parsers/index.js +41 -0
  48. package/lib/parsers/json.d.ts +4 -2
  49. package/lib/parsers/json.js +7 -2
  50. package/lib/parsers/jsonc/parse.d.ts +2 -5
  51. package/lib/parsers/jsonc/parse.js +8 -6
  52. package/lib/parsers/to-format.d.ts +2 -0
  53. package/lib/parsers/to-format.js +50 -0
  54. package/lib/parsers/yaml.d.ts +4 -2
  55. package/lib/parsers/yaml.js +7 -2
  56. package/lib/routes/command.js +7 -0
  57. package/lib/routes/index.d.ts +4 -3
  58. package/lib/routes/index.js +9 -7
  59. package/lib/routes/{list-sort-concat.d.ts → list-concat-after.d.ts} +1 -1
  60. package/lib/routes/{list-sort-concat.js → list-concat-after.js} +2 -2
  61. package/lib/routes/merge-dot-js.d.ts +2 -0
  62. package/lib/routes/merge-dot-js.js +8 -0
  63. package/lib/steps/configure-install-file-actions.js +1 -20
  64. package/lib/steps/configure-update-file-actions.js +1 -20
  65. package/lib/steps/execute-first-block.js +1 -1
  66. package/lib/steps/index.d.ts +0 -2
  67. package/lib/steps/index.js +4 -3
  68. package/lib/steps/merge-text-files.d.ts +1 -1
  69. package/lib/steps/merge-text-files.js +6 -2
  70. package/lib/steps/read-files.d.ts +1 -1
  71. package/lib/steps/read-files.js +56 -42
  72. package/lib/steps/read-incoming-config.js +1 -1
  73. package/lib/steps/remove-files.d.ts +1 -1
  74. package/lib/steps/remove-files.js +3 -2
  75. package/lib/steps/rename-files.d.ts +1 -1
  76. package/lib/steps/rename-files.js +3 -2
  77. package/lib/steps/validate-newer-package.d.ts +1 -1
  78. package/lib/steps/validate-newer-package.js +13 -2
  79. package/lib/types/config.d.ts +11 -7
  80. package/lib/types/context.d.ts +23 -3
  81. package/lib/types/context.js +6 -0
  82. package/lib/types/travel.d.ts +1 -0
  83. package/lib/utils/build-journey-plan.d.ts +2 -2
  84. package/lib/utils/build-route.d.ts +1 -1
  85. package/lib/utils/build-route.js +50 -19
  86. package/lib/utils/build-travel-plan.js +1 -0
  87. package/lib/utils/command/merge-and-chains.js +1 -1
  88. package/lib/utils/command/merge-command-records.js +1 -1
  89. package/lib/utils/command/merge-parts-by-prefix.js +12 -1
  90. package/lib/utils/command/merge-semicolon-segments.js +161 -4
  91. package/lib/utils/fnmatch.d.ts +1 -0
  92. package/lib/utils/fnmatch.js +11 -0
  93. package/lib/utils/format-table.d.ts +1 -0
  94. package/lib/utils/format-table.js +58 -0
  95. package/lib/utils/get-format.js +2 -9
  96. package/lib/utils/load-package.d.ts +6 -0
  97. package/lib/utils/load-package.js +26 -0
  98. package/lib/utils/template.js +1 -3
  99. package/lib/utils/time-difference.d.ts +1 -0
  100. package/lib/utils/time-difference.js +28 -0
  101. package/package.json +128 -125
  102. package/lib/journeys/fixpack/index.d.ts +0 -2
  103. package/lib/journeys/fixpack/index.js +0 -16
  104. package/lib/steps/validate-not-present-package.d.ts +0 -3
  105. package/lib/steps/validate-not-present-package.js +0 -24
  106. package/lib/utils/try-json.d.ts +0 -1
  107. package/lib/utils/try-json.js +0 -11
package/README.md CHANGED
@@ -68,6 +68,26 @@ Artifacts published to npm must be prefixed with `artifact-`.
68
68
  Command Reference
69
69
  -----------------
70
70
 
71
+ ### Usage
72
+
73
+ ```
74
+ Usage: artifact [options] [command]
75
+
76
+ Boilerplate your project & keep your configurations up to date
77
+
78
+ Options:
79
+ -v, --version output the version number
80
+ -h, --help display help for command
81
+
82
+ Commands:
83
+ add [options] <artifacts...> add an artifact to the current project
84
+ list|ls list the installed artifacts in the project
85
+ outdated|od check for outdated artifacts
86
+ remove|rm [options] [artifacts...] remove an artifact from the current project
87
+ update|up [options] update the current project using the installed artifacts
88
+ help [command] display help for command
89
+ ```
90
+
71
91
  ### `artifact add`
72
92
 
73
93
  Registers and applies one or more artifacts in the current project.
@@ -78,12 +98,12 @@ Registers and applies one or more artifacts in the current project.
78
98
 
79
99
  `<artifact>` can be `name` or `name:variant`.
80
100
 
81
- ### `artifact list` / `artifact l`
101
+ ### `artifact list` / `artifact ls`
82
102
 
83
103
  Shows the artifacts currently tracked in `.artifactrc*`, including versions and, when available, requested variants.
84
104
 
85
105
  - Syntax: `artifact list`
86
- - Alias: `artifact l`
106
+ - Alias: `artifact ls`
87
107
  - Output: prints each artifact as `name@version:variant`.
88
108
 
89
109
  ### `artifact update` / `artifact up`
package/lib/cli.js CHANGED
@@ -28,23 +28,28 @@ program
28
28
  .argument('<artifacts...>')
29
29
  .action(index_js_1.add);
30
30
  program
31
- .command('update')
32
- .description('update the current project using the installed artifacts')
33
- .option('-d, --dry-run', 'fake update')
34
- .option('--verbose', 'output more details')
35
- .alias('up')
36
- .action(index_js_1.update);
31
+ .command('list')
32
+ .description('list the installed artifacts in the project')
33
+ .alias('ls')
34
+ .action(index_js_1.list);
35
+ program
36
+ .command('outdated')
37
+ .description('check for outdated artifacts')
38
+ .alias('od')
39
+ .action(index_js_1.outdated);
37
40
  program
38
41
  .command('remove')
39
42
  .description('remove an artifact from the current project')
40
43
  .option('-d, --dry-run', 'fake uninstall')
41
44
  .option('--verbose', 'output more details')
42
- .argument('<artifacts...>')
45
+ .argument('[artifacts...]')
43
46
  .alias('rm')
44
47
  .action(index_js_1.remove);
45
48
  program
46
- .command('list')
47
- .description('list the installed artifacts in the project')
48
- .alias('l')
49
- .action(index_js_1.list);
49
+ .command('update')
50
+ .description('update the current project using the installed artifacts')
51
+ .option('-d, --dry-run', 'fake update')
52
+ .option('--verbose', 'output more details')
53
+ .alias('up')
54
+ .action(index_js_1.update);
50
55
  program.parse();
@@ -4,16 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.add = add;
7
- const process_1 = __importDefault(require("process"));
7
+ const node_process_1 = __importDefault(require("node:process"));
8
8
  const cli_utils_1 = require("@zokugun/cli-utils");
9
+ const async_1 = require("@zokugun/xtry/async");
9
10
  const pacote_1 = __importDefault(require("pacote"));
10
11
  const tempy_1 = __importDefault(require("tempy"));
11
12
  const index_js_1 = require("../configs/index.js");
13
+ const read_listing_config_js_1 = require("../configs/package/read-listing-config.js");
12
14
  const index_js_2 = require("../steps/index.js");
15
+ const load_package_js_1 = require("../utils/load-package.js");
13
16
  const resolve_request_js_1 = require("../utils/resolve-request.js");
14
17
  const { mainFlow } = (0, index_js_2.composeSteps)([
15
18
  index_js_2.steps.readIncomingPackage,
16
- index_js_2.steps.validateNotPresentPackage,
17
19
  index_js_2.steps.readIncomingConfig,
18
20
  index_js_2.steps.executeFirstBlock,
19
21
  ], [
@@ -35,7 +37,48 @@ const { mainFlow } = (0, index_js_2.composeSteps)([
35
37
  ]);
36
38
  async function add(specs, inputOptions) {
37
39
  cli_utils_1.logger.beginTimer();
38
- const targetPath = process_1.default.cwd();
40
+ if (specs.length === 1 && /^@\w+$/.test(specs[0])) {
41
+ const request = `${specs.shift()}/artifact-listing`;
42
+ const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(request)}`);
43
+ const dir = tempy_1.default.directory();
44
+ const pkgResult = await (0, async_1.xtry)(pacote_1.default.extract(request, dir));
45
+ if (pkgResult.fails) {
46
+ cli_utils_1.logger.fatal(`The artifact '${request}' couldn't be found.`);
47
+ }
48
+ spinner.succeed();
49
+ cli_utils_1.logger.stopProgress();
50
+ const listing = await (0, read_listing_config_js_1.readListingConfig)(dir);
51
+ if (listing.fails) {
52
+ cli_utils_1.logger.fatal(listing.error);
53
+ }
54
+ const { value } = await (0, async_1.xtry)(cli_utils_1.enquirer.prompt({
55
+ type: 'multiselect',
56
+ name: 'specs',
57
+ message: 'Pick the artifacts to add',
58
+ // @ts-expect-error TS2353
59
+ limit: 7,
60
+ choices: listing.value.map(({ name, description }) => ({ name, message: `${name}${cli_utils_1.c.grey(`: ${description}`)}` })),
61
+ }));
62
+ const marked = value?.specs;
63
+ if (!marked || marked.length === 0) {
64
+ cli_utils_1.logger.warn('No artifacts marked for addition');
65
+ }
66
+ else {
67
+ const { value } = await (0, async_1.xtry)(cli_utils_1.enquirer.prompt([
68
+ (0, cli_utils_1.confirm)({
69
+ name: 'addition',
70
+ message: `Adds the following artifacts: ${marked.map((name) => cli_utils_1.c.green(name)).join(',')}`,
71
+ }),
72
+ ]));
73
+ if (value?.addition) {
74
+ specs.push(...marked);
75
+ }
76
+ else {
77
+ cli_utils_1.logger.warn('Artifacts addition has been rejected');
78
+ }
79
+ }
80
+ }
81
+ const targetPath = node_process_1.default.cwd();
39
82
  const options = {
40
83
  dryRun: inputOptions?.dryRun ?? false,
41
84
  force: inputOptions?.force ?? false,
@@ -52,29 +95,59 @@ async function add(specs, inputOptions) {
52
95
  if (configResult.fails) {
53
96
  cli_utils_1.logger.fatal(configResult.error);
54
97
  }
55
- const { config, configStats } = configResult.value;
98
+ const config = configResult.value;
99
+ const requests = [];
56
100
  for (const spec of specs) {
57
- const requestResult = (0, resolve_request_js_1.resolveRequest)(spec);
58
- if (requestResult.fails) {
59
- cli_utils_1.logger.fatal(requestResult.error);
101
+ const request = (0, resolve_request_js_1.resolveRequest)(spec);
102
+ if (request.fails) {
103
+ cli_utils_1.logger.fatal(request.error);
60
104
  }
61
- const request = requestResult.value;
62
- const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(request.name)}`);
63
- const dir = tempy_1.default.directory();
64
- const pkgResult = await pacote_1.default.extract(request.name, dir);
65
- if (!pkgResult.resolved) {
66
- if (options.force || options.skip) {
67
- spinner.fail();
68
- if (options.verbose) {
69
- cli_utils_1.logger.warn(`The artifact '${spec}' couldn't be found, skipping...`);
105
+ if (!options.force) {
106
+ const { name } = request.value;
107
+ const artifact = config.artifacts[name];
108
+ if (artifact) {
109
+ if (options.skip) {
110
+ if (options.verbose) {
111
+ cli_utils_1.logger.debug(`The "${name}" artifact is already present, skipping...`);
112
+ }
113
+ }
114
+ else {
115
+ cli_utils_1.logger.fatal(`The "${name}" artifact has already been added.`);
70
116
  }
71
- continue;
72
- }
73
- else {
74
- cli_utils_1.logger.fatal(pkgResult.from);
75
117
  }
76
118
  }
77
- const flowResult = await mainFlow(targetPath, dir, request, config, options);
119
+ requests.push(request.value);
120
+ }
121
+ const global = {
122
+ journeys: {},
123
+ overwrittenTextFiles: [],
124
+ routes: {},
125
+ };
126
+ for (const [name, { version }] of Object.entries(config.artifacts)) {
127
+ const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(name)}`);
128
+ const dir = await (0, load_package_js_1.loadPackage)(`${name}@${version}`, spinner, options);
129
+ if (!dir) {
130
+ continue;
131
+ }
132
+ const result = await (0, index_js_1.readPackageConfig)(dir, global.routes);
133
+ if (result.fails) {
134
+ cli_utils_1.logger.fatal(result.error);
135
+ }
136
+ for (const [name, journey] of Object.entries(result.value.journeys)) {
137
+ global.journeys[name] = journey;
138
+ }
139
+ for (const [name, route] of Object.entries(result.value.routes)) {
140
+ global.routes[name] = route;
141
+ }
142
+ spinner.succeed();
143
+ }
144
+ for (const request of requests) {
145
+ const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(request.name)}`);
146
+ const dir = await (0, load_package_js_1.loadPackage)(request.name, spinner, options);
147
+ if (!dir) {
148
+ continue;
149
+ }
150
+ const flowResult = await mainFlow(targetPath, dir, request, config, global, options);
78
151
  if (flowResult.fails) {
79
152
  cli_utils_1.logger.fatal(flowResult.error);
80
153
  }
@@ -83,7 +156,7 @@ async function add(specs, inputOptions) {
83
156
  continue;
84
157
  }
85
158
  (0, index_js_1.updateInstallConfig)(config, flowResult.value.result);
86
- await (0, index_js_1.writeInstallConfig)(config, configStats, flowResult.value.formats, targetPath, options);
159
+ await (0, index_js_1.writeInstallConfig)(config, flowResult.value.formats, targetPath, options);
87
160
  spinner.succeed();
88
161
  }
89
162
  cli_utils_1.logger.finishTimer();
@@ -1,4 +1,5 @@
1
1
  export { add } from './add.js';
2
2
  export { list } from './list.js';
3
+ export { outdated } from './outdated.js';
3
4
  export { remove } from './remove.js';
4
5
  export { update } from './update.js';
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.update = exports.remove = exports.list = exports.add = void 0;
3
+ exports.update = exports.remove = exports.outdated = exports.list = exports.add = void 0;
4
4
  var add_js_1 = require("./add.js");
5
5
  Object.defineProperty(exports, "add", { enumerable: true, get: function () { return add_js_1.add; } });
6
6
  var list_js_1 = require("./list.js");
7
7
  Object.defineProperty(exports, "list", { enumerable: true, get: function () { return list_js_1.list; } });
8
+ var outdated_js_1 = require("./outdated.js");
9
+ Object.defineProperty(exports, "outdated", { enumerable: true, get: function () { return outdated_js_1.outdated; } });
8
10
  var remove_js_1 = require("./remove.js");
9
11
  Object.defineProperty(exports, "remove", { enumerable: true, get: function () { return remove_js_1.remove; } });
10
12
  var update_js_1 = require("./update.js");
@@ -4,12 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.list = list;
7
+ const node_path_1 = __importDefault(require("node:path"));
7
8
  const process_1 = __importDefault(require("process"));
8
9
  const cli_utils_1 = require("@zokugun/cli-utils");
9
- const lodash_es_1 = require("lodash-es");
10
+ const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
11
+ const xtry_1 = require("@zokugun/xtry");
10
12
  const index_js_1 = require("../configs/index.js");
13
+ const format_table_js_1 = require("../utils/format-table.js");
11
14
  function formatVariant(artifact) {
12
- const variant = Array.isArray(artifact.requires) ? (0, lodash_es_1.last)(artifact.requires) ?? '' : '';
15
+ const variant = Array.isArray(artifact.requires) ? artifact.requires.at(-1) ?? '' : '';
13
16
  if (variant.length > 0) {
14
17
  return `:${variant}`;
15
18
  }
@@ -18,22 +21,37 @@ function formatVariant(artifact) {
18
21
  }
19
22
  }
20
23
  async function list() {
21
- const targetPath = process_1.default.env.INIT_CWD;
24
+ const targetPath = process_1.default.cwd();
22
25
  const configResult = await (0, index_js_1.readInstallConfig)(targetPath);
23
26
  if (configResult.fails) {
24
27
  cli_utils_1.logger.fatal(configResult.error);
25
28
  }
26
- const { config, configStats } = configResult.value;
29
+ const packageResult = await async_1.default.readJSON(node_path_1.default.resolve(targetPath, './package.json'));
30
+ if (packageResult.fails) {
31
+ cli_utils_1.logger.fatal((0, xtry_1.stringifyError)(packageResult.error));
32
+ }
33
+ const { name } = packageResult.value;
34
+ const config = configResult.value;
27
35
  const artifacts = Object.entries(config.artifacts);
36
+ cli_utils_1.logger.newLine();
28
37
  if (artifacts.length === 0) {
29
38
  cli_utils_1.logger.info('No artifacts have been installed.');
30
39
  }
31
40
  else {
32
- cli_utils_1.logger.info(`List of installed artifacts (${configStats.name}):\n`);
41
+ cli_utils_1.logger.print(`${name} ${cli_utils_1.c.grey(config.file.name)}`);
42
+ cli_utils_1.logger.newLine();
43
+ const table = [];
33
44
  for (const [name, artifact] of artifacts) {
34
- const version = artifact.version ? `@${artifact.version}` : '';
35
- cli_utils_1.logger.info(`- ${name}${version}${formatVariant(artifact)}`);
45
+ const line = [
46
+ ' ',
47
+ name,
48
+ ' ',
49
+ artifact.version ? `${cli_utils_1.c.green(artifact.version)}${cli_utils_1.c.gray(formatVariant(artifact))}` : '',
50
+ ];
51
+ table.push(line);
36
52
  }
53
+ const lines = (0, format_table_js_1.formatTable)(table, 'LLLL');
54
+ cli_utils_1.logger.print(lines.join('\n'));
37
55
  }
38
56
  cli_utils_1.logger.newLine();
39
57
  }
@@ -0,0 +1 @@
1
+ export declare function outdated(): Promise<void>;
@@ -0,0 +1,73 @@
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.outdated = outdated;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const process_1 = __importDefault(require("process"));
9
+ const cli_utils_1 = require("@zokugun/cli-utils");
10
+ const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
11
+ const xtry_1 = require("@zokugun/xtry");
12
+ const cli_progress_1 = require("cli-progress");
13
+ const pacote_1 = __importDefault(require("pacote"));
14
+ const semver_1 = require("semver");
15
+ const index_js_1 = require("../configs/index.js");
16
+ const format_table_js_1 = require("../utils/format-table.js");
17
+ const time_difference_js_1 = require("../utils/time-difference.js");
18
+ async function outdated() {
19
+ const targetPath = process_1.default.cwd();
20
+ const configResult = await (0, index_js_1.readInstallConfig)(targetPath);
21
+ if (configResult.fails) {
22
+ cli_utils_1.logger.fatal(configResult.error);
23
+ }
24
+ const packageResult = await async_1.default.readJSON(node_path_1.default.resolve(targetPath, './package.json'));
25
+ if (packageResult.fails) {
26
+ cli_utils_1.logger.fatal((0, xtry_1.stringifyError)(packageResult.error));
27
+ }
28
+ const { name } = packageResult.value;
29
+ const config = configResult.value;
30
+ const artifacts = Object.entries(config.artifacts);
31
+ cli_utils_1.logger.newLine();
32
+ if (artifacts.length === 0) {
33
+ cli_utils_1.logger.info('No artifacts have been installed.');
34
+ }
35
+ else {
36
+ cli_utils_1.logger.print(`${name} ${cli_utils_1.c.grey(config.file.name)}`);
37
+ const bar = new cli_progress_1.SingleBar({
38
+ clearOnComplete: true,
39
+ hideCursor: true,
40
+ format: `{bar} {value}/{total} ${cli_utils_1.c.gray('{name}')}`,
41
+ linewrap: false,
42
+ barsize: 40,
43
+ }, cli_progress_1.Presets.shades_classic);
44
+ bar.start(artifacts.length, 0);
45
+ const table = [];
46
+ for (const [index, [name, artifact]] of artifacts.entries()) {
47
+ const current = await pacote_1.default.manifest(`${name}@${artifact.version}`, {
48
+ fullMetadata: true,
49
+ });
50
+ const latest = await pacote_1.default.manifest(name, {
51
+ fullMetadata: true,
52
+ });
53
+ const newer = (0, semver_1.gt)(latest.version, artifact.version);
54
+ const line = [
55
+ ' ',
56
+ newer ? name : cli_utils_1.c.grey(name),
57
+ ' ',
58
+ (0, time_difference_js_1.timeDifference)(current._time),
59
+ artifact.version ? cli_utils_1.c.grey(artifact.version) : '',
60
+ cli_utils_1.c.dim.grey('→'),
61
+ newer ? latest.version : cli_utils_1.c.grey.strikethrough(latest.version),
62
+ newer ? (0, time_difference_js_1.timeDifference)(latest._time) : '',
63
+ ];
64
+ table.push(line);
65
+ bar.update(index, { name });
66
+ }
67
+ bar.stop();
68
+ cli_utils_1.logger.newLine();
69
+ const lines = (0, format_table_js_1.formatTable)(table, 'LLLLRRRL');
70
+ cli_utils_1.logger.print(lines.join('\n'));
71
+ }
72
+ cli_utils_1.logger.newLine();
73
+ }
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.remove = remove;
7
7
  const process_1 = __importDefault(require("process"));
8
8
  const cli_utils_1 = require("@zokugun/cli-utils");
9
- const pacote_1 = __importDefault(require("pacote"));
10
- const tempy_1 = __importDefault(require("tempy"));
9
+ const async_1 = require("@zokugun/xtry/async");
11
10
  const index_js_1 = require("../configs/index.js");
12
11
  const index_js_2 = require("../steps/index.js");
12
+ const load_package_js_1 = require("../utils/load-package.js");
13
13
  const resolve_request_js_1 = require("../utils/resolve-request.js");
14
14
  const { mainFlow } = (0, index_js_2.composeSteps)([
15
15
  index_js_2.steps.readIncomingPackage,
@@ -42,7 +42,38 @@ async function remove(specs, inputOptions) {
42
42
  if (configResult.fails) {
43
43
  cli_utils_1.logger.fatal(configResult.error);
44
44
  }
45
- const { config, configStats } = configResult.value;
45
+ const config = configResult.value;
46
+ if (specs.length === 0) {
47
+ const { value } = await (0, async_1.xtry)(cli_utils_1.enquirer.prompt({
48
+ type: 'multiselect',
49
+ name: 'specs',
50
+ message: 'Pick the artifacts to remove',
51
+ choices: Object.keys(config.artifacts).map((name) => ({ name })),
52
+ }));
53
+ const marked = value?.specs;
54
+ if (!marked || marked.length === 0) {
55
+ cli_utils_1.logger.warn('No artifacts marked for removal');
56
+ }
57
+ else {
58
+ const { value } = await (0, async_1.xtry)(cli_utils_1.enquirer.prompt([
59
+ (0, cli_utils_1.confirm)({
60
+ name: 'remove',
61
+ message: `Remove the following artifacts: ${marked.map((name) => cli_utils_1.c.green(name)).join(',')}`,
62
+ }),
63
+ ]));
64
+ if (value?.remove) {
65
+ specs.push(...marked);
66
+ }
67
+ else {
68
+ cli_utils_1.logger.warn('Artifacts removal has been rejected');
69
+ }
70
+ }
71
+ }
72
+ const global = {
73
+ journeys: {},
74
+ overwrittenTextFiles: [],
75
+ routes: {},
76
+ };
46
77
  for (const spec of specs) {
47
78
  const requestResult = (0, resolve_request_js_1.resolveRequest)(spec);
48
79
  if (requestResult.fails) {
@@ -50,21 +81,11 @@ async function remove(specs, inputOptions) {
50
81
  }
51
82
  const request = requestResult.value;
52
83
  const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(request.name)}`);
53
- const dir = tempy_1.default.directory();
54
- const pkgResult = await pacote_1.default.extract(request.name, dir);
55
- if (!pkgResult.resolved) {
56
- if (options.force || options.skip) {
57
- spinner.fail();
58
- if (options.verbose) {
59
- cli_utils_1.logger.debug(`The artifact '${spec}' couldn't be found, skipping...`);
60
- }
61
- continue;
62
- }
63
- else {
64
- cli_utils_1.logger.fatal(pkgResult.from);
65
- }
84
+ const dir = await (0, load_package_js_1.loadPackage)(request.name, spinner, options);
85
+ if (!dir) {
86
+ continue;
66
87
  }
67
- const flowResult = await mainFlow(targetPath, dir, request, config, options);
88
+ const flowResult = await mainFlow(targetPath, dir, request, config, global, options);
68
89
  if (flowResult.fails) {
69
90
  cli_utils_1.logger.fatal(flowResult.error);
70
91
  }
@@ -73,7 +94,7 @@ async function remove(specs, inputOptions) {
73
94
  continue;
74
95
  }
75
96
  (0, index_js_1.updateUninstallConfig)(config, flowResult.value.result);
76
- await (0, index_js_1.writeInstallConfig)(config, configStats, flowResult.value.formats, targetPath, options);
97
+ await (0, index_js_1.writeInstallConfig)(config, flowResult.value.formats, targetPath, options);
77
98
  spinner.succeed();
78
99
  }
79
100
  cli_utils_1.logger.finishTimer();
@@ -7,10 +7,9 @@ exports.update = update;
7
7
  const process_1 = __importDefault(require("process"));
8
8
  const cli_utils_1 = require("@zokugun/cli-utils");
9
9
  const lodash_es_1 = require("lodash-es");
10
- const pacote_1 = __importDefault(require("pacote"));
11
- const tempy_1 = __importDefault(require("tempy"));
12
10
  const index_js_1 = require("../configs/index.js");
13
11
  const index_js_2 = require("../steps/index.js");
12
+ const load_package_js_1 = require("../utils/load-package.js");
14
13
  const { mainFlow } = (0, index_js_2.composeSteps)([
15
14
  index_js_2.steps.readIncomingPackage,
16
15
  index_js_2.steps.validateNewerPackage,
@@ -47,34 +46,50 @@ async function update(inputOptions) {
47
46
  if (configResult.fails) {
48
47
  cli_utils_1.logger.fatal(configResult.error);
49
48
  }
50
- const { config, configStats } = configResult.value;
49
+ const config = configResult.value;
50
+ const global = {
51
+ journeys: {},
52
+ overwrittenTextFiles: [],
53
+ routes: {},
54
+ };
51
55
  for (const [name, artifact] of Object.entries(config.artifacts)) {
52
56
  const spinner = cli_utils_1.logger.createSpinner(`${cli_utils_1.c.cyan.bold(name)}`);
53
- const dir = tempy_1.default.directory();
54
- const pkgResult = await pacote_1.default.extract(name, dir);
55
- if (!pkgResult.resolved) {
56
- if (options.force) {
57
- spinner.fail();
58
- if (options.verbose) {
59
- cli_utils_1.logger.debug(`The artifact '${name}' couldn't be found, skipping...`);
60
- }
61
- continue;
57
+ const request = artifact.requires ? { name, variant: (0, lodash_es_1.last)(artifact.requires) } : { name };
58
+ const dir = await (0, load_package_js_1.loadPackage)(request.name, spinner, options);
59
+ if (!dir) {
60
+ continue;
61
+ }
62
+ const result = await mainFlow(targetPath, dir, request, config, global, options);
63
+ if (result.fails) {
64
+ cli_utils_1.logger.fatal(result.error);
65
+ }
66
+ const context = result.value;
67
+ if (context?.incomingConfig) {
68
+ for (const [name, journey] of Object.entries(context.incomingConfig.journeys)) {
69
+ global.journeys[name] = journey;
62
70
  }
63
- else {
64
- cli_utils_1.logger.fatal(pkgResult.from);
71
+ for (const [name, route] of Object.entries(context.incomingConfig.routes)) {
72
+ global.routes[name] = route;
65
73
  }
66
74
  }
67
- const request = artifact.requires ? { name, variant: (0, lodash_es_1.last)(artifact.requires) } : { name };
68
- const flowResult = await mainFlow(targetPath, dir, request, config, options);
69
- if (flowResult.fails) {
70
- cli_utils_1.logger.fatal(flowResult.error);
75
+ else {
76
+ const result = await (0, index_js_1.readPackageConfig)(dir, global.routes);
77
+ if (result.fails) {
78
+ cli_utils_1.logger.fatal(result.error);
79
+ }
80
+ for (const [name, journey] of Object.entries(result.value.journeys)) {
81
+ global.journeys[name] = journey;
82
+ }
83
+ for (const [name, route] of Object.entries(result.value.routes)) {
84
+ global.routes[name] = route;
85
+ }
71
86
  }
72
- if (!flowResult.value?.result) {
87
+ if (!context?.result) {
73
88
  spinner.succeed();
74
89
  continue;
75
90
  }
76
- (0, index_js_1.updateInstallConfig)(config, flowResult.value.result);
77
- await (0, index_js_1.writeInstallConfig)(config, configStats, flowResult.value.formats, targetPath, options);
91
+ (0, index_js_1.updateInstallConfig)(config, context.result);
92
+ await (0, index_js_1.writeInstallConfig)(config, context.formats, targetPath, options);
78
93
  spinner.succeed();
79
94
  }
80
95
  cli_utils_1.logger.finishTimer();
@@ -0,0 +1,3 @@
1
+ import { type Codec } from '../types/context.js';
2
+ import { type Route } from '../types/travel.js';
3
+ export declare function codec(codecs: Codec[], ...routes: Array<Route<Record<string, any>>>): Route<string>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.codec = codec;
4
+ const is_it_type_1 = require("@zokugun/is-it-type");
5
+ const list_concat_js_1 = require("../routes/list-concat.js");
6
+ const primitive_js_1 = require("../routes/primitive.js");
7
+ const apply_transforms_js_1 = require("../utils/apply-transforms.js");
8
+ const flow_js_1 = require("../utils/flow.js");
9
+ const compose_js_1 = require("./compose.js");
10
+ const fork_js_1 = require("./fork.js");
11
+ const merge = (0, compose_js_1.compose)({
12
+ $$default: (0, fork_js_1.fork)([is_it_type_1.isArray, list_concat_js_1.listConcat], [is_it_type_1.isRecord, async (...args) => merge(...args)], primitive_js_1.primitive),
13
+ });
14
+ function codec(codecs, ...routes) {
15
+ return async ({ current, incoming, filters, ignores, transforms }) => {
16
+ if (!(0, is_it_type_1.isNonBlankString)(current)) {
17
+ return incoming;
18
+ }
19
+ for (const { parse, stringify } of codecs) {
20
+ const currentResult = parse(current);
21
+ if (currentResult.fails) {
22
+ continue;
23
+ }
24
+ if ((0, is_it_type_1.isNonBlankString)(incoming)) {
25
+ const incomingResult = parse(incoming);
26
+ if (incomingResult.fails) {
27
+ continue;
28
+ }
29
+ const incomingData = incomingResult.value.data;
30
+ if (!(0, is_it_type_1.isArray)(incomingData) && !(0, is_it_type_1.isRecord)(incomingData)) {
31
+ return incoming;
32
+ }
33
+ const mergedTransform = currentResult.value.transform
34
+ ? await merge({ current: currentResult.value.transform, incoming: incomingResult.value.transform })
35
+ : incomingResult.value.transform;
36
+ const run = (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), (data) => stringify(data, mergedTransform));
37
+ return run({ current: currentResult.value.data, incoming: incomingData, filters, ignores });
38
+ }
39
+ else {
40
+ const run = (0, flow_js_1.flow)(...routes, (0, apply_transforms_js_1.applyTransforms)(transforms), (data) => stringify(data, currentResult.value.transform));
41
+ return run({ current: currentResult.value.data, filters, ignores });
42
+ }
43
+ }
44
+ return incoming;
45
+ };
46
+ }
@@ -2,6 +2,7 @@ import { type Route } from '../types/travel.js';
2
2
  type ComposeMap = {
3
3
  [key: string]: Route<any> | string[] | undefined;
4
4
  $$ignore?: string[];
5
+ $$remove?: string[];
5
6
  };
6
7
  export declare function compose(map: ComposeMap): Route<Record<string, any>>;
7
8
  export {};
@@ -7,7 +7,11 @@ async function apply(map, keys, current, incoming, result) {
7
7
  return;
8
8
  }
9
9
  const ignores = map.$$ignore ?? [];
10
+ const removes = map.$$remove ?? [];
10
11
  for (const key of keys) {
12
+ if (removes.includes(key)) {
13
+ continue;
14
+ }
11
15
  const currentValue = current[key];
12
16
  const transform = map[key] ?? map.$$default;
13
17
  if (!transform || !(0, lodash_es_1.has)(incoming, key) || ignores.includes(key)) {
@@ -1,3 +1,4 @@
1
+ export { codec } from './codec.js';
1
2
  export { compose } from './compose.js';
2
3
  export { fork } from './fork.js';
3
4
  export { json } from './json.js';