mirror of
https://github.com/Eugeny/tabby.git
synced 2025-06-08 21:40:03 +00:00
fixed #2 - search for NPM in profile search paths
This commit is contained in:
parent
c0c2373ed6
commit
da89560d6b
@ -36,7 +36,8 @@
|
|||||||
"rxjs": "5.3.0"
|
"rxjs": "5.3.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.16.2"
|
"axios": "^0.16.2",
|
||||||
|
"mz": "^2.6.0"
|
||||||
},
|
},
|
||||||
"false": {}
|
"false": {}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import { Observable } from 'rxjs'
|
import * as path from 'path'
|
||||||
import { Injectable } from '@angular/core'
|
import * as fs from 'mz/fs'
|
||||||
import { Logger, LogService, ConfigService } from 'terminus-core'
|
|
||||||
import { exec } from 'mz/child_process'
|
import { exec } from 'mz/child_process'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
|
import { Observable } from 'rxjs'
|
||||||
|
import { Injectable } from '@angular/core'
|
||||||
|
import { Logger, LogService, ConfigService, HostAppService, Platform } from 'terminus-core'
|
||||||
|
|
||||||
const NAME_PREFIX = 'terminus-'
|
const NAME_PREFIX = 'terminus-'
|
||||||
const KEYWORD = 'terminus-plugin'
|
const KEYWORD = 'terminus-plugin'
|
||||||
@ -23,17 +25,35 @@ export class PluginManagerService {
|
|||||||
builtinPluginsPath: string = (window as any).builtinPluginsPath
|
builtinPluginsPath: string = (window as any).builtinPluginsPath
|
||||||
userPluginsPath: string = (window as any).userPluginsPath
|
userPluginsPath: string = (window as any).userPluginsPath
|
||||||
installedPlugins: IPluginInfo[] = (window as any).installedPlugins
|
installedPlugins: IPluginInfo[] = (window as any).installedPlugins
|
||||||
|
npmPath: string
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
log: LogService,
|
log: LogService,
|
||||||
private config: ConfigService,
|
private config: ConfigService,
|
||||||
|
private hostApp: HostAppService,
|
||||||
) {
|
) {
|
||||||
this.logger = log.create('pluginManager')
|
this.logger = log.create('pluginManager')
|
||||||
|
this.detectPath()
|
||||||
|
}
|
||||||
|
|
||||||
|
async detectPath () {
|
||||||
|
this.npmPath = this.config.store.npm
|
||||||
|
if (this.hostApp.platform !== Platform.Windows) {
|
||||||
|
let searchPaths = (await exec('bash -c -l "echo $PATH"'))[0].toString().trim().split(':')
|
||||||
|
for (let searchPath of searchPaths) {
|
||||||
|
if (await fs.exists(path.join(searchPath, 'npm'))) {
|
||||||
|
this.logger.debug('Found npm in', searchPath)
|
||||||
|
this.npmPath = path.join(searchPath, 'npm')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async isNPMInstalled (): Promise<boolean> {
|
async isNPMInstalled (): Promise<boolean> {
|
||||||
|
await this.detectPath()
|
||||||
try {
|
try {
|
||||||
await exec(`${this.config.store.npm} -v`)
|
await exec(`${this.npmPath} -v`)
|
||||||
return true
|
return true
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
return false
|
return false
|
||||||
@ -56,14 +76,14 @@ export class PluginManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async installPlugin (plugin: IPluginInfo) {
|
async installPlugin (plugin: IPluginInfo) {
|
||||||
let result = await exec(`${this.config.store.npm} --prefix "${this.userPluginsPath}" install ${plugin.packageName}@${plugin.version}`)
|
let result = await exec(`${this.npmPath} --prefix "${this.userPluginsPath}" install ${plugin.packageName}@${plugin.version}`)
|
||||||
console.log(result)
|
console.log(result)
|
||||||
this.installedPlugins = this.installedPlugins.filter(x => x.packageName !== plugin.packageName)
|
this.installedPlugins = this.installedPlugins.filter(x => x.packageName !== plugin.packageName)
|
||||||
this.installedPlugins.push(plugin)
|
this.installedPlugins.push(plugin)
|
||||||
}
|
}
|
||||||
|
|
||||||
async uninstallPlugin (plugin: IPluginInfo) {
|
async uninstallPlugin (plugin: IPluginInfo) {
|
||||||
await exec(`${this.config.store.npm} --prefix "${this.userPluginsPath}" remove ${plugin.packageName}`)
|
await exec(`${this.npmPath} --prefix "${this.userPluginsPath}" remove ${plugin.packageName}`)
|
||||||
this.installedPlugins = this.installedPlugins.filter(x => x.packageName !== plugin.packageName)
|
this.installedPlugins = this.installedPlugins.filter(x => x.packageName !== plugin.packageName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,10 +37,10 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
externals: [
|
externals: [
|
||||||
'fs',
|
'fs',
|
||||||
'fs-promise',
|
|
||||||
'font-manager',
|
'font-manager',
|
||||||
'path',
|
'path',
|
||||||
'node-pty',
|
'node-pty',
|
||||||
|
'mz/fs',
|
||||||
'mz/child_process',
|
'mz/child_process',
|
||||||
'winreg',
|
'winreg',
|
||||||
/^rxjs/,
|
/^rxjs/,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user