add test and add micro-app deploy
This commit is contained in:
parent
0ee7d9a69a
commit
c96674349c
6
demo/deploy-org/docs/index.html
Normal file
6
demo/deploy-org/docs/index.html
Normal file
@ -0,0 +1,6 @@
|
||||
this is a test for system user upload to root user
|
||||
|
||||
<script>
|
||||
console.log('hello world');
|
||||
</script>
|
||||
|
16
demo/deploy-org/package.json
Normal file
16
demo/deploy-org/package.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "deploy-org",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"pub": "envision deploy ./docs -k deploy-test -v 0.0.1 -o root"
|
||||
},
|
||||
"files": [
|
||||
"docs"
|
||||
],
|
||||
"keywords": [],
|
||||
"author": "abearxiong <xiongxiao@xiongxiao.me>",
|
||||
"license": "MIT",
|
||||
"type": "module"
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/envision-cli",
|
||||
"version": "0.0.29-alpha.2",
|
||||
"version": "0.0.29",
|
||||
"description": "envision command tools",
|
||||
"main": "dist/index.js",
|
||||
"type": "module",
|
||||
|
@ -13,9 +13,10 @@ export const appCommand = new Command('app').description('app 命令').action(()
|
||||
program.addCommand(appCommand);
|
||||
|
||||
const downloadAppCommand = new Command('download')
|
||||
.description('下载 app serve client的包')
|
||||
.description('下载 app serve client的包. \napp download -i root/code-center')
|
||||
.option('-i, --id <id>', '下载 app serve client的包, id 或者user/key')
|
||||
.option('-o, --output <output>', '下载 app serve client的包, 输出路径')
|
||||
.option('-r, --registry <registry>', '下载 app serve client的包, 使用私有源')
|
||||
.action(async (options) => {
|
||||
const id = options.id || '';
|
||||
if (!id) {
|
||||
@ -31,12 +32,16 @@ const downloadAppCommand = new Command('download')
|
||||
data.id = id;
|
||||
}
|
||||
const res = await queryApp(data);
|
||||
let registry = 'https://kevisual.xiongxiao.me';
|
||||
if (options?.registry) {
|
||||
registry = new URL(options.registry).origin;
|
||||
}
|
||||
if (res.code === 200) {
|
||||
const app = res.data;
|
||||
const result = await installApp(app, {
|
||||
appDir: '',
|
||||
// kevisualUrl: 'https://kevisual.cn',
|
||||
kevisualUrl: 'https://kevisual.xiongxiao.me',
|
||||
kevisualUrl: registry,
|
||||
});
|
||||
if (result.code === 200) {
|
||||
console.log(chalk.green('下载成功', res.data?.user, res.data?.key));
|
||||
@ -85,4 +90,4 @@ const uninstallAppCommand = new Command('uninstall')
|
||||
});
|
||||
|
||||
appCommand.addCommand(downloadAppCommand);
|
||||
appCommand.addCommand(uninstallAppCommand);
|
||||
appCommand.addCommand(uninstallAppCommand);
|
||||
|
@ -32,10 +32,11 @@ program.addCommand(appCommand);
|
||||
|
||||
// https://kevisual.xiongxiao.me/api/micro-app/download/file?notNeedToken=y&title=mark-0.0.2.tgz
|
||||
const downloadAppCommand = new Command('download')
|
||||
.description('下载 app serve client的包')
|
||||
.description('下载 app serve client的包. \nmicro-app download -i mark-0.0.2.tgz -o test/mark.tgz -x test2')
|
||||
.option('-i, --id <id>', '下载 app serve client的包, id 或者title, mark-0.0.2.tgz')
|
||||
.option('-o, --output <output>', '下载 app serve client的包, 输出路径')
|
||||
.option('-x, --extract <extract>', '下载 app serve client的包, 解压, 默认解压到当前目录')
|
||||
.option('-r, --registry <registry>', '下载 app serve client的包, 使用私有源')
|
||||
.action(async (options) => {
|
||||
const id = options.id || '';
|
||||
if (!id) {
|
||||
@ -46,16 +47,21 @@ const downloadAppCommand = new Command('download')
|
||||
if (id.includes('.tgz')) {
|
||||
title = id;
|
||||
}
|
||||
|
||||
let curlUrl = `https://kevisual.xiongxiao.me/api/micro-app/download/${id}?notNeedToken=y`;
|
||||
if (title) {
|
||||
curlUrl = `https://kevisual.xiongxiao.me/api/micro-app/download/file?notNeedToken=y&title=${title}`;
|
||||
let registry = '';
|
||||
if (options?.registry) {
|
||||
registry = new URL(options.registry).origin;
|
||||
} else {
|
||||
registry = 'https://kevisual.xiongxiao.me';
|
||||
}
|
||||
console.log('download url', curlUrl);
|
||||
let curlUrl = `${registry}/api/micro-app/download/${id}?notNeedToken=y`;
|
||||
if (title) {
|
||||
curlUrl = `${registry}/api/micro-app/download/file?notNeedToken=y&title=${title}`;
|
||||
}
|
||||
console.log(chalk.blue('下载地址:'), curlUrl);
|
||||
fetch(curlUrl)
|
||||
.then((res) => {
|
||||
.then(async (res) => {
|
||||
const contentDisposition = res.headers.get('content-disposition');
|
||||
let filename = 'downloaded-file.tgz'; // Default filename
|
||||
let filename = ''; // Default filename
|
||||
|
||||
if (contentDisposition) {
|
||||
const match = contentDisposition.match(/filename="?(.+)"?/);
|
||||
@ -63,7 +69,10 @@ const downloadAppCommand = new Command('download')
|
||||
filename = match[1].replace(/^"|"$/g, '');
|
||||
}
|
||||
}
|
||||
console.log('filename', filename, contentDisposition);
|
||||
if (!filename) {
|
||||
console.log(chalk.red('下载失败: 没有找到下载文件, 请检查下载地址是否正确,或手动下载'));
|
||||
return;
|
||||
}
|
||||
const outputPath = options.output || filename;
|
||||
const fileStream = fs.createWriteStream(outputPath);
|
||||
|
||||
@ -75,13 +84,18 @@ const downloadAppCommand = new Command('download')
|
||||
if (options.extract) {
|
||||
console.log(chalk.green(`解压: ${outputPath}`));
|
||||
const extractPath = path.join(process.cwd(), options.extract || '.');
|
||||
console.log('extractPath', extractPath);
|
||||
// const res = await tar.extract({
|
||||
// file: outputPath,
|
||||
// cwd: extractPath,
|
||||
// });
|
||||
// console.log('res', res);
|
||||
// untar.extract({ file: outputPath, cwd: extractPath });
|
||||
const fileInput = path.join(process.cwd(), outputPath);
|
||||
tar
|
||||
.extract({
|
||||
file: fileInput,
|
||||
cwd: extractPath,
|
||||
})
|
||||
.then((res) => {
|
||||
console.log(chalk.green(`解压成功: ${outputPath}`));
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(chalk.red(`解压失败: ${outputPath}, 请手动解压, tar -xvf ${outputPath}`));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,51 +0,0 @@
|
||||
/**
|
||||
* 下载 app serve client的包的命令
|
||||
*/
|
||||
|
||||
import { chalk } from '@/module/chalk.ts';
|
||||
import { program, Command } from '../program.ts';
|
||||
import { queryApp } from '../query/app-manager/query-app.ts';
|
||||
import { installApp } from '@/module/download/install.ts';
|
||||
export const downloadCommand = new Command('download').description('下载 app serve client的包').action(() => {
|
||||
console.log('download');
|
||||
});
|
||||
|
||||
program.addCommand(downloadCommand);
|
||||
|
||||
const downloadAppCommand = new Command('app')
|
||||
.description('下载 app serve client的包')
|
||||
.option('-i, --id <id>', '下载 app serve client的包, id 或者user/key')
|
||||
.option('-o, --output <output>', '下载 app serve client的包, 输出路径')
|
||||
.action(async (options) => {
|
||||
const id = options.id || '';
|
||||
if (!id) {
|
||||
console.error(chalk.red('id is required'));
|
||||
return;
|
||||
}
|
||||
const [user, key] = id.split('/');
|
||||
const data: any = {};
|
||||
if (user && key) {
|
||||
data.user = user;
|
||||
data.key = key;
|
||||
} else {
|
||||
data.id = id;
|
||||
}
|
||||
const res = await queryApp(data);
|
||||
if (res.code === 200) {
|
||||
const app = res.data;
|
||||
const result = await installApp(app, {
|
||||
appDir: '',
|
||||
// kevisualUrl: 'https://kevisual.cn',
|
||||
kevisualUrl: 'https://kevisual.xiongxiao.me',
|
||||
});
|
||||
if (result.code === 200) {
|
||||
console.log(chalk.green('下载成功', res.data?.user, res.data?.key));
|
||||
} else {
|
||||
console.error(chalk.red(result.message || '下载失败'));
|
||||
}
|
||||
} else {
|
||||
console.error(chalk.red(res.message || '下载失败'));
|
||||
}
|
||||
});
|
||||
|
||||
downloadCommand.addCommand(downloadAppCommand);
|
@ -12,7 +12,6 @@ import './command/npm.ts';
|
||||
import './command/publish.ts';
|
||||
import './command/init.ts';
|
||||
import './command/proxy.ts';
|
||||
// import './command/download.ts';
|
||||
import './command/app/index.ts';
|
||||
|
||||
// program.parse(process.argv);
|
||||
|
Loading…
x
Reference in New Issue
Block a user