Skip to content

Commit

Permalink
add a custom npm path option (fixes #10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Jul 5, 2017
1 parent 48e8ffd commit f2a8eb9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
2 changes: 1 addition & 1 deletion terminus-core/src/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions terminus-plugin-manager/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ConfigProvider } from 'terminus-core'

export class PluginsConfigProvider extends ConfigProvider {
defaults = {
npm: 'npm',
}
}
3 changes: 3 additions & 0 deletions terminus-plugin-manager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -19,6 +21,7 @@ import { PluginsSettingsTabProvider } from './settings'
],
providers: [
{ provide: SettingsTabProvider, useClass: PluginsSettingsTabProvider, multi: true },
{ provide: ConfigProvider, useClass: PluginsConfigProvider, multi: true },
PluginManagerService,
],
entryComponents: [
Expand Down
10 changes: 5 additions & 5 deletions terminus-plugin-manager/src/services/pluginManager.service.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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
Expand All @@ -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)
}
}

0 comments on commit f2a8eb9

Please sign in to comment.