@pagopa/dx-cli 0.4.3 → 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.
- package/bin/index.js +86 -19
- 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
|
|
43
|
+
import { Command as Command5 } from "commander";
|
|
9
44
|
|
|
10
|
-
// src/adapters/commander/commands/
|
|
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
|
|
@@ -22,9 +79,8 @@ var scriptSchema = z.object({
|
|
|
22
79
|
name: ScriptName,
|
|
23
80
|
script: z.string()
|
|
24
81
|
});
|
|
25
|
-
var DependencyName = z.string().brand();
|
|
26
82
|
var dependencySchema = z.object({
|
|
27
|
-
name:
|
|
83
|
+
name: z.string(),
|
|
28
84
|
version: z.string()
|
|
29
85
|
});
|
|
30
86
|
var PackageName = z.string().min(1).brand();
|
|
@@ -36,12 +92,9 @@ var scriptsSchema = z.record(ScriptName, z.string()).optional().transform(
|
|
|
36
92
|
]) : []
|
|
37
93
|
)
|
|
38
94
|
);
|
|
39
|
-
var dependenciesSchema = z.record(
|
|
95
|
+
var dependenciesSchema = z.record(z.string(), z.string()).optional().transform(
|
|
40
96
|
(obj) => new Map(
|
|
41
|
-
obj ? Object.entries(obj).map(([name, version]) => [
|
|
42
|
-
DependencyName.parse(name),
|
|
43
|
-
version
|
|
44
|
-
]) : []
|
|
97
|
+
obj ? Object.entries(obj).map(([name, version]) => [name, version]) : []
|
|
45
98
|
)
|
|
46
99
|
);
|
|
47
100
|
var packageManagerSchema = z.enum(["npm", "pnpm", "yarn"]);
|
|
@@ -249,7 +302,7 @@ var toDoctorResult = (validationCheckResults) => {
|
|
|
249
302
|
var printDoctorResult = ({ validationReporter: validationReporter2 }, result) => result.checks.map(validationReporter2.reportCheckResult);
|
|
250
303
|
|
|
251
304
|
// src/adapters/commander/commands/doctor.ts
|
|
252
|
-
var makeDoctorCommand = (dependencies, config2) => new
|
|
305
|
+
var makeDoctorCommand = (dependencies, config2) => new Command2().name("doctor").description(
|
|
253
306
|
"Verify the repository setup according to the DevEx guidelines"
|
|
254
307
|
).action(async () => {
|
|
255
308
|
const result = await runDoctor(dependencies, config2);
|
|
@@ -259,7 +312,7 @@ var makeDoctorCommand = (dependencies, config2) => new Command().name("doctor").
|
|
|
259
312
|
});
|
|
260
313
|
|
|
261
314
|
// src/adapters/commander/commands/info.ts
|
|
262
|
-
import { Command as
|
|
315
|
+
import { Command as Command3 } from "commander";
|
|
263
316
|
|
|
264
317
|
// src/domain/info.ts
|
|
265
318
|
import { getLogger } from "@logtape/logtape";
|
|
@@ -306,29 +359,32 @@ var printInfo = (result) => {
|
|
|
306
359
|
};
|
|
307
360
|
|
|
308
361
|
// src/adapters/commander/commands/info.ts
|
|
309
|
-
var makeInfoCommand = (dependencies, config2) => new
|
|
362
|
+
var makeInfoCommand = (dependencies, config2) => new Command3().name("info").description("Display information about the project").action(async () => {
|
|
310
363
|
const result = await getInfo(dependencies, config2);
|
|
311
364
|
printInfo(result);
|
|
312
365
|
});
|
|
313
366
|
|
|
314
367
|
// src/adapters/commander/commands/version.ts
|
|
315
|
-
import { Command as
|
|
368
|
+
import { Command as Command4 } from "commander";
|
|
316
369
|
|
|
317
370
|
// src/domain/version.ts
|
|
318
371
|
import { getLogger as getLogger2 } from "@logtape/logtape";
|
|
319
372
|
function printVersion() {
|
|
320
373
|
const logger2 = getLogger2(["dx-cli", "version"]);
|
|
321
|
-
logger2.info(`dx CLI version: ${"0.
|
|
374
|
+
logger2.info(`dx CLI version: ${"0.5.0"}`);
|
|
322
375
|
}
|
|
323
376
|
|
|
324
377
|
// src/adapters/commander/commands/version.ts
|
|
325
|
-
var makeVersionCommand = () => new
|
|
378
|
+
var makeVersionCommand = () => new Command4().name("version").alias("v").action(() => printVersion());
|
|
326
379
|
|
|
327
380
|
// src/adapters/commander/index.ts
|
|
328
381
|
var makeCli = (deps2, config2) => {
|
|
329
|
-
const program2 = new
|
|
330
|
-
program2.name("dx").description("The CLI for DX-Platform").version("0.
|
|
382
|
+
const program2 = new Command5();
|
|
383
|
+
program2.name("dx").description("The CLI for DX-Platform").version("0.5.0");
|
|
331
384
|
program2.addCommand(makeDoctorCommand(deps2, config2));
|
|
385
|
+
if (process.env.ENABLE_CODEMODS) {
|
|
386
|
+
program2.addCommand(makeCodemodCommand(deps2));
|
|
387
|
+
}
|
|
332
388
|
program2.addCommand(makeVersionCommand());
|
|
333
389
|
program2.addCommand(makeInfoCommand(deps2, config2));
|
|
334
390
|
return program2;
|
|
@@ -408,7 +464,7 @@ var makePackageJsonReader = () => ({
|
|
|
408
464
|
|
|
409
465
|
// src/adapters/node/repository.ts
|
|
410
466
|
import * as glob from "glob";
|
|
411
|
-
import { okAsync, ResultAsync as ResultAsync6 } from "neverthrow";
|
|
467
|
+
import { okAsync as okAsync3, ResultAsync as ResultAsync6 } from "neverthrow";
|
|
412
468
|
import * as path from "path";
|
|
413
469
|
import { z as z3 } from "zod/v4";
|
|
414
470
|
|
|
@@ -446,7 +502,7 @@ var getWorkspaces = (repoRoot2) => readFile(path.join(repoRoot2, "pnpm-workspace
|
|
|
446
502
|
(obj) => (
|
|
447
503
|
// If no packages are defined, go on with an empty array
|
|
448
504
|
decode(z3.object({ packages: z3.array(z3.string()) }))(obj).orElse(
|
|
449
|
-
() =>
|
|
505
|
+
() => okAsync3({ packages: [] })
|
|
450
506
|
)
|
|
451
507
|
)
|
|
452
508
|
).andThen(
|
|
@@ -487,6 +543,15 @@ var getConfig = (repositoryRoot2) => ({
|
|
|
487
543
|
}
|
|
488
544
|
});
|
|
489
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
|
+
|
|
490
555
|
// src/index.ts
|
|
491
556
|
await configure({
|
|
492
557
|
loggers: [
|
|
@@ -524,6 +589,8 @@ if (repoPackageJson.isErr()) {
|
|
|
524
589
|
}
|
|
525
590
|
var packageJson = repoPackageJson.value;
|
|
526
591
|
var deps = {
|
|
592
|
+
applyCodemodById: applyCodemodById(codemods_default),
|
|
593
|
+
listCodemods: listCodemods(codemods_default),
|
|
527
594
|
packageJson,
|
|
528
595
|
packageJsonReader,
|
|
529
596
|
repositoryReader,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagopa/dx-cli",
|
|
3
|
-
"version": "0.
|
|
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
|
}
|