@toolproof-core/schema 1.0.8 → 1.0.9
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/index.d.ts +1 -1
- package/dist/scripts/generateConstants.js +1 -1
- package/package.json +8 -7
- package/src/Genesis.json +1833 -1833
- package/src/index.ts +70 -69
- package/src/scripts/_lib/config.ts +215 -215
- package/src/scripts/extractSchemasFromResourceTypeShells.ts +261 -261
- package/src/scripts/generateConstants.ts +217 -217
- package/src/scripts/generateDependencies.ts +121 -121
- package/src/scripts/generateSchemaShims.ts +127 -127
- package/src/scripts/generateStandaloneSchema.ts +185 -185
- package/src/scripts/generateStandaloneType.ts +127 -127
- package/src/scripts/generateTerminals.ts +73 -73
- package/src/scripts/generateTypes.ts +531 -531
- package/src/scripts/normalizeAnchorsToPointers.ts +141 -141
- package/src/scripts/wrapResourceTypesWithResourceShells.ts +82 -82
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { getConfig } from './_lib/config.js';
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* Rewrite anchor-style references to JSON Pointer references in Genesis.json.
|
|
7
|
-
* We also strip all $anchor fields from the output since they are no longer needed after rewriting refs.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// PURE: Remove all `$anchor` keys from a schema tree without rewriting refs.
|
|
11
|
-
export function stripAnchors<T>(schema: T): T {
|
|
12
|
-
const seen = new WeakMap<object, unknown>();
|
|
13
|
-
|
|
14
|
-
function walk(node: unknown): unknown {
|
|
15
|
-
if (!node || typeof node !== 'object') return node;
|
|
16
|
-
|
|
17
|
-
const existing = seen.get(node as object);
|
|
18
|
-
if (existing) return existing;
|
|
19
|
-
|
|
20
|
-
if (Array.isArray(node)) {
|
|
21
|
-
const out: unknown[] = [];
|
|
22
|
-
seen.set(node, out);
|
|
23
|
-
for (const item of node) out.push(walk(item));
|
|
24
|
-
return out;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const out: Record<string, unknown> = {};
|
|
28
|
-
seen.set(node as object, out);
|
|
29
|
-
|
|
30
|
-
for (const [key, value] of Object.entries(node as Record<string, unknown>)) {
|
|
31
|
-
if (key === '$anchor') continue;
|
|
32
|
-
out[key] = walk(value);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return out;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return walk(schema) as T;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// PURE: Rewrite anchor-style `$ref` strings (`#Anchor`) into JSON Pointer refs (`#/$defs/DefName`).
|
|
42
|
-
function normalizeAnchorsToPointers(input: any): any {
|
|
43
|
-
if (!input || typeof input !== "object") return input;
|
|
44
|
-
|
|
45
|
-
// Deep clone the input to ensure the function is pure (no side effects on input)
|
|
46
|
-
const root = JSON.parse(JSON.stringify(input));
|
|
47
|
-
|
|
48
|
-
// Build a map of anchors to their definition names
|
|
49
|
-
const defs: Record<string, any> = root.$defs && typeof root.$defs === "object" ? root.$defs : {};
|
|
50
|
-
const anchorToDef: Record<string, string> = {};
|
|
51
|
-
|
|
52
|
-
// For Genesis structure: each def is a Type envelope with nucleusSchema.$anchor
|
|
53
|
-
for (const [defName, defValue] of Object.entries(defs)) {
|
|
54
|
-
if (!defValue || typeof defValue !== "object") continue;
|
|
55
|
-
|
|
56
|
-
// Check if this is a Type envelope (has nucleusSchema property)
|
|
57
|
-
const nucleusSchema = (defValue as any).nucleusSchema;
|
|
58
|
-
if (nucleusSchema && typeof nucleusSchema === "object") {
|
|
59
|
-
// Look for $anchor inside the nucleusSchema
|
|
60
|
-
const anchor = nucleusSchema.$anchor;
|
|
61
|
-
if (typeof anchor === "string" && !anchorToDef[anchor]) {
|
|
62
|
-
anchorToDef[anchor] = defName;
|
|
63
|
-
}
|
|
64
|
-
} else {
|
|
65
|
-
// Fallback: check for $anchor at the def level (non-envelope case)
|
|
66
|
-
const anchor = (defValue as any).$anchor;
|
|
67
|
-
if (typeof anchor === "string" && !anchorToDef[anchor]) {
|
|
68
|
-
anchorToDef[anchor] = defName;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// Walk the entire tree and rewrite anchor refs to pointer refs
|
|
74
|
-
function walk(node: any): void {
|
|
75
|
-
if (Array.isArray(node)) {
|
|
76
|
-
for (const item of node) walk(item);
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
if (!node || typeof node !== "object") return;
|
|
80
|
-
|
|
81
|
-
// Rewrite $ref if it's an anchor-style reference
|
|
82
|
-
if (typeof node.$ref === "string") {
|
|
83
|
-
const ref: string = node.$ref;
|
|
84
|
-
// Match anchor refs: starts with # but not #/ (JSON Pointer syntax)
|
|
85
|
-
if (ref.startsWith("#") && !ref.startsWith("#/")) {
|
|
86
|
-
const anchor = ref.slice(1);
|
|
87
|
-
const defName = anchorToDef[anchor];
|
|
88
|
-
if (defName) {
|
|
89
|
-
node.$ref = `#/$defs/${defName}`;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Recursively walk all properties
|
|
95
|
-
for (const val of Object.values(node)) {
|
|
96
|
-
walk(val);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
walk(root);
|
|
101
|
-
return root;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
|
|
105
|
-
function main() {
|
|
106
|
-
try {
|
|
107
|
-
const config = getConfig();
|
|
108
|
-
const genesisSourcePath = config.getSourcePath();
|
|
109
|
-
|
|
110
|
-
// Create a generated/normalized version (anchor refs rewritten to pointers)
|
|
111
|
-
const normalizedPath = config.getNormalizedSourcePath();
|
|
112
|
-
|
|
113
|
-
if (!fs.existsSync(genesisSourcePath)) {
|
|
114
|
-
throw new Error(`Genesis source file not found at ${genesisSourcePath}`);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const raw = fs.readFileSync(genesisSourcePath, 'utf-8');
|
|
118
|
-
const genesis = JSON.parse(raw);
|
|
119
|
-
|
|
120
|
-
// Validate structure
|
|
121
|
-
if (!genesis.nucleusSchema || !genesis.nucleusSchema.$defs) {
|
|
122
|
-
throw new Error('Genesis.json must have nucleusSchema.$defs');
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// Rewrite anchors in the nucleusSchema (pure function call)
|
|
126
|
-
genesis.nucleusSchema = normalizeAnchorsToPointers(genesis.nucleusSchema);
|
|
127
|
-
|
|
128
|
-
// Strip $anchor fields from the schemas (pure function call)
|
|
129
|
-
genesis.nucleusSchema = stripAnchors(genesis.nucleusSchema);
|
|
130
|
-
|
|
131
|
-
// Write normalized version
|
|
132
|
-
fs.mkdirSync(path.dirname(normalizedPath), { recursive: true });
|
|
133
|
-
fs.writeFileSync(normalizedPath, JSON.stringify(genesis, null, 4), 'utf-8');
|
|
134
|
-
console.log(`Wrote normalized Genesis with pointer refs to ${normalizedPath}`);
|
|
135
|
-
} catch (e) {
|
|
136
|
-
console.error(e);
|
|
137
|
-
process.exitCode = 1;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
main();
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getConfig } from './_lib/config.js';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Rewrite anchor-style references to JSON Pointer references in Genesis.json.
|
|
7
|
+
* We also strip all $anchor fields from the output since they are no longer needed after rewriting refs.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// PURE: Remove all `$anchor` keys from a schema tree without rewriting refs.
|
|
11
|
+
export function stripAnchors<T>(schema: T): T {
|
|
12
|
+
const seen = new WeakMap<object, unknown>();
|
|
13
|
+
|
|
14
|
+
function walk(node: unknown): unknown {
|
|
15
|
+
if (!node || typeof node !== 'object') return node;
|
|
16
|
+
|
|
17
|
+
const existing = seen.get(node as object);
|
|
18
|
+
if (existing) return existing;
|
|
19
|
+
|
|
20
|
+
if (Array.isArray(node)) {
|
|
21
|
+
const out: unknown[] = [];
|
|
22
|
+
seen.set(node, out);
|
|
23
|
+
for (const item of node) out.push(walk(item));
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const out: Record<string, unknown> = {};
|
|
28
|
+
seen.set(node as object, out);
|
|
29
|
+
|
|
30
|
+
for (const [key, value] of Object.entries(node as Record<string, unknown>)) {
|
|
31
|
+
if (key === '$anchor') continue;
|
|
32
|
+
out[key] = walk(value);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return walk(schema) as T;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// PURE: Rewrite anchor-style `$ref` strings (`#Anchor`) into JSON Pointer refs (`#/$defs/DefName`).
|
|
42
|
+
function normalizeAnchorsToPointers(input: any): any {
|
|
43
|
+
if (!input || typeof input !== "object") return input;
|
|
44
|
+
|
|
45
|
+
// Deep clone the input to ensure the function is pure (no side effects on input)
|
|
46
|
+
const root = JSON.parse(JSON.stringify(input));
|
|
47
|
+
|
|
48
|
+
// Build a map of anchors to their definition names
|
|
49
|
+
const defs: Record<string, any> = root.$defs && typeof root.$defs === "object" ? root.$defs : {};
|
|
50
|
+
const anchorToDef: Record<string, string> = {};
|
|
51
|
+
|
|
52
|
+
// For Genesis structure: each def is a Type envelope with nucleusSchema.$anchor
|
|
53
|
+
for (const [defName, defValue] of Object.entries(defs)) {
|
|
54
|
+
if (!defValue || typeof defValue !== "object") continue;
|
|
55
|
+
|
|
56
|
+
// Check if this is a Type envelope (has nucleusSchema property)
|
|
57
|
+
const nucleusSchema = (defValue as any).nucleusSchema;
|
|
58
|
+
if (nucleusSchema && typeof nucleusSchema === "object") {
|
|
59
|
+
// Look for $anchor inside the nucleusSchema
|
|
60
|
+
const anchor = nucleusSchema.$anchor;
|
|
61
|
+
if (typeof anchor === "string" && !anchorToDef[anchor]) {
|
|
62
|
+
anchorToDef[anchor] = defName;
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
// Fallback: check for $anchor at the def level (non-envelope case)
|
|
66
|
+
const anchor = (defValue as any).$anchor;
|
|
67
|
+
if (typeof anchor === "string" && !anchorToDef[anchor]) {
|
|
68
|
+
anchorToDef[anchor] = defName;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Walk the entire tree and rewrite anchor refs to pointer refs
|
|
74
|
+
function walk(node: any): void {
|
|
75
|
+
if (Array.isArray(node)) {
|
|
76
|
+
for (const item of node) walk(item);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (!node || typeof node !== "object") return;
|
|
80
|
+
|
|
81
|
+
// Rewrite $ref if it's an anchor-style reference
|
|
82
|
+
if (typeof node.$ref === "string") {
|
|
83
|
+
const ref: string = node.$ref;
|
|
84
|
+
// Match anchor refs: starts with # but not #/ (JSON Pointer syntax)
|
|
85
|
+
if (ref.startsWith("#") && !ref.startsWith("#/")) {
|
|
86
|
+
const anchor = ref.slice(1);
|
|
87
|
+
const defName = anchorToDef[anchor];
|
|
88
|
+
if (defName) {
|
|
89
|
+
node.$ref = `#/$defs/${defName}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Recursively walk all properties
|
|
95
|
+
for (const val of Object.values(node)) {
|
|
96
|
+
walk(val);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
walk(root);
|
|
101
|
+
return root;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
|
|
105
|
+
function main() {
|
|
106
|
+
try {
|
|
107
|
+
const config = getConfig();
|
|
108
|
+
const genesisSourcePath = config.getSourcePath();
|
|
109
|
+
|
|
110
|
+
// Create a generated/normalized version (anchor refs rewritten to pointers)
|
|
111
|
+
const normalizedPath = config.getNormalizedSourcePath();
|
|
112
|
+
|
|
113
|
+
if (!fs.existsSync(genesisSourcePath)) {
|
|
114
|
+
throw new Error(`Genesis source file not found at ${genesisSourcePath}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const raw = fs.readFileSync(genesisSourcePath, 'utf-8');
|
|
118
|
+
const genesis = JSON.parse(raw);
|
|
119
|
+
|
|
120
|
+
// Validate structure
|
|
121
|
+
if (!genesis.nucleusSchema || !genesis.nucleusSchema.$defs) {
|
|
122
|
+
throw new Error('Genesis.json must have nucleusSchema.$defs');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Rewrite anchors in the nucleusSchema (pure function call)
|
|
126
|
+
genesis.nucleusSchema = normalizeAnchorsToPointers(genesis.nucleusSchema);
|
|
127
|
+
|
|
128
|
+
// Strip $anchor fields from the schemas (pure function call)
|
|
129
|
+
genesis.nucleusSchema = stripAnchors(genesis.nucleusSchema);
|
|
130
|
+
|
|
131
|
+
// Write normalized version
|
|
132
|
+
fs.mkdirSync(path.dirname(normalizedPath), { recursive: true });
|
|
133
|
+
fs.writeFileSync(normalizedPath, JSON.stringify(genesis, null, 4), 'utf-8');
|
|
134
|
+
console.log(`Wrote normalized Genesis with pointer refs to ${normalizedPath}`);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
console.error(e);
|
|
137
|
+
process.exitCode = 1;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
main();
|
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
|
-
import { getConfig } from './_lib/config.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Wrap each ResourceType definition (from Genesis.nucleusSchema.$defs) with a Resource shell
|
|
7
|
-
* that conforms to the Resource.nucleusSchema pattern defined in Genesis.json.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// PURE: Build Resource shell envelopes for each $defs entry (no I/O, no mutation of inputs).
|
|
11
|
-
function generateResourceShellLogic(genesis: any): Record<string, any> {
|
|
12
|
-
if (!genesis.nucleusSchema || !genesis.nucleusSchema.$defs) {
|
|
13
|
-
throw new Error('Genesis.json must have nucleusSchema.$defs');
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const defs = genesis.nucleusSchema.$defs;
|
|
17
|
-
const defKeys = Object.keys(defs);
|
|
18
|
-
|
|
19
|
-
const resources: Record<string, any> = {};
|
|
20
|
-
|
|
21
|
-
// Genesis timestamp: 2025-11-30T00:00:00.000Z marks the genesis of ToolProof
|
|
22
|
-
const genesisTimestamp = '2025-11-30T00:00:00.000Z';
|
|
23
|
-
|
|
24
|
-
resources['Genesis'] = {
|
|
25
|
-
identity: 'RESOURCE-Genesis',
|
|
26
|
-
resourceTypeHandle: 'TYPE-ResourceType',
|
|
27
|
-
creationContext: {
|
|
28
|
-
resourceRoleHandle: 'ROLE-Genesis',
|
|
29
|
-
jobStepHandle: 'JOB_STEP-Genesis'
|
|
30
|
-
},
|
|
31
|
-
kind: 'materialized',
|
|
32
|
-
timestamp: genesisTimestamp,
|
|
33
|
-
nucleus: {}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
defKeys.forEach((defName) => {
|
|
37
|
-
const defValue = defs[defName];
|
|
38
|
-
|
|
39
|
-
resources[defName] = {
|
|
40
|
-
identity: `RESOURCE-${defName}`,
|
|
41
|
-
resourceTypeHandle: 'TYPE-ResourceType',
|
|
42
|
-
creationContext: {
|
|
43
|
-
resourceRoleHandle: 'ROLE-Genesis',
|
|
44
|
-
jobStepHandle: `JOB_STEP-${defName}`
|
|
45
|
-
},
|
|
46
|
-
kind: 'materialized',
|
|
47
|
-
timestamp: genesisTimestamp,
|
|
48
|
-
nucleus: defValue
|
|
49
|
-
};
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
return resources;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
|
|
56
|
-
function main() {
|
|
57
|
-
try {
|
|
58
|
-
const config = getConfig();
|
|
59
|
-
const genesisSourcePath = config.getNormalizedSourcePath();
|
|
60
|
-
const outputPath = path.join(config.getResourcesDir(), 'Genesis.json');
|
|
61
|
-
|
|
62
|
-
if (!fs.existsSync(genesisSourcePath)) {
|
|
63
|
-
throw new Error(`Genesis source file not found at ${genesisSourcePath}`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const raw = fs.readFileSync(genesisSourcePath, 'utf-8');
|
|
67
|
-
const genesis = JSON.parse(raw);
|
|
68
|
-
|
|
69
|
-
const resources = generateResourceShellLogic(genesis);
|
|
70
|
-
|
|
71
|
-
const outputDir = path.dirname(outputPath);
|
|
72
|
-
fs.mkdirSync(outputDir, { recursive: true });
|
|
73
|
-
|
|
74
|
-
fs.writeFileSync(outputPath, JSON.stringify(resources, null, 4) + '\n', 'utf-8');
|
|
75
|
-
console.log(`Generated ${Object.keys(resources).length} Resource envelopes -> ${outputPath}`);
|
|
76
|
-
} catch (error: any) {
|
|
77
|
-
console.error(error?.message ?? error);
|
|
78
|
-
process.exitCode = 1;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
main();
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { getConfig } from './_lib/config.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Wrap each ResourceType definition (from Genesis.nucleusSchema.$defs) with a Resource shell
|
|
7
|
+
* that conforms to the Resource.nucleusSchema pattern defined in Genesis.json.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// PURE: Build Resource shell envelopes for each $defs entry (no I/O, no mutation of inputs).
|
|
11
|
+
function generateResourceShellLogic(genesis: any): Record<string, any> {
|
|
12
|
+
if (!genesis.nucleusSchema || !genesis.nucleusSchema.$defs) {
|
|
13
|
+
throw new Error('Genesis.json must have nucleusSchema.$defs');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const defs = genesis.nucleusSchema.$defs;
|
|
17
|
+
const defKeys = Object.keys(defs);
|
|
18
|
+
|
|
19
|
+
const resources: Record<string, any> = {};
|
|
20
|
+
|
|
21
|
+
// Genesis timestamp: 2025-11-30T00:00:00.000Z marks the genesis of ToolProof
|
|
22
|
+
const genesisTimestamp = '2025-11-30T00:00:00.000Z';
|
|
23
|
+
|
|
24
|
+
resources['Genesis'] = {
|
|
25
|
+
identity: 'RESOURCE-Genesis',
|
|
26
|
+
resourceTypeHandle: 'TYPE-ResourceType',
|
|
27
|
+
creationContext: {
|
|
28
|
+
resourceRoleHandle: 'ROLE-Genesis',
|
|
29
|
+
jobStepHandle: 'JOB_STEP-Genesis'
|
|
30
|
+
},
|
|
31
|
+
kind: 'materialized',
|
|
32
|
+
timestamp: genesisTimestamp,
|
|
33
|
+
nucleus: {}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
defKeys.forEach((defName) => {
|
|
37
|
+
const defValue = defs[defName];
|
|
38
|
+
|
|
39
|
+
resources[defName] = {
|
|
40
|
+
identity: `RESOURCE-${defName}`,
|
|
41
|
+
resourceTypeHandle: 'TYPE-ResourceType',
|
|
42
|
+
creationContext: {
|
|
43
|
+
resourceRoleHandle: 'ROLE-Genesis',
|
|
44
|
+
jobStepHandle: `JOB_STEP-${defName}`
|
|
45
|
+
},
|
|
46
|
+
kind: 'materialized',
|
|
47
|
+
timestamp: genesisTimestamp,
|
|
48
|
+
nucleus: defValue
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return resources;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// IMPURE: Script entrypoint (config + filesystem I/O + console + process exit code).
|
|
56
|
+
function main() {
|
|
57
|
+
try {
|
|
58
|
+
const config = getConfig();
|
|
59
|
+
const genesisSourcePath = config.getNormalizedSourcePath();
|
|
60
|
+
const outputPath = path.join(config.getResourcesDir(), 'Genesis.json');
|
|
61
|
+
|
|
62
|
+
if (!fs.existsSync(genesisSourcePath)) {
|
|
63
|
+
throw new Error(`Genesis source file not found at ${genesisSourcePath}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const raw = fs.readFileSync(genesisSourcePath, 'utf-8');
|
|
67
|
+
const genesis = JSON.parse(raw);
|
|
68
|
+
|
|
69
|
+
const resources = generateResourceShellLogic(genesis);
|
|
70
|
+
|
|
71
|
+
const outputDir = path.dirname(outputPath);
|
|
72
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
73
|
+
|
|
74
|
+
fs.writeFileSync(outputPath, JSON.stringify(resources, null, 4) + '\n', 'utf-8');
|
|
75
|
+
console.log(`Generated ${Object.keys(resources).length} Resource envelopes -> ${outputPath}`);
|
|
76
|
+
} catch (error: any) {
|
|
77
|
+
console.error(error?.message ?? error);
|
|
78
|
+
process.exitCode = 1;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
main();
|