fite/index.js

49 lines
1.0 KiB
JavaScript
Raw Normal View History

2022-10-21 14:10:38 +08:00
#!/usr/bin/env node
2022-09-28 18:56:47 +08:00
/**
* {}
* @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'
2023-02-21 18:34:48 +08:00
import { join, normalize } 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-21 14:10:38 +08:00
const WORK_SPACE = process.cwd()
2022-10-21 14:22:27 +08:00
const IS_WINDOWS = process.platform === 'win32'
2022-09-28 18:56:47 +08:00
2023-02-21 18:34:48 +08:00
const CONFIG_FILE = normalize(join(WORK_SPACE, 'vue.live.js'))
2022-10-21 14:22:27 +08:00
const PROTOCOL = IS_WINDOWS ? 'file://' : ''
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-21 14:22:27 +08:00
import(PROTOCOL + CONFIG_FILE)
2022-09-28 18:56:47 +08:00
.then(function (conf) {
2023-02-16 15:32:17 +08:00
createServer(WORK_SPACE, 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-21 14:22:27 +08:00
import(PROTOCOL + CONFIG_FILE)
2022-10-09 19:19:21 +08:00
.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)
2023-02-16 15:32:17 +08:00
compile(WORK_SPACE, 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
}