#!/usr/bin/env node /** * {} * @author yutent * @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('.').slice(0, 2).join('.') let args = process.argv.slice(2) let mode = args.shift() || 'prod' let clean = args.shift() !== '--no-clean' 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() } 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)) { fs.rm(dist) } compile(WORK_SPACE, dist, conf.default) }) .catch(err => { console.log(err) }) break }