Skip to content
Merged
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
4 changes: 4 additions & 0 deletions .changeset/major-lies-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

Build tooling change: Schema versioning now preserves released versions and only rebuilds latest/ during development.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dev": "bash -c 'source <(grep CONDUCTOR_PORT .env.local | sed \"s/^/export /\") && DOTENV_CONFIG_PATH=.env.local concurrently --names \"HTTP,DOCS,STRIPE\" -c \"bgBlue.bold,bgGreen.bold,bgMagenta.bold\" \"npm run start\" \"npm run start:mintlify\" \"npm run start:stripe\"'",
"db:migrate": "DOTENV_CONFIG_PATH=.env.local tsx --import dotenv/config server/src/db/migrate.ts",
"db:seed": "DOTENV_CONFIG_PATH=.env.local tsx server/src/db/seed-registry.ts",
"build": "tsc --project server/tsconfig.json && npm run build:schemas",
"build": "tsc --project server/tsconfig.json && npm run build:schemas -- --release",
"build:schemas": "node scripts/build-schemas.js",
"build:mintlify": "cd mintlify-docs && mintlify build",
"deploy:mintlify": "mintlify deploy",
Expand All @@ -30,7 +30,7 @@
"precommit": "npm test",
"prepare": "husky",
"changeset": "changeset",
"version": "changeset version && npm run build:schemas",
"version": "changeset version && npm run build:schemas -- --release",
"update-schema-versions": "echo 'Schema versioning is now handled by build:schemas script'",
"release": "npm run version && npm test && npm run build && git add -A && git commit -m 'Version packages' && git push",
"verify-version-sync": "node scripts/verify-version-sync.js"
Expand Down
236 changes: 179 additions & 57 deletions scripts/build-schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
/**
* Build script for AdCP schema versioning
*
* This script copies schemas from static/schemas/source to dist/schemas/{version}
* and updates all $id and $ref fields to include the version path.
* This script has two modes:
*
* It also generates bundled (dereferenced) schemas at dist/schemas/{version}/bundled/
* for tools that don't support $ref resolution.
* 1. Development build (default): `npm run build:schemas`
* - Rebuilds only dist/schemas/latest/ with current source schemas
* - Preserves existing released version directories (e.g., 2.5.0/)
* - Updates symlinks to point to appropriate versions
*
* Version is read from package.json and follows these rules:
* - Full semantic version: dist/schemas/2.5.0/
* - Major version alias: dist/schemas/v2/ (symlink to latest 2.x)
* - Latest alias: dist/schemas/latest/ (symlink to current version)
* - Backward compat: dist/schemas/v1/ (symlink to current version)
* 2. Release build: `npm run build:schemas -- --release`
* - Creates a new versioned directory (e.g., dist/schemas/2.6.0/)
* - Updates major/minor symlinks to point to new release
* - Also updates latest/ to match the release
*
* Schema paths:
* - /schemas/latest/ - Current development schemas (rebuilt on every build)
* - /schemas/{version}/ - Released versions (only created with --release)
* - /schemas/v{major}/ - Points to latest release of that major version
* - /schemas/v{major}.{minor}/ - Points to latest release of that minor version
* - /schemas/v1/ - Backward compatibility (always points to latest/)
*/

const fs = require('fs');
Expand All @@ -23,11 +30,40 @@ const SOURCE_DIR = path.join(__dirname, '../static/schemas/source');
const DIST_DIR = path.join(__dirname, '../dist/schemas');
const PACKAGE_JSON = path.join(__dirname, '../package.json');

// Parse command line arguments
const args = process.argv.slice(2);
const isRelease = args.includes('--release');

function getVersion() {
const pkg = JSON.parse(fs.readFileSync(PACKAGE_JSON, 'utf8'));
return pkg.version;
}

/**
* Find the latest released version directory in dist/schemas/
* Returns null if no released versions exist
*/
function findLatestReleasedVersion() {
if (!fs.existsSync(DIST_DIR)) {
return null;
}

const entries = fs.readdirSync(DIST_DIR, { withFileTypes: true });
const versionDirs = entries
.filter(e => e.isDirectory() && /^\d+\.\d+\.\d+$/.test(e.name))
.map(e => e.name)
.sort((a, b) => {
// Sort by semver (descending)
const [aMajor, aMinor, aPatch] = a.split('.').map(Number);
const [bMajor, bMinor, bPatch] = b.split('.').map(Number);
if (aMajor !== bMajor) return bMajor - aMajor;
if (aMinor !== bMinor) return bMinor - aMinor;
return bPatch - aPatch;
});

return versionDirs[0] || null;
}

