mirror of
https://gitee.com/eolink_admin/postcat.git
synced 2024-12-02 11:47:57 +08:00
feat: set registry automaic
This commit is contained in:
parent
831b4bce2b
commit
8f641799d6
@ -69,6 +69,13 @@ export class ModuleHandler extends CoreHandler {
|
|||||||
* @param isLocal 本地安装用link
|
* @param isLocal 本地安装用link
|
||||||
*/
|
*/
|
||||||
async install(modules: any[], isLocal: boolean): Promise<ModuleHandlerResult> {
|
async install(modules: any[], isLocal: boolean): Promise<ModuleHandlerResult> {
|
||||||
|
// * Check the registry before install
|
||||||
|
// const check = spawn('npm', ['config', 'get', 'registry']);
|
||||||
|
// check.stdout
|
||||||
|
// .on('data', (data: string) => {
|
||||||
|
// console.log('===========>>>>>>>>', data.toString());
|
||||||
|
// })
|
||||||
|
// .pipe(process.stdout);
|
||||||
return await this.execCommand(isLocal ? 'link' : 'install', modules);
|
return await this.execCommand(isLocal ? 'link' : 'install', modules);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -137,34 +144,12 @@ export class ModuleHandler extends CoreHandler {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private executeBySystemNpm(command: string, modules: string[], resolve) {
|
private setRegistry() {
|
||||||
let args = [command].concat(modules).concat('--color=always', '--save');
|
return new Promise(resolve => {
|
||||||
if (!['link', 'unlink', 'uninstall', 'update'].includes(command)) {
|
const npm = spawn('npm', ['config', 'set', 'registry', this.registry], { cwd: this.baseDir });
|
||||||
if (this.registry) {
|
npm.on('close', () => {
|
||||||
args = args.concat(`--registry=${this.registry}`);
|
resolve(true);
|
||||||
}
|
});
|
||||||
if (this.proxy) {
|
|
||||||
args = args.concat(`--proxy=${this.proxy}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const npm = spawn('npm', args, { cwd: this.baseDir });
|
|
||||||
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 {
|
|
||||||
resolve({ code: code, data: output });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -174,8 +159,11 @@ export class ModuleHandler extends CoreHandler {
|
|||||||
* @param modules
|
* @param modules
|
||||||
*/
|
*/
|
||||||
private async execCommand(command: string, modules: any[]): Promise<ModuleHandlerResult> {
|
private async execCommand(command: string, modules: any[]): Promise<ModuleHandlerResult> {
|
||||||
return await new Promise((resolve: any, reject: any): void => {
|
return await new Promise(async (resolve: any, reject: any): Promise<void> => {
|
||||||
// this.executeBySystemNpm(command, modules, resolve)
|
// this.executeBySystemNpm(command, modules, resolve)
|
||||||
|
// * Set Proxy
|
||||||
|
// * Set registry
|
||||||
|
await this.setRegistry();
|
||||||
this.executeByAppNpm(command, modules, resolve, reject);
|
this.executeByAppNpm(command, modules, resolve, reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { LanguageService } from 'eo/app/electron-main/language.service';
|
||||||
import { isNotEmpty } from 'eo/shared/common/common';
|
import { isNotEmpty } from 'eo/shared/common/common';
|
||||||
import { HOME_DIR } from 'eo/shared/electron-main/constant';
|
import { HOME_DIR } from 'eo/shared/electron-main/constant';
|
||||||
import { ExtensionInfo, SidebarView, FeatureInfo } from 'eo/workbench/browser/src/app/shared/models/extension-manager';
|
import { ExtensionInfo, SidebarView, FeatureInfo } from 'eo/workbench/browser/src/app/shared/models/extension-manager';
|
||||||
@ -43,8 +44,14 @@ export class ModuleManager {
|
|||||||
*/
|
*/
|
||||||
private readonly features: Map<string, Map<string, FeatureInfo>>;
|
private readonly features: Map<string, Map<string, FeatureInfo>>;
|
||||||
|
|
||||||
|
private lang;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.moduleHandler = new ModuleHandler({ baseDir: HOME_DIR });
|
this.lang = LanguageService;
|
||||||
|
this.moduleHandler = new ModuleHandler({
|
||||||
|
baseDir: HOME_DIR,
|
||||||
|
registry: this.lang.get === 'zh-Hans' ? 'https://registry.npmmirror.com' : 'https://registry.npmjs.org'
|
||||||
|
});
|
||||||
this.modules = new Map();
|
this.modules = new Map();
|
||||||
this.features = new Map();
|
this.features = new Map();
|
||||||
this.init();
|
this.init();
|
||||||
|
Loading…
Reference in New Issue
Block a user