增加多页应用的初始化
parent
d477caf939
commit
bab661640c
56
index.js
56
index.js
|
@ -28,17 +28,27 @@ import {
|
|||
writeStore
|
||||
} from './lib/demo-js.js'
|
||||
|
||||
const NODE_VERSION = +process.versions.node.split('.').slice(0, 2).join('.')
|
||||
const CURRENT_DIR = process.cwd()
|
||||
const root = normalize(
|
||||
dirname(import.meta.url.slice(process.platform === 'win32' ? 8 : 7))
|
||||
)
|
||||
const VERSION = '1.0.1'
|
||||
|
||||
const DEFAULT_NAME = 'vue-live-app'
|
||||
|
||||
let args = process.argv.slice(2)
|
||||
let targetDir = ''
|
||||
|
||||
if (NODE_VERSION < 16.6) {
|
||||
console.log(red('Error: 你当前的环境不满足 Vue-live 构建工具的要求'))
|
||||
console.log(
|
||||
'Vue-live 需要Node.js版本在 %s 以上, \n你当前的Node.js版本为: %s',
|
||||
blue('v16.6.0'),
|
||||
red(process.version),
|
||||
'\n\n'
|
||||
)
|
||||
process.exit()
|
||||
}
|
||||
|
||||
function isEmpty(dir) {
|
||||
let list = fs.ls(dir)
|
||||
if (list && list.length) {
|
||||
|
@ -68,27 +78,7 @@ function sleep(num = 1) {
|
|||
return new Promise(resolve => setTimeout(resolve, num * 1000))
|
||||
}
|
||||
|
||||
function printHelp() {
|
||||
console.log('Usage: vue-live-cli {command} [arguments]')
|
||||
console.log(' ', 'vue-live-cli init', '初始化一个符合vue-live的vue项目')
|
||||
console.log(' ', 'vue-live-cli -h[--help]', '打印帮助信息')
|
||||
console.log()
|
||||
process.exit()
|
||||
}
|
||||
|
||||
!(async function () {
|
||||
switch (args[0]) {
|
||||
case '-v':
|
||||
case '--version':
|
||||
console.log('v' + VERSION)
|
||||
break
|
||||
|
||||
case '-h':
|
||||
case '--help':
|
||||
printHelp()
|
||||
break
|
||||
|
||||
default:
|
||||
let res = await prompts([
|
||||
{
|
||||
name: 'projectName',
|
||||
|
@ -116,6 +106,14 @@ function printHelp() {
|
|||
}
|
||||
return null
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'isSPA',
|
||||
type: 'toggle',
|
||||
message: _ => `是否初始化为单页应用? (否则为多页应用)`,
|
||||
initial: true,
|
||||
active: '是',
|
||||
inactive: '否'
|
||||
}
|
||||
])
|
||||
|
||||
|
@ -153,11 +151,7 @@ function printHelp() {
|
|||
|
||||
console.log('[c---------]', '10%')
|
||||
|
||||
writePackageJson(
|
||||
join(targetDir, 'package.json'),
|
||||
res.projectName,
|
||||
vueLiveVer
|
||||
)
|
||||
writePackageJson(join(targetDir, 'package.json'), res.projectName, vueLiveVer)
|
||||
writeConfigFile(join(targetDir, 'vue.live.js'))
|
||||
writeGitIgnore(join(targetDir, '.gitignore'))
|
||||
writePrettierrc(join(targetDir, '.prettierrc.yaml'))
|
||||
|
@ -167,10 +161,7 @@ function printHelp() {
|
|||
writeHtmlFile(join(targetDir, 'index.html'))
|
||||
|
||||
writeLogo(join(targetDir, 'src/assets/logo.svg'))
|
||||
fs.cp(
|
||||
join(root, 'lib/favicon.ico'),
|
||||
join(targetDir, 'public/favicon.ico')
|
||||
)
|
||||
fs.cp(join(root, 'lib/favicon.ico'), join(targetDir, 'public/favicon.ico'))
|
||||
|
||||
console.log('[oooooc----]', '60%')
|
||||
|
||||
|
@ -186,7 +177,4 @@ function printHelp() {
|
|||
console.log(cyan('初始化完成, 可依次执行以下命令启动项目: '))
|
||||
console.log(blue('npm i'))
|
||||
console.log(blue('npm start'))
|
||||
|
||||
break
|
||||
}
|
||||
})()
|
||||
|
|
Loading…
Reference in New Issue