quick-create-app-cli
Version:
前端基础建设模版脚手架,快速搭建PC、HybridApp、微信小程序、微前端等项目
69 lines (63 loc) • 1.72 kB
JavaScript
const { fsExtra, chalk } = require('./utils/dependencies')
const {
removeFile,
createLoadSpinner,
downloadTask,
cloneRepository
} = require('./utils/index')
//下载模版
const downloadTemplate = async function (fileUrl, tplPath) {
if (fileUrl && tplPath) {
// 清空模版文件
try {
removeFile(tplPath)
} catch (err) {
console.error(err)
process.exit()
}
//开始加载动画
let downloadSpinner = createLoadSpinner('Downloading template...')
try {
await downloadTask(fileUrl, tplPath)
downloadSpinner.text = 'Download template successful.'
downloadSpinner.succeed()
} catch (error) {
downloadSpinner.text = chalk.red(`Download template failed. ${error}`)
downloadSpinner.fail()
process.exit()
}
} else {
console.error('下载地址或模版仓库地址不可为空')
process.exit()
}
}
//拉取模版
const cloneTemplate = async function (fileUrl, tplPath, options) {
if (fileUrl && tplPath) {
// 清空模版文件
try {
removeFile(tplPath)
} catch (err) {
console.error(err)
process.exit()
}
//开始加载动画
let downloadSpinner = createLoadSpinner('Cloning template...')
try {
await cloneRepository(fileUrl, tplPath, options)
downloadSpinner.text = 'Clone template successful.'
downloadSpinner.succeed()
} catch (error) {
downloadSpinner.text = chalk.red(`Clone template failed. ${error}`)
downloadSpinner.fail()
process.exit()
}
} else {
console.error('远程仓库地址或模版仓库地址不可为空')
process.exit()
}
}
module.exports = {
downloadTemplate,
cloneTemplate
}