@chidchanun/bcp 0.2.1 → 0.2.2
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/README.md +206 -204
- package/docs/README.md +118 -79
- package/docs/api-manifest.json +4 -3
- package/docs/api-reference.md +12 -2
- package/docs/configuration.md +96 -1
- package/docs/docs-web-manifest.json +4 -2
- package/docs/environment-validation.md +224 -0
- package/docs/platform-manifest.json +9 -4
- package/docs/releases/0.2.2.md +118 -0
- package/package.json +1 -1
- package/packages/cli/src/args.ts +50 -9
- package/packages/cli/src/bootstrap.ts +22 -7
- package/packages/cli/src/configuration.ts +235 -0
- package/packages/cli/src/index.ts +101 -1
- package/packages/client/src/config.ts +26 -0
- package/packages/config/src/diagnostics.ts +226 -0
- package/packages/config/src/environment-loader.ts +101 -0
- package/packages/config/src/environment-schema.ts +677 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import {
|
|
4
|
+
pathToFileURL,
|
|
5
|
+
} from "node:url";
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
assertEnvironmentSchema,
|
|
9
|
+
type BcpEnvironmentSchema,
|
|
10
|
+
} from "./environment-schema.js";
|
|
11
|
+
|
|
12
|
+
const ENVIRONMENT_SCHEMA_FILES = [
|
|
13
|
+
"bcp.environment.ts",
|
|
14
|
+
"bcp.environment.mts",
|
|
15
|
+
"bcp.environment.js",
|
|
16
|
+
"bcp.environment.mjs",
|
|
17
|
+
] as const;
|
|
18
|
+
|
|
19
|
+
export interface LoadedBcpEnvironmentSchema {
|
|
20
|
+
file: string | null;
|
|
21
|
+
schema: BcpEnvironmentSchema;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function getEnvironmentSchemaFileNames(): string[] {
|
|
25
|
+
return [
|
|
26
|
+
...ENVIRONMENT_SCHEMA_FILES,
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export async function loadBcpEnvironmentSchema(
|
|
31
|
+
rootDirectory: string
|
|
32
|
+
): Promise<LoadedBcpEnvironmentSchema> {
|
|
33
|
+
const matches =
|
|
34
|
+
ENVIRONMENT_SCHEMA_FILES
|
|
35
|
+
.map(
|
|
36
|
+
(fileName) =>
|
|
37
|
+
path.join(
|
|
38
|
+
rootDirectory,
|
|
39
|
+
fileName
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
.filter(
|
|
43
|
+
(filePath) =>
|
|
44
|
+
fs.existsSync(
|
|
45
|
+
filePath
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
if (
|
|
50
|
+
matches.length > 1
|
|
51
|
+
) {
|
|
52
|
+
throw new Error(
|
|
53
|
+
`BCP Framework: multiple environment schema files found: ${matches.map((file) => path.basename(file)).join(", ")}. Keep only one bcp.environment file.`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (
|
|
58
|
+
matches.length === 0
|
|
59
|
+
) {
|
|
60
|
+
return {
|
|
61
|
+
file: null,
|
|
62
|
+
schema: {},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const file =
|
|
67
|
+
matches[0];
|
|
68
|
+
const url =
|
|
69
|
+
pathToFileURL(
|
|
70
|
+
file
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
url.searchParams.set(
|
|
74
|
+
"bcp-environment",
|
|
75
|
+
`${Date.now()}-${Math.random()}`
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const module =
|
|
79
|
+
await import(
|
|
80
|
+
url.href
|
|
81
|
+
);
|
|
82
|
+
const schema =
|
|
83
|
+
module.default;
|
|
84
|
+
|
|
85
|
+
if (
|
|
86
|
+
schema === undefined
|
|
87
|
+
) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`BCP Framework: ${path.basename(file)} must export a default environment schema.`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
assertEnvironmentSchema(
|
|
94
|
+
schema
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
file,
|
|
99
|
+
schema,
|
|
100
|
+
};
|
|
101
|
+
}
|