UNPKG

jay-code

Version:

Streamlined AI CLI orchestration engine with mathematical rigor and enterprise-grade reliability

150 lines (128 loc) โ€ข 5.89 kB
#!/usr/bin/env node /** * 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.');