Compare commits

...

5 Commits

Author SHA1 Message Date
limix
7b55716742
Merge 2307faf31aa312324c499155705c921720dd712e into 5ca1ba1271c5600270ab8f5c12e92325343e4d13 2024-12-12 08:39:31 +08:00
wangwei1240
5ca1ba1271 feat: 为了更好的安装体验,切换到依赖本地 node 环境 2024-12-11 20:06:21 +08:00
wangwei1240
8c3186afef Merge remote-tracking branch 'origin/master' 2024-12-11 20:05:20 +08:00
wangwei1240
de0e9ed8f2 fix: 更新版本 2024-12-11 20:05:00 +08:00
limix
2307faf31a
Update README.zh-CN.md
添加局限性描述
2024-08-20 23:29:41 +08:00
3 changed files with 39 additions and 26 deletions

View File

@ -90,6 +90,9 @@
[Rubick Plugin CLI](https://github.com/rubickCenter/rubick-plugin-cli) [Rubick Plugin CLI](https://github.com/rubickCenter/rubick-plugin-cli)
## 局限性
npm包最终大小不宜超过100MB,所以插件包大小也不宜超过此大小,建议20MB以内,如果包体积过大,预期会导致推送npm仓库失败
## 赞助 ## 赞助
### 1. 加入知识星球 ### 1. 加入知识星球
我们在知识星球积累了大量的关于 rubick 的知识和常见问题,您可以付费加入我们的知识星球来一起讨论。我们将随时解答! 我们在知识星球积累了大量的关于 rubick 的知识和常见问题,您可以付费加入我们的知识星球来一起讨论。我们将随时解答!

View File

@ -1,6 +1,6 @@
{ {
"name": "rubick", "name": "rubick",
"version": "4.2.9", "version": "4.3.0",
"author": "muwoo <2424880409@qq.com>", "author": "muwoo <2424880409@qq.com>",
"private": true, "private": true,
"scripts": { "scripts": {

View File

@ -7,11 +7,10 @@ import path from 'path';
import got from 'got'; import got from 'got';
import fixPath from 'fix-path'; import fixPath from 'fix-path';
import spawn from 'cross-spawn';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
import axios from 'axios'; import axios from 'axios';
import npm from 'npm';
fixPath(); fixPath();
/** /**
@ -42,7 +41,7 @@ class AdapterHandler {
} }
this.baseDir = options.baseDir; this.baseDir = options.baseDir;
let register = options.registry || 'https://registry.npmmirror.com/'; let register = options.registry || 'https://registry.npm.taobao.org';
try { try {
const dbdata = ipcRenderer.sendSync('msg-trigger', { const dbdata = ipcRenderer.sendSync('msg-trigger', {
@ -61,7 +60,7 @@ class AdapterHandler {
const packageJSON = JSON.parse( const packageJSON = JSON.parse(
fs.readFileSync(`${this.baseDir}/package.json`, 'utf-8') fs.readFileSync(`${this.baseDir}/package.json`, 'utf-8')
); );
const registryUrl = `${this.registry}${name}`; const registryUrl = `https://registry.npm.taobao.org/${name}`;
// 从npm源中获取依赖包的最新版本 // 从npm源中获取依赖包的最新版本
try { try {
@ -158,32 +157,43 @@ class AdapterHandler {
*/ */
private async execCommand(cmd: string, modules: string[]): Promise<string> { private async execCommand(cmd: string, modules: string[]): Promise<string> {
return new Promise((resolve: any, reject: any) => { return new Promise((resolve: any, reject: any) => {
const module = let args: string[] = [cmd].concat(
cmd !== 'uninstall' && cmd !== 'link' cmd !== 'uninstall' && cmd !== 'link'
? modules.map((m) => `${m}@latest`) ? modules.map((m) => `${m}@latest`)
: modules; : modules
const config: any = { );
prefix: this.baseDir,
save: true,
cache: path.join(this.baseDir, 'cache'),
};
if (cmd !== 'link') { if (cmd !== 'link') {
config.registry = this.registry; args = args
} .concat('--color=always')
npm.load(config, function (err) { .concat('--save')
npm.commands[cmd](module, function (er, data) { .concat(`--registry=${this.registry}`);
if (!err) {
console.log(data);
resolve({ code: -1, data });
} else {
reject({ code: -1, data: err });
} }
const npm = spawn('npm', args, {
cwd: this.baseDir,
}); });
npm.on('log', function (message) { console.log(args);
// log installation progress
console.log(message); let output = '';
}); npm.stdout
.on('data', (data: string) => {
output += data; // 获取输出日志
})
.pipe(process.stdout);
npm.stderr
.on('data', (data: string) => {
output += data; // 获取报错日志
})
.pipe(process.stderr);
npm.on('close', (code: number) => {
if (!code) {
resolve({ code: 0, data: output }); // 如果没有报错就输出正常日志
} else {
reject({ code: code, data: output }); // 如果报错就输出报错日志
}
}); });
}); });
} }