Skip to content

Commit

Permalink
✨ feat(error): 新增 错误捕获功能
Browse files Browse the repository at this point in the history
  • Loading branch information
ErKeLost committed Aug 1, 2022
1 parent 3a869fc commit 7937711
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ export default async function () {
gradient('cyan', 'purple')('\n🚀 Welcome To Create Template for Vite!\n')
)

try {
await createProjectQuestions()
} catch (error) {
cyan('\n ✖ Goodbye Exit!')
process.exit(1)
return
}
await createProjectQuestions()
console.log(options.name, '🎨 🎨🎨 🎨')

// CLI 模板文件夹路径
Expand Down
48 changes: 26 additions & 22 deletions packages/vite-cli/src/core/questions/creator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,39 @@ import {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const prompts = require('prompts')
async function createQuestion(util, question) {
const result: QuestionCollection = await util(question)
const result: QuestionCollection = await util(question, {
onCancel: () => {
throw new Error('🎨🎨' + ' Operation cancelled')
}
})
Object.assign(options, result)
// 在 回答问题得时候 map 映射 每一个 库 版本 问题 要不要考虑
return Promise.resolve(true)
}

async function createProjectQuestions(): Promise<void> {
// 项目名
await createQuestion(prompts, projectName)
// 选择框架
await createQuestion(prompts, frame)
// 包管理器版本
await createQuestion(prompts, PackageDevice)
// 新特性 新预设
await createQuestion(prompts, future)
// pc or mobile
await createQuestion(prompts, device)
// ui library
await createQuestion(prompts, components)
// vite plugins
await createQuestion(prompts, Plugins)
// css
await createQuestion(prompts, precss)
// cancel
await createQuestion(prompts, {
onCancel: () => {
throw new Error('🎨🎨' + ' Operation cancelled')
}
})
try {
await createQuestion(prompts, projectName)
// 选择框架
await createQuestion(prompts, frame)
// 包管理器版本
await createQuestion(prompts, PackageDevice)
// 新特性 新预设
await createQuestion(prompts, future)
// pc or mobile
await createQuestion(prompts, device)
// ui library
await createQuestion(prompts, components)
// vite plugins
await createQuestion(prompts, Plugins)
// css
await createQuestion(prompts, precss)
// cancel
} catch (cancelled) {
console.log(cancelled.message)
process.exit(1)
}
// options 对象属性 所有 属性
// 获取 选中 components
// console.log(componentsMap.get(options.components))
Expand Down

0 comments on commit 7937711

Please sign in to comment.