add install base

This commit is contained in:
2025-05-17 03:32:38 +08:00
parent 717e434ce0
commit 035ddc248c
28 changed files with 667 additions and 260 deletions

View File

@@ -66,7 +66,7 @@ const downloadAppCommand = new Command('download')
registry = new URL(config.baseURL).origin;
}
const res = await queryApp(data, { url: getUrl(registry) });
console.log('registry', registry, data);
console.log('registry', registry, data, options.type);
if (res.code === 200) {
const app = res.data;
let appType: 'app' | 'web' = 'web';

View File

@@ -81,23 +81,44 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => {
try {
let files = _app.data.files || [];
const version = _app.version;
let hasPackage = false;
const user = _app.user;
const key = _app.key;
const downFiles = files.map((file: any) => {
const noVersionPath = file.path.replace(`/${version}`, '');
let downloadPath = noVersionPath;
if (appType === 'app') {
downloadPath = noVersionPath.replace(`${user}/${key}/`, '');
}
return {
...file,
downloadPath: path.join(appDir, downloadPath),
downloadUrl: `${kevisualUrl}/${noVersionPath}`,
};
});
const packagePath = path.join(appDir, appType === 'app' ? 'package.json' : `${user}/${key}/package.json`);
const downFiles = files
.filter((file: any) => file?.path)
.map((file: any) => {
const name = file?.name || '';
if (name.startsWith('package.json')) {
hasPackage = true;
}
const noVersionPath = file.path.replace(`/${version}`, '');
let downloadPath = noVersionPath;
let downloadUrl = '';
if (appType === 'app') {
downloadPath = noVersionPath.replace(`${user}/${key}/`, '');
}
if (file.path.startsWith('http')) {
downloadUrl = file.path;
} else {
downloadUrl = `${kevisualUrl}/${noVersionPath}`;
}
return {
...file,
downloadPath: path.join(appDir, downloadPath),
downloadUrl: downloadUrl,
};
});
const downloadTasks: DownloadTask[] = downFiles as any;
console.log('downloadTasks', downloadTasks);
if (!hasPackage) {
console.log('没有package.json文件, 生成一个');
const pkg = { ..._app };
if (pkg.data) {
delete pkg.data.permission;
}
fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2));
}
// return;
for (const file of downloadTasks) {
const downloadPath = file.downloadPath;