From f2a8eb92a18c4329a78688b1b87bfb11c7c6f1de Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Wed, 5 Jul 2017 11:35:50 +0200 Subject: [PATCH] add a custom npm path option (fixes #10) --- terminus-core/src/services/config.service.ts | 2 +- .../src/components/pluginsSettingsTab.component.pug | 4 ++-- terminus-plugin-manager/src/config.ts | 7 +++++++ terminus-plugin-manager/src/index.ts | 3 +++ .../src/services/pluginManager.service.ts | 10 +++++----- 5 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 terminus-plugin-manager/src/config.ts diff --git a/terminus-core/src/services/config.service.ts b/terminus-core/src/services/config.service.ts index 0fe1474ebf..bfe9e92304 100644 --- a/terminus-core/src/services/config.service.ts +++ b/terminus-core/src/services/config.service.ts @@ -67,7 +67,7 @@ export class ConfigService { this.defaults = configProviders.map(provider => { let defaults = {} if (provider.platformDefaults) { - defaults = configMerge(defaults, provider.platformDefaults[hostApp.platform]) + defaults = configMerge(defaults, provider.platformDefaults[hostApp.platform] || {}) } if (provider.defaults) { defaults = configMerge(defaults, provider.defaults) diff --git a/terminus-plugin-manager/src/components/pluginsSettingsTab.component.pug b/terminus-plugin-manager/src/components/pluginsSettingsTab.component.pug index 072c0f9634..8264573018 100644 --- a/terminus-plugin-manager/src/components/pluginsSettingsTab.component.pug +++ b/terminus-plugin-manager/src/components/pluginsSettingsTab.component.pug @@ -42,11 +42,11 @@ h3 Installed .text-center.mt-5(*ngIf='npmMissing') h4 npm not installed - p.mb-2 a(href='https://www.npmjs.com/')npm is required to install Terminus plugins. + p.mb-2 npm is required to install Terminus plugins. .btn-group button.btn.btn-outline-primary((click)='downloadNPM()') i.fa.fa-download - span Download NPM + span Get npm button.btn.btn-outline-info((click)='checkNPM()') i.fa.fa-refresh span Try again diff --git a/terminus-plugin-manager/src/config.ts b/terminus-plugin-manager/src/config.ts new file mode 100644 index 0000000000..9ea4ee4de5 --- /dev/null +++ b/terminus-plugin-manager/src/config.ts @@ -0,0 +1,7 @@ +import { ConfigProvider } from 'terminus-core' + +export class PluginsConfigProvider extends ConfigProvider { + defaults = { + npm: 'npm', + } +} diff --git a/terminus-plugin-manager/src/index.ts b/terminus-plugin-manager/src/index.ts index e3b7d58a44..e091249116 100644 --- a/terminus-plugin-manager/src/index.ts +++ b/terminus-plugin-manager/src/index.ts @@ -4,10 +4,12 @@ import { FormsModule } from '@angular/forms' import { NgPipesModule } from 'ngx-pipes' import { NgbModule } from '@ng-bootstrap/ng-bootstrap' +import { ConfigProvider } from 'terminus-core' import { SettingsTabProvider } from 'terminus-settings' import { PluginsSettingsTabComponent } from './components/pluginsSettingsTab.component' import { PluginManagerService } from './services/pluginManager.service' +import { PluginsConfigProvider } from './config' import { PluginsSettingsTabProvider } from './settings' @NgModule({ @@ -19,6 +21,7 @@ import { PluginsSettingsTabProvider } from './settings' ], providers: [ { provide: SettingsTabProvider, useClass: PluginsSettingsTabProvider, multi: true }, + { provide: ConfigProvider, useClass: PluginsConfigProvider, multi: true }, PluginManagerService, ], entryComponents: [ diff --git a/terminus-plugin-manager/src/services/pluginManager.service.ts b/terminus-plugin-manager/src/services/pluginManager.service.ts index 952c9dc6af..f1645f6c90 100644 --- a/terminus-plugin-manager/src/services/pluginManager.service.ts +++ b/terminus-plugin-manager/src/services/pluginManager.service.ts @@ -1,6 +1,6 @@ import { Observable } from 'rxjs' import { Injectable } from '@angular/core' -import { Logger, LogService } from 'terminus-core' +import { Logger, LogService, ConfigService } from 'terminus-core' import { exec } from 'mz/child_process' import axios from 'axios' @@ -23,17 +23,17 @@ export class PluginManagerService { builtinPluginsPath: string = (window as any).builtinPluginsPath userPluginsPath: string = (window as any).userPluginsPath installedPlugins: IPluginInfo[] = (window as any).installedPlugins - npmBinary = 'npm' constructor ( log: LogService, + private config: ConfigService, ) { this.logger = log.create('pluginManager') } async isNPMInstalled (): Promise { try { - await exec(`${this.npmBinary} -v`) + await exec(`${this.config.store.npm} -v`) return true } catch (_) { return false @@ -56,14 +56,14 @@ export class PluginManagerService { } async installPlugin (plugin: IPluginInfo) { - let result = await exec(`${this.npmBinary} --prefix "${this.userPluginsPath}" install ${plugin.packageName}@${plugin.version}`) + let result = await exec(`${this.config.store.npm} --prefix "${this.userPluginsPath}" install ${plugin.packageName}@${plugin.version}`) console.log(result) this.installedPlugins = this.installedPlugins.filter(x => x.packageName !== plugin.packageName) this.installedPlugins.push(plugin) } async uninstallPlugin (plugin: IPluginInfo) { - await exec(`${this.npmBinary} --prefix "${this.userPluginsPath}" remove ${plugin.packageName}`) + await exec(`${this.config.store.npm} --prefix "${this.userPluginsPath}" remove ${plugin.packageName}`) this.installedPlugins = this.installedPlugins.filter(x => x.packageName !== plugin.packageName) } }