parent
e2fc1d8e31
commit
0f26eef35f
35
index.js
35
index.js
|
@ -5,6 +5,7 @@
|
||||||
* @date 2022/10/10 15:17:36
|
* @date 2022/10/10 15:17:36
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { request } from 'https'
|
||||||
import { red, cyan, blue } from 'kolorist'
|
import { red, cyan, blue } from 'kolorist'
|
||||||
import prompts from 'prompts'
|
import prompts from 'prompts'
|
||||||
import fs from 'iofs'
|
import fs from 'iofs'
|
||||||
|
@ -46,6 +47,23 @@ function isEmpty(dir) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getVueLiveVersion() {
|
||||||
|
return new Promise(yes => {
|
||||||
|
request('https://registry.npmmirror.com/@bytedo/vue-live', res => {
|
||||||
|
let data = ''
|
||||||
|
res.on('data', chunk => (data += chunk))
|
||||||
|
res.on('end', _ => {
|
||||||
|
try {
|
||||||
|
data = JSON.parse(data)
|
||||||
|
yes(data['dist-tags'].latest)
|
||||||
|
} catch (e) {
|
||||||
|
yes('0.1.1')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}).end()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function sleep(num = 1) {
|
function sleep(num = 1) {
|
||||||
return new Promise(resolve => setTimeout(resolve, num * 1000))
|
return new Promise(resolve => setTimeout(resolve, num * 1000))
|
||||||
}
|
}
|
||||||
|
@ -94,7 +112,7 @@ function printHelp() {
|
||||||
type: shouldOverwrite => {
|
type: shouldOverwrite => {
|
||||||
if (shouldOverwrite === false) {
|
if (shouldOverwrite === false) {
|
||||||
console.log(red('✖') + ' 操作取消~~')
|
console.log(red('✖') + ' 操作取消~~')
|
||||||
process.exit(1)
|
process.exit()
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
@ -103,6 +121,11 @@ function printHelp() {
|
||||||
|
|
||||||
console.log()
|
console.log()
|
||||||
|
|
||||||
|
if (res.projectName === undefined) {
|
||||||
|
console.log('已取消操作~~')
|
||||||
|
process.exit()
|
||||||
|
}
|
||||||
|
|
||||||
if (res.projectName === '.') {
|
if (res.projectName === '.') {
|
||||||
res.projectName = DEFAULT_NAME
|
res.projectName = DEFAULT_NAME
|
||||||
}
|
}
|
||||||
|
@ -122,11 +145,17 @@ function printHelp() {
|
||||||
|
|
||||||
console.log(cyan('\n初始化项目...'))
|
console.log(cyan('\n初始化项目...'))
|
||||||
|
|
||||||
|
let vueLiveVer = await getVueLiveVersion()
|
||||||
|
|
||||||
fs.mkdir(join(targetDir, 'src'))
|
fs.mkdir(join(targetDir, 'src'))
|
||||||
|
|
||||||
console.log('[c---------]', '10%')
|
console.log('[c---------]', '10%')
|
||||||
|
|
||||||
writePackageJson(join(targetDir, 'package.json'), res.projectName)
|
writePackageJson(
|
||||||
|
join(targetDir, 'package.json'),
|
||||||
|
res.projectName,
|
||||||
|
vueLiveVer
|
||||||
|
)
|
||||||
writeConfigFile(join(targetDir, 'vue.live.js'))
|
writeConfigFile(join(targetDir, 'vue.live.js'))
|
||||||
writeGitIgnore(join(targetDir, '.gitignore'))
|
writeGitIgnore(join(targetDir, '.gitignore'))
|
||||||
writePrettierrc(join(targetDir, '.prettierrc.yaml'))
|
writePrettierrc(join(targetDir, '.prettierrc.yaml'))
|
||||||
|
@ -146,7 +175,7 @@ function printHelp() {
|
||||||
writeAboutVue(join(targetDir, 'src/views/about.vue'))
|
writeAboutVue(join(targetDir, 'src/views/about.vue'))
|
||||||
writeHelloVue(join(targetDir, 'src/components/hello.vue'))
|
writeHelloVue(join(targetDir, 'src/components/hello.vue'))
|
||||||
writeRouter(join(targetDir, 'src/router.js'))
|
writeRouter(join(targetDir, 'src/router.js'))
|
||||||
writeStore(join(targetDir, 'src/store.js'))
|
writeStore(join(targetDir, 'src/store.js'), vueLiveVer)
|
||||||
|
|
||||||
console.log('[oooooooooo]', '100%')
|
console.log('[oooooooooo]', '100%')
|
||||||
console.log(cyan('初始化完成, 可依次执行以下命令启动项目: '))
|
console.log(cyan('初始化完成, 可依次执行以下命令启动项目: '))
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
import fs from 'iofs'
|
import fs from 'iofs'
|
||||||
|
|
||||||
export function writePackageJson(file, name) {
|
export function writePackageJson(file, name, version) {
|
||||||
fs.echo(
|
fs.echo(
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,7 @@ export function writePackageJson(file, name) {
|
||||||
build: 'vue-live build'
|
build: 'vue-live build'
|
||||||
},
|
},
|
||||||
devDependencies: {
|
devDependencies: {
|
||||||
'@bytedo/vue-live': '^0.1.0'
|
'@bytedo/vue-live': `^${version}`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
null,
|
null,
|
||||||
|
|
|
@ -54,14 +54,14 @@ export default router
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function writeStore(file) {
|
export function writeStore(file, version) {
|
||||||
fs.echo(
|
fs.echo(
|
||||||
`
|
`
|
||||||
import { reactive } from 'vue'
|
import { reactive } from 'vue'
|
||||||
|
|
||||||
const store = reactive({
|
const store = reactive({
|
||||||
foo: 'bar',
|
foo: 'bar',
|
||||||
version: '0.1.0'
|
version: '${version}'
|
||||||
})
|
})
|
||||||
|
|
||||||
export default function (app) {
|
export default function (app) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "create-vue-live",
|
"name": "create-vue-live",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"version": "0.1.0",
|
"version": "1.0.0",
|
||||||
"bin": {
|
"bin": {
|
||||||
"create-vue-live": "index.js"
|
"create-vue-live": "index.js"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue