@toolproof-core/schema 1.0.2 → 1.0.4
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/dist/generated/normalized/Genesis.d.ts +2 -0
- package/dist/generated/normalized/Genesis.js +2 -0
- package/dist/generated/normalized/Genesis.json +2008 -0
- package/dist/generated/resources/Genesis.d.ts +2 -0
- package/dist/generated/resources/Genesis.js +2 -0
- package/dist/generated/resources/Genesis.json +2907 -0
- package/dist/generated/schemas/Genesis.d.ts +2 -0
- package/dist/generated/schemas/Genesis.js +2 -0
- package/dist/generated/schemas/Genesis.json +1466 -0
- package/dist/generated/schemas/standalone/Goal.d.ts +2 -0
- package/dist/generated/schemas/standalone/Goal.js +2 -0
- package/dist/generated/schemas/standalone/Goal.json +86 -0
- package/dist/generated/schemas/standalone/Job.d.ts +2 -0
- package/dist/generated/schemas/standalone/Job.js +2 -0
- package/dist/generated/schemas/standalone/Job.json +236 -0
- package/dist/generated/schemas/standalone/RawStrategy.d.ts +2 -0
- package/dist/generated/schemas/standalone/RawStrategy.js +2 -0
- package/dist/generated/schemas/standalone/RawStrategy.json +650 -0
- package/dist/generated/schemas/standalone/ResourceType.d.ts +2 -0
- package/dist/generated/schemas/standalone/ResourceType.js +2 -0
- package/dist/generated/schemas/standalone/ResourceType.json +140 -0
- package/dist/generated/schemas/standalone/RunnableStrategy.d.ts +2 -0
- package/dist/generated/schemas/standalone/RunnableStrategy.js +2 -0
- package/dist/generated/schemas/standalone/RunnableStrategy.json +720 -0
- package/dist/generated/schemas/standalone/StrategyRun.d.ts +2 -0
- package/dist/generated/schemas/standalone/StrategyRun.js +2 -0
- package/dist/generated/schemas/standalone/StrategyRun.json +1002 -0
- package/dist/generated/{types → typesTS}/standalone/Resource_Genesis.d.ts +1 -1
- package/{src/generated/types → dist/generated/typesTS}/standalone/Resource_Job.d.ts +1 -1
- package/{src/generated/types → dist/generated/typesTS}/standalone/Resource_RawStrategy.d.ts +1 -1
- package/{src/generated/types → dist/generated/typesTS}/standalone/Resource_ResourceType.d.ts +1 -1
- package/dist/generated/{types → typesTS}/standalone/Resource_RunnableStrategy.d.ts +1 -1
- package/dist/generated/typesTS/typesTS.d.ts +745 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +5 -0
- package/dist/scripts/_lib/config.d.ts +10 -10
- package/dist/scripts/_lib/config.js +23 -23
- package/dist/scripts/extractSchemasFromResourceTypeShells.js +109 -103
- package/dist/scripts/generateDependencies.js +15 -14
- package/dist/scripts/generateSchemaShims.js +76 -84
- package/dist/scripts/generateStandaloneSchema.js +47 -37
- package/dist/scripts/generateStandaloneTypeTS.js +108 -0
- package/dist/scripts/generateTypesTS.js +430 -0
- package/dist/scripts/normalizeAnchorsToPointers.js +37 -30
- package/dist/scripts/wrapResourceTypesWithResourceShells.js +14 -16
- package/package.json +11 -12
- package/src/Genesis.json +2007 -1999
- package/src/generated/{dependencyMap.json → dependencies/dependencyMap.json} +7 -6
- package/src/generated/normalized/Genesis.json +17 -9
- package/src/generated/resources/Genesis.json +19 -11
- package/src/generated/schemas/Genesis.json +15 -7
- package/src/generated/schemas/standalone/RawStrategy.json +15 -7
- package/src/generated/schemas/standalone/RunnableStrategy.json +15 -7
- package/src/generated/schemas/standalone/StrategyRun.json +15 -7
- package/src/generated/{types → typesTS}/standalone/Resource_Genesis.d.ts +1 -1
- package/{dist/generated/types → src/generated/typesTS}/standalone/Resource_Job.d.ts +1 -1
- package/{dist/generated/types → src/generated/typesTS}/standalone/Resource_RawStrategy.d.ts +1 -1
- package/{dist/generated/types → src/generated/typesTS}/standalone/Resource_ResourceType.d.ts +1 -1
- package/src/generated/{types → typesTS}/standalone/Resource_RunnableStrategy.d.ts +1 -1
- package/src/generated/typesTS/typesTS.d.ts +745 -0
- package/src/index.ts +67 -1
- package/src/scripts/_lib/config.ts +205 -205
- package/src/scripts/extractSchemasFromResourceTypeShells.ts +261 -218
- package/src/scripts/generateDependencies.ts +121 -120
- package/src/scripts/generateSchemaShims.ts +127 -135
- package/src/scripts/generateStandaloneSchema.ts +185 -175
- package/src/scripts/generateStandaloneTypeTS.ts +127 -0
- package/src/scripts/generateTypesTS.ts +532 -0
- package/src/scripts/normalizeAnchorsToPointers.ts +115 -123
- package/src/scripts/wrapResourceTypesWithResourceShells.ts +82 -84
- package/dist/generated/types/types.d.ts +0 -1723
- package/dist/scripts/generateStandaloneType.js +0 -102
- package/dist/scripts/generateTypes.js +0 -550
- package/src/generated/types/types.d.ts +0 -1723
- package/src/scripts/generateStandaloneType.ts +0 -119
- package/src/scripts/generateTypes.ts +0 -615
- /package/dist/generated/{types → typesTS}/standalone/Resource_Genesis.js +0 -0
- /package/dist/generated/{types → typesTS}/standalone/Resource_Job.js +0 -0
- /package/dist/generated/{types → typesTS}/standalone/Resource_RawStrategy.js +0 -0
- /package/dist/generated/{types → typesTS}/standalone/Resource_ResourceType.js +0 -0
- /package/dist/generated/{types → typesTS}/standalone/Resource_RunnableStrategy.js +0 -0
- /package/dist/generated/{types/types.js → typesTS/typesTS.js} +0 -0
- /package/dist/scripts/{generateStandaloneType.d.ts → generateStandaloneTypeTS.d.ts} +0 -0
- /package/dist/scripts/{generateTypes.d.ts → generateTypesTS.d.ts} +0 -0
- /package/src/generated/{types → typesTS}/standalone/Resource_Genesis.js +0 -0
- /package/src/generated/{types → typesTS}/standalone/Resource_Job.js +0 -0
- /package/src/generated/{types → typesTS}/standalone/Resource_RawStrategy.js +0 -0
- /package/src/generated/{types → typesTS}/standalone/Resource_ResourceType.js +0 -0
- /package/src/generated/{types → typesTS}/standalone/Resource_RunnableStrategy.js +0 -0
- /package/src/generated/{types/types.js → typesTS/typesTS.js} +0 -0
|
@@ -1,175 +1,185 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { getConfig } from './_lib/config.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Create a standalone JSON Schema for a single $defs entry under Genesis.json,
|
|
7
|
-
* embedding all direct & transitive local $defs dependencies.
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
* node ./dist/scripts/generateStandaloneSchema.js --name <DefName>
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
const
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getConfig } from './_lib/config.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create a standalone JSON Schema for a single $defs entry under Genesis.json,
|
|
7
|
+
* embedding all direct & transitive local $defs dependencies.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
* node ./dist/scripts/generateStandaloneSchema.js --name <DefName>
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// PURE: Extract a standalone subschema from a flattened Genesis schema, returning warnings instead of logging
|
|
14
|
+
function extractStandaloneSchemaLogic(genesis: any, name: string): { schema: any; warnings: string[] } {
|
|
15
|
+
const rootDefs: Record<string, any> | undefined = genesis.$defs;
|
|
16
|
+
if (!rootDefs || typeof rootDefs !== 'object') {
|
|
17
|
+
throw new Error('No $defs object found in Genesis.json');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const target = rootDefs[name];
|
|
21
|
+
if (!target) {
|
|
22
|
+
throw new Error(`Subschema named '${name}' not found under $defs in Genesis.json`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const needed = collectLocalDefClosure(target, rootDefs);
|
|
26
|
+
|
|
27
|
+
const targetClone = deepClone(target);
|
|
28
|
+
const defsOut: Record<string, any> = {};
|
|
29
|
+
const warnings: string[] = [];
|
|
30
|
+
for (const defName of needed) {
|
|
31
|
+
if (defName === name) continue;
|
|
32
|
+
const defSchema = rootDefs[defName];
|
|
33
|
+
if (defSchema === undefined) {
|
|
34
|
+
warnings.push(`Warning: referenced def '${defName}' missing in root $defs (skipped).`);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
defsOut[defName] = deepClone(defSchema);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const existingInner = isObject(targetClone.$defs) ? targetClone.$defs : {};
|
|
41
|
+
targetClone.$defs = { ...existingInner, ...defsOut };
|
|
42
|
+
|
|
43
|
+
return { schema: targetClone, warnings };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// PURE: Strip accidental surrounding quotes from CLI values (PowerShell/cmd).
|
|
47
|
+
function stripSurroundingQuotes(value: string): string {
|
|
48
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
49
|
+
return value.slice(1, -1);
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// PURE: Parse CLI args (no defaults, no filesystem probing).
|
|
55
|
+
function parseArgs(args: string[]): { name?: string } {
|
|
56
|
+
let name: string | undefined;
|
|
57
|
+
for (let i = 0; i < args.length; i++) {
|
|
58
|
+
const a = args[i];
|
|
59
|
+
if (a === '--name') {
|
|
60
|
+
name = args[i + 1];
|
|
61
|
+
i++;
|
|
62
|
+
} else if (a.startsWith('--name=')) {
|
|
63
|
+
name = a.split('=')[1];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const normalized = typeof name === 'string' ? stripSurroundingQuotes(name) : undefined;
|
|
67
|
+
return { name: normalized?.trim() ? normalized : undefined };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// PURE: Narrow unknown values to plain objects.
|
|
71
|
+
function isObject(v: any): v is Record<string, any> {
|
|
72
|
+
return v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// PURE: Deep-clone JSON-ish values (no mutation of input).
|
|
76
|
+
function deepClone<T>(v: T): T {
|
|
77
|
+
if (Array.isArray(v)) return v.map((x) => deepClone(x)) as any;
|
|
78
|
+
if (isObject(v)) {
|
|
79
|
+
const out: Record<string, any> = {};
|
|
80
|
+
for (const k of Object.keys(v)) out[k] = deepClone((v as any)[k]);
|
|
81
|
+
return out as any;
|
|
82
|
+
}
|
|
83
|
+
return v;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// PURE: Extract a $defs key from a local JSON pointer ref.
|
|
87
|
+
function extractPointerDefName(ref: string): string | null {
|
|
88
|
+
if (!ref || !ref.startsWith('#/')) return null;
|
|
89
|
+
const parts = ref.slice(2).split('/');
|
|
90
|
+
if (parts.length !== 2) return null;
|
|
91
|
+
if (parts[0] !== '$defs') return null;
|
|
92
|
+
const name = parts[1].replace(/~1/g, '/').replace(/~0/g, '~');
|
|
93
|
+
return name;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// PURE: Resolve an internal ref (pointer or anchor) to a root $defs key.
|
|
97
|
+
function resolveRefToDefName(ref: string, rootDefs: Record<string, any>): string | null {
|
|
98
|
+
if (!ref) return null;
|
|
99
|
+
const byPointer = extractPointerDefName(ref);
|
|
100
|
+
if (byPointer) return byPointer;
|
|
101
|
+
|
|
102
|
+
if (ref.startsWith('#') && !ref.startsWith('#/')) {
|
|
103
|
+
const anchor = ref.slice(1);
|
|
104
|
+
if (!anchor) return null;
|
|
105
|
+
for (const [defName, defSchema] of Object.entries(rootDefs)) {
|
|
106
|
+
if (!defSchema || typeof defSchema !== 'object') continue;
|
|
107
|
+
const topLevelAnchor = (defSchema as any).$anchor;
|
|
108
|
+
const nested = (defSchema as any).nucleusSchema;
|
|
109
|
+
const nestedAnchor = nested && typeof nested === 'object' ? nested.$anchor : undefined;
|
|
110
|
+
const defAnchor = typeof topLevelAnchor === 'string' ? topLevelAnchor : (typeof nestedAnchor === 'string' ? nestedAnchor : undefined);
|
|
111
|
+
if (defAnchor === anchor) {
|
|
112
|
+
return defName;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// PURE: Compute the transitive closure of local $defs dependencies for a node.
|
|
121
|
+
function collectLocalDefClosure(node: any, rootDefs: Record<string, any>): Set<string> {
|
|
122
|
+
const needed = new Set<string>();
|
|
123
|
+
const queue: string[] = [];
|
|
124
|
+
|
|
125
|
+
function visit(n: any) {
|
|
126
|
+
if (Array.isArray(n)) {
|
|
127
|
+
for (const item of n) visit(item);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
if (!isObject(n)) return;
|
|
131
|
+
if (typeof n.$ref === 'string') {
|
|
132
|
+
const name = resolveRefToDefName(n.$ref, rootDefs);
|
|
133
|
+
if (name && !needed.has(name)) {
|
|
134
|
+
needed.add(name);
|
|
135
|
+
queue.push(name);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
for (const val of Object.values(n)) visit(val);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
visit(node);
|
|
142
|
+
|
|
143
|
+
while (queue.length > 0) {
|
|
144
|
+
const name = queue.shift()!;
|
|
145
|
+
const def = rootDefs[name];
|
|
146
|
+
if (!def) continue;
|
|
147
|
+
visit(def);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return needed;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
|
|
154
|
+
async function main() {
|
|
155
|
+
try {
|
|
156
|
+
const config = getConfig();
|
|
157
|
+
const { name } = parseArgs(process.argv.slice(2));
|
|
158
|
+
if (!name) {
|
|
159
|
+
throw new Error('Missing --name <DefName> argument');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const schemasDir = config.getSchemasDir();
|
|
163
|
+
const genesisPath = path.join(schemasDir, config.getSourceFile());
|
|
164
|
+
const outPath = config.getSchemaStandalonePath(`${name}.json`);
|
|
165
|
+
|
|
166
|
+
if (!fs.existsSync(genesisPath)) {
|
|
167
|
+
throw new Error(`Genesis.json not found at ${genesisPath}. Run extractSchemasFromResourceTypeShells first.`);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const raw = fs.readFileSync(genesisPath, 'utf-8');
|
|
171
|
+
const genesis = JSON.parse(raw);
|
|
172
|
+
|
|
173
|
+
const { schema, warnings } = extractStandaloneSchemaLogic(genesis, name);
|
|
174
|
+
for (const w of warnings) console.warn(w);
|
|
175
|
+
|
|
176
|
+
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
177
|
+
fs.writeFileSync(outPath, JSON.stringify(schema, null, 2) + '\n');
|
|
178
|
+
console.log(`Created standalone subschema '${name}' -> ${outPath}`);
|
|
179
|
+
} catch (error: any) {
|
|
180
|
+
console.error(error?.message ?? error);
|
|
181
|
+
process.exitCode = 1;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
void main();
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { getConfig } from "./_lib/config.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generate a typed Resource variant where `nucleus` is typed to a specific schema
|
|
6
|
+
* extracted under the configured output directory.
|
|
7
|
+
*
|
|
8
|
+
* Usage: node ./dist/scripts/generateStandaloneType.js --name Job
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// PURE: Generate the content of a standalone Resource type definition file for a given schema name.
|
|
12
|
+
function generateStandaloneTypeLogic(name: string): string {
|
|
13
|
+
const header = "// Auto-generated strict composite type. Do not edit.\n";
|
|
14
|
+
const ts =
|
|
15
|
+
`import type { ShellMaterializedBase, ${name} as NucleusSchema } from "../typesTS.js";\n` +
|
|
16
|
+
`export type Resource_${name} = ShellMaterializedBase & { nucleus: NucleusSchema };\n`;
|
|
17
|
+
return header + ts;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// PURE: Strip accidental surrounding quotes from CLI values (PowerShell/cmd).
|
|
21
|
+
function stripSurroundingQuotes(value: string): string {
|
|
22
|
+
if ((value.startsWith("\"") && value.endsWith("\"")) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
23
|
+
return value.slice(1, -1);
|
|
24
|
+
}
|
|
25
|
+
return value;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// PURE: Validate a standalone schema and return warnings (no logging).
|
|
29
|
+
function validateStandaloneSchemaForWarnings(schema: any): string[] {
|
|
30
|
+
const warnings: string[] = [];
|
|
31
|
+
if (schema?.$schema && schema.$schema !== "https://json-schema.org/draft/2020-12/schema") {
|
|
32
|
+
warnings.push(
|
|
33
|
+
`Warning: schema $schema is '${String(schema.$schema)}', expected draft 2020-12. Proceeding anyway.`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (schema?.type && schema.type !== "object") {
|
|
37
|
+
warnings.push(
|
|
38
|
+
`Warning: nucleusSchema usually has type: 'object' but this schema has type: '${String(schema.type)}'. Proceeding.`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return warnings;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// PURE: Parse CLI args (no defaults, no filesystem probing).
|
|
45
|
+
function parseArgs(args: string[]): { name?: string } {
|
|
46
|
+
let name: string | undefined;
|
|
47
|
+
for (let i = 0; i < args.length; i++) {
|
|
48
|
+
const a = args[i];
|
|
49
|
+
if (a === "--name") {
|
|
50
|
+
name = args[i + 1];
|
|
51
|
+
i++;
|
|
52
|
+
} else if (a.startsWith("--name=")) {
|
|
53
|
+
name = a.split("=")[1];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const normalized = typeof name === "string" ? stripSurroundingQuotes(name) : undefined;
|
|
57
|
+
return { name: normalized?.trim() ? normalized : undefined };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// IMPURE: Script entrypoint (config + filesystem I/O + console + process exit).
|
|
61
|
+
function main() {
|
|
62
|
+
try {
|
|
63
|
+
const config = getConfig();
|
|
64
|
+
const { name } = parseArgs(process.argv.slice(2));
|
|
65
|
+
|
|
66
|
+
if (!name) {
|
|
67
|
+
throw new Error("Missing --name <SchemaBasename> argument");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const inPath =
|
|
71
|
+
name === "Genesis"
|
|
72
|
+
? config.getSchemaPath("Genesis.json")
|
|
73
|
+
: config.getSchemaStandalonePath(`${name}.json`);
|
|
74
|
+
|
|
75
|
+
if (!fs.existsSync(inPath)) {
|
|
76
|
+
if (name === "Genesis") {
|
|
77
|
+
console.error(`Schema file not found: ${inPath}`);
|
|
78
|
+
console.error("Run extractSchemasFromResourceTypeShells first.");
|
|
79
|
+
} else {
|
|
80
|
+
console.error(`Standalone schema file not found: ${inPath}`);
|
|
81
|
+
console.error(`Run generateStandaloneSchema -- --name ${name} first.`);
|
|
82
|
+
}
|
|
83
|
+
throw new Error("Input schema file not found");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Basic validation against the expected shape of nucleusSchema.
|
|
87
|
+
const raw = fs.readFileSync(inPath, "utf8");
|
|
88
|
+
const parsed: any = JSON.parse(raw);
|
|
89
|
+
|
|
90
|
+
for (const warning of validateStandaloneSchemaForWarnings(parsed)) console.warn(warning);
|
|
91
|
+
|
|
92
|
+
const tsContent = generateStandaloneTypeLogic(name);
|
|
93
|
+
const jsContent = "export {}\n";
|
|
94
|
+
|
|
95
|
+
// Output setup
|
|
96
|
+
const outName = `Resource_${name}.d.ts`;
|
|
97
|
+
const outJsName = `Resource_${name}.js`;
|
|
98
|
+
const outDir = config.getStandaloneTypeTsSrcDir();
|
|
99
|
+
const distLibDir = config.getStandaloneTypeTsDistDir();
|
|
100
|
+
|
|
101
|
+
// Process src output
|
|
102
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
103
|
+
const outPath = config.getStandaloneTypeTsSrcPath(outName);
|
|
104
|
+
const outJsPath = config.getStandaloneTypeTsSrcPath(outJsName);
|
|
105
|
+
fs.writeFileSync(outPath, tsContent, "utf8");
|
|
106
|
+
console.log(`Wrote ${outPath}`);
|
|
107
|
+
|
|
108
|
+
if (!fs.existsSync(outJsPath)) {
|
|
109
|
+
fs.writeFileSync(outJsPath, jsContent, "utf8");
|
|
110
|
+
console.log(`Wrote ${outJsPath}`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Process dist output
|
|
114
|
+
fs.mkdirSync(distLibDir, { recursive: true });
|
|
115
|
+
const distDtsPath = config.getStandaloneTypeTsDistPath(outName);
|
|
116
|
+
const distJsPath = config.getStandaloneTypeTsDistPath(outJsName);
|
|
117
|
+
fs.writeFileSync(distDtsPath, tsContent, "utf8");
|
|
118
|
+
fs.writeFileSync(distJsPath, jsContent, "utf8");
|
|
119
|
+
console.log(`Wrote ${distDtsPath}`);
|
|
120
|
+
console.log(`Wrote ${distJsPath}`);
|
|
121
|
+
} catch (e) {
|
|
122
|
+
console.error(e);
|
|
123
|
+
process.exitCode = 1;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
main();
|