@pagopa/dx-cli 0.22.4 → 0.23.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 (37) hide show
  1. package/README.md +18 -0
  2. package/dist/adapters/commander/__tests__/spec.test.d.ts +8 -0
  3. package/dist/adapters/commander/__tests__/spec.test.js +264 -0
  4. package/dist/adapters/commander/commands/__tests__/init-command.test.d.ts +4 -0
  5. package/dist/adapters/commander/commands/__tests__/init-command.test.js +44 -0
  6. package/dist/adapters/commander/commands/__tests__/savemoney.test.d.ts +8 -0
  7. package/dist/adapters/commander/commands/__tests__/savemoney.test.js +60 -0
  8. package/dist/adapters/commander/commands/__tests__/spec.test.d.ts +7 -0
  9. package/dist/adapters/commander/commands/__tests__/spec.test.js +85 -0
  10. package/dist/adapters/commander/commands/add.d.ts +2 -6
  11. package/dist/adapters/commander/commands/add.js +4 -8
  12. package/dist/adapters/commander/commands/init.d.ts +2 -6
  13. package/dist/adapters/commander/commands/init.js +6 -5
  14. package/dist/adapters/commander/commands/savemoney.d.ts +11 -0
  15. package/dist/adapters/commander/commands/savemoney.js +30 -5
  16. package/dist/adapters/commander/commands/spec.d.ts +10 -0
  17. package/dist/adapters/commander/commands/spec.js +13 -0
  18. package/dist/adapters/commander/index.js +6 -2
  19. package/dist/adapters/commander/spec.d.ts +16 -0
  20. package/dist/adapters/commander/spec.js +54 -0
  21. package/dist/adapters/plop/generators/__tests__/temp-dir.d.ts +2 -0
  22. package/dist/adapters/plop/generators/__tests__/temp-dir.js +13 -0
  23. package/dist/adapters/plop/generators/environment/__tests__/generation.test.d.ts +1 -0
  24. package/dist/adapters/plop/generators/environment/__tests__/generation.test.js +213 -0
  25. package/dist/adapters/plop/generators/environment/actions.js +3 -3
  26. package/dist/adapters/plop/generators/monorepo/__tests__/generation.test.d.ts +1 -0
  27. package/dist/adapters/plop/generators/monorepo/__tests__/generation.test.js +79 -0
  28. package/dist/adapters/plop/index.js +3 -5
  29. package/dist/adapters/plop/templates-path.d.ts +5 -0
  30. package/dist/adapters/plop/templates-path.js +6 -0
  31. package/dist/domain/__tests__/data.d.ts +3 -7
  32. package/dist/domain/__tests__/data.js +2 -4
  33. package/dist/domain/dependencies.d.ts +15 -2
  34. package/dist/domain/spec.d.ts +50 -0
  35. package/dist/domain/spec.js +8 -0
  36. package/dist/index.js +15 -12
  37. package/package.json +2 -2
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Spec Domain
3
+ *
4
+ * Pure types that describe the shape of the CLI spec output.
5
+ * Technology-agnostic: no dependency on Commander or any CLI framework.
6
+ * Consumed by the Commander adapter and by agent tooling that parses `dx spec`.
7
+ */
8
+ export type ArgumentSpec = {
9
+ /** Allowed values when the argument is constrained to a set */
10
+ choices: string[];
11
+ defaultValue: unknown;
12
+ description: string;
13
+ name: string;
14
+ required: boolean;
15
+ variadic: boolean;
16
+ };
17
+ export type CliSpec = {
18
+ /** Top-level subcommands with their own options, arguments, and nested commands. */
19
+ commands: CommandSpec[];
20
+ description: string;
21
+ /** Options defined directly on the root `dx` program (global flags). */
22
+ globalOptions: OptionSpec[];
23
+ name: string;
24
+ /** Stable version of the spec JSON shape. Increment on breaking changes. */
25
+ specVersion: "1";
26
+ version: string;
27
+ };
28
+ export type CommandSpec = {
29
+ arguments: ArgumentSpec[];
30
+ commands: CommandSpec[];
31
+ description: string;
32
+ name: string;
33
+ options: OptionSpec[];
34
+ };
35
+ export type OptionSpec = {
36
+ /** Allowed values when the option is an enum */
37
+ choices: string[];
38
+ defaultValue: unknown;
39
+ description: string;
40
+ /** Raw flags string as shown in help, e.g. "-v, --verbose" */
41
+ flags: string;
42
+ /** Long flag, e.g. "--verbose" */
43
+ long: string | undefined;
44
+ /** True when the option value is optional (e.g. `--output [mode]`) */
45
+ optional: boolean;
46
+ /** True when the option value is mandatory (e.g. `--output <mode>`) */
47
+ required: boolean;
48
+ /** Short flag, e.g. "-v" (undefined when not present) */
49
+ short: string | undefined;
50
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Spec Domain
3
+ *
4
+ * Pure types that describe the shape of the CLI spec output.
5
+ * Technology-agnostic: no dependency on Commander or any CLI framework.
6
+ * Consumed by the Commander adapter and by agent tooling that parses `dx spec`.
7
+ */
8
+ export {};
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "core-js/actual/set/index.js";
2
2
  import { configure, getConsoleSink } from "@logtape/logtape";
3
- import * as assert from "node:assert/strict";
3
+ import { errAsync, okAsync, ResultAsync } from "neverthrow";
4
4
  import { Octokit } from "octokit";
5
5
  import codemodRegistry from "./adapters/codemods/index.js";
6
6
  import { makeCli } from "./adapters/commander/index.js";
@@ -13,7 +13,6 @@ import { getConfig } from "./config.js";
13
13
  import { getInfo } from "./domain/info.js";
14
14
  import { applyCodemodById } from "./use-cases/apply-codemod.js";
15
15
  import { listCodemods } from "./use-cases/list-codemods.js";
16
- import { requestAuthorization } from "./use-cases/request-authorization.js";
17
16
  /**
18
17
  * Returns `true` when `-v` or `--verbose` is present in argv.
19
18
  *
@@ -50,29 +49,33 @@ const configureLogging = async (verbose) => {
50
49
  };
51
50
  export const runCli = async (version) => {
52
51
  await configureLogging(detectVerboseFromArgv(process.argv));
53
- // Creating the adapters
54
52
  const repositoryReader = makeRepositoryReader();
55
53
  const packageJsonReader = makePackageJsonReader();
56
54
  const validationReporter = makeValidationReporter();
57
- const auth = await getGitHubPAT();
58
- assert.ok(auth, "GitHub PAT is required. Please set the GH_TOKEN environment variable or login using GitHub CLI.");
59
- const octokit = new Octokit({
60
- auth,
55
+ /**
56
+ * Lazily creates GitHub-authenticated services on first call.
57
+ * Only commands that actually need GitHub (init, add) will trigger this,
58
+ * so credential-free commands (spec, doctor, info, …) never require a PAT.
59
+ */
60
+ const requireGitHubAuth = () => ResultAsync.fromPromise(getGitHubPAT(), (cause) => new Error("Failed to read GitHub PAT", { cause })).andThen((auth) => {
61
+ if (!auth) {
62
+ return errAsync(new Error("GitHub PAT is required. Please set the GH_TOKEN environment variable or login using GitHub CLI."));
63
+ }
64
+ const octokit = new Octokit({ auth });
65
+ const gitHubService = new OctokitGitHubService(octokit);
66
+ const authorizationService = makeAzureAuthorizationService(gitHubService);
67
+ return okAsync({ authorizationService, gitHubService });
61
68
  });
62
- const gitHubService = new OctokitGitHubService(octokit);
63
- const authorizationService = makeAzureAuthorizationService(gitHubService);
64
69
  const deps = {
65
- authorizationService,
66
- gitHubService,
67
70
  packageJsonReader,
68
71
  repositoryReader,
72
+ requireGitHubAuth,
69
73
  validationReporter,
70
74
  };
71
75
  const config = getConfig();
72
76
  const useCases = {
73
77
  applyCodemodById: applyCodemodById(codemodRegistry, getInfo(deps)),
74
78
  listCodemods: listCodemods(codemodRegistry),
75
- requestAuthorization: requestAuthorization(authorizationService),
76
79
  };
77
80
  const program = makeCli(deps, config, useCases, version);
78
81
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/dx-cli",
3
- "version": "0.22.4",
3
+ "version": "0.23.0",
4
4
  "type": "module",
5
5
  "description": "A CLI useful to manage DX tools.",
6
6
  "repository": {
@@ -48,7 +48,7 @@
48
48
  "semver": "^7.7.4",
49
49
  "yaml": "^2.8.4",
50
50
  "zod": "^4.4.2",
51
- "@pagopa/dx-savemoney": "^0.2.6"
51
+ "@pagopa/dx-savemoney": "^0.3.0"
52
52
  },
53
53
  "devDependencies": {
54
54
  "@tsconfig/node24": "24.0.4",