mirror of
https://github.com/rubickCenter/rubick
synced 2025-12-26 12:42:34 +08:00
bugfix: 修复 安装包下载
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
import {WINDOW_MAX_HEIGHT, WINDOW_MIN_HEIGHT, PRE_ITEM_HEIGHT, SYSTEM_PLUGINS} from './constans';
|
||||
import download from 'download-git-repo';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import process from 'child_process';
|
||||
import Store from 'electron-store';
|
||||
import downloadFile from 'download';
|
||||
import {nativeImage} from 'electron';
|
||||
import {APP_FINDER_PATH} from './constans';
|
||||
import {getlocalDataFile} from "../../../main/common/utils";
|
||||
|
||||
const store = new Store();
|
||||
|
||||
@@ -35,69 +34,21 @@ function existOrNot(path) {
|
||||
});
|
||||
}
|
||||
|
||||
function mkdirFolder(name) {
|
||||
return new Promise((resolve, reject) => {
|
||||
process.exec(`mkdir ${name}`, async function (error, stdout, stderr) {
|
||||
if (error) {
|
||||
reject(false);
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
const appPath = getlocalDataFile();
|
||||
|
||||
async function downloadZip(downloadRepoUrl, name) {
|
||||
try {
|
||||
const plugin_path = path.join(__static, './plugins');
|
||||
const targetUrl = downloadRepoUrl ? downloadRepoUrl : `https://github.com/clouDr-f2e/${name}/archive/refs/heads/master.zip`;
|
||||
if (!(await existOrNot(plugin_path))) {
|
||||
await mkdirFolder(plugin_path);
|
||||
}
|
||||
const plugin_path = appPath;
|
||||
// 基础模版所在目录,如果是初始化,则是模板名称,否则是项目名称
|
||||
const temp_dest = `${plugin_path}/${name}-master`;
|
||||
// 下载模板
|
||||
if (await existOrNot(temp_dest)) {
|
||||
await process.execSync(`rm -rf ${temp_dest}`);
|
||||
}
|
||||
await downloadFile(targetUrl, `${__static}/plugins`,{extract: true})
|
||||
// const temp_dest = `${plugin_path}/${name}`;
|
||||
await downloadFile(downloadRepoUrl, plugin_path,{extract: true});
|
||||
|
||||
return `${plugin_path}/${name}`
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
function downloadFunc(downloadRepoUrl, name) {
|
||||
const targetGit = downloadRepoUrl ? downloadRepoUrl : `github:clouDr-f2e/${name}`;
|
||||
const plugin_path = path.join(__static, './plugins');
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
if (!(await existOrNot(plugin_path))) {
|
||||
await mkdirFolder(plugin_path);
|
||||
}
|
||||
// 基础模版所在目录,如果是初始化,则是模板名称,否则是项目名称
|
||||
const temp_dest = `${plugin_path}/${name}`;
|
||||
// 下载模板
|
||||
if (await existOrNot(temp_dest)) {
|
||||
await process.execSync(`rm -rf ${temp_dest}`);
|
||||
}
|
||||
|
||||
download(targetGit, temp_dest, {clone: true}, function (err) {
|
||||
console.log(err ? 'Error' : 'Success')
|
||||
if (err) {
|
||||
console.log(err);
|
||||
reject('请求模板下载失败');
|
||||
} else {
|
||||
resolve('请求模板下载成功');
|
||||
}
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
const sysFile = {
|
||||
savePlugins(plugins) {
|
||||
store.set('user-plugins', plugins);
|
||||
@@ -113,7 +64,6 @@ const sysFile = {
|
||||
store.delete('user-plugins');
|
||||
}
|
||||
}
|
||||
sysFile.removeAllPlugins()
|
||||
|
||||
function mergePlugins(plugins) {
|
||||
return [
|
||||
@@ -218,7 +168,6 @@ function debounce(fn, delay) {
|
||||
export {
|
||||
getWindowHeight,
|
||||
searchKeyValues,
|
||||
downloadFunc,
|
||||
sysFile,
|
||||
mergePlugins,
|
||||
find,
|
||||
|
||||
Reference in New Issue
Block a user