Skip to content

Commit febb364

Browse files
committed
feat(core): use clack instead of inquire
1 parent 82fcf09 commit febb364

File tree

10 files changed

+152
-131
lines changed

10 files changed

+152
-131
lines changed

.eslintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"rules": {
44
"no-console": "off",
55
"no-prototype-builtins":"off",
6-
"no-return-await":"off"
6+
"no-return-await":"off",
7+
"promise/no-promise-in-callback": "off"
78
}
89
}

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
<a href="https://magic-cli.netlify.app/">🧑‍💻 Document <sup>Beta</sup></a>
1010
</p>
1111

12+
## New version of Magic preview, Stay tuned!
13+
14+
![](https://jsd.cdn.zzko.cn/gh/yzh990918/static@master/Kapture-2023-03-04-at-14.q6m1ppb4psg.gif)
15+
1216
## Getting Start
1317

1418
This section will help you learn how to use [Magic-cli](https://github.com/vbs-plus/magic-cli). If you already have an existing project and would like to keep project inside the project, start from Step 2.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"deploy": "zr build && zr docs:build"
2323
},
2424
"dependencies": {
25+
"@clack/prompts": "^0.6.1",
2526
"@commitlint/cli": "^12.1.4",
2627
"@commitlint/config-conventional": "^12.1.4",
2728
"@vbs/eslint-config": "^1.0.0",

packages/core/src/commander.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ export const InitCommander = () => {
1313
.name(Object.keys(pkg.bin)[0])
1414
.usage('<command> [options]')
1515
.version(pkg.version)
16-
.option('-d, --debug', '是否开启 Debug 模式', false)
17-
.option('-tp, --targetPath <targetPath>', '指定目标安装目录', '')
16+
.option('-d, --debug', 'Whether to turn on Debug mode', false)
17+
.option('-tp, --targetPath <targetPath>', 'Specifies the command working directory', '')
1818

1919
program
2020
.command('init [projectName]')
21-
.option('-f, --force', '是否强制初始化项目', false)
21+
.option('-f, --force', 'Whether to force initialization of the project', false)
2222
.action((projectName: string, { force }: { force: boolean }, cmd: Command) => {
2323
exec(projectName, force, cmd)
2424
})
2525

2626
program
2727
.command('add [templateName]')
28-
.option('-f, --force', '是否强制添加模板', false)
28+
.option('-f, --force', 'Whether to force the addition of a template', false)
2929
.action((templateName: string, { force }: { force: boolean }, cmd: Command) => {
3030
info(templateName)
3131
info(force)
@@ -40,7 +40,7 @@ export const InitCommander = () => {
4040
try {
4141
const HOME_PATH = process.env.MAGIC_CLI_HOME_PATH || ''
4242
fse.removeSync(HOME_PATH)
43-
consola.success('重启应用成功! \n')
43+
consola.success('The app is restarted successfully! \n')
4444
} catch (error) {
4545
consola.error(error)
4646
}
@@ -50,7 +50,7 @@ export const InitCommander = () => {
5050
program.on('option:debug', () => {
5151
if (program.opts().debug) {
5252
process.env.DEBUG = 'debug'
53-
info('开启 DEBUG 模式')
53+
info('Turn on DEBUG mode!')
5454
} else {
5555
process.env.DEBUG = ''
5656
}
@@ -65,7 +65,7 @@ export const InitCommander = () => {
6565
const avaliableCommands = program.commands.map(item => item.name())
6666
consola.error(`未知命令${cmd[0]}`)
6767

68-
if (avaliableCommands.length) echo(' 可用命令 ', avaliableCommands.join(','))
68+
if (avaliableCommands.length) echo(' Available commands ', avaliableCommands.join(','))
6969
})
7070

7171
program.parse(process.argv)

packages/core/src/exec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ export const exec = async(...args: any[]) => {
4747

4848
// 判断缓存目录是否已存在
4949
if (await pkg.exists()) {
50-
debug('执行更新')
50+
debug('Perform the update')
5151
await pkg.update()
5252
} else {
53-
debug('执行初始化')
53+
debug('Perform initialization')
5454
await pkg.init()
5555
}
5656
}
5757

5858
const execFilePath = await pkg.getRootFilePath()
5959
if (!execFilePath)
60-
throw new Error(error('当前指定文件夹路径有误', { needConsole: false }))
60+
throw new Error(error('The folder path specified is incorrect!', { needConsole: false }))
6161

6262
debug(`execFilePath:${execFilePath}`)
6363
debug(`TP_PATH:${TP_PATH}`)
@@ -86,12 +86,12 @@ export const exec = async(...args: any[]) => {
8686
)
8787

8888
child.on('error', (e: Error) => {
89-
error(`多进程代码执行异常: ${e.message}`)
89+
error(`Multi-process code execution exception: ${e.message}`)
9090
process.exit(1)
9191
})
9292

9393
child.on('exit', (e: number) => {
94-
debug(`${curCommand} 命令执行成功`)
94+
debug(`${curCommand} The command was executed successfully`)
9595
process.exit(e)
9696
})
9797
} catch (e: any) {

packages/core/src/prepare.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const homePath = os.homedir()
1414

1515
export function checkUserHome(homePath: string) {
1616
if (!homePath || !fse.existsSync(homePath))
17-
consola.error(new Error('当前登录用户主目录不存在'))
17+
consola.error(new Error('The home directory of the currently logged-on user does not exist!'))
1818
}
1919

2020
export function initDefaultConfig() {
@@ -44,7 +44,7 @@ export async function checkPackageUpdate() {
4444
if (latestVersion && semver.gt(latestVersion, version)) {
4545
console.log()
4646
consola.warn(
47-
`最新版本已发布,请手动更新脚手架版本,当前版本为:${version},最新版本为:${latestVersion} []~( ̄▽ ̄)~*,探索跟多关于 Magic,请访问: https://magic-cli.netlify.app/\n`,
47+
`The latest version is released, please manually update the scaffolding version, the current version is: ${version}, the latest version is: ${latestVersion} []~( ̄▽ ̄)~*, to explore and learn more about Magic, please visit: https://magic-cli.netlify.app/\n`,
4848
)
4949
console.log()
5050
}
@@ -53,14 +53,14 @@ export async function checkPackageUpdate() {
5353
export function checkNodeVersion() {
5454
const currentVersion = process.version
5555
if (!semver.gte(currentVersion, LOWEST_NODE_VERSION))
56-
throw new Error(error(`当前 Node 版本过低,推荐安装 v${LOWEST_NODE_VERSION} 以上 Node 版本`, { needConsole: false }))
56+
throw new Error(error(`The current Node version is too low, it is recommended to install v${LOWEST_NODE_VERSION} or above Node version`, { needConsole: false }))
5757
}
5858

5959
export async function prepare() {
6060
printMagicLogo(pkg.version)
6161

6262
const spinner = ora({
63-
text: '👉 检查构建环境... \n',
63+
text: '👉 Check the build environment... \n',
6464
spinner: 'material',
6565
})
6666

@@ -71,9 +71,9 @@ export async function prepare() {
7171
checkEnv()
7272
await checkPackageUpdate()
7373
checkNodeVersion()
74-
spinner.succeed('构建环境正常!\n')
74+
spinner.succeed('The build environment is normal!\n')
7575
} catch (error) {
76-
spinner.fail('检查构建环境异常! \n')
76+
spinner.fail('Check for build environment exceptions! \n')
7777
console.log(error)
7878
process.exit(-1)
7979
}

0 commit comments

Comments
 (0)