Skip to content

Commit

Permalink
🎨 Minor enhancements in installDependencies helper
Browse files Browse the repository at this point in the history
  • Loading branch information
steelbrain committed Feb 16, 2016
1 parent 9ffd9cb commit 5befd2b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export function spawnAPM(dependencies, progressCallback) {
options: {},
stdout: function(contents) {
const matches = extractionRegex.exec(contents)
progressCallback()
if (matches[2] === '✓' || matches[2] === 'done') {
// Succeeded
progressCallback(matches[1], true)
} else {
progressCallback(matches[1], false)
errors.push(matches[1])
}
},
Expand All @@ -37,19 +37,23 @@ export function spawnAPM(dependencies, progressCallback) {

export async function installDependencies(name, packages) {
const view = new View(name, packages)
const installedPackages = []
try {
await spawnAPM(packages, function() {
await spawnAPM(packages, function(name, status) {
view.advance()
if (status) {
installedPackages.push(name)
}
})
view.markFinished()
} catch (error) {
view.dismiss()
atom.notifications.addError(`Error installing ${this.name} dependencies`, {
atom.notifications.addError(`Error installing ${name} dependencies`, {
detail: error.stack,
dismissable: true
})
} finally {
await Promise.all(packages.map(name => atom.packages.activatePackage(name)))
await Promise.all(installedPackages.map(name => atom.packages.activatePackage(name)))
}
}

Expand Down

0 comments on commit 5befd2b

Please sign in to comment.