-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
ability to install extensions from server-side service, REST route and settings page on the client
- Loading branch information
1 parent
9953d61
commit 798a1ea
Showing
8 changed files
with
140 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,46 @@ | ||
import npm from 'npm' | ||
|
||
import Extension from '../models/Extension' | ||
|
||
let npmLoaded = false | ||
|
||
function loadNpm (): Promise<void> { | ||
return new Promise((resolve, reject) => { | ||
npm.load({}, (err) => { | ||
npm.load({ | ||
save: false | ||
}, (err) => { | ||
if (err) { return reject(err) } | ||
|
||
resolve() | ||
}) | ||
}) | ||
} | ||
|
||
export async function install (packageName: string): Promise<void> { | ||
export async function install (packageName: string): Promise<Extension> { | ||
if (!npmLoaded) { | ||
await loadNpm() | ||
npmLoaded = true | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
npm.commands.install([ packageName ], (err, ...results) => { | ||
npm.commands.install([ packageName ], (err, results: string[][]) => { | ||
// results from npm.install() is this: | ||
// [ | ||
// [ 'fsevents@2.1.2', '/home/luca/dev/couch-buddy/server/node_modules/fsevents' ], | ||
// [ 'couch-buddy-movies-explorer@1.0.1', '/home/luca/dev/couch-buddy/server/node_modules/couch-buddy-movies-explorer' ] | ||
// ] | ||
if (err) { return reject(err) } | ||
|
||
console.log(`Package ${packageName} installed`, results) | ||
resolve() | ||
const installedPackage = results.pop() | ||
const [ name, version ] = installedPackage[0].split(/(?<!^)@/) | ||
|
||
const extension = Extension.create({ | ||
name, | ||
path: installedPackage[1], | ||
version | ||
}) | ||
|
||
resolve(extension) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters