mirror of
https://github.com/rubickCenter/rubick
synced 2025-06-29 01:02:47 +08:00
Compare commits
1 Commits
7b55716742
...
241095664d
Author | SHA1 | Date | |
---|---|---|---|
|
241095664d |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "rubick",
|
"name": "rubick",
|
||||||
"version": "4.3.0",
|
"version": "4.2.9",
|
||||||
"author": "muwoo <2424880409@qq.com>",
|
"author": "muwoo <2424880409@qq.com>",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -7,10 +7,11 @@ 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();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,7 +42,7 @@ class AdapterHandler {
|
|||||||
}
|
}
|
||||||
this.baseDir = options.baseDir;
|
this.baseDir = options.baseDir;
|
||||||
|
|
||||||
let register = options.registry || 'https://registry.npm.taobao.org';
|
let register = options.registry || 'https://registry.npmmirror.com/';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const dbdata = ipcRenderer.sendSync('msg-trigger', {
|
const dbdata = ipcRenderer.sendSync('msg-trigger', {
|
||||||
@ -60,7 +61,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 = `https://registry.npm.taobao.org/${name}`;
|
const registryUrl = `${this.registry}${name}`;
|
||||||
|
|
||||||
// 从npm源中获取依赖包的最新版本
|
// 从npm源中获取依赖包的最新版本
|
||||||
try {
|
try {
|
||||||
@ -157,43 +158,32 @@ 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) => {
|
||||||
let args: string[] = [cmd].concat(
|
const module =
|
||||||
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') {
|
||||||
args = args
|
config.registry = this.registry;
|
||||||
.concat('--color=always')
|
|
||||||
.concat('--save')
|
|
||||||
.concat(`--registry=${this.registry}`);
|
|
||||||
}
|
}
|
||||||
|
npm.load(config, function (err) {
|
||||||
|
npm.commands[cmd](module, function (er, data) {
|
||||||
|
if (!err) {
|
||||||
|
console.log(data);
|
||||||
|
resolve({ code: -1, data });
|
||||||
|
} else {
|
||||||
|
reject({ code: -1, data: err });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const npm = spawn('npm', args, {
|
npm.on('log', function (message) {
|
||||||
cwd: this.baseDir,
|
// log installation progress
|
||||||
});
|
console.log(message);
|
||||||
|
});
|
||||||
console.log(args);
|
|
||||||
|
|
||||||
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 }); // 如果报错就输出报错日志
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user