1import chalk from 'chalk'; 2import { CommanderStatic } from 'commander'; 3 4import { Config } from '../Config'; 5import TemplateProject from '../TemplateProject'; 6import { DefaultOptions, registerCommand } from '../registerCommand'; 7 8interface CreateProjectOptions extends DefaultOptions { 9 app: string; 10} 11 12async function createProjectAsync(config: Config, options: CreateProjectOptions) { 13 const app = config.applications[options.app]; 14 15 if (app.preset === 'detox') { 16 console.log(`Using ${chalk.green('detox')} preset.`); 17 const preset = new TemplateProject(app, options.app, options.platform, options.configFile); 18 19 console.log(`Creating test app in ${chalk.green(options.path)}.`); 20 await preset.createApplicationAsync(options.path); 21 } else { 22 throw new Error(`Unknown preset: ${app.preset}`); 23 } 24} 25 26export default (program: CommanderStatic) => { 27 registerCommand(program, 'create-project', createProjectAsync).option( 28 '-a, --app [string]', 29 'Name of the application to create.' 30 ); 31}; 32