mirror of
https://github.com/Eugeny/tabby.git
synced 2025-07-19 18:07:58 +00:00
wip
This commit is contained in:
40
app/lib/pluginManager.ts
Normal file
40
app/lib/pluginManager.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { promisify } from 'util'
|
||||
|
||||
|
||||
export class PluginManager {
|
||||
npm: any
|
||||
npmReady?: Promise<void>
|
||||
|
||||
async ensureLoaded (): Promise<void> {
|
||||
if (!this.npmReady) {
|
||||
this.npmReady = new Promise(resolve => {
|
||||
const npm = require('npm')
|
||||
npm.load(err => {
|
||||
if (err) {
|
||||
console.error(err)
|
||||
return
|
||||
}
|
||||
npm.config.set('global', false)
|
||||
this.npm = npm
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
}
|
||||
return this.npmReady
|
||||
}
|
||||
|
||||
async install (path: string, name: string, version: string): Promise<void> {
|
||||
await this.ensureLoaded()
|
||||
this.npm.prefix = path
|
||||
return promisify(this.npm.commands.install)([`${name}@${version}`])
|
||||
}
|
||||
|
||||
async uninstall (path: string, name: string): Promise<void> {
|
||||
await this.ensureLoaded()
|
||||
this.npm.prefix = path
|
||||
return promisify(this.npm.commands.remove)([name])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const pluginManager = new PluginManager()
|
Reference in New Issue
Block a user