Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,238 changes: 1,223 additions & 15 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@
],
"scripts": {
"fetch:spec-types": "tsx scripts/fetch-spec-types.ts",
"generate:schemas": "tsx scripts/generate-schemas.ts",
"typecheck": "tsgo --noEmit",
"build": "npm run build:esm && npm run build:cjs",
"build": "tsx scripts/generate-schemas.ts --if-changed && npm run build:esm && npm run build:cjs",
"build:esm": "mkdir -p dist/esm && echo '{\"type\": \"module\"}' > dist/esm/package.json && tsc -p tsconfig.prod.json",
"build:esm:w": "npm run build:esm -- -w",
"build:cjs": "mkdir -p dist/cjs && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json && tsc -p tsconfig.cjs.json",
Expand All @@ -78,7 +79,8 @@
"prepack": "npm run build:esm && npm run build:cjs",
"lint": "eslint src/ && prettier --check .",
"lint:fix": "eslint src/ --fix && prettier --write .",
"check": "npm run typecheck && npm run lint",
"check": "npm run typecheck && npm run lint && npm run check:schemas",
"check:schemas": "tsx scripts/check-schemas-sync.ts",
"test": "vitest run",
"test:watch": "vitest",
"start": "npm run server",
Expand Down Expand Up @@ -132,6 +134,8 @@
"eslint-plugin-n": "^17.23.1",
"prettier": "3.6.2",
"supertest": "^7.0.0",
"ts-morph": "^27.0.2",
"ts-to-zod": "^5.1.0",
"tsx": "^4.16.5",
"typescript": "^5.5.4",
"typescript-eslint": "^8.48.1",
Expand Down
72 changes: 72 additions & 0 deletions scripts/check-schemas-sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env npx tsx
/**
* Checks if generated schemas are in sync with source types.
* Exits with code 1 if regeneration would produce different output.
*
* Usage:
* npx tsx scripts/check-schemas-sync.ts
* npm run check:schemas
*/

import { execSync } from 'child_process';
import { readFileSync } from 'fs';
import { join } from 'path';

const GENERATED_FILES = ['src/generated/sdk.types.ts', 'src/generated/sdk.schemas.ts'];

function main(): void {
const rootDir = join(import.meta.dirname, '..');

// Capture current content of generated files
const originalContents = new Map<string, string>();
for (const file of GENERATED_FILES) {
const filePath = join(rootDir, file);
try {
originalContents.set(file, readFileSync(filePath, 'utf-8'));
} catch {
console.error(`Error: Generated file ${file} does not exist.`);
console.error("Run 'npm run generate:schemas' to generate it.");
process.exit(1);
}
}

// Regenerate schemas
console.log('Regenerating schemas to check for drift...');
try {
execSync('npm run generate:schemas', {
cwd: rootDir,
stdio: 'pipe'
});
} catch (error) {
console.error('Error: Schema generation failed.');
console.error((error as Error).message);
process.exit(1);
}

// Compare with original content
let hasDrift = false;
for (const file of GENERATED_FILES) {
const filePath = join(rootDir, file);
const newContent = readFileSync(filePath, 'utf-8');
const originalContent = originalContents.get(file)!;

if (newContent !== originalContent) {
console.error(`\n❌ ${file} is out of sync with source types.`);
hasDrift = true;
} else {
console.log(`✓ ${file} is up to date.`);
}
}

if (hasDrift) {
console.error('\n' + '='.repeat(60));
console.error('Generated schemas are out of sync!');
console.error("Run 'npm run generate:schemas' and commit the changes.");
console.error('='.repeat(60));
process.exit(1);
}

console.log('\n✓ All generated schemas are in sync.');
}

main();
Loading
Loading