const inquirer = require('inquirer');
const chalk = require('chalk');
const DEFAULT_TEMPLATE_SRC = 'github:NervJS/taro-project-templates#v3.1'
const DEFAULT_TEMPLATE_SRC_GITEE = 'direct:https://gitee.com/o2team/taro-project-templates.git#v3.1'
const askProjectName = function (conf, prompts) {
if ((typeof conf.projectName) !== 'string') {
prompts.push({
type: 'input',
name: 'projectName',
message: '请输入项目名称!',
validate(input) {
if (!input) {
return '项目名不能为空!'
}
if (fs.existsSync(input)) {
return '当前目录已经存在同名项目,请换一个项目名!'
}
return true
}
})
} else if (fs.existsSync(conf.projectName)) {
prompts.push({
type: 'input',
name: 'projectName',
message: '当前目录已经存在同名项目,请换一个项目名!',
validate(input) {
if (!input) {
return '项目名不能为空!'
}
if (fs.existsSync(input)) {
return '项目名依然重复!'
}
return true
}
})
}
}
const askTemplateSource = async function (conf, prompts) {
let localTemplateSource = DEFAULT_TEMPLATE_SRC
const choices = [
{
name: 'Gitee(最快)',
value: DEFAULT_TEMPLATE_SRC_GITEE
},
{
name: 'Github(最新)',
value: DEFAULT_TEMPLATE_SRC
}
]
if (localTemplateSource && localTemplateSource !== DEFAULT_TEMPLATE_SRC && localTemplateSource !== DEFAULT_TEMPLATE_SRC_GITEE) {
choices.unshift({
name: `本地模板源:${localTemplateSource}`,
value: localTemplateSource
})
}
prompts.push({
type: 'list',
name: 'templateSource',
message: '请选择模板源',
choices
})
}
async function ask() {
let prompts = []
const conf = {}
askProjectName(conf, prompts)
await askTemplateSource(conf, prompts)
console.log(chalk.green('Taro 即将创建一个新项目!'))
const answers = await inquirer.prompt(prompts)
console.log("🚀 ~ file: addExper.js ~ line 87 ~ answers", answers)
};
ask()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!