70f528fbab
- Update CHANGELOG.md for 1.1.0 (date, refactoring, repository fixes) - Add overwrite guardrails to imhotep-cli init — skips existing files - Add bugs/homepage/keywords metadata to 5 public packages - Mark imhotep-bench and imhotep-fixtures as private packages - Add selector field to SourceReference interface (core types) - Remove 7 casts from check-all.ts (folAst.position, cardinality results) - Generate package-lock.json for reproducible installs
75 lines
2.2 KiB
JavaScript
75 lines
2.2 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 {
|
|
const result = initProject({ preset, targetDir });
|
|
console.log(`✓ Scaffolded ${preset} project in ${targetDir}`);
|
|
|
|
if (result.created.length > 0) {
|
|
console.log(` Created: ${result.created.map(f => f.replace(targetDir, '.')).join(', ')}`);
|
|
}
|
|
if (result.skipped.length > 0) {
|
|
console.warn(` Skipped (already exists): ${result.skipped.map(f => f.replace(targetDir, '.')).join(', ')}`);
|
|
}
|
|
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();
|