cmte
Version:
Design by Committee™ except it's just you and LLMs
71 lines (64 loc) • 2.28 kB
JavaScript
import { build } from 'esbuild';
import * as fs from 'fs';
import * as path from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
async function buildProject() {
try {
// Ensure dist directory exists
const distDir = path.join(__dirname, 'dist');
await fs.promises.mkdir(distDir, { recursive: true });
// --- Build the main library ---
await build({
entryPoints: ['src/index.js'],
bundle: true,
platform: 'node',
target: 'node18',
outfile: 'dist/index.js',
format: 'esm',
sourcemap: true,
minify: false,
external: [
// Add any external dependencies that shouldn't be bundled for the library
'esbuild',
'glob',
// May need others depending on library usage
]
});
console.log('Library build completed.');
// --- Build the CLI entry point ---
await build({
entryPoints: ['src/bin/cmte.js'], // CLI entry point
bundle: true,
platform: 'node',
target: 'node18',
outfile: 'dist/bin/cmte.js', // Output for bin
format: 'esm',
sourcemap: true,
minify: false,
external: [
// Externalize dependencies causing dynamic require issues or needing native parts
'esbuild',
'glob',
'logform',
'winston' ,
'commander',
'dotenv',
'node-fetch',
'agentkeepalive',
'llmxml',
'readline/promises',
'fsevents' // Optional native dependency, often better externalized
// Add other direct/indirect CLI dependencies if issues arise
]
});
console.log('CLI build completed.');
console.log('Build completed successfully!');
} catch (error) {
console.error('Build failed:', error);
process.exit(1);
}
}
buildProject();