UNPKG

builder-cli

Version:

A front-end builder

65 lines (55 loc) 1.54 kB
#!/usr/bin/env node const inquirer = require('inquirer') const logger = require('./logger') const ora = require('ora') const download = require('download-git-repo') const program = require('commander') const template = typeof program.args[1] === 'string' ? program.args[1] : '' const questions = [ { type: 'input', name: 'storage', message: 'Where do you want to deploy this template ? (relative path)', validate (val) { return val !== '' } } ] if (template === '') { questions.push( { type: 'list', name: 'template', message: 'Which template do you want to use ? ', choices: [ 'js-template', 'ts-template' ] } ) } inquirer .prompt(questions) .then(answer => { // custom template or default template const repo = answer.template ? `lbwa/${answer.template}` : template repo && builder(repo, answer.storage) }) .catch(() => { logger.err('Oops ! build fail.\n') }) function builder (template, destination) { const targetPath = /\/$/.test(destination) ? `${destination}${program.args[0]}` : `${destination}/${program.args[0]}` const spinner = ora('Downloading template ...') spinner.start() logger.info(template) // default domain: github // default branch: master download(`${template}`, targetPath, { clone: true }, err => { err && logger.err(`Fail to download ${template}: ${err.message.trim()}`) logger.success(`${template} has been created in ${targetPath}.\n`) spinner.stop() }) }