build-all.jsโข3.96 kB
#!/usr/bin/env node
/**
* Build script that:
* 1. Builds the MagentaA11y project to generate fresh content.json
* 2. Copies content.json to our data folder
* 3. Builds our MCP server
* 4. Resets the submodule to clean state
*/
import { execSync } from 'child_process';
import * as fs from 'fs/promises';
import * as path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const MAGENTA_DIR = path.join(__dirname, 'magentaA11y');
const DATA_DIR = path.join(__dirname, 'data');
const SOURCE_CONTENT = path.join(MAGENTA_DIR, 'src', 'shared', 'content.json');
const TARGET_CONTENT = path.join(DATA_DIR, 'content.json');
console.log('๐ Starting MagentaA11y MCP build process...\n');
try {
// Step 1: Check if MagentaA11y submodule is initialized
console.log('๐ Step 1: Checking MagentaA11y submodule...');
try {
await fs.access(SOURCE_CONTENT);
console.log('โ
MagentaA11y submodule found');
} catch (error) {
console.log('โ ๏ธ MagentaA11y submodule not found, initializing...');
execSync('git submodule update --init --recursive', {
cwd: __dirname,
stdio: 'inherit'
});
}
// Step 2: Install dependencies in MagentaA11y if needed
console.log('\n๐ฆ Step 2: Installing MagentaA11y dependencies...');
try {
await fs.access(path.join(MAGENTA_DIR, 'node_modules'));
console.log('โ
Dependencies already installed');
} catch (error) {
console.log('๐ฆ Installing dependencies...');
execSync('npm install', {
cwd: MAGENTA_DIR,
stdio: 'inherit'
});
}
// Step 3: Build MagentaA11y to generate fresh content.json
console.log('\n๐จ Step 3: Building MagentaA11y project...');
execSync('npm run build', {
cwd: MAGENTA_DIR,
stdio: 'inherit'
});
console.log('โ
MagentaA11y build complete');
// Step 4: Copy content.json to our data folder
console.log('\n๐ Step 4: Copying content.json...');
await fs.mkdir(DATA_DIR, { recursive: true });
await fs.copyFile(SOURCE_CONTENT, TARGET_CONTENT);
console.log(`โ
Copied content.json to ${TARGET_CONTENT}`);
// Step 5: Build our MCP server
console.log('\n๐ง Step 5: Building MCP server...');
execSync('tsc', {
cwd: __dirname,
stdio: 'inherit'
});
console.log('โ
MCP server build complete');
// Step 6: Reset the submodule to clean state
console.log('\n๐งน Step 6: Cleaning up MagentaA11y submodule...');
execSync('git reset --hard HEAD', {
cwd: MAGENTA_DIR,
stdio: 'inherit'
});
execSync('git clean -fd', {
cwd: MAGENTA_DIR,
stdio: 'inherit'
});
console.log('โ
MagentaA11y submodule reset to clean state');
// Step 7: Verify the content was copied successfully
console.log('\n๐ Step 7: Verifying content...');
const stats = await fs.stat(TARGET_CONTENT);
const content = await fs.readFile(TARGET_CONTENT, 'utf-8');
const data = JSON.parse(content);
const webCount = data.web?.reduce((count, category) => count + (category.children?.length || 0), 0) || 0;
const nativeCount = data.native?.reduce((count, category) => count + (category.children?.length || 0), 0) || 0;
console.log(`โ
Content verified: ${webCount} web + ${nativeCount} native components`);
console.log(`๐ File size: ${(stats.size / 1024).toFixed(1)} KB`);
console.log(`๐
Last modified: ${stats.mtime.toISOString()}`);
console.log('\n๐ Build process completed successfully!');
console.log('\n๐ Summary:');
console.log(` โข Built MagentaA11y project`);
console.log(` โข Copied fresh content.json (${webCount} web + ${nativeCount} native components)`);
console.log(` โข Built MCP server with 11 tools`);
console.log(` โข Reset submodule to clean state`);
console.log('\nโจ Your MCP server is ready to use!');
} catch (error) {
console.error('\nโ Build failed:', error.message);
process.exit(1);
}