fix: 更新初始化和pack的 cmd

This commit is contained in:
2025-11-17 18:14:47 +08:00
parent 5df5a943ed
commit ba171fb744
5 changed files with 408 additions and 258 deletions

View File

@@ -6,7 +6,6 @@ import FormData from 'form-data';
import { getBaseURL, query, storage } from '@/module/query.ts';
import { getConfig } from '@/module/index.ts';
import inquirer from 'inquirer';
import { packLib, unpackLib } from './publish.ts';
import chalk from 'chalk';
import { installDeps } from '@/uitls/npm.ts';
import { upload } from '@/module/download/upload.ts';
@@ -293,42 +292,3 @@ const deployLoad = new Command('deploy-load')
});
app.addCommand(deployLoad);
const local = new Command('local')
.description('本地部署')
.argument('<key>', 'key')
.option('-i, --ignore', '使用 .npmignore 文件模式去忽略文件进行打包, 不需要package.json中的files字段')
.option('-u, --update', 'query查询 127.0.0.1:11015/api/router?path=local-apps&key=detect')
.action(async (key, opts) => {
console.log('local deploy');
const { outputFilePath } = await packLib(opts?.ignore);
const mainAppPath = getConfig().mainAppPath;
const appsPath = getConfig().appsPath || path.join(mainAppPath, 'apps');
if (!key) {
console.error(chalk.red('key is required'));
return;
}
const appPath = path.join(appsPath, key);
if (!fs.existsSync(appPath)) {
fs.mkdirSync(appPath, { recursive: true });
}
// 复制应用到apps目录下
if (outputFilePath) {
await unpackLib(outputFilePath, appPath);
fs.unlinkSync(outputFilePath);
installDeps({ appPath });
if (opts?.update) {
const res = await query.post(
{ path: 'local-apps', key: 'detect' },
{
url: `http://127.0.0.1:11015/api/router?path=local-apps&key=detect`,
},
);
if (res.code === 200) {
console.log('local deploy success');
} else {
console.error('local deploy failed', res.message);
}
}
}
});
app.addCommand(local);