68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
|
|
#!/usr/bin/env node
|
||
|
|
// CLI entry point for imhotep command
|
||
|
|
import { initProject } from './init.js';
|
||
|
|
import { getPresetNames } from './presets/index.js';
|
||
|
|
|
||
|
|
function showHelp(): void {
|
||
|
|
console.log(`
|
||
|
|
Usage: imhotep init --preset <name> [--dir <path>]
|
||
|
|
|
||
|
|
Commands:
|
||
|
|
init Scaffold a new Imhotep project
|
||
|
|
|
||
|
|
Options:
|
||
|
|
--preset <name> Project preset (${getPresetNames().join(', ')})
|
||
|
|
--dir <path> Target directory (default: current directory)
|
||
|
|
--help Show this help message
|
||
|
|
|
||
|
|
Examples:
|
||
|
|
npx imhotep init --preset react
|
||
|
|
npx imhotep init --preset next --dir ./next-tests
|
||
|
|
npx imhotep init --preset nuxt --dir ./nuxt-tests
|
||
|
|
npx imhotep init --preset vue --dir ./my-project
|
||
|
|
npx imhotep init --preset storybook --dir ./storybook-tests
|
||
|
|
`);
|
||
|
|
}
|
||
|
|
|
||
|
|
function main(): void {
|
||
|
|
const args = process.argv.slice(2);
|
||
|
|
|
||
|
|
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
|
||
|
|
showHelp();
|
||
|
|
process.exit(0);
|
||
|
|
}
|
||
|
|
|
||
|
|
const command = args[0];
|
||
|
|
|
||
|
|
if (command === 'init') {
|
||
|
|
const presetIndex = args.indexOf('--preset');
|
||
|
|
const dirIndex = args.indexOf('--dir');
|
||
|
|
|
||
|
|
if (presetIndex === -1 || !args[presetIndex + 1]) {
|
||
|
|
console.error('Error: --preset is required');
|
||
|
|
console.error(`Available presets: ${getPresetNames().join(', ')}`);
|
||
|
|
process.exit(1);
|
||
|
|
}
|
||
|
|
|
||
|
|
const preset = args[presetIndex + 1];
|
||
|
|
const targetDir = dirIndex !== -1
|
||
|
|
? args[dirIndex + 1]
|
||
|
|
: process.cwd();
|
||
|
|
|
||
|
|
try {
|
||
|
|
initProject({ preset, targetDir });
|
||
|
|
console.log(`✓ Scaffolded ${preset} project in ${targetDir}`);
|
||
|
|
console.log(` Run: cd ${targetDir} && npm install && npm test`);
|
||
|
|
} catch (error: any) {
|
||
|
|
console.error(`Error: ${error.message}`);
|
||
|
|
process.exit(1);
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
console.error(`Unknown command: ${command}`);
|
||
|
|
showHelp();
|
||
|
|
process.exit(1);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
main();
|