jay-code
Version:
Streamlined AI CLI orchestration engine with mathematical rigor and enterprise-grade reliability
150 lines (128 loc) โข 5.89 kB
JavaScript
/**
* Prepare for npm publish by ensuring all versions are synchronized
* and dist files are built correctly
*/
import fs from 'fs';
import path from 'path';
import { execSync } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const rootDir = path.resolve(__dirname, '..');
console.log('๐ Preparing for npm publish...\n');
// 1. Get version from package.json
const packageJsonPath = path.join(rootDir, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const version = packageJson.version;
console.log(`๐ฆ Package version: ${version}\n`);
// 2. Files that need version updates
const versionFiles = [
{ path: 'src/cli/simple-cli.ts', pattern: /const VERSION = '[^']+';/, replacement: `const VERSION = '${version}';` },
{ path: 'src/cli/simple-cli.js', pattern: /const VERSION = '[^']+';/, replacement: `const VERSION = '${version}';` },
{ path: 'src/cli/index.ts', pattern: /const VERSION = '[^']+';/, replacement: `const VERSION = '${version}';` },
{ path: 'src/cli/index-remote.ts', pattern: /const VERSION = '[^']+';/, replacement: `const VERSION = '${version}';` },
{ path: 'bin/jay-code', pattern: /VERSION="[^"]+"/, replacement: `VERSION="${version}"` },
{ path: 'src/cli/commands/status.ts', pattern: /version: '[^']+'/g, replacement: `version: '${version}'` },
{ path: 'src/cli/simple-commands/status.js', pattern: /version: '[^']+'/g, replacement: `version: '${version}'` },
{ path: 'src/cli/simple-commands/config.js', pattern: /version: "[^"]+"/g, replacement: `version: "${version}"` },
{ path: 'src/cli/simple-commands/process-ui-enhanced.js', pattern: /Jay-Code Process Management UI v[0-9.]+/, replacement: `Jay-Code Process Management UI v${version}` },
{ path: 'src/cli/init/claude-config.ts', pattern: /version: "[^"]+"/g, replacement: `version: "${version}"` },
{ path: 'src/cli/init/directory-structure.ts', pattern: /version: "[^"]+"/g, replacement: `version: "${version}"` }
];
// 3. Update version in all files
console.log('๐ Updating version in source files...');
let updatedCount = 0;
versionFiles.forEach(({ path: filePath, pattern, replacement }) => {
const fullPath = path.join(rootDir, filePath);
if (fs.existsSync(fullPath)) {
const content = fs.readFileSync(fullPath, 'utf8');
const newContent = content.replace(pattern, replacement);
if (content !== newContent) {
fs.writeFileSync(fullPath, newContent);
console.log(` โ
Updated ${filePath}`);
updatedCount++;
} else {
console.log(` โญ๏ธ ${filePath} already up to date`);
}
} else {
console.log(` โ ๏ธ ${filePath} not found`);
}
});
console.log(`\n Updated ${updatedCount} files\n`);
// 4. Clean dist directory
console.log('๐งน Cleaning dist directory...');
const distDir = path.join(rootDir, 'dist');
if (fs.existsSync(distDir)) {
execSync('rm -rf dist', { cwd: rootDir });
console.log(' โ
Cleaned dist directory');
}
// 5. Build TypeScript files
console.log('\n๐จ Building TypeScript files...');
try {
// First try to build just the CLI files with relaxed config
execSync('npx tsc -p tsconfig.cli.json', { cwd: rootDir, stdio: 'inherit' });
console.log(' โ
CLI files built successfully');
} catch (error) {
console.log(' โ ๏ธ Build had errors, trying fallback...');
try {
// Fallback: try the regular build
execSync('npm run build:ts', { cwd: rootDir, stdio: 'inherit' });
} catch (error2) {
console.log(' โ ๏ธ Build had errors, but continuing...');
// Continue anyway as there might be type errors that don't affect runtime
}
}
// 6. Verify dist files have correct version
console.log('\n๐ Verifying dist files...');
const distFiles = [
'dist/cli/simple-cli.js',
'dist/cli/index.js'
];
distFiles.forEach(distFile => {
const fullPath = path.join(rootDir, distFile);
if (fs.existsSync(fullPath)) {
const content = fs.readFileSync(fullPath, 'utf8');
const versionMatch = content.match(/VERSION = ['"]([^'"]+)['"]/);
if (versionMatch) {
if (versionMatch[1] === version) {
console.log(` โ
${distFile}: ${versionMatch[1]}`);
} else {
console.log(` โ ${distFile}: ${versionMatch[1]} (expected ${version})`);
}
} else {
console.log(` โ ๏ธ ${distFile}: version not found`);
}
} else {
console.log(` โ ๏ธ ${distFile}: file not found`);
}
});
// 7. Check what will be published
console.log('\n๐ Files to be published:');
try {
const packOutput = execSync('npm pack --dry-run --json', { cwd: rootDir, encoding: 'utf8' });
const packInfo = JSON.parse(packOutput);
if (packInfo[0] && packInfo[0].files) {
const importantFiles = packInfo[0].files.filter(f =>
f.path.includes('cli.js') ||
f.path.includes('simple-cli') ||
f.path.includes('package.json') ||
f.path.includes('README.md')
);
importantFiles.forEach(file => {
console.log(` ๐ ${file.path} (${(file.size / 1024).toFixed(1)}KB)`);
});
console.log(`\n Total files: ${packInfo[0].files.length}`);
console.log(` Total size: ${(packInfo[0].size / 1024 / 1024).toFixed(2)}MB`);
}
} catch (error) {
console.log(' โ ๏ธ Could not get pack info');
}
console.log('\nโ
Ready to publish!');
console.log('\n๐ Next steps:');
console.log(' 1. Review the changes above');
console.log(' 2. Commit any version changes: git add -A && git commit -m "chore: sync versions"');
console.log(' 3. Publish to npm: npm publish');
console.log(' 4. Create git tag: git tag v' + version + ' && git push --tags');
console.log('\n๐ก The prepublishOnly script will automatically run this before publish.');