-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
47 lines (42 loc) · 1.16 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const execSync = require('child_process').execSync
const path = require('path')
const fs = require('fs')
const chalk = require('chalk')
const figlet = require('figlet')
const pkg = require('./package.json')
const config = require('./config.json')
class Cli {
constructor() {
this.cliConfig = config
}
// 检查版本,如果过低则提示更新
checkCliUpdate() {
try {
const name = pkg.name
const version = `"${pkg.version}"`
const ltsVersion = execSync(`npm view ${name} version --json`) + ''
if (version !== ltsVersion.trim()) {
this._log(`⚠️ The cli version is to old, we recommend execute ${chalk.red(`npm i -g ${name}@latest`)} to upgrade cli: ${version} -> ${ltsVersion}`)
process.exit(0)
}
} catch (err) {
this._log('Check Upgrading failed.')
process.exit(0)
}
}
// 获取模版列表
getTemplateList() {
return this.cliConfig.list || []
}
// 命令行输出
_log() {
console.log.apply(null, arguments)
}
// 打印欢迎语
welcome() {
this._log(
chalk.white(`${figlet.textSync(`MIEO`)}\n 🐱 Welcome to be here.`)
)
}
}
module.exports = Cli