Skip to content

Commit

Permalink
fix: Ora new message length error
Browse files Browse the repository at this point in the history
  • Loading branch information
FliPPeDround committed Jun 30, 2023
1 parent f212c0b commit 42084d6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
31 changes: 17 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,23 @@ async function init() {
else if (!existsSync(root))
mkdirSync(root)

if (result.templateType!.type !== 'custom') {
const loading = ora(`${bold('正在下载模板...')}`).start()
const { cloneRepo, getRepoUrl } = await import('./utils/')
const repoUrl = getRepoUrl(result.templateType!.url)
try {
await cloneRepo(repoUrl, root)
}
catch {
loading.fail(`${bold('模板下载失败')}`)
process.exit(1)
}

loading.succeed(`${bold('模板下载完成')}`)
}
if (result.templateType!.type !== 'custom')
await dowloadTemplate(result.templateType!.url, root)
}

init()

async function dowloadTemplate(url: BaseTemplateList['value']['url'], root: string) {
const loading = ora(`${bold('正在下载模板...')}`).start()
const { cloneRepo, getRepoUrl } = await import('./utils/')
const repoUrlList = getRepoUrl(url)
try {
await cloneRepo(repoUrlList, root)
}
catch {
loading.fail(`${bold('模板下载失败')}`)
process.exit(1)
}

loading.succeed(`${bold('模板下载完成')}`)
}
2 changes: 1 addition & 1 deletion src/utils/banners.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
export function printBanner() {
const text = 'Uni-creator - 帮你快速创建 uni-app 项目'
const text = 'Uni-creator - 快速创建 uni-app 项目'
let output = ''

const startColor = { r: 0x3B, g: 0xD1, b: 0x91 }
Expand Down
8 changes: 6 additions & 2 deletions src/utils/loading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class Ora {
this.interval = null
}

setFinishMessage(newMessage: string): string {
return newMessage + ' '.repeat(this.message.length - newMessage.length)
}

start(): Ora {
let i = 0
this.interval = setInterval(() => {
Expand All @@ -24,14 +28,14 @@ class Ora {
if (!this.interval)
return
clearInterval(this.interval)
process.stdout.write('\r' + `${red('✖')} ${message}\n`)
process.stdout.write('\r' + `${red('✖')} ${this.setFinishMessage(message)}\n`)
}

succeed(message: string): void {
if (!this.interval)
return
clearInterval(this.interval)
process.stdout.write('\r' + `${green('✔')} ${message}\n`)
process.stdout.write('\r' + `${green('✔')} ${this.setFinishMessage(message)}\n`)
}
}

Expand Down

0 comments on commit 42084d6

Please sign in to comment.