2022-09-28 18:56:47 +08:00
|
|
|
#!/bin/env node
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {}
|
|
|
|
* @author yutent<yutent.io@gmail.com>
|
|
|
|
* @date 2022/09/28 15:12:45
|
|
|
|
*/
|
|
|
|
|
2022-10-11 19:31:04 +08:00
|
|
|
import fs from 'iofs'
|
2022-09-28 18:56:47 +08:00
|
|
|
import { join } from 'path'
|
2022-10-10 15:05:30 +08:00
|
|
|
|
|
|
|
import createServer from './lib/dev.js'
|
|
|
|
import compile from './lib/prod.js'
|
2022-09-28 18:56:47 +08:00
|
|
|
|
2022-10-11 19:31:04 +08:00
|
|
|
const WORK_SPACE = process.env.PWD
|
2022-09-28 18:56:47 +08:00
|
|
|
|
2022-10-09 19:19:21 +08:00
|
|
|
const CONFIG_FILE = join(WORK_SPACE, 'vue.live.js')
|
2022-10-10 15:05:30 +08:00
|
|
|
const SOURCE_DIR = join(WORK_SPACE, 'src')
|
2022-10-09 19:19:21 +08:00
|
|
|
|
2022-09-28 18:56:47 +08:00
|
|
|
let args = process.argv.slice(2)
|
|
|
|
|
|
|
|
switch (args[0]) {
|
|
|
|
case 'dev':
|
2022-10-09 19:19:21 +08:00
|
|
|
import(CONFIG_FILE)
|
2022-09-28 18:56:47 +08:00
|
|
|
.then(function (conf) {
|
2022-10-10 15:05:30 +08:00
|
|
|
createServer(SOURCE_DIR, conf.default)
|
2022-09-28 18:56:47 +08:00
|
|
|
})
|
|
|
|
.catch(err => {
|
2022-10-11 19:31:04 +08:00
|
|
|
console.log(err)
|
2022-09-28 18:56:47 +08:00
|
|
|
})
|
|
|
|
break
|
|
|
|
|
|
|
|
case 'build':
|
2022-10-09 19:19:21 +08:00
|
|
|
import(CONFIG_FILE)
|
|
|
|
.then(function (conf) {
|
2022-10-11 19:31:04 +08:00
|
|
|
let dist = conf.buildDir || 'dist'
|
|
|
|
if (fs.isdir(dist)) {
|
|
|
|
fs.rm(dist, true)
|
|
|
|
}
|
|
|
|
fs.mkdir(dist)
|
|
|
|
compile(SOURCE_DIR, dist, conf.default)
|
2022-10-09 19:19:21 +08:00
|
|
|
})
|
|
|
|
.catch(err => {
|
2022-10-11 19:31:04 +08:00
|
|
|
console.log(err)
|
2022-10-09 19:19:21 +08:00
|
|
|
})
|
2022-09-28 18:56:47 +08:00
|
|
|
break
|
|
|
|
}
|