add a custom npm path option (fixes #10)

This commit is contained in:
Eugene Pankov 2017-07-05 11:35:50 +02:00
parent 48e8ffd729
commit f2a8eb92a1
5 changed files with 18 additions and 8 deletions

View file

@ -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)

View file

@ -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

View file

@ -0,0 +1,7 @@
import { ConfigProvider } from 'terminus-core'
export class PluginsConfigProvider extends ConfigProvider {
defaults = {
npm: 'npm',
}
}

View file

@ -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: [

View file

@ -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<boolean> {
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)
}
}