feat: update ev cli
This commit is contained in:
@@ -94,6 +94,29 @@ const checkDelete = async (opts?: { force?: boolean; dir?: string; yes?: boolean
|
||||
}
|
||||
}
|
||||
};
|
||||
export const rewritePkg = (packagePath: string, pkg: Package) => {
|
||||
const readJsonFile = (filePath: string) => {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
} catch (error) {
|
||||
return {};
|
||||
}
|
||||
};
|
||||
try {
|
||||
const dirname = path.dirname(packagePath);
|
||||
if (!fs.existsSync(dirname)) {
|
||||
fs.mkdirSync(dirname, { recursive: true });
|
||||
}
|
||||
const json = readJsonFile(packagePath);
|
||||
json.id = pkg?.id;
|
||||
json.appInfo = pkg;
|
||||
|
||||
fs.writeFileSync(packagePath, JSON.stringify(json, null, 2));
|
||||
} catch (error) {
|
||||
fs.writeFileSync(packagePath, JSON.stringify({ appInfo: pkg, id: pkg?.id }, null, 2));
|
||||
}
|
||||
return pkg;
|
||||
};
|
||||
type InstallAppOpts = {
|
||||
appDir?: string;
|
||||
kevisualUrl?: string;
|
||||
@@ -118,7 +141,6 @@ 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 downloadDirPath = appType === 'web' ? path.join(appDir, user, key) : path.join(appDir);
|
||||
@@ -128,9 +150,6 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => {
|
||||
.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 = '';
|
||||
@@ -150,15 +169,7 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => {
|
||||
});
|
||||
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;
|
||||
const downloadUrl = file.downloadUrl;
|
||||
@@ -186,6 +197,7 @@ export const installApp = async (app: Package, opts: InstallAppOpts = {}) => {
|
||||
// fs.writeFileSync(path.join(appDir, `${user}/${key}/index.html`), JSON.stringify(app, null, 2));
|
||||
// }
|
||||
_app.data.files = files;
|
||||
rewritePkg(packagePath, _app);
|
||||
return {
|
||||
code: 200,
|
||||
data: _app,
|
||||
|
||||
Reference in New Issue
Block a user