69 lines
1.7 KiB
JavaScript
Executable File
69 lines
1.7 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
/**
|
|
* {}
|
|
* @author yutent<yutent.io@gmail.com>
|
|
* @date 2022/09/28 15:12:45
|
|
*/
|
|
|
|
import fs from 'iofs'
|
|
import { join, normalize } from 'node:path'
|
|
import { red, blue } from 'kolorist'
|
|
|
|
import createServer from './lib/dev.js'
|
|
import compile from './lib/prod.js'
|
|
|
|
const WORK_SPACE = process.cwd()
|
|
const IS_WINDOWS = process.platform === 'win32'
|
|
|
|
const CONFIG_FILE = normalize(join(WORK_SPACE, 'fite.config.js'))
|
|
const PROTOCOL = IS_WINDOWS ? 'file://' : ''
|
|
const NODE_VERSION = process.versions.node.split('.').map(n => +n)
|
|
|
|
let args = process.argv.slice(2)
|
|
let mode = args.shift() || 'prod'
|
|
let clean = !args.includes('--no-clean') //
|
|
let verbose = args.includes('--verbose') //
|
|
|
|
if (NODE_VERSION[0] < 16 || (NODE_VERSION[0] === 16 && NODE_VERSION[1] < 6)) {
|
|
console.log(red('Error: 你当前的环境不满足 fite 构建工具的要求'))
|
|
console.log(
|
|
'fite 需要Node.js版本在 %s 以上, \n你当前的Node.js版本为: %s',
|
|
blue('v16.6.0'),
|
|
red(process.version),
|
|
'\n\n'
|
|
)
|
|
process.exit()
|
|
}
|
|
|
|
switch (mode) {
|
|
case 'dev':
|
|
process.env.NODE_ENV = 'development'
|
|
|
|
import(PROTOCOL + CONFIG_FILE)
|
|
.then(function (conf) {
|
|
createServer(WORK_SPACE, conf.default)
|
|
})
|
|
.catch(err => {
|
|
console.log(err)
|
|
})
|
|
break
|
|
|
|
case 'build':
|
|
process.env.NODE_ENV = 'production'
|
|
|
|
import(PROTOCOL + CONFIG_FILE)
|
|
.then(function (conf) {
|
|
let dist = conf.buildDir || 'dist'
|
|
if (clean && fs.isdir(dist)) {
|
|
console.log('清除dist目录...')
|
|
fs.rm(dist)
|
|
}
|
|
compile(WORK_SPACE, dist, conf.default, verbose)
|
|
})
|
|
.catch(err => {
|
|
console.log(err)
|
|
})
|
|
break
|
|
}
|