@pagopa/dx-cli 0.4.4 → 0.5.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 (2) hide show
  1. package/bin/index.js +83 -12
  2. package/package.json +2 -2
package/bin/index.js CHANGED
@@ -4,11 +4,68 @@
4
4
  import "core-js/actual/set/index.js";
5
5
  import { configure, getConsoleSink, getLogger as getLogger4 } from "@logtape/logtape";
6
6
 
7
+ // src/adapters/codemods/example.ts
8
+ import { okAsync } from "neverthrow";
9
+ var apply = () => {
10
+ console.log("Hello from example codemod!");
11
+ return okAsync(void 0);
12
+ };
13
+ var example_default = {
14
+ apply,
15
+ description: "An example codemod that does nothing",
16
+ id: "example"
17
+ };
18
+
19
+ // src/adapters/codemods/registry.ts
20
+ import { okAsync as okAsync2 } from "neverthrow";
21
+ var LocalCodemodRegistry = class {
22
+ #m;
23
+ constructor() {
24
+ this.#m = /* @__PURE__ */ new Map();
25
+ }
26
+ add(codemod) {
27
+ this.#m.set(codemod.id, codemod);
28
+ }
29
+ getAll() {
30
+ return okAsync2(Array.from(this.#m.values()));
31
+ }
32
+ getById(id) {
33
+ return okAsync2(this.#m.get(id));
34
+ }
35
+ };
36
+
37
+ // src/adapters/codemods/index.ts
38
+ var registry = new LocalCodemodRegistry();
39
+ registry.add(example_default);
40
+ var codemods_default = registry;
41
+
7
42
  // src/adapters/commander/index.ts
8
- import { Command as Command4 } from "commander";
43
+ import { Command as Command5 } from "commander";
9
44
 
10
- // src/adapters/commander/commands/doctor.ts
45
+ // src/adapters/commander/commands/codemod.ts
11
46
  import { Command } from "commander";
47
+ var makeCodemodCommand = ({
48
+ applyCodemodById: applyCodemodById2,
49
+ listCodemods: listCodemods2
50
+ }) => new Command("codemod").description("Manage and apply migration scripts to the repository").addCommand(
51
+ new Command("list").description("List available migration scripts").action(async function() {
52
+ await listCodemods2().andTee(
53
+ (codemods) => (
54
+ // eslint-disable-next-line no-console
55
+ console.table(codemods, ["id", "description"])
56
+ )
57
+ ).orTee((error) => this.error(error.message));
58
+ })
59
+ ).addCommand(
60
+ new Command("apply").argument("<id>", "The id of the codemod to apply").description("Apply migration scripts to the repository").action(async function(id) {
61
+ await applyCodemodById2(id).andTee(() => {
62
+ console.log("Codemod applied successfully \u2705");
63
+ }).orTee((error) => this.error(error.message));
64
+ })
65
+ );
66
+
67
+ // src/adapters/commander/commands/doctor.ts
68
+ import { Command as Command2 } from "commander";
12
69
  import * as process2 from "process";
13
70
 
14
71
  // src/domain/doctor.ts
@@ -245,7 +302,7 @@ var toDoctorResult = (validationCheckResults) => {
245
302
  var printDoctorResult = ({ validationReporter: validationReporter2 }, result) => result.checks.map(validationReporter2.reportCheckResult);
246
303
 
247
304
  // src/adapters/commander/commands/doctor.ts
248
- var makeDoctorCommand = (dependencies, config2) => new Command().name("doctor").description(
305
+ var makeDoctorCommand = (dependencies, config2) => new Command2().name("doctor").description(
249
306
  "Verify the repository setup according to the DevEx guidelines"
250
307
  ).action(async () => {
251
308
  const result = await runDoctor(dependencies, config2);
@@ -255,7 +312,7 @@ var makeDoctorCommand = (dependencies, config2) => new Command().name("doctor").
255
312
  });
256
313
 
257
314
  // src/adapters/commander/commands/info.ts
258
- import { Command as Command2 } from "commander";
315
+ import { Command as Command3 } from "commander";
259
316
 
260
317
  // src/domain/info.ts
261
318
  import { getLogger } from "@logtape/logtape";
@@ -302,29 +359,32 @@ var printInfo = (result) => {
302
359
  };
303
360
 
304
361
  // src/adapters/commander/commands/info.ts
305
- var makeInfoCommand = (dependencies, config2) => new Command2().name("info").description("Display information about the project").action(async () => {
362
+ var makeInfoCommand = (dependencies, config2) => new Command3().name("info").description("Display information about the project").action(async () => {
306
363
  const result = await getInfo(dependencies, config2);
307
364
  printInfo(result);
308
365
  });
309
366
 
310
367
  // src/adapters/commander/commands/version.ts
311
- import { Command as Command3 } from "commander";
368
+ import { Command as Command4 } from "commander";
312
369
 
313
370
  // src/domain/version.ts
314
371
  import { getLogger as getLogger2 } from "@logtape/logtape";
315
372
  function printVersion() {
316
373
  const logger2 = getLogger2(["dx-cli", "version"]);
317
- logger2.info(`dx CLI version: ${"0.4.4"}`);
374
+ logger2.info(`dx CLI version: ${"0.5.0"}`);
318
375
  }
319
376
 
320
377
  // src/adapters/commander/commands/version.ts
321
- var makeVersionCommand = () => new Command3().name("version").alias("v").action(() => printVersion());
378
+ var makeVersionCommand = () => new Command4().name("version").alias("v").action(() => printVersion());
322
379
 
323
380
  // src/adapters/commander/index.ts
324
381
  var makeCli = (deps2, config2) => {
325
- const program2 = new Command4();
326
- program2.name("dx").description("The CLI for DX-Platform").version("0.4.4");
382
+ const program2 = new Command5();
383
+ program2.name("dx").description("The CLI for DX-Platform").version("0.5.0");
327
384
  program2.addCommand(makeDoctorCommand(deps2, config2));
385
+ if (process.env.ENABLE_CODEMODS) {
386
+ program2.addCommand(makeCodemodCommand(deps2));
387
+ }
328
388
  program2.addCommand(makeVersionCommand());
329
389
  program2.addCommand(makeInfoCommand(deps2, config2));
330
390
  return program2;
@@ -404,7 +464,7 @@ var makePackageJsonReader = () => ({
404
464
 
405
465
  // src/adapters/node/repository.ts
406
466
  import * as glob from "glob";
407
- import { okAsync, ResultAsync as ResultAsync6 } from "neverthrow";
467
+ import { okAsync as okAsync3, ResultAsync as ResultAsync6 } from "neverthrow";
408
468
  import * as path from "path";
409
469
  import { z as z3 } from "zod/v4";
410
470
 
@@ -442,7 +502,7 @@ var getWorkspaces = (repoRoot2) => readFile(path.join(repoRoot2, "pnpm-workspace
442
502
  (obj) => (
443
503
  // If no packages are defined, go on with an empty array
444
504
  decode(z3.object({ packages: z3.array(z3.string()) }))(obj).orElse(
445
- () => okAsync({ packages: [] })
505
+ () => okAsync3({ packages: [] })
446
506
  )
447
507
  )
448
508
  ).andThen(
@@ -483,6 +543,15 @@ var getConfig = (repositoryRoot2) => ({
483
543
  }
484
544
  });
485
545
 
546
+ // src/use-cases/apply-codemod.ts
547
+ import { errAsync, okAsync as okAsync4 } from "neverthrow";
548
+ var applyCodemodById = (registry2) => (id) => registry2.getById(id).andThen(
549
+ (codemod) => codemod ? okAsync4(codemod) : errAsync(new Error(`Codemod with id ${id} not found`))
550
+ ).andThen((codemod) => codemod.apply());
551
+
552
+ // src/use-cases/list-codemods.ts
553
+ var listCodemods = (registry2) => () => registry2.getAll();
554
+
486
555
  // src/index.ts
487
556
  await configure({
488
557
  loggers: [
@@ -520,6 +589,8 @@ if (repoPackageJson.isErr()) {
520
589
  }
521
590
  var packageJson = repoPackageJson.value;
522
591
  var deps = {
592
+ applyCodemodById: applyCodemodById(codemods_default),
593
+ listCodemods: listCodemods(codemods_default),
523
594
  packageJson,
524
595
  packageJsonReader,
525
596
  repositoryReader,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/dx-cli",
3
- "version": "0.4.4",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "description": "A CLI useful to manage DX tools.",
6
6
  "repository": {
@@ -53,6 +53,6 @@
53
53
  "format:check": "prettier --check .",
54
54
  "typecheck": "tsc --noEmit",
55
55
  "test": "vitest run",
56
- "test:coverage": "vitest --coverage"
56
+ "test:coverage": "vitest run --coverage"
57
57
  }
58
58
  }