@corpdk/engine-kit 2026.10.0-alpha.14 → 2026.10.0-alpha.16
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 +29 -1
- package/dist/bin/check-publish-order.d.ts +2 -0
- package/dist/bin/check-publish-order.js +20 -0
- package/dist/bin/check-publish-order.js.map +1 -0
- package/dist/canonical.d.ts +16 -0
- package/dist/canonical.js +79 -0
- package/dist/canonical.js.map +1 -0
- package/dist/cli.d.ts +31 -0
- package/dist/cli.js +97 -0
- package/dist/cli.js.map +1 -0
- package/dist/fs.d.ts +10 -0
- package/dist/fs.js +80 -0
- package/dist/fs.js.map +1 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +8 -1
- package/dist/index.js.map +1 -1
- package/dist/merge.d.ts +20 -0
- package/dist/merge.js +95 -0
- package/dist/merge.js.map +1 -0
- package/dist/publish-load.d.ts +11 -0
- package/dist/publish-load.js +48 -0
- package/dist/publish-load.js.map +1 -0
- package/dist/publish.d.ts +21 -0
- package/dist/publish.js +95 -0
- package/dist/publish.js.map +1 -0
- package/dist/template.d.ts +10 -0
- package/dist/template.js +34 -0
- package/dist/template.js.map +1 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/upgrade.d.ts +22 -0
- package/dist/upgrade.js +59 -0
- package/dist/upgrade.js.map +1 -0
- package/package.json +12 -2
package/README.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
1
|
# @corpdk/engine-kit
|
|
2
2
|
|
|
3
|
-
Shared CLI and
|
|
3
|
+
Shared CLI, filesystem, merge, upgrade, canonical, and publish-order helpers for `create-ds`, `create-graphql-sdk`, and `create-graphql-cli`.
|
|
4
|
+
|
|
5
|
+
Design: [doc 15 — Generator engine family](../docs/developer/15-create-ds-generator-integration.md#113-corpdkengine-kit).
|
|
6
|
+
|
|
7
|
+
## Modules
|
|
8
|
+
|
|
9
|
+
| Module | Exports |
|
|
10
|
+
| ----------- | --------------------------------------------------------------------------------------------- |
|
|
11
|
+
| `fs` | `pathExists`, `readJson`, `writeJson`, `copyDir` (caller-provided `exclude`, `requireSource`) |
|
|
12
|
+
| `merge` | `mergePackageJson`, `mergeYamlConfig` (deep map merge) |
|
|
13
|
+
| `template` | `resolveCanonical`, `readEngineRelease`, `initialCalVer`, `engineRootFromImportMeta` |
|
|
14
|
+
| `upgrade` | `runUpgradePlan`, `writeEngineVersion` |
|
|
15
|
+
| `canonical` | `syncCanonical`, `checkCanonical` |
|
|
16
|
+
| `publish` | `checkPublishOrder`, `DS_AUTOMATION_PUBLISH_ORDER` |
|
|
17
|
+
| `cli` | `parseEngineCli`, `runEngineCli` (§11.2 exit codes) |
|
|
18
|
+
|
|
19
|
+
## Scripts
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm --filter @corpdk/engine-kit build
|
|
23
|
+
pnpm --filter @corpdk/engine-kit test
|
|
24
|
+
pnpm --filter @corpdk/engine-kit check:publish-order # after build
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
The publish-order guard runs in [`.github/scripts/publish-ds-automation.sh`](../../.github/scripts/publish-ds-automation.sh) before lockstep publish.
|
|
28
|
+
|
|
29
|
+
## Dependencies
|
|
30
|
+
|
|
31
|
+
Runtime: `@clack/prompts`, `yaml` only.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { checkPublishOrder, DS_AUTOMATION_PACKAGE_JSON_PATH, DS_AUTOMATION_PUBLISH_ORDER, DS_AUTOMATION_TRUSTED_PACKAGES, } from "../publish.js";
|
|
5
|
+
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "..");
|
|
6
|
+
const result = await checkPublishOrder({
|
|
7
|
+
repoRoot,
|
|
8
|
+
publishOrder: DS_AUTOMATION_PUBLISH_ORDER,
|
|
9
|
+
packageJsonPath: (name) => DS_AUTOMATION_PACKAGE_JSON_PATH[name] ?? "",
|
|
10
|
+
trustedPackages: DS_AUTOMATION_TRUSTED_PACKAGES,
|
|
11
|
+
workflowFile: "publish-ds-automation.yml",
|
|
12
|
+
});
|
|
13
|
+
if (!result.ok) {
|
|
14
|
+
for (const err of result.errors) {
|
|
15
|
+
console.error(err);
|
|
16
|
+
}
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
console.log("Publish order guard OK (topological order matches PUBLISH_ORDER).");
|
|
20
|
+
//# sourceMappingURL=check-publish-order.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-publish-order.js","sourceRoot":"","sources":["../../src/bin/check-publish-order.ts"],"names":[],"mappings":";AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EACL,iBAAiB,EACjB,+BAA+B,EAC/B,2BAA2B,EAC3B,8BAA8B,GAC/B,MAAM,eAAe,CAAC;AAEvB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAC3B,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAC5C,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,IAAI,CACL,CAAC;AAEF,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC;IACrC,QAAQ;IACR,YAAY,EAAE,2BAA2B;IACzC,eAAe,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,+BAA+B,CAAC,IAAI,CAAC,IAAI,EAAE;IACtE,eAAe,EAAE,8BAA8B;IAC/C,YAAY,EAAE,2BAA2B;CAC1C,CAAC,CAAC;AAEH,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;IACf,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAChC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,OAAO,CAAC,GAAG,CACT,mEAAmE,CACpE,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type CanonicalSyncOptions = {
|
|
2
|
+
from: string;
|
|
3
|
+
to: string;
|
|
4
|
+
exclude?: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare function syncCanonical(options: CanonicalSyncOptions): Promise<void>;
|
|
7
|
+
export type CanonicalCheckOptions = {
|
|
8
|
+
from: string;
|
|
9
|
+
to: string;
|
|
10
|
+
exclude?: string[];
|
|
11
|
+
};
|
|
12
|
+
export type CanonicalCheckResult = {
|
|
13
|
+
ok: boolean;
|
|
14
|
+
mismatches: string[];
|
|
15
|
+
};
|
|
16
|
+
export declare function checkCanonical(options: CanonicalCheckOptions): Promise<CanonicalCheckResult>;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { copyDir, pathExists } from "./fs.js";
|
|
5
|
+
const DEFAULT_EXCLUDE = [
|
|
6
|
+
"node_modules",
|
|
7
|
+
"dist",
|
|
8
|
+
".turbo",
|
|
9
|
+
".next",
|
|
10
|
+
"drizzle",
|
|
11
|
+
"src/generated",
|
|
12
|
+
];
|
|
13
|
+
export async function syncCanonical(options) {
|
|
14
|
+
const exclude = options.exclude ?? [...DEFAULT_EXCLUDE];
|
|
15
|
+
await fs.rm(options.to, { recursive: true, force: true });
|
|
16
|
+
await copyDir(options.from, options.to, {
|
|
17
|
+
exclude,
|
|
18
|
+
requireSource: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async function fileSha256(filePath) {
|
|
22
|
+
const buf = await fs.readFile(filePath);
|
|
23
|
+
return crypto.createHash("sha256").update(buf).digest("hex");
|
|
24
|
+
}
|
|
25
|
+
async function walkFiles(root, relPrefix, exclude) {
|
|
26
|
+
const abs = relPrefix ? path.join(root, relPrefix) : root;
|
|
27
|
+
if (!(await pathExists(abs)))
|
|
28
|
+
return [];
|
|
29
|
+
const entries = await fs.readdir(abs, { withFileTypes: true });
|
|
30
|
+
const childLists = await Promise.all(entries.map(async (entry) => {
|
|
31
|
+
const rel = relPrefix ? path.join(relPrefix, entry.name) : entry.name;
|
|
32
|
+
const segments = rel.split(path.sep);
|
|
33
|
+
if (segments.some((seg) => exclude.has(seg))) {
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
if (entry.isDirectory()) {
|
|
37
|
+
return walkFiles(root, rel, exclude);
|
|
38
|
+
}
|
|
39
|
+
if (entry.isFile()) {
|
|
40
|
+
return [rel];
|
|
41
|
+
}
|
|
42
|
+
return [];
|
|
43
|
+
}));
|
|
44
|
+
return childLists.flat();
|
|
45
|
+
}
|
|
46
|
+
export async function checkCanonical(options) {
|
|
47
|
+
const exclude = new Set(options.exclude ?? [...DEFAULT_EXCLUDE]);
|
|
48
|
+
const fromFiles = await walkFiles(options.from, "", exclude);
|
|
49
|
+
const toFiles = await walkFiles(options.to, "", exclude);
|
|
50
|
+
const allRels = new Set([...fromFiles, ...toFiles]);
|
|
51
|
+
const mismatches = [];
|
|
52
|
+
const sortedRels = [...allRels].sort((a, b) => a.localeCompare(b));
|
|
53
|
+
const compareResults = await Promise.all(sortedRels.map(async (rel) => {
|
|
54
|
+
const fromPath = path.join(options.from, rel);
|
|
55
|
+
const toPath = path.join(options.to, rel);
|
|
56
|
+
const [fromOk, toOk] = await Promise.all([
|
|
57
|
+
pathExists(fromPath),
|
|
58
|
+
pathExists(toPath),
|
|
59
|
+
]);
|
|
60
|
+
if (!fromOk)
|
|
61
|
+
return `extra in to: ${rel}`;
|
|
62
|
+
if (!toOk)
|
|
63
|
+
return `missing in to: ${rel}`;
|
|
64
|
+
const [fromHash, toHash] = await Promise.all([
|
|
65
|
+
fileSha256(fromPath),
|
|
66
|
+
fileSha256(toPath),
|
|
67
|
+
]);
|
|
68
|
+
if (fromHash !== toHash) {
|
|
69
|
+
return `content differs: ${rel}`;
|
|
70
|
+
}
|
|
71
|
+
return null;
|
|
72
|
+
}));
|
|
73
|
+
for (const row of compareResults) {
|
|
74
|
+
if (row)
|
|
75
|
+
mismatches.push(row);
|
|
76
|
+
}
|
|
77
|
+
return { ok: mismatches.length === 0, mismatches };
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=canonical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.js","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAQ9C,MAAM,eAAe,GAAG;IACtB,cAAc;IACd,MAAM;IACN,QAAQ;IACR,OAAO;IACP,SAAS;IACT,eAAe;CACP,CAAC;AAEX,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAA6B;IAE7B,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,CAAC,GAAG,eAAe,CAAC,CAAC;IACxD,MAAM,EAAE,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,MAAM,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,EAAE,EAAE;QACtC,OAAO;QACP,aAAa,EAAE,IAAI;KACpB,CAAC,CAAC;AACL,CAAC;AAaD,KAAK,UAAU,UAAU,CAAC,QAAgB;IACxC,MAAM,GAAG,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACxC,OAAO,MAAM,CAAC,UAAU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,IAAI,CAAC,IAAI;YAAE,OAAO,kBAAkB,GAAG,EAAE,CAAC;QAE1C,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YAC3C,UAAU,CAAC,QAAQ,CAAC;YACpB,UAAU,CAAC,MAAM,CAAC;SACnB,CAAC,CAAC;QACH,IAAI,QAAQ,KAAK,MAAM,EAAE,CAAC;YACxB,OAAO,oBAAoB,GAAG,EAAE,CAAC;QACnC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CACH,CAAC;IACF,KAAK,MAAM,GAAG,IAAI,cAAc,EAAE,CAAC;QACjC,IAAI,GAAG;YAAE,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;AACrD,CAAC"}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EXIT_SUCCESS, EXIT_USAGE, type EngineResult } from "./types.js";
|
|
2
|
+
export type EngineCommandHandler = (positional: string[], values: Record<string, string | boolean | undefined>) => Promise<EngineResult>;
|
|
3
|
+
export type EngineCommandDef = {
|
|
4
|
+
name: string;
|
|
5
|
+
handler: EngineCommandHandler;
|
|
6
|
+
};
|
|
7
|
+
export type DefineEngineCliOptions = {
|
|
8
|
+
name: string;
|
|
9
|
+
version: string;
|
|
10
|
+
help: string;
|
|
11
|
+
commands: EngineCommandDef[];
|
|
12
|
+
argv?: string[];
|
|
13
|
+
};
|
|
14
|
+
export type ParsedEngineCli = {
|
|
15
|
+
kind: "help";
|
|
16
|
+
exitCode: typeof EXIT_SUCCESS;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "usage";
|
|
19
|
+
exitCode: typeof EXIT_USAGE;
|
|
20
|
+
message: string;
|
|
21
|
+
} | {
|
|
22
|
+
kind: "run";
|
|
23
|
+
command: EngineCommandDef;
|
|
24
|
+
positional: string[];
|
|
25
|
+
values: Record<string, string | boolean | undefined>;
|
|
26
|
+
};
|
|
27
|
+
export declare function parseEngineCli(options: DefineEngineCliOptions): ParsedEngineCli;
|
|
28
|
+
export declare function runEngineCli(options: DefineEngineCliOptions, hooks?: {
|
|
29
|
+
onHelp?: () => void;
|
|
30
|
+
onResult?: (result: EngineResult) => void;
|
|
31
|
+
}): Promise<number>;
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { parseArgs as nodeParseArgs } from "node:util";
|
|
2
|
+
import { EXIT_SUCCESS, EXIT_TOOL, EXIT_USAGE, } from "./types.js";
|
|
3
|
+
const GLOBAL_OPTIONS = {
|
|
4
|
+
help: { type: "boolean", short: "h" },
|
|
5
|
+
version: { type: "boolean" },
|
|
6
|
+
};
|
|
7
|
+
export function parseEngineCli(options) {
|
|
8
|
+
const argv = options.argv ?? process.argv;
|
|
9
|
+
const args = argv.slice(2);
|
|
10
|
+
if (args.length === 0) {
|
|
11
|
+
return {
|
|
12
|
+
kind: "usage",
|
|
13
|
+
exitCode: EXIT_USAGE,
|
|
14
|
+
message: `Missing command. Run ${options.name} --help.`,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
const first = args[0];
|
|
18
|
+
if (first === "--help" || first === "-h") {
|
|
19
|
+
return { kind: "help", exitCode: EXIT_SUCCESS };
|
|
20
|
+
}
|
|
21
|
+
if (first === "--version") {
|
|
22
|
+
console.log(options.version);
|
|
23
|
+
return { kind: "help", exitCode: EXIT_SUCCESS };
|
|
24
|
+
}
|
|
25
|
+
const command = options.commands.find((c) => c.name === first);
|
|
26
|
+
if (!command) {
|
|
27
|
+
return {
|
|
28
|
+
kind: "usage",
|
|
29
|
+
exitCode: EXIT_USAGE,
|
|
30
|
+
message: `Unknown command: ${first}`,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
const rest = args.slice(1);
|
|
34
|
+
const positional = [];
|
|
35
|
+
const tokens = [];
|
|
36
|
+
for (const token of rest) {
|
|
37
|
+
if (token.startsWith("-")) {
|
|
38
|
+
tokens.push(token);
|
|
39
|
+
}
|
|
40
|
+
else if (positional.length === 0) {
|
|
41
|
+
positional.push(token);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
tokens.push(token);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const { values, positionals } = nodeParseArgs({
|
|
49
|
+
args: tokens,
|
|
50
|
+
options: GLOBAL_OPTIONS,
|
|
51
|
+
strict: true,
|
|
52
|
+
allowPositionals: true,
|
|
53
|
+
});
|
|
54
|
+
if (values.help) {
|
|
55
|
+
return { kind: "help", exitCode: EXIT_SUCCESS };
|
|
56
|
+
}
|
|
57
|
+
if (values.version) {
|
|
58
|
+
console.log(options.version);
|
|
59
|
+
return { kind: "help", exitCode: EXIT_SUCCESS };
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
kind: "run",
|
|
63
|
+
command,
|
|
64
|
+
positional: [...positional, ...positionals],
|
|
65
|
+
values: values,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
70
|
+
return { kind: "usage", exitCode: EXIT_USAGE, message };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export async function runEngineCli(options, hooks) {
|
|
74
|
+
const parsed = parseEngineCli(options);
|
|
75
|
+
if (parsed.kind === "help") {
|
|
76
|
+
hooks?.onHelp?.() ?? console.log(options.help);
|
|
77
|
+
return parsed.exitCode;
|
|
78
|
+
}
|
|
79
|
+
if (parsed.kind === "usage") {
|
|
80
|
+
console.error(parsed.message);
|
|
81
|
+
console.error(options.help);
|
|
82
|
+
return parsed.exitCode;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const result = await parsed.command.handler(parsed.positional, parsed.values);
|
|
86
|
+
hooks?.onResult?.(result);
|
|
87
|
+
if (result.nextSteps?.length) {
|
|
88
|
+
console.log("\nNext steps:\n" + result.nextSteps.map((s) => ` ${s}`).join("\n"));
|
|
89
|
+
}
|
|
90
|
+
return result.exitCode;
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
console.error(err instanceof Error ? err.message : err);
|
|
94
|
+
return EXIT_TOOL;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,EACL,YAAY,EACZ,SAAS,EACT,UAAU,GAEX,MAAM,YAAY,CAAC;AA8BpB,MAAM,cAAc,GAAG;IACrB,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE;IACrC,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;CACpB,CAAC;AAEX,MAAM,UAAU,cAAc,CAC5B,OAA+B;IAE/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAE3B,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO;YACL,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,UAAU;YACpB,OAAO,EAAE,wBAAwB,OAAO,CAAC,IAAI,UAAU;SACxD,CAAC;IACJ,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;IACtB,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACzC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,YAA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,CAAC;IACzB,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,OAAO,CACzC,MAAM,CAAC,UAAU,EACjB,MAAM,CAAC,MAAM,CACd,CAAC;QACF,KAAK,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,CAAC;QAC1B,IAAI,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CACT,iBAAiB,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CACrE,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC,QAAQ,CAAC;IACzB,CAAC;IAAC,OAAO,GAAY,EAAE,CAAC;QACtB,OAAO,CAAC,KAAK,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACxD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
package/dist/fs.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function pathExists(p: string): Promise<boolean>;
|
|
2
|
+
export declare function readJson<T>(filePath: string): Promise<T>;
|
|
3
|
+
export declare function writeJson(filePath: string, data: unknown): Promise<void>;
|
|
4
|
+
export type CopyDirOptions = {
|
|
5
|
+
exclude?: string[];
|
|
6
|
+
transform?: (content: string, relPath: string) => string;
|
|
7
|
+
skipIfExists?: boolean;
|
|
8
|
+
requireSource?: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare function copyDir(src: string, dest: string, options?: CopyDirOptions): Promise<void>;
|
package/dist/fs.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
export async function pathExists(p) {
|
|
4
|
+
try {
|
|
5
|
+
await fs.access(p);
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
export async function readJson(filePath) {
|
|
13
|
+
const content = await fs.readFile(filePath, "utf8");
|
|
14
|
+
return JSON.parse(content);
|
|
15
|
+
}
|
|
16
|
+
export async function writeJson(filePath, data) {
|
|
17
|
+
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
18
|
+
await fs.writeFile(filePath, JSON.stringify(data, null, 2) + "\n", "utf8");
|
|
19
|
+
}
|
|
20
|
+
function matchExcludePattern(pattern, name) {
|
|
21
|
+
if (pattern.startsWith("*"))
|
|
22
|
+
return name.endsWith(pattern.slice(1));
|
|
23
|
+
if (pattern.endsWith("*"))
|
|
24
|
+
return name.startsWith(pattern.slice(0, -1));
|
|
25
|
+
return name === pattern;
|
|
26
|
+
}
|
|
27
|
+
function segmentExcluded(relPath, exclude) {
|
|
28
|
+
const segments = relPath.split(path.sep);
|
|
29
|
+
for (const seg of segments) {
|
|
30
|
+
if (exclude.has(seg))
|
|
31
|
+
return true;
|
|
32
|
+
for (const pattern of exclude) {
|
|
33
|
+
if (pattern.includes("*") && matchExcludePattern(pattern, seg)) {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
export async function copyDir(src, dest, options = {}) {
|
|
41
|
+
const { exclude = [], transform, skipIfExists = false, requireSource = true, } = options;
|
|
42
|
+
const excludeSet = new Set(exclude);
|
|
43
|
+
if (!(await pathExists(src))) {
|
|
44
|
+
if (requireSource) {
|
|
45
|
+
throw new Error(`Copy source not found: ${src}`);
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
await fs.mkdir(dest, { recursive: true });
|
|
50
|
+
await copyDirRecursive(src, dest, "", {
|
|
51
|
+
excludeSet,
|
|
52
|
+
transform,
|
|
53
|
+
skipIfExists,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async function copyDirRecursive(src, dest, relPrefix, options) {
|
|
57
|
+
const entries = await fs.readdir(src, { withFileTypes: true });
|
|
58
|
+
await Promise.all(entries.map(async (entry) => {
|
|
59
|
+
const relPath = relPrefix ? path.join(relPrefix, entry.name) : entry.name;
|
|
60
|
+
if (segmentExcluded(relPath, options.excludeSet))
|
|
61
|
+
return;
|
|
62
|
+
const srcPath = path.join(src, entry.name);
|
|
63
|
+
const destPath = path.join(dest, entry.name);
|
|
64
|
+
if (entry.isDirectory()) {
|
|
65
|
+
await fs.mkdir(destPath, { recursive: true });
|
|
66
|
+
await copyDirRecursive(srcPath, destPath, relPath, options);
|
|
67
|
+
}
|
|
68
|
+
else if (entry.isFile()) {
|
|
69
|
+
if (options.skipIfExists && (await pathExists(destPath)))
|
|
70
|
+
return;
|
|
71
|
+
const raw = await fs.readFile(srcPath, "utf8");
|
|
72
|
+
const content = options.transform
|
|
73
|
+
? options.transform(raw, relPath)
|
|
74
|
+
: raw;
|
|
75
|
+
await fs.mkdir(path.dirname(destPath), { recursive: true });
|
|
76
|
+
await fs.writeFile(destPath, content, "utf8");
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=fs.js.map
|
package/dist/fs.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fs.js","sourceRoot":"","sources":["../src/fs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,CAAS;IACxC,IAAI,CAAC;QACH,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QACnB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AA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1
|
+
export { EXIT_SUCCESS, EXIT_TOOL, EXIT_USAGE, EXIT_VALIDATION, type EngineExitCode, type EngineResult, type Reporter, } from "./types.js";
|
|
2
|
+
export { copyDir, pathExists, readJson, writeJson, type CopyDirOptions, } from "./fs.js";
|
|
3
|
+
export { mergePackageJson, mergeYamlConfig, type MergePackageJsonOptions, } from "./merge.js";
|
|
4
|
+
export { engineRootFromImportMeta, initialCalVer, isBundledCanonical, readEngineRelease, resolveCanonical, type ResolveCanonicalOptions, } from "./template.js";
|
|
5
|
+
export { MissingOverwriteSourceError, runUpgradePlan, writeEngineVersion, type RunUpgradePlanOptions, type UpgradeMergeHandler, type UpgradePlanResult, } from "./upgrade.js";
|
|
6
|
+
export { checkCanonical, syncCanonical, type CanonicalCheckOptions, type CanonicalCheckResult, type CanonicalSyncOptions, } from "./canonical.js";
|
|
7
|
+
export { checkPublishOrder, DS_AUTOMATION_PACKAGE_JSON_PATH, DS_AUTOMATION_PUBLISH_ORDER, DS_AUTOMATION_TRUSTED_PACKAGES, type PackageRef, type PublishOrderGuardOptions, type PublishOrderGuardResult, } from "./publish.js";
|
|
8
|
+
export { parseEngineCli, runEngineCli, runEngineCli as defineEngineCli, type DefineEngineCliOptions, type EngineCommandDef, type EngineCommandHandler, type ParsedEngineCli, } from "./cli.js";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { EXIT_SUCCESS, EXIT_TOOL, EXIT_USAGE, EXIT_VALIDATION, } from "./types.js";
|
|
2
|
+
export { copyDir, pathExists, readJson, writeJson, } from "./fs.js";
|
|
3
|
+
export { mergePackageJson, mergeYamlConfig, } from "./merge.js";
|
|
4
|
+
export { engineRootFromImportMeta, initialCalVer, isBundledCanonical, readEngineRelease, resolveCanonical, } from "./template.js";
|
|
5
|
+
export { MissingOverwriteSourceError, runUpgradePlan, writeEngineVersion, } from "./upgrade.js";
|
|
6
|
+
export { checkCanonical, syncCanonical, } from "./canonical.js";
|
|
7
|
+
export { checkPublishOrder, DS_AUTOMATION_PACKAGE_JSON_PATH, DS_AUTOMATION_PUBLISH_ORDER, DS_AUTOMATION_TRUSTED_PACKAGES, } from "./publish.js";
|
|
8
|
+
export { parseEngineCli, runEngineCli, runEngineCli as defineEngineCli, } from "./cli.js";
|
|
2
9
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,SAAS,EACT,UAAU,EACV,eAAe,GAIhB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,OAAO,EACP,UAAU,EACV,QAAQ,EACR,SAAS,GAEV,MAAM,SAAS,CAAC;AAEjB,OAAO,EACL,gBAAgB,EAChB,eAAe,GAEhB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,wBAAwB,EACxB,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,GAEjB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,2BAA2B,EAC3B,cAAc,EACd,kBAAkB,GAInB,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,cAAc,EACd,aAAa,GAId,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,iBAAiB,EACjB,+BAA+B,EAC/B,2BAA2B,EAC3B,8BAA8B,GAI/B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,cAAc,EACd,YAAY,EACZ,YAAY,IAAI,eAAe,GAKhC,MAAM,UAAU,CAAC"}
|
package/dist/merge.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type PkgJson = {
|
|
2
|
+
name?: string;
|
|
3
|
+
version?: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
publishConfig?: Record<string, string>;
|
|
6
|
+
scripts?: Record<string, string>;
|
|
7
|
+
dependencies?: Record<string, string>;
|
|
8
|
+
devDependencies?: Record<string, string>;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
};
|
|
11
|
+
export type MergePackageJsonOptions = {
|
|
12
|
+
owned?: ReadonlySet<string>;
|
|
13
|
+
removed?: ReadonlySet<string>;
|
|
14
|
+
preserveKeys?: readonly string[];
|
|
15
|
+
scriptsTransform?: (scripts: Record<string, string>) => Record<string, string>;
|
|
16
|
+
releaseVersion?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function mergeYamlConfig(template: unknown, consumer: unknown): unknown;
|
|
19
|
+
export declare function mergePackageJson(consumer: PkgJson, template: PkgJson, options?: MergePackageJsonOptions): PkgJson;
|
|
20
|
+
export {};
|
package/dist/merge.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
const DEFAULT_PRESERVE_KEYS = [
|
|
2
|
+
"private",
|
|
3
|
+
"license",
|
|
4
|
+
"engines",
|
|
5
|
+
"packageManager",
|
|
6
|
+
"author",
|
|
7
|
+
"repository",
|
|
8
|
+
"bugs",
|
|
9
|
+
"homepage",
|
|
10
|
+
"keywords",
|
|
11
|
+
"bin",
|
|
12
|
+
"man",
|
|
13
|
+
"publishConfig",
|
|
14
|
+
];
|
|
15
|
+
function rewriteCorpdkWorkspaceDeps(deps, releaseVersion) {
|
|
16
|
+
if (!deps)
|
|
17
|
+
return {};
|
|
18
|
+
const out = { ...deps };
|
|
19
|
+
for (const [key, value] of Object.entries(out)) {
|
|
20
|
+
if (key.startsWith("@corpdk/") &&
|
|
21
|
+
(value === "workspace:*" || value === "workspace:^")) {
|
|
22
|
+
out[key] = `^${releaseVersion}`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
function mergeDepRecords(templateDeps, consumerDeps, owned, removed) {
|
|
28
|
+
const merged = templateDeps ? { ...templateDeps } : {};
|
|
29
|
+
for (const key of removed) {
|
|
30
|
+
delete merged[key];
|
|
31
|
+
}
|
|
32
|
+
if (!consumerDeps)
|
|
33
|
+
return merged;
|
|
34
|
+
for (const [key, value] of Object.entries(consumerDeps)) {
|
|
35
|
+
if (!owned.has(key)) {
|
|
36
|
+
merged[key] = value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return merged;
|
|
40
|
+
}
|
|
41
|
+
function isPlainObject(value) {
|
|
42
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
43
|
+
}
|
|
44
|
+
export function mergeYamlConfig(template, consumer) {
|
|
45
|
+
if (!isPlainObject(template))
|
|
46
|
+
return consumer ?? template;
|
|
47
|
+
if (!isPlainObject(consumer))
|
|
48
|
+
return { ...template };
|
|
49
|
+
const out = { ...template };
|
|
50
|
+
for (const [key, consumerVal] of Object.entries(consumer)) {
|
|
51
|
+
const templateVal = template[key];
|
|
52
|
+
if (isPlainObject(templateVal) && isPlainObject(consumerVal)) {
|
|
53
|
+
out[key] = mergeYamlConfig(templateVal, consumerVal);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
out[key] = consumerVal;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
export function mergePackageJson(consumer, template, options) {
|
|
62
|
+
const owned = options?.owned ?? new Set();
|
|
63
|
+
const removed = options?.removed ?? new Set();
|
|
64
|
+
const preserveKeys = options?.preserveKeys ?? DEFAULT_PRESERVE_KEYS;
|
|
65
|
+
const scriptsTransform = options?.scriptsTransform ?? ((s) => s);
|
|
66
|
+
const { publishConfig: _templatePublishConfig, ...templateWithoutPublish } = template;
|
|
67
|
+
const merged = {
|
|
68
|
+
...templateWithoutPublish,
|
|
69
|
+
name: consumer.name ?? template.name,
|
|
70
|
+
version: consumer.version ?? template.version,
|
|
71
|
+
description: consumer.description ?? template.description,
|
|
72
|
+
scripts: scriptsTransform(template.scripts ?? {}),
|
|
73
|
+
dependencies: mergeDepRecords(template.dependencies, consumer.dependencies, owned, removed),
|
|
74
|
+
devDependencies: mergeDepRecords(template.devDependencies, consumer.devDependencies, owned, removed),
|
|
75
|
+
};
|
|
76
|
+
if (options?.releaseVersion) {
|
|
77
|
+
merged.dependencies = rewriteCorpdkWorkspaceDeps(merged.dependencies, options.releaseVersion);
|
|
78
|
+
merged.devDependencies = rewriteCorpdkWorkspaceDeps(merged.devDependencies, options.releaseVersion);
|
|
79
|
+
}
|
|
80
|
+
for (const key of preserveKeys) {
|
|
81
|
+
if (key === "publishConfig")
|
|
82
|
+
continue;
|
|
83
|
+
if (Object.hasOwn(consumer, key)) {
|
|
84
|
+
merged[key] = consumer[key];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (Object.hasOwn(consumer, "publishConfig")) {
|
|
88
|
+
merged.publishConfig = consumer.publishConfig;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
delete merged.publishConfig;
|
|
92
|
+
}
|
|
93
|
+
return merged;
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=merge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../src/merge.ts"],"names":[],"mappings":"AAqBA,MAAM,qBAAqB,GAAG;IAC5B,SAAS;IACT,SAAS;IACT,SAAS;IACT,gBAAgB;IAChB,QAAQ;IACR,YAAY;IACZ,MAAM;IACN,UAAU;IACV,UAAU;IACV,KAAK;IACL,KAAK;IACL,eAAe;CACP,CAAC;AAEX,SAAS,0BAA0B,CACjC,IAAwC,EACxC,cAAsB;IAEtB,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IACrB,MAAM,GAAG,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC;IACxB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,IACE,GAAG,CAAC,UAAU,CAAC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AE,eAAe,CAC3B,QAAQ,CAAC,YAAY,EACrB,QAAQ,CAAC,YAAY,EACrB,KAAK,EACL,OAAO,CACR;QACD,eAAe,EAAE,eAAe,CAC9B,QAAQ,CAAC,eAAe,EACxB,QAAQ,CAAC,eAAe,EACxB,KAAK,EACL,OAAO,CACR;KACF,CAAC;IAEF,IAAI,OAAO,EAAE,cAAc,EAAE,CAAC;QAC5B,MAAM,CAAC,YAAY,GAAG,0BAA0B,CAC9C,MAAM,CAAC,YAAY,EACnB,OAAO,CAAC,cAAc,CACvB,CAAC;QACF,MAAM,CAAC,eAAe,GAAG,0BAA0B,CACjD,MAAM,CAAC,eAAe,EACtB,OAAO,CAAC,cAAc,CACvB,CAAC;IACJ,CAAC;IAED,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/B,IAAI,GAAG,KAAK,eAAe;YAAE,SAAS;QACtC,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC;YACjC,MAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,eAAe,CAAC,EAAE,CAAC;QAC7C,MAAM,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC;IAChD,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAC,aAAa,CAAC;IAC9B,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type PkgJson = {
|
|
2
|
+
name?: string;
|
|
3
|
+
dependencies?: Record<string, string>;
|
|
4
|
+
devDependencies?: Record<string, string>;
|
|
5
|
+
};
|
|
6
|
+
export declare function loadOrderedPackages(repoRoot: string, publishOrder: readonly string[], packageJsonPath: (name: string) => string): Promise<{
|
|
7
|
+
packages: Map<string, PkgJson>;
|
|
8
|
+
errors: string[];
|
|
9
|
+
}>;
|
|
10
|
+
export declare function firstPublishOrderMismatch(actual: readonly string[], derived: readonly string[]): string | null;
|
|
11
|
+
export declare function trustedPackagesErrors(trusted: readonly string[] | undefined, orderSet: Set<string>, workflow: string): string[];
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { readJson } from "./fs.js";
|
|
3
|
+
export async function loadOrderedPackages(repoRoot, publishOrder, packageJsonPath) {
|
|
4
|
+
const errors = [];
|
|
5
|
+
const packages = new Map();
|
|
6
|
+
const loaded = await Promise.all(publishOrder.map(async (name) => {
|
|
7
|
+
const rel = packageJsonPath(name);
|
|
8
|
+
const full = path.join(repoRoot, rel);
|
|
9
|
+
try {
|
|
10
|
+
const pkg = await readJson(full);
|
|
11
|
+
if (pkg.name && pkg.name !== name) {
|
|
12
|
+
errors.push(`${rel}: name is ${pkg.name}, expected ${name}`);
|
|
13
|
+
}
|
|
14
|
+
return { name, pkg };
|
|
15
|
+
}
|
|
16
|
+
catch (err) {
|
|
17
|
+
errors.push(`Cannot read ${rel}: ${err instanceof Error ? err.message : String(err)}`);
|
|
18
|
+
return { name, pkg: null };
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
for (const row of loaded) {
|
|
22
|
+
if (row.pkg) {
|
|
23
|
+
packages.set(row.name, row.pkg);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return { packages, errors };
|
|
27
|
+
}
|
|
28
|
+
export function firstPublishOrderMismatch(actual, derived) {
|
|
29
|
+
if (actual.length !== derived.length) {
|
|
30
|
+
return "PUBLISH_ORDER length differs from derived topological order";
|
|
31
|
+
}
|
|
32
|
+
for (let i = 0; i < actual.length; i++) {
|
|
33
|
+
if (actual[i] !== derived[i]) {
|
|
34
|
+
return `PUBLISH_ORDER mismatch at index ${i}: got ${actual[i]}, expected ${derived[i]} (dependency order)`;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
export function trustedPackagesErrors(trusted, orderSet, workflow) {
|
|
40
|
+
const errors = [];
|
|
41
|
+
for (const name of trusted ?? []) {
|
|
42
|
+
if (!orderSet.has(name)) {
|
|
43
|
+
errors.push(`Trusted-publisher manifest lists ${name} but it is missing from PUBLISH_ORDER (workflow ${workflow})`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return errors;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=publish-load.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish-load.js","sourceRoot":"","sources":["../src/publish-load.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQnC,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,QAAgB,EAChB,YAA+B,EAC/B,eAAyC;IAEzC,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAmB,CAAC;IAE5C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAC9B,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;QAC9B,MAAM,GAAG,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACtC,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAU,IAAI,CAAC,CAAC;YAC1C,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;gBAClC,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,aAAa,GAAG,CAAC,IAAI,cAAc,IAAI,EAAE,CAAC,CAAC;YAC/D,CAAC;YACD,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;QACvB,CAAC;QAAC,OAAO,GAA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AG,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,MAAM,CAAC,IAAI,CACT,oCAAoC,IAAI,mDAAmD,QAAQ,GAAG,CACvG,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type PackageRef = {
|
|
2
|
+
name: string;
|
|
3
|
+
packageJsonPath: string;
|
|
4
|
+
};
|
|
5
|
+
export type PublishOrderGuardOptions = {
|
|
6
|
+
repoRoot: string;
|
|
7
|
+
publishOrder: readonly string[];
|
|
8
|
+
packageJsonPath: (name: string) => string;
|
|
9
|
+
trustedPackages?: readonly string[];
|
|
10
|
+
workflowFile?: string;
|
|
11
|
+
};
|
|
12
|
+
export type PublishOrderGuardResult = {
|
|
13
|
+
ok: boolean;
|
|
14
|
+
errors: string[];
|
|
15
|
+
derivedOrder: string[];
|
|
16
|
+
};
|
|
17
|
+
export declare function checkPublishOrder(options: PublishOrderGuardOptions): Promise<PublishOrderGuardResult>;
|
|
18
|
+
export declare const DS_AUTOMATION_PUBLISH_ORDER: readonly ["@corpdk/graphql-dsl", "@corpdk/scalar-zod", "@corpdk/dal-core", "@corpdk/pub-sub", "@corpdk/graphql-input-zod", "@corpdk/dal-codegen", "@corpdk/engine-kit", "@corpdk/graphql-cli-core", "@corpdk/create-graphql-sdk", "@corpdk/create-graphql-cli", "@corpdk/codegen-cli", "@corpdk/create-ds"];
|
|
19
|
+
export declare const DS_AUTOMATION_PACKAGE_JSON_PATH: Record<string, string>;
|
|
20
|
+
/** B0 generator packages that must have npm trusted publishing configured. */
|
|
21
|
+
export declare const DS_AUTOMATION_TRUSTED_PACKAGES: readonly ["@corpdk/scalar-zod", "@corpdk/graphql-input-zod", "@corpdk/graphql-dsl", "@corpdk/engine-kit", "@corpdk/graphql-cli-core", "@corpdk/create-graphql-sdk", "@corpdk/create-graphql-cli"];
|
package/dist/publish.js
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { firstPublishOrderMismatch, loadOrderedPackages, trustedPackagesErrors, } from "./publish-load.js";
|
|
2
|
+
function depEdges(pkg, orderSet) {
|
|
3
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
4
|
+
const out = [];
|
|
5
|
+
for (const key of Object.keys(deps ?? {})) {
|
|
6
|
+
if (key.startsWith("@corpdk/") && orderSet.has(key)) {
|
|
7
|
+
out.push(key);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return out;
|
|
11
|
+
}
|
|
12
|
+
function topologicalSort(packages, orderSet) {
|
|
13
|
+
const visited = new Set();
|
|
14
|
+
const visiting = new Set();
|
|
15
|
+
const sorted = [];
|
|
16
|
+
function visit(name) {
|
|
17
|
+
if (visited.has(name))
|
|
18
|
+
return;
|
|
19
|
+
if (visiting.has(name)) {
|
|
20
|
+
throw new Error(`Circular @corpdk dependency involving ${name}`);
|
|
21
|
+
}
|
|
22
|
+
visiting.add(name);
|
|
23
|
+
const pkg = packages.get(name);
|
|
24
|
+
if (pkg) {
|
|
25
|
+
for (const dep of depEdges(pkg, orderSet)) {
|
|
26
|
+
visit(dep);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
visiting.delete(name);
|
|
30
|
+
visited.add(name);
|
|
31
|
+
sorted.push(name);
|
|
32
|
+
}
|
|
33
|
+
for (const name of orderSet) {
|
|
34
|
+
visit(name);
|
|
35
|
+
}
|
|
36
|
+
return sorted;
|
|
37
|
+
}
|
|
38
|
+
export async function checkPublishOrder(options) {
|
|
39
|
+
const orderSet = new Set(options.publishOrder);
|
|
40
|
+
const { packages, errors } = await loadOrderedPackages(options.repoRoot, options.publishOrder, options.packageJsonPath);
|
|
41
|
+
let derivedOrder = [];
|
|
42
|
+
try {
|
|
43
|
+
derivedOrder = topologicalSort(packages, orderSet);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
errors.push(err instanceof Error ? err.message : String(err));
|
|
47
|
+
return { ok: false, errors, derivedOrder: [] };
|
|
48
|
+
}
|
|
49
|
+
const mismatch = firstPublishOrderMismatch(options.publishOrder, derivedOrder);
|
|
50
|
+
if (mismatch) {
|
|
51
|
+
errors.push(mismatch);
|
|
52
|
+
}
|
|
53
|
+
const workflow = options.workflowFile ?? "publish-ds-automation.yml";
|
|
54
|
+
errors.push(...trustedPackagesErrors(options.trustedPackages, orderSet, workflow));
|
|
55
|
+
return { ok: errors.length === 0, errors, derivedOrder };
|
|
56
|
+
}
|
|
57
|
+
export const DS_AUTOMATION_PUBLISH_ORDER = [
|
|
58
|
+
"@corpdk/graphql-dsl",
|
|
59
|
+
"@corpdk/scalar-zod",
|
|
60
|
+
"@corpdk/dal-core",
|
|
61
|
+
"@corpdk/pub-sub",
|
|
62
|
+
"@corpdk/graphql-input-zod",
|
|
63
|
+
"@corpdk/dal-codegen",
|
|
64
|
+
"@corpdk/engine-kit",
|
|
65
|
+
"@corpdk/graphql-cli-core",
|
|
66
|
+
"@corpdk/create-graphql-sdk",
|
|
67
|
+
"@corpdk/create-graphql-cli",
|
|
68
|
+
"@corpdk/codegen-cli",
|
|
69
|
+
"@corpdk/create-ds",
|
|
70
|
+
];
|
|
71
|
+
export const DS_AUTOMATION_PACKAGE_JSON_PATH = {
|
|
72
|
+
"@corpdk/graphql-dsl": "libraries/graphql-dsl/package.json",
|
|
73
|
+
"@corpdk/scalar-zod": "libraries/scalar-zod/package.json",
|
|
74
|
+
"@corpdk/dal-core": "libraries/dal-core/package.json",
|
|
75
|
+
"@corpdk/pub-sub": "libraries/pub-sub/package.json",
|
|
76
|
+
"@corpdk/graphql-input-zod": "libraries/graphql-input-zod/package.json",
|
|
77
|
+
"@corpdk/dal-codegen": "libraries/dal-codegen/package.json",
|
|
78
|
+
"@corpdk/engine-kit": "libraries/engine-kit/package.json",
|
|
79
|
+
"@corpdk/graphql-cli-core": "libraries/graphql-cli-core/package.json",
|
|
80
|
+
"@corpdk/create-graphql-sdk": "engines/create-graphql-sdk/package.json",
|
|
81
|
+
"@corpdk/create-graphql-cli": "engines/create-graphql-cli/package.json",
|
|
82
|
+
"@corpdk/codegen-cli": "libraries/codegen-cli/package.json",
|
|
83
|
+
"@corpdk/create-ds": "engines/create-ds/package.json",
|
|
84
|
+
};
|
|
85
|
+
/** B0 generator packages that must have npm trusted publishing configured. */
|
|
86
|
+
export const DS_AUTOMATION_TRUSTED_PACKAGES = [
|
|
87
|
+
"@corpdk/scalar-zod",
|
|
88
|
+
"@corpdk/graphql-input-zod",
|
|
89
|
+
"@corpdk/graphql-dsl",
|
|
90
|
+
"@corpdk/engine-kit",
|
|
91
|
+
"@corpdk/graphql-cli-core",
|
|
92
|
+
"@corpdk/create-graphql-sdk",
|
|
93
|
+
"@corpdk/create-graphql-cli",
|
|
94
|
+
];
|
|
95
|
+
//# sourceMappingURL=publish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,qBAAqB,GAEtB,MAAM,mBAAmB,CAAC;AAe3B,SAAS,QAAQ,CAAC,GAAY,EAAE,QAAqB;IACnD,MAAM,IAAI,GAAG,EAAE,GAAG,GAAG,CAAC,YAAY,EAAE,GAAG,GAAG,CAAC,eAAe,EAAE,CAAC;IAC7D,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC;QAC1C,IAAI,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACpD,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAChB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,eAAe,CACtB,QAA8B,EAC9B,QAAqB;IAErB,MAAM,OAA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AAqB,EAAE,oCAAoC;IAC3D,oBAAoB,EAAE,mCAAmC;IACzD,0BAA0B,EAAE,yCAAyC;IACrE,4BAA4B,EAAE,yCAAyC;IACvE,4BAA4B,EAAE,yCAAyC;IACvE,qBAAqB,EAAE,oCAAoC;IAC3D,mBAAmB,EAAE,gCAAgC;CACtD,CAAC;AAEF,8EAA8E;AAC9E,MAAM,CAAC,MAAM,8BAA8B,GAAG;IAC5C,oBAAoB;IACpB,2BAA2B;IAC3B,qBAAqB;IACrB,oBAAoB;IACpB,0BAA0B;IAC1B,4BAA4B;IAC5B,4BAA4B;CACpB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ResolveCanonicalOptions = {
|
|
2
|
+
engineRoot: string;
|
|
3
|
+
monorepoPath: string;
|
|
4
|
+
bundledPath: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function resolveCanonical(options: ResolveCanonicalOptions): Promise<string>;
|
|
7
|
+
export declare function engineRootFromImportMeta(metaUrl: string): string;
|
|
8
|
+
export declare function readEngineRelease(engineRoot: string): Promise<string>;
|
|
9
|
+
export declare function initialCalVer(asOf?: Date): string;
|
|
10
|
+
export declare function isBundledCanonical(templateDir: string, bundledPath: string): boolean;
|
package/dist/template.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { readJson } from "./fs.js";
|
|
4
|
+
export async function resolveCanonical(options) {
|
|
5
|
+
const { monorepoPath, bundledPath } = options;
|
|
6
|
+
const { pathExists } = await import("./fs.js");
|
|
7
|
+
if (await pathExists(path.join(monorepoPath, "package.json"))) {
|
|
8
|
+
return monorepoPath;
|
|
9
|
+
}
|
|
10
|
+
if (await pathExists(path.join(bundledPath, "package.json"))) {
|
|
11
|
+
return bundledPath;
|
|
12
|
+
}
|
|
13
|
+
throw new Error("Canonical template not found (expected monorepo path or bundled canonical/)");
|
|
14
|
+
}
|
|
15
|
+
export function engineRootFromImportMeta(metaUrl) {
|
|
16
|
+
const dir = path.dirname(fileURLToPath(metaUrl));
|
|
17
|
+
return path.resolve(dir, "..");
|
|
18
|
+
}
|
|
19
|
+
export async function readEngineRelease(engineRoot) {
|
|
20
|
+
const pkg = await readJson(path.join(engineRoot, "package.json"));
|
|
21
|
+
if (!pkg.version) {
|
|
22
|
+
throw new Error(`package.json missing version under ${engineRoot}`);
|
|
23
|
+
}
|
|
24
|
+
return pkg.version;
|
|
25
|
+
}
|
|
26
|
+
export function initialCalVer(asOf = new Date()) {
|
|
27
|
+
const year = asOf.getUTCFullYear();
|
|
28
|
+
const month = asOf.getUTCMonth() + 1;
|
|
29
|
+
return `${year}.${month}.0`;
|
|
30
|
+
}
|
|
31
|
+
export function isBundledCanonical(templateDir, bundledPath) {
|
|
32
|
+
return path.resolve(templateDir) === path.resolve(bundledPath);
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQnC,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,OAAgC;IAEhC,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAC9C,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;IAC/C,IAAI,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;QAC9D,OAAO,YAAY,CAAC;IACtB,CAAC;IACD,IAAI,MAAM,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;QAC7D,OAAO,WAAW,CAAC;IACrB,CAAC;IACD,MAAM,IAAI,KAAK,CACb,6EAA6E,CAC9E,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,OAAe;IACtD,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;IACjD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,UAAkB;IACxD,MAAM,GAAG,GAAG,MAAM,QAAQ,CACxB,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,CACtC,CAAC;IACF,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,sCAAsC,UAAU,EAAE,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,OAAa,IAAI,IAAI,EAAE;IACnD,MAAM,IAAI,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;IACnC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC;IACrC,OAAO,GAAG,IAAI,IAAI,KAAK,IAAI,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,WAAmB,EACnB,WAAmB;IAEnB,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AACjE,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type EngineExitCode = 0 | 1 | 2 | 3;
|
|
2
|
+
export type EngineResult = {
|
|
3
|
+
exitCode: EngineExitCode;
|
|
4
|
+
nextSteps?: string[];
|
|
5
|
+
changedFiles: string[];
|
|
6
|
+
message?: string;
|
|
7
|
+
};
|
|
8
|
+
export interface Reporter {
|
|
9
|
+
step(message: string): void;
|
|
10
|
+
info(message: string): void;
|
|
11
|
+
warn(message: string): void;
|
|
12
|
+
}
|
|
13
|
+
export declare const EXIT_SUCCESS: 0;
|
|
14
|
+
export declare const EXIT_VALIDATION: 1;
|
|
15
|
+
export declare const EXIT_USAGE: 2;
|
|
16
|
+
export declare const EXIT_TOOL: 3;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAeA,MAAM,CAAC,MAAM,YAAY,GAAG,CAAU,CAAC;AACvC,MAAM,CAAC,MAAM,eAAe,GAAG,CAAU,CAAC;AAC1C,MAAM,CAAC,MAAM,UAAU,GAAG,CAAU,CAAC;AACrC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAU,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type UpgradeMergeHandler = (rel: string, templatePath: string, destPath: string) => Promise<void>;
|
|
2
|
+
export type RunUpgradePlanOptions = {
|
|
3
|
+
overwrite: readonly string[];
|
|
4
|
+
merge: readonly string[];
|
|
5
|
+
templateDir: string;
|
|
6
|
+
packageDir: string;
|
|
7
|
+
dryRun?: boolean;
|
|
8
|
+
/** When true (default), every overwrite path must exist under templateDir. */
|
|
9
|
+
requireOverwriteSources?: boolean;
|
|
10
|
+
mergeFile?: UpgradeMergeHandler;
|
|
11
|
+
afterWrite?: () => Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
export declare class MissingOverwriteSourceError extends Error {
|
|
14
|
+
readonly relPath: string;
|
|
15
|
+
readonly templatePath: string;
|
|
16
|
+
constructor(relPath: string, templatePath: string);
|
|
17
|
+
}
|
|
18
|
+
export type UpgradePlanResult = {
|
|
19
|
+
changedFiles: string[];
|
|
20
|
+
};
|
|
21
|
+
export declare function runUpgradePlan(options: RunUpgradePlanOptions): Promise<UpgradePlanResult>;
|
|
22
|
+
export declare function writeEngineVersion(engineName: string, packageDir: string, version: string, dryRun?: boolean): Promise<string>;
|
package/dist/upgrade.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pathExists } from "./fs.js";
|
|
4
|
+
export class MissingOverwriteSourceError extends Error {
|
|
5
|
+
relPath;
|
|
6
|
+
templatePath;
|
|
7
|
+
constructor(relPath, templatePath) {
|
|
8
|
+
super(`Canonical template file missing: ${relPath} (expected ${templatePath})`);
|
|
9
|
+
this.name = "MissingOverwriteSourceError";
|
|
10
|
+
this.relPath = relPath;
|
|
11
|
+
this.templatePath = templatePath;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export async function runUpgradePlan(options) {
|
|
15
|
+
const changedFiles = [];
|
|
16
|
+
const dryRun = options.dryRun ?? false;
|
|
17
|
+
const requireSources = options.requireOverwriteSources ?? true;
|
|
18
|
+
const mergeSet = new Set(options.merge);
|
|
19
|
+
const overwriteRows = await Promise.all(options.overwrite.map(async (rel) => {
|
|
20
|
+
const templatePath = path.join(options.templateDir, rel);
|
|
21
|
+
const destPath = path.join(options.packageDir, rel);
|
|
22
|
+
const exists = await pathExists(templatePath);
|
|
23
|
+
return { rel, templatePath, destPath, exists };
|
|
24
|
+
}));
|
|
25
|
+
const toWrite = [];
|
|
26
|
+
for (const row of overwriteRows) {
|
|
27
|
+
if (!row.exists) {
|
|
28
|
+
if (requireSources) {
|
|
29
|
+
throw new MissingOverwriteSourceError(row.rel, row.templatePath);
|
|
30
|
+
}
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
changedFiles.push(row.rel);
|
|
34
|
+
if (!dryRun) {
|
|
35
|
+
toWrite.push(row);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
await Promise.all(toWrite.map(async (row) => {
|
|
39
|
+
if (mergeSet.has(row.rel) && options.mergeFile) {
|
|
40
|
+
await options.mergeFile(row.rel, row.templatePath, row.destPath);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
await fs.mkdir(path.dirname(row.destPath), { recursive: true });
|
|
44
|
+
await fs.copyFile(row.templatePath, row.destPath);
|
|
45
|
+
}));
|
|
46
|
+
if (!dryRun && options.afterWrite) {
|
|
47
|
+
await options.afterWrite();
|
|
48
|
+
}
|
|
49
|
+
return { changedFiles };
|
|
50
|
+
}
|
|
51
|
+
export async function writeEngineVersion(engineName, packageDir, version, dryRun) {
|
|
52
|
+
const rel = `.${engineName}-version`;
|
|
53
|
+
const dest = path.join(packageDir, rel);
|
|
54
|
+
if (!dryRun) {
|
|
55
|
+
await fs.writeFile(dest, `${version}\n`, "utf8");
|
|
56
|
+
}
|
|
57
|
+
return rel;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=upgrade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrade.js","sourceRoot":"","sources":["../src/upgrade.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAoBrC,MAAM,OAAO,2BAA4B,SAAQ,KAAK;IAC3C,OAAO,CAAS;IAChB,YAAY,CAAS;IAE9B,YAAY,OAAe,EAAE,YAAoB;QAC/C,KAAK,CACH,oCAAoC,OAAO,cAAc,YAAY,GAAG,CACzE,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,6BAA6B,CAAC;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACnC,CAAC;CACF;AAMD,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAA8B;IAE9B,MAAM,YAAY,GAAa,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC;IACvC,MAAM,cAA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MAAM,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;YACjE,OAAO;QACT,CAAC;QACD,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAChE,MAAM,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;IACpD,CAAC,CAAC,CACH,CAAC;IAEF,IAAI,CAAC,MAAM,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QAClC,MAAM,OAAO,CAAC,UAAU,EAAE,CAAC;IAC7B,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,UAAkB,EAClB,UAAkB,EAClB,OAAe,EACf,MAAgB;IAEhB,MAAM,GAAG,GAAG,IAAI,UAAU,UAAU,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,GAAG,OAAO,IAAI,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@corpdk/engine-kit",
|
|
3
|
-
"version": "2026.10.0-alpha.
|
|
3
|
+
"version": "2026.10.0-alpha.16",
|
|
4
4
|
"description": "Shared init/upgrade engine kit for create-* CLIs",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,9 +24,17 @@
|
|
|
24
24
|
"import": "./dist/index.js"
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
|
+
"bin": {
|
|
28
|
+
"check-ds-publish-order": "./dist/bin/check-publish-order.js"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@clack/prompts": "^1.1.0",
|
|
32
|
+
"yaml": "^2.8.3"
|
|
33
|
+
},
|
|
27
34
|
"devDependencies": {
|
|
28
35
|
"@types/node": "^24.0.0",
|
|
29
|
-
"typescript": "^6.0.2"
|
|
36
|
+
"typescript": "^6.0.2",
|
|
37
|
+
"vitest": "^4.1.2"
|
|
30
38
|
},
|
|
31
39
|
"engines": {
|
|
32
40
|
"node": ">=24.0.0"
|
|
@@ -34,6 +42,8 @@
|
|
|
34
42
|
"scripts": {
|
|
35
43
|
"build": "tsc",
|
|
36
44
|
"typecheck": "tsc --noEmit",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"check:publish-order": "node ./dist/bin/check-publish-order.js",
|
|
37
47
|
"clean": "rm -rf dist node_modules .turbo *.tsbuildinfo"
|
|
38
48
|
}
|
|
39
49
|
}
|