UNPKG

@gati-framework/cli

Version:

CLI tool for Gati framework - create, develop, build and deploy cloud-native applications

109 lines • 3.89 kB
/** * @module cli/commands/create * @description Create command for scaffolding new Gati projects */ import { Command } from 'commander'; import prompts from 'prompts'; import chalk from 'chalk'; import ora from 'ora'; import { existsSync } from 'fs'; import { resolve } from 'path'; import { generateProject } from '../utils/file-generator.js'; export const createCommand = new Command('create') .description('Create a new Gati project') .argument('[project-name]', 'Name of the project') .option('-t, --template <template>', 'Project template', 'default') .option('--skip-prompts', 'Skip interactive prompts') .option('--skip-install', 'Skip dependency installation') .action(async (projectName, options) => { // eslint-disable-next-line no-console console.log(chalk.bold.cyan('\nšŸš€ Gati Project Creator\n')); let name = projectName; let template = options.template; let description = ''; let author = ''; // Interactive prompts if not skipped if (!options.skipPrompts) { const answers = await prompts([ { type: name ? null : 'text', name: 'projectName', message: 'Project name:', initial: 'my-gati-app', validate: (value) => value.length > 0 ? true : 'Project name is required', }, { type: 'text', name: 'description', message: 'Project description:', initial: 'A Gati application', }, { type: 'text', name: 'author', message: 'Author:', initial: '', }, { type: 'select', name: 'template', message: 'Select a template:', choices: [ { title: 'Default', value: 'default', description: 'Basic Gati app with example handlers' }, { title: 'Minimal', value: 'minimal', description: 'Minimal setup with no examples' }, ], initial: 0, }, ], { onCancel: () => { // eslint-disable-next-line no-console console.log(chalk.red('\nāœ– Operation cancelled')); process.exit(0); }, }); if (!name) name = answers.projectName; description = answers.description; author = answers.author; template = answers.template; } if (!name) { console.error(chalk.red('āœ– Project name is required')); process.exit(1); } const projectPath = resolve(process.cwd(), name); // Check if directory already exists if (existsSync(projectPath)) { console.error(chalk.red(`āœ– Directory "${name}" already exists`)); process.exit(1); } const spinner = ora('Creating project...').start(); try { // Generate project structure await generateProject({ projectPath, projectName: name, description, author, template, skipInstall: options.skipInstall, }); spinner.succeed(chalk.green('Project created successfully!')); // Print next steps /* eslint-disable no-console */ console.log(chalk.bold('\nšŸ“¦ Next steps:\n')); console.log(chalk.cyan(` cd ${name}`)); if (options.skipInstall) { console.log(chalk.cyan(' pnpm install')); } console.log(chalk.cyan(' pnpm dev')); console.log(chalk.dim('\n Happy coding! šŸŽ‰\n')); /* eslint-enable no-console */ } catch (error) { spinner.fail(chalk.red('Failed to create project')); console.error(error); process.exit(1); } }); //# sourceMappingURL=create.js.map