UNPKG

@puppedo/cli

Version:

A CLI for scarfolding PuppeDo projects

79 lines (71 loc) 1.74 kB
import arg from 'arg'; import inquirer from 'inquirer'; import { createProject } from './main'; function parseArgumentsIntoOptions(rawArgs) { const args = arg( { '--git': Boolean, '--yes': Boolean, '--install': Boolean, '-g': '--git', '-y': '--yes', '-i': '--install', }, { argv: rawArgs.slice(2), }, ); return { skipPrompts: args['--yes'] || false, git: args['--git'] || false, template: args._[0], install: args['--install'] || false, }; } async function promptForMissingOptions(options) { const defaultTemplate = 'PPD-Simple'; if (options.skipPrompts) { return { ...options, template: options.template || defaultTemplate, }; } const questions = []; if (!options.template) { questions.push({ type: 'list', name: 'template', message: 'Please choose which project template to use', choices: ['PPD-Simple', 'PPD-Blank'], default: defaultTemplate, }); } if (!options.git) { questions.push({ type: 'confirm', name: 'git', message: 'Initialize a git repository?', default: true, }); } if (!options.install) { questions.push({ type: 'confirm', name: 'install', message: 'Install dependencies?', default: true, }); } const answers = await inquirer.prompt(questions); return { ...options, template: options.template || answers.template, git: options.git || answers.git, install: options.install || answers.install, }; } export async function cli(args) { let options = parseArgumentsIntoOptions(args); options = await promptForMissingOptions(options); await createProject(options); }