template-maker
Version:
A CLI to generate project templates with alot of options!!
83 lines (73 loc) • 1.95 kB
JavaScript
import arg from 'arg'
import inquirer from 'inquirer';
import {createProject} from './main'
function parseArguementsIntoOptions(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],
runInstall:args['--install'] || false
}
}
const prompForMissingOptions = async (options) => {
const defaultTemplate = "Vanilla"
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:[
"Vanilla",
"Node-Ejs",
"Backend",
"Web",
"PHP",
"Python",
"TypeScript-Temp",
"React-Temp",
"Angular-Temp",
"Vue-Temp"
],
default:defaultTemplate
})
}
if (!options.git) {
questions.push({
type:"confirm",
name:"git",
message:"Initialize a git repo?",
default:false
})
}
const answers = await inquirer.prompt(questions)
return {
...options,
template:options.template || answers.template,
git: options.git || answers.git
}
}
export async function cli(args) {
let options = parseArguementsIntoOptions(args)
options = await prompForMissingOptions(options)
await createProject(options)
}