add envision-cli 0.0.6
This commit is contained in:
@@ -5,6 +5,45 @@ import fs from 'fs';
|
||||
import { chalk } from '@/module/chalk.ts';
|
||||
import inquirer from 'inquirer';
|
||||
|
||||
// 设置工作目录
|
||||
const setWorkdir = async (options: { workdir: string }) => {
|
||||
const execPath = process.cwd();
|
||||
let flag = false;
|
||||
let config = getConfig();
|
||||
const workdir = options.workdir;
|
||||
if (workdir) {
|
||||
let finalPath: string;
|
||||
if (workdir.startsWith('/')) {
|
||||
// 如果以 / 开头,处理为绝对路径
|
||||
finalPath = workdir;
|
||||
} else {
|
||||
// 否则,处理为相对路径
|
||||
finalPath = path.join(execPath, workdir);
|
||||
}
|
||||
if (!checkFileExists(finalPath)) {
|
||||
console.log('路径不存在');
|
||||
fs.mkdirSync(finalPath, { recursive: true });
|
||||
}
|
||||
const answers = await inquirer.prompt([
|
||||
{
|
||||
type: 'confirm',
|
||||
name: 'confirm',
|
||||
message: `Are you sure you want to set the workdir to: ${finalPath}?`,
|
||||
default: false,
|
||||
},
|
||||
]);
|
||||
if (answers.confirm) {
|
||||
flag = true;
|
||||
config.workdir = finalPath;
|
||||
console.log(chalk.green(`set workdir success:`, finalPath));
|
||||
} else {
|
||||
console.log('Cancel set workdir');
|
||||
}
|
||||
}
|
||||
if (flag) {
|
||||
writeConfig(config);
|
||||
}
|
||||
};
|
||||
const command = new Command('config')
|
||||
.description('')
|
||||
.option('-d, --dev <dev>', 'Specify dev')
|
||||
@@ -14,7 +53,7 @@ const command = new Command('config')
|
||||
.option('-v --value <value>', 'value')
|
||||
.option('-w --workdir <path>', 'web config')
|
||||
.action(async (options) => {
|
||||
const { dev, list, workdir } = options || {};
|
||||
const { dev, workdir } = options || {};
|
||||
let config = getConfig();
|
||||
let flag = false;
|
||||
const execPath = process.cwd();
|
||||
@@ -107,11 +146,29 @@ const setCommand = new Command('set')
|
||||
when: () => value === 'not_input',
|
||||
},
|
||||
]);
|
||||
if (answer.value === 'not_input') {
|
||||
value = '';
|
||||
}
|
||||
value = answer.value || value;
|
||||
if (key === 'workdir') {
|
||||
await setWorkdir({ workdir: value });
|
||||
return;
|
||||
}
|
||||
if (key && value) {
|
||||
flag = true;
|
||||
console.log(chalk.green(`set ${key} success:`, value));
|
||||
config[key] = value;
|
||||
if (key === 'dev') {
|
||||
if (value === 'true') {
|
||||
config.dev = true;
|
||||
} else {
|
||||
config.dev = false;
|
||||
}
|
||||
} else {
|
||||
config[key] = value;
|
||||
}
|
||||
console.log(chalk.green(`set ${key} success:`, config.key));
|
||||
} else if (key) {
|
||||
flag = true;
|
||||
delete config[key];
|
||||
}
|
||||
if (flag) {
|
||||
writeConfig(config);
|
||||
@@ -144,6 +201,19 @@ const getCommand = new Command('get')
|
||||
});
|
||||
command.addCommand(getCommand);
|
||||
|
||||
const removeCommand = new Command('remove')
|
||||
.argument('<key>')
|
||||
.description('remove config')
|
||||
.action(async (key) => {
|
||||
const config = getConfig();
|
||||
if (key) {
|
||||
delete config[key];
|
||||
writeConfig(config);
|
||||
console.log(chalk.green(`remove ${key} success`));
|
||||
}
|
||||
});
|
||||
command.addCommand(removeCommand);
|
||||
|
||||
const list = new Command('list').action(async () => {
|
||||
const config = getConfig();
|
||||
console.log(chalk.green('config', JSON.stringify(config, null, 2)));
|
||||
|
||||
Reference in New Issue
Block a user