Skip to content

Commit 99dece0

Browse files
committed
feat: update schema generation scripts to prevent data loss and enhance eager loading
1 parent 300cdf8 commit 99dece0

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

packages/spec/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
"build": "pnpm gen:schema && pnpm gen:openapi && tsup && NODE_OPTIONS=\"--max-old-space-size=4096\" BUILD_DTS=true tsup",
9999
"dev": "tsc --watch",
100100
"clean": "rm -rf dist",
101-
"gen:schema": "tsx scripts/build-schemas.ts",
101+
"gen:schema": "OBJECTSTACK_EAGER_SCHEMAS=1 tsx scripts/build-schemas.ts",
102102
"gen:openapi": "tsx scripts/build-openapi.ts",
103103
"gen:docs": "tsx scripts/build-docs.ts",
104104
"gen:skill-refs": "tsx scripts/build-skill-references.ts",

packages/spec/scripts/build-docs.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,22 @@ function generateZodFileMarkdown(zodFile: string, schemas: Array<{name: string,
266266

267267
console.log('Building documentation...');
268268

269-
// 1. Clean existing category folders from DOCS_ROOT
269+
// 1. Clean existing category folders from DOCS_ROOT — but only when there are
270+
// JSON schemas to regenerate from. Otherwise we'd silently delete every .mdx
271+
// file when the upstream `gen:schema` step produced nothing (data loss).
270272
Object.keys(CATEGORIES).forEach(category => {
271273
const dir = path.join(DOCS_ROOT, category);
274+
const schemaDir = path.join(SCHEMA_DIR, category);
275+
const hasSchemas = fs.existsSync(schemaDir)
276+
&& fs.readdirSync(schemaDir).some(f => f.endsWith('.json'));
277+
if (!hasSchemas) {
278+
if (fs.existsSync(dir)) {
279+
console.warn(`⚠ Skipping clean of ${category}/ — no JSON schemas found in ${schemaDir}. Run \`pnpm gen:schema\` first.`);
280+
}
281+
return;
282+
}
272283
if (fs.existsSync(dir)) {
273284
fs.rmSync(dir, { recursive: true, force: true });
274-
// console.log(`Cleaned ${dir}`);
275285
}
276286
});
277287

packages/spec/scripts/build-schemas.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,29 @@ process.env.OBJECTSTACK_EAGER_SCHEMAS = '1';
88
import fs from 'fs';
99
import path from 'path';
1010
import { z } from 'zod';
11-
import * as Protocol from '../src/index';
11+
import * as AI from '../src/ai';
12+
import * as API from '../src/api';
13+
import * as Automation from '../src/automation';
14+
import * as Cloud from '../src/cloud';
15+
import * as Contracts from '../src/contracts';
16+
import * as Data from '../src/data';
17+
import * as Identity from '../src/identity';
18+
import * as Integration from '../src/integration';
19+
import * as Kernel from '../src/kernel';
20+
import * as QA from '../src/qa';
21+
import * as Security from '../src/security';
22+
import * as Shared from '../src/shared';
23+
import * as Studio from '../src/studio';
24+
import * as System from '../src/system';
25+
import * as UI from '../src/ui';
26+
27+
// Root index no longer re-exports namespaces (removed for tree-shaking — see
28+
// packages/spec/src/index.ts). Build subpath-by-subpath instead so every
29+
// category folder under json-schema/ gets populated.
30+
const Protocol: Record<string, Record<string, unknown>> = {
31+
AI, API, Automation, Cloud, Contracts, Data, Identity, Integration,
32+
Kernel, QA, Security, Shared, Studio, System, UI,
33+
};
1234

1335
const OUT_DIR = path.resolve(__dirname, '../json-schema');
1436
const SPEC_VERSION = JSON.parse(fs.readFileSync(path.resolve(__dirname, '../package.json'), 'utf-8')).version;

0 commit comments

Comments
 (0)