feat: add vite dev containers
This commit is contained in:
@@ -1,24 +1,51 @@
|
||||
import { program as app, Command } from '@/program.ts';
|
||||
import { getConfig, writeConfig } from '@/module/index.ts';
|
||||
import { checkFileExists, getConfig, writeConfig } from '@/module/index.ts';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
const command = new Command('config')
|
||||
.description('')
|
||||
.option('-d, --dev <dev>', 'Specify dev')
|
||||
.option('-l --list', 'list config')
|
||||
.option('-w --workdir <path>', 'web config')
|
||||
.action(async (options) => {
|
||||
const { dev, list } = options || {};
|
||||
const { dev, list, workdir } = options || {};
|
||||
let config = getConfig();
|
||||
let flag = false;
|
||||
if (dev === 'true' || dev === 'false') {
|
||||
flag = true;
|
||||
const config = getConfig();
|
||||
if (dev === 'true') {
|
||||
writeConfig({ ...config, dev: true });
|
||||
config.dev = true;
|
||||
} else {
|
||||
writeConfig({ ...config, dev: false });
|
||||
config.dev = false;
|
||||
}
|
||||
}
|
||||
if (options.workdir) {
|
||||
let finalPath: string;
|
||||
flag = true;
|
||||
const workdir = options.workdir;
|
||||
|
||||
if (workdir.startsWith('/')) {
|
||||
// 如果以 / 开头,处理为绝对路径
|
||||
finalPath = workdir;
|
||||
} else {
|
||||
// 否则,处理为相对路径
|
||||
finalPath = path.resolve(workdir);
|
||||
}
|
||||
if (!checkFileExists(finalPath)) {
|
||||
console.log('路径不存在');
|
||||
fs.mkdirSync(finalPath, { recursive: true });
|
||||
}
|
||||
config.workdir = finalPath;
|
||||
}
|
||||
if (list) {
|
||||
const config = getConfig();
|
||||
console.log('config', config);
|
||||
}
|
||||
if (flag) {
|
||||
writeConfig(config);
|
||||
}
|
||||
});
|
||||
|
||||
app.addCommand(command);
|
||||
|
||||
Reference in New Issue
Block a user