function getMajorVersion(version) {
return version.split('.')[0];
}
Expand Down Expand Up @@ -247,65 +283,151 @@ async function main() {
const version = getVersion();
const majorVersion = getMajorVersion(version);
const minorVersion = getMinorVersion(version);
const latestReleasedVersion = findLatestReleasedVersion();

console.log(`📦 Building schemas for AdCP v${version}`);
if (isRelease) {
console.log(`🚀 RELEASE BUILD: Creating schemas for AdCP v${version}`);
} else {
console.log(`📦 Development build: Updating latest/ schemas`);
}
console.log(` Source: ${SOURCE_DIR}`);
console.log(` Target: ${DIST_DIR}`);
if (latestReleasedVersion) {
console.log(` Latest released version: ${latestReleasedVersion}`);
}
console.log('');

// Update source registry version
updateSourceRegistry(version);

// Clean and create dist directory
if (fs.existsSync(DIST_DIR)) {
console.log('🧹 Cleaning existing dist directory...');
fs.rmSync(DIST_DIR, { recursive: true, force: true });
}
// Ensure dist directory exists
ensureDir(DIST_DIR);

// Copy schemas with version in paths
const versionDir = path.join(DIST_DIR, version);
console.log(`📋 Copying schemas to dist/schemas/${version}/`);
ensureDir(versionDir);
copyAndTransformSchemas(SOURCE_DIR, versionDir, version);

// Generate bundled (dereferenced) schemas
const bundledDir = path.join(versionDir, 'bundled');
console.log(`📦 Generating bundled schemas to dist/schemas/${version}/bundled/`);
const { successCount, errorCount } = await generateBundledSchemas(SOURCE_DIR, bundledDir, version);
console.log(` ✓ Bundled ${successCount} schemas${errorCount > 0 ? ` (${errorCount} failed)` : ''}`);

// Create major version symlink (v2 -> 2.5.0)
const majorLink = path.join(DIST_DIR, `v${majorVersion}`);
console.log(`🔗 Creating symlink: v${majorVersion} → ${version}`);
createSymlink(versionDir, majorLink);

// Create minor version symlink (v2.5 -> 2.5.0)
const minorLink = path.join(DIST_DIR, `v${minorVersion}`);
console.log(`🔗 Creating symlink: v${minorVersion} → ${version}`);
createSymlink(versionDir, minorLink);

// Create v1 symlink for backward compatibility (v1 -> 2.x.x)
// Clients expecting /schemas/v1/ will still work
const v1Link = path.join(DIST_DIR, 'v1');
console.log(`🔗 Creating symlink: v1 → ${version} (backward compatibility)`);
createSymlink(versionDir, v1Link);

// Create latest symlink
const latestLink = path.join(DIST_DIR, 'latest');
console.log(`🔗 Creating symlink: latest → ${version}`);
createSymlink(versionDir, latestLink);
if (isRelease) {
// RELEASE MODE: Create a new versioned directory
const versionDir = path.join(DIST_DIR, version);

if (fs.existsSync(versionDir)) {
console.log(`⚠️ Version ${version} already exists. Overwriting...`);
fs.rmSync(versionDir, { recursive: true, force: true });
}

console.log(`📋 Creating release: dist/schemas/${version}/`);
ensureDir(versionDir);
copyAndTransformSchemas(SOURCE_DIR, versionDir, version);

// Generate bundled schemas for release
const bundledDir = path.join(versionDir, 'bundled');
console.log(`📦 Generating bundled schemas to dist/schemas/${version}/bundled/`);
const { successCount, errorCount } = await generateBundledSchemas(SOURCE_DIR, bundledDir, version);
console.log(` ✓ Bundled ${successCount} schemas${errorCount > 0 ? ` (${errorCount} failed)` : ''}`);

// Update major version symlink (v2 -> 2.5.0)
const majorLink = path.join(DIST_DIR, `v${majorVersion}`);
console.log(`🔗 Updating symlink: v${majorVersion} → ${version}`);
createSymlink(versionDir, majorLink);

// Update minor version symlink (v2.5 -> 2.5.0)
const minorLink = path.join(DIST_DIR, `v${minorVersion}`);
console.log(`🔗 Updating symlink: v${minorVersion} → ${version}`);
createSymlink(versionDir, minorLink);

// Also update latest/ to match the release
const latestDir = path.join(DIST_DIR, 'latest');
if (fs.existsSync(latestDir)) {
fs.rmSync(latestDir, { recursive: true, force: true });
}
console.log(`📋 Updating latest/ to match release`);
ensureDir(latestDir);
copyAndTransformSchemas(SOURCE_DIR, latestDir, 'latest');

// Generate bundled schemas for latest
const latestBundledDir = path.join(latestDir, 'bundled');
await generateBundledSchemas(SOURCE_DIR, latestBundledDir, 'latest');

// Create v1 symlink pointing to latest/ for backward compatibility
const v1Link = path.join(DIST_DIR, 'v1');
console.log(`🔗 Creating symlink: v1 → latest (backward compatibility)`);
createSymlink(latestDir, v1Link);

console.log('');
console.log('✅ Release build complete!');
console.log('');
console.log('Released paths:');
console.log(` /schemas/${version}/ - Exact version (pin for production)`);
console.log(` /schemas/${version}/bundled/ - Bundled schemas (no $ref)`);
console.log(` /schemas/v${minorVersion}/ - Minor alias → ${version}`);
console.log(` /schemas/v${majorVersion}/ - Major alias → ${version}`);
console.log(` /schemas/latest/ - Development (matches release)`);
console.log(` /schemas/v1/ - Backward compatibility → latest`);

} else {
// DEVELOPMENT MODE: Only rebuild latest/
const latestDir = path.join(DIST_DIR, 'latest');

// Clean and rebuild latest/ only
if (fs.existsSync(latestDir)) {
console.log('🧹 Cleaning existing latest/ directory...');
fs.rmSync(latestDir, { recursive: true, force: true });
}

console.log(`📋 Building schemas to dist/schemas/latest/`);
ensureDir(latestDir);
copyAndTransformSchemas(SOURCE_DIR, latestDir, 'latest');

// Generate bundled schemas for latest
const bundledDir = path.join(latestDir, 'bundled');
console.log(`📦 Generating bundled schemas to dist/schemas/latest/bundled/`);
const { successCount, errorCount } = await generateBundledSchemas(SOURCE_DIR, bundledDir, 'latest');
console.log(` ✓ Bundled ${successCount} schemas${errorCount > 0 ? ` (${errorCount} failed)` : ''}`);

// Symlinks for v2, v2.5, v1 should point to the latest RELEASED version
// Only create/update these symlinks if we have a released version
if (latestReleasedVersion) {
const releasedVersionDir = path.join(DIST_DIR, latestReleasedVersion);
const releasedMajor = getMajorVersion(latestReleasedVersion);
const releasedMinor = getMinorVersion(latestReleasedVersion);

const majorLink = path.join(DIST_DIR, `v${releasedMajor}`);
if (!fs.existsSync(majorLink)) {
console.log(`🔗 Creating symlink: v${releasedMajor} → ${latestReleasedVersion}`);
createSymlink(releasedVersionDir, majorLink);
}

const minorLink = path.join(DIST_DIR, `v${releasedMinor}`);
if (!fs.existsSync(minorLink)) {
console.log(`🔗 Creating symlink: v${releasedMinor} → ${latestReleasedVersion}`);
createSymlink(releasedVersionDir, minorLink);
}

}

// v1 always points to latest/ (not a released version)
const v1Link = path.join(DIST_DIR, 'v1');
if (!fs.existsSync(v1Link)) {
console.log(`🔗 Creating symlink: v1 → latest`);
createSymlink(latestDir, v1Link);
}

console.log('');
console.log('✅ Development build complete!');
console.log('');
console.log('Available paths:');
console.log(` /schemas/latest/ - Development schemas (just rebuilt)`);
console.log(` /schemas/v1/ - Backward compatibility → latest`);
if (latestReleasedVersion) {
const releasedMajor = getMajorVersion(latestReleasedVersion);
const releasedMinor = getMinorVersion(latestReleasedVersion);
console.log(` /schemas/${latestReleasedVersion}/ - Latest release (unchanged)`);
console.log(` /schemas/v${releasedMinor}/ - Minor alias → ${latestReleasedVersion}`);
console.log(` /schemas/v${releasedMajor}/ - Major alias → ${latestReleasedVersion}`);
} else {
console.log('');
console.log('⚠️ No released versions found. Run with --release to create one:');
console.log(' npm run build:schemas -- --release');
}
}

console.log('');
console.log('✅ Schema build complete!');
console.log('');
console.log('Available paths:');
console.log(` /schemas/${version}/ - Exact version (pin for production)`);
console.log(` /schemas/${version}/bundled/ - Bundled schemas (no $ref, for tools that need it)`);
console.log(` /schemas/v${minorVersion}/ - Minor alias (patch updates only)`);
console.log(` /schemas/v${majorVersion}/ - Major alias (minor + patch updates)`);
console.log(` /schemas/v1/ - Backward compatibility (same as v${majorVersion})`);
console.log(` /schemas/latest/ - Latest release (all updates)`);
console.log('');
console.log('📖 See docs/reference/schema-versioning.mdx for guidance on which to use.');
}
Expand Down