Skip to content

Commit

Permalink
feat: error message
Browse files Browse the repository at this point in the history
  • Loading branch information
FliPPeDround committed Jul 20, 2023
1 parent 5aeccbd commit 1c86449
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ async function init() {
try {
result = await question()
}
catch {
catch(cancelled) {

Check failure on line 47 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Expected space(s) after "catch"
console.log((<{message:string}>cancelled).message)

Check failure on line 48 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement

Check failure on line 48 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

A space is required after '{'

Check failure on line 48 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

Expected a space after the ':'

Check failure on line 48 in src/index.ts

View workflow job for this annotation

GitHub Actions / lint

A space is required before '}'
process.exit(1)
}

Expand Down
7 changes: 5 additions & 2 deletions src/question/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import prompts from 'prompts'
import { red } from 'kolorist'
import { bold, red } from 'kolorist'

import projectName from './name'
import model from './model'
import template from './template'

import figures from 'prompts/lib/util/figures.js'

Check failure on line 8 in src/question/index.ts

View workflow job for this annotation

GitHub Actions / lint

`prompts/lib/util/figures.js` import should occur before import of `./name`


Check failure on line 10 in src/question/index.ts

View workflow job for this annotation

GitHub Actions / lint

More than 1 blank line not allowed
export async function question() {
const questions = [
...projectName(),
template(),
]

const onCancel = () => {
throw new Error(`${red('✖')} Operation cancelled`)
throw new Error(`${red(figures.cross)} ${bold('操作已取消')}`)
}

let answers = await prompts(questions, { onCancel })
Expand Down
5 changes: 3 additions & 2 deletions src/question/name.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { PromptObject } from 'prompts'
import { red } from 'kolorist'
import { bold, red } from 'kolorist'
import { canSkipEmptying } from '../utils'
import figures from 'prompts/lib/util/figures.js'

Check failure on line 4 in src/question/name.ts

View workflow job for this annotation

GitHub Actions / lint

`prompts/lib/util/figures.js` import should occur before import of `../utils`

export default (): PromptObject<string>[] => {
let targetDir = 'uni-app'
Expand Down Expand Up @@ -29,7 +30,7 @@ export default (): PromptObject<string>[] => {
name: 'overwriteChecker',
type: (_prev, values) => {
if (values.shouldOverwrite === false)
throw new Error(`${red('✖')} Operation cancelled`)
throw new Error(`${red(figures.cross)} ${bold('操作已取消')}`)

return null
},
Expand Down

0 comments on commit 1c86449

Please sign in to comment.