UNPKG

bod

Version:
35 lines (34 loc) 1.27 kB
var _a; import { __awaiter } from "tslib"; import fs from 'node:fs'; import path from 'node:path'; import process from 'node:process'; import { fileURLToPath } from 'node:url'; import { CommandFactory } from './index.js'; import { color, printer, program } from './utils/index.js'; const dirname = path.dirname(fileURLToPath(import.meta.url)); const packageJsonPath = path.join(dirname, '../package.json'); const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, { encoding: 'utf-8' })); program.version((_a = packageJson.version) !== null && _a !== void 0 ? _a : '0.0.1', '-v, --version'); for (const command of CommandFactory.values()) { program .command(command.getUsage()) .alias(command.getAlias()) .description(command.getDescription()) .action((appName) => __awaiter(void 0, void 0, void 0, function* () { try { yield command.run(appName); } catch (error) { printer.error(error); program.outputHelp(); } })); } program.on('--help', () => { printer.log(''); printer.info(` Run ${color.cyan(`bod <command> --help`)} for detailed usage of given command.`); printer.log(''); }); program.showHelpAfterError(); program.parse(process.argv);