fix bugs and change version

This commit is contained in:
熊潇 2024-10-10 02:10:16 +08:00
parent 2d2cabde75
commit edb0d56094
5 changed files with 84 additions and 15 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@kevisual/envision-cli",
"version": "0.0.1",
"version": "0.0.3",
"description": "envision command tools",
"main": "dist/index.js",
"type": "module",

View File

@ -2,7 +2,7 @@ import { program , Command} from 'commander';
import fs from 'fs';
// 将多个子命令加入主程序中
program.name('app').description('A CLI tool with envison').version('0.0.1');
program.name('app').description('A CLI tool with envison').version('0.0.3');
const ls =new Command('ls')
.description('List files in the current directory')

View File

@ -12,9 +12,10 @@ const command = new Command('deploy')
.argument('<filePath>', 'Path to the file to be uploaded') // 定义文件路径参数
.option('-v, --version <version>', 'verbose')
.option('-k, --key <key>', 'key')
.option('-y, --yes <yes>', 'yes')
.action(async (filePath, options) => {
try {
let { version, key } = options;
let { version, key, yes } = options;
if (!version || !key) {
const answers = await inquirer.prompt([
{
@ -36,20 +37,22 @@ const command = new Command('deploy')
const pwd = process.cwd();
const directory = path.join(pwd, filePath);
const gPath = path.join(directory, '**/*');
const files = await glob(gPath, { cwd: pwd, ignore: ['node_modules/**/*'] });
const files = await glob(gPath, { cwd: pwd, ignore: ['node_modules/**/*'], nodir: true });
const _relativeFiles = files.map((file) => file.replace(directory + '/', ''));
console.log('upload Files', _relativeFiles);
console.log('upload Files Key', key, version);
// 确认是否上传
const confirm = await inquirer.prompt([
{
type: 'confirm',
name: 'confirm',
message: 'Do you want to upload these files?',
},
]);
if (!confirm.confirm) {
return;
if (!yes) {
// 确认是否上传
const confirm = await inquirer.prompt([
{
type: 'confirm',
name: 'confirm',
message: 'Do you want to upload these files?',
},
]);
if (!confirm.confirm) {
return;
}
}
const res = await uploadFiles(_relativeFiles, directory, { key, version });

View File

@ -1,6 +1,6 @@
import { app, program, Command } from '@/app.ts';
import { getConfig, writeConfig } from '@/module/get-config.ts';
import { queryLogin, queryMe } from '@/route/index.ts';
import { queryLogin, queryMe, switchOrg, switchMe } from '@/route/index.ts';
import inquirer from 'inquirer';
// 导入 login 命令
@ -57,3 +57,50 @@ const loginCommand = new Command('login')
});
app.addCommand(loginCommand);
const showMe = async () => {
const me = await queryMe();
if (me.code === 200) {
console.log('Me', me.data);
} else {
console.log('Me failed', me.message);
}
};
const switchOrgCommand = new Command('switchOrg').argument('<username>', 'Switch to another organization').action(async (options) => {
// console.log('options', options);
const config = getConfig();
if (!config.token) {
console.log('Please login first');
return;
}
const res = await switchOrg(options);
if (res.code === 200) {
const token = res.data.token;
writeConfig({ ...config, token });
console.log('Switch Org Success');
showMe();
} else {
console.log('Switch Org Failed', res.message || '');
}
});
app.addCommand(switchOrgCommand);
const switchMeCommand = new Command('switchMe').action(async () => {
const config = getConfig();
if (!config.token) {
console.log('Please login first');
return;
}
const res = await switchMe();
if (res.code === 200) {
const token = res.data.token;
writeConfig({ ...config, token });
console.log('Switch Me Success');
showMe();
} else {
console.log('Switch Me Failed', res.message || '');
}
});
app.addCommand(switchMeCommand);

View File

@ -17,3 +17,22 @@ export const queryMe = async () => {
key: 'me',
});
};
export const switchOrg = async (username) => {
return await query.post({
path: 'user',
key: 'switchOrg',
data: {
username,
},
});
};
export const switchMe = async () => {
return await query.post({
path: 'user',
key: 'switchOrg',
data: {
type: 'user',
},
});
};