diff --git a/demo/deploy-org/docs/index.html b/demo/deploy-org/docs/index.html new file mode 100644 index 0000000..971a69a --- /dev/null +++ b/demo/deploy-org/docs/index.html @@ -0,0 +1,6 @@ +this is a test for system user upload to root user + + + diff --git a/demo/deploy-org/package.json b/demo/deploy-org/package.json new file mode 100644 index 0000000..4b20fbc --- /dev/null +++ b/demo/deploy-org/package.json @@ -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 ", + "license": "MIT", + "type": "module" +} diff --git a/package.json b/package.json index fc8433d..fe2ea7f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/command/app/front-app/index.ts b/src/command/app/front-app/index.ts index 091c02f..a517d0b 100644 --- a/src/command/app/front-app/index.ts +++ b/src/command/app/front-app/index.ts @@ -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 ', '下载 app serve client的包, id 或者user/key') .option('-o, --output ', '下载 app serve client的包, 输出路径') + .option('-r, --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); \ No newline at end of file +appCommand.addCommand(uninstallAppCommand); diff --git a/src/command/app/micro-app/index.ts b/src/command/app/micro-app/index.ts index 668d5fb..592832b 100644 --- a/src/command/app/micro-app/index.ts +++ b/src/command/app/micro-app/index.ts @@ -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 ', '下载 app serve client的包, id 或者title, mark-0.0.2.tgz') .option('-o, --output ', '下载 app serve client的包, 输出路径') .option('-x, --extract ', '下载 app serve client的包, 解压, 默认解压到当前目录') + .option('-r, --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}`)); + }); } }); diff --git a/src/command/download.ts b/src/command/download.ts deleted file mode 100644 index 7c9ce6d..0000000 --- a/src/command/download.ts +++ /dev/null @@ -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 ', '下载 app serve client的包, id 或者user/key') - .option('-o, --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); diff --git a/src/index.ts b/src/index.ts index ea1ecb3..c6155f0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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);