#!/usr/bin/env node import { readFileSync, writeFileSync, chmodSync, copyFileSync, mkdirSync, existsSync } from 'fs'; import { join, dirname } from 'path'; const bundlePaths = [ join(process.cwd(), 'dist/task-master.cjs'), // CLI tool join(process.cwd(), 'dist/task-master-mcp.cjs') // MCP server ]; try { // Copy necessary asset files to dist const assetsToCopy = [ { src: 'scripts/modules/supported-models.json', dest: 'dist/supported-models.json' }, { src: 'README-task-master.md', dest: 'dist/README-task-master.md' } ]; console.log('๐Ÿ“ Copying assets...'); for (const asset of assetsToCopy) { const srcPath = join(process.cwd(), asset.src); const destPath = join(process.cwd(), asset.dest); if (existsSync(srcPath)) { // Ensure destination directory exists const destDir = dirname(destPath); if (!existsSync(destDir)) { mkdirSync(destDir, { recursive: true }); } copyFileSync(srcPath, destPath); console.log(` โœ… Copied ${asset.src} โ†’ ${asset.dest}`); } else { console.log(` โš ๏ธ Source not found: ${asset.src}`); } } // Process each bundle file for (const bundlePath of bundlePaths) { const fileName = bundlePath.split('/').pop(); if (!existsSync(bundlePath)) { console.log(`โš ๏ธ Bundle not found: ${fileName}`); continue; } // Read the existing bundle const bundleContent = readFileSync(bundlePath, 'utf8'); // Add shebang if it doesn't already exist if (!bundleContent.startsWith('#!/usr/bin/env node')) { const contentWithShebang = '#!/usr/bin/env node\n' + bundleContent; writeFileSync(bundlePath, contentWithShebang); console.log(`โœ… Added shebang to ${fileName}`); } else { console.log(`โœ… Shebang already exists in ${fileName}`); } // Make it executable chmodSync(bundlePath, 0o755); console.log(`โœ… Made ${fileName} executable`); } console.log('๐Ÿ“ฆ Both bundles ready:'); console.log(' ๐Ÿ”ง CLI tool: dist/task-master.cjs'); console.log(' ๐Ÿ”Œ MCP server: dist/task-master-mcp.cjs'); console.log('๐Ÿงช Test with:'); console.log(' node dist/task-master.cjs --version'); console.log(' node dist/task-master-mcp.cjs --help'); } catch (error) { console.error('โŒ Post-build failed:', error.message); process.exit(1); }