@ldsg/cli 0.3.31 → 0.3.33
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/.rush/temp/package-deps_build.json +27 -27
- package/.rush/temp/shrinkwrap-deps.json +58 -3
- package/.tsbuildinfo +1 -1
- package/CHANGELOG.json +52 -0
- package/CHANGELOG.md +15 -1
- package/README.md +5 -2
- package/dist/__tests__/commands.test.js +104 -104
- package/dist/__tests__/formatter.test.js +66 -63
- package/dist/__tests__/formatter.test.js.map +1 -1
- package/dist/__tests__/json-file-mutator.test.js +48 -45
- package/dist/__tests__/json-file-mutator.test.js.map +1 -1
- package/dist/__tests__/source-resolver.test.js +39 -39
- package/dist/cli.js +89 -89
- package/dist/cli.js.map +1 -1
- package/dist/commands/resource/convert.d.ts +1 -1
- package/dist/commands/resource/convert.js +9 -7
- package/dist/commands/resource/convert.js.map +1 -1
- package/dist/commands/resource/create.d.ts +2 -2
- package/dist/commands/resource/create.js +5 -5
- package/dist/commands/resource/delete.d.ts +2 -2
- package/dist/commands/resource/delete.js.map +1 -1
- package/dist/commands/resource/diff.d.ts +2 -2
- package/dist/commands/resource/diff.js +8 -8
- package/dist/commands/resource/get.d.ts +1 -1
- package/dist/commands/resource/list.d.ts +2 -2
- package/dist/commands/resource/list.js +11 -11
- package/dist/commands/resource/list.js.map +1 -1
- package/dist/commands/resource/tree.d.ts +1 -1
- package/dist/commands/resource/update.d.ts +2 -2
- package/dist/commands/resource/update.js +1 -1
- package/dist/constants.js +2 -2
- package/dist/types/get-extend-app-data-params.d.ts +2 -2
- package/dist/types/resource-record.d.ts +2 -2
- package/dist/utils/formatter.d.ts +1 -1
- package/dist/utils/formatter.js +25 -25
- package/dist/utils/get-extend-app-data-params-using-npm-ldsg-module.d.ts +1 -1
- package/dist/utils/get-extend-app-data-params-using-npm-ldsg-module.js +12 -12
- package/dist/utils/get-extend-app-data-params-using-npm-ldsg-module.js.map +1 -1
- package/dist/utils/get-extend-app-data-params-using-workspace-ldsg-module/index.d.ts +1 -1
- package/dist/utils/get-extend-app-data-params-using-workspace-ldsg-module/index.js +20 -20
- package/dist/utils/get-extend-app-data-params-using-workspace-ldsg-module/index.js.map +1 -1
- package/dist/utils/json-file-mutator.d.ts +2 -2
- package/dist/utils/json-file-mutator.js +4 -4
- package/dist/utils/json-file-mutator.js.map +1 -1
- package/dist/utils/source-resolver.d.ts +1 -1
- package/dist/utils/source-resolver.js +15 -15
- package/dist/utils/source-resolver.js.map +1 -1
- package/jest.config.js +8 -8
- package/package.json +13 -10
- package/src/__tests__/commands.test.ts +116 -116
- package/src/__tests__/formatter.test.ts +68 -65
- package/src/__tests__/json-file-mutator.test.ts +57 -52
- package/src/__tests__/source-resolver.test.ts +43 -43
- package/src/cli.ts +132 -114
- package/src/commands/resource/convert.ts +13 -11
- package/src/commands/resource/create.ts +8 -8
- package/src/commands/resource/delete.ts +6 -4
- package/src/commands/resource/diff.ts +10 -10
- package/src/commands/resource/get.ts +2 -2
- package/src/commands/resource/list.ts +20 -18
- package/src/commands/resource/tree.ts +2 -2
- package/src/commands/resource/update.ts +4 -4
- package/src/constants.ts +2 -2
- package/src/types/get-extend-app-data-params.ts +5 -3
- package/src/types/resource-record.ts +2 -2
- package/src/utils/formatter.ts +27 -27
- package/src/utils/get-extend-app-data-params-using-npm-ldsg-module.ts +20 -16
- package/src/utils/get-extend-app-data-params-using-workspace-ldsg-module/index.ts +28 -26
- package/src/utils/json-file-mutator.ts +18 -12
- package/src/utils/source-resolver.ts +26 -21
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import fs from
|
|
2
|
-
import { ResourceRecords } from
|
|
3
|
-
import { DEFAULT_SOURCE_FILE } from
|
|
4
|
-
import { SourceData, SourceFormat } from
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import { ResourceRecords } from "@ldsg/types";
|
|
3
|
+
import { DEFAULT_SOURCE_FILE } from "../constants";
|
|
4
|
+
import { SourceData, SourceFormat } from "../types/resource-record";
|
|
5
5
|
|
|
6
6
|
async function readJsonFile(filePath: string): Promise<unknown> {
|
|
7
7
|
if (!(await fs.pathExists(filePath))) {
|
|
@@ -10,19 +10,22 @@ async function readJsonFile(filePath: string): Promise<unknown> {
|
|
|
10
10
|
return fs.readJson(filePath);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
function parseResourceRecords(data: unknown): {
|
|
13
|
+
function parseResourceRecords(data: unknown): {
|
|
14
|
+
resourceRecords: ResourceRecords;
|
|
15
|
+
format: SourceFormat;
|
|
16
|
+
} {
|
|
14
17
|
if (Array.isArray(data)) {
|
|
15
|
-
return { resourceRecords: data as ResourceRecords, format:
|
|
18
|
+
return { resourceRecords: data as ResourceRecords, format: "array" };
|
|
16
19
|
}
|
|
17
20
|
|
|
18
|
-
if (data && typeof data ===
|
|
21
|
+
if (data && typeof data === "object") {
|
|
19
22
|
const obj = data as Record<string, unknown>;
|
|
20
23
|
if (Array.isArray(obj.resourceRecords)) {
|
|
21
|
-
return { resourceRecords: obj.resourceRecords as ResourceRecords, format:
|
|
24
|
+
return { resourceRecords: obj.resourceRecords as ResourceRecords, format: "object" };
|
|
22
25
|
}
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
throw new Error(
|
|
28
|
+
throw new Error("Invalid resource records format: expected an array or { resourceRecords: [] }");
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
async function resolveFile(filePath: string): Promise<SourceData> {
|
|
@@ -32,31 +35,31 @@ async function resolveFile(filePath: string): Promise<SourceData> {
|
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
async function resolveDirectory(dirPath: string): Promise<SourceData> {
|
|
35
|
-
const filePath = `${dirPath.replace(/\/$/,
|
|
38
|
+
const filePath = `${dirPath.replace(/\/$/, "")}/${DEFAULT_SOURCE_FILE}`;
|
|
36
39
|
return resolveFile(filePath);
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
async function resolveStdin(): Promise<SourceData> {
|
|
40
43
|
return new Promise((resolve, reject) => {
|
|
41
44
|
const chunks: Buffer[] = [];
|
|
42
|
-
process.stdin.setEncoding(
|
|
45
|
+
process.stdin.setEncoding("utf-8");
|
|
43
46
|
|
|
44
|
-
process.stdin.on(
|
|
47
|
+
process.stdin.on("data", (chunk: string | Buffer) => {
|
|
45
48
|
chunks.push(Buffer.from(chunk));
|
|
46
49
|
});
|
|
47
50
|
|
|
48
|
-
process.stdin.on(
|
|
51
|
+
process.stdin.on("end", () => {
|
|
49
52
|
try {
|
|
50
|
-
const raw = Buffer.concat(chunks).toString(
|
|
53
|
+
const raw = Buffer.concat(chunks).toString("utf-8");
|
|
51
54
|
const data = JSON.parse(raw);
|
|
52
55
|
const { resourceRecords, format } = parseResourceRecords(data);
|
|
53
|
-
resolve({ resourceRecords, format, filePath:
|
|
56
|
+
resolve({ resourceRecords, format, filePath: "-stdin-" });
|
|
54
57
|
} catch (error) {
|
|
55
58
|
reject(new Error(`Failed to parse stdin as JSON: ${(error as Error).message}`));
|
|
56
59
|
}
|
|
57
60
|
});
|
|
58
61
|
|
|
59
|
-
process.stdin.on(
|
|
62
|
+
process.stdin.on("error", (error) => {
|
|
60
63
|
reject(new Error(`Failed to read stdin: ${error.message}`));
|
|
61
64
|
});
|
|
62
65
|
});
|
|
@@ -68,10 +71,12 @@ export async function resolveSource(source?: string): Promise<SourceData> {
|
|
|
68
71
|
if (await fs.pathExists(defaultPath)) {
|
|
69
72
|
return resolveFile(defaultPath);
|
|
70
73
|
}
|
|
71
|
-
throw new Error(
|
|
74
|
+
throw new Error(
|
|
75
|
+
`Default source file not found: ${defaultPath}. Use --source to specify a file.`,
|
|
76
|
+
);
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
if (source ===
|
|
79
|
+
if (source === "-") {
|
|
75
80
|
return resolveStdin();
|
|
76
81
|
}
|
|
77
82
|
|
|
@@ -88,15 +93,15 @@ export async function resolveSource(source?: string): Promise<SourceData> {
|
|
|
88
93
|
}
|
|
89
94
|
|
|
90
95
|
export function isStdinSource(source?: string): boolean {
|
|
91
|
-
return source ===
|
|
96
|
+
return source === "-";
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
export function getSourceDescription(source?: string): string {
|
|
95
100
|
if (!source || source === DEFAULT_SOURCE_FILE) {
|
|
96
101
|
return `./${DEFAULT_SOURCE_FILE}`;
|
|
97
102
|
}
|
|
98
|
-
if (source ===
|
|
99
|
-
return
|
|
103
|
+
if (source === "-") {
|
|
104
|
+
return "stdin";
|
|
100
105
|
}
|
|
101
106
|
return source;
|
|
102
107
|
}
|