Skip to content

Commit

Permalink
Use new atom-npm-client-api
Browse files Browse the repository at this point in the history
  • Loading branch information
tomi77 committed Oct 2, 2016
1 parent 41a330a commit 0670df0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
13 changes: 5 additions & 8 deletions lib/atom-npm.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ RunView = require './views/run-view'
OutdatedView = require './views/outdated-view'
InstallDependenciesView = require './views/install-dependencies-view'
UpdateDependenciesView = require './views/update-dependencies-view'
Promise = require 'promise'
{getPackage} = require 'atom-npm-client-api'
{getPackages} = require 'atom-npm-client-api'

module.exports =
subscriptions: null
Expand All @@ -16,15 +15,13 @@ module.exports =

# Register command that toggles this view
@subscriptions.add atom.commands.add 'atom-workspace',
'atom-npm:run': () => @getPackages().done (pkgs) -> new RunView pkgs
'atom-npm:outdated': () => @getPackages().done (pkgs) -> new OutdatedView pkgs
'atom-npm:install-dependencies': () => @getPackages().done (pkgs) -> new InstallDependenciesView pkgs
'atom-npm:update-dependencies': () => @getPackages().done (pkgs) -> new UpdateDependenciesView pkgs
'atom-npm:run': () => getPackages().done (pkgs) -> new RunView pkgs
'atom-npm:outdated': () => getPackages().done (pkgs) -> new OutdatedView pkgs
'atom-npm:install-dependencies': () => getPackages().done (pkgs) -> new InstallDependenciesView pkgs
'atom-npm:update-dependencies': () => getPackages().done (pkgs) -> new UpdateDependenciesView pkgs

return

deactivate: () ->
@subscriptions.dispose()
return

getPackages: () -> Promise.all atom.project.getDirectories().map (dir) -> getPackage dir.path
24 changes: 11 additions & 13 deletions lib/views/run-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,19 @@ module.exports =
confirmed: ({script, pkg}) ->
@cancel()

info = atom.notifications.addInfo "npm run #{script} (#{pkg.name or pkg.wd})",
info = atom.notifications.addInfo "npm run #{script} @ #{pkg.name or pkg.wd}",
detail: "Running..."
dismissable: yes

pkg.once 'exit', (status, stdout, stderr) =>
info.dismiss()

if status
atom.notifications.addError "npm run #{script} (#{pkg.name or pkg.wd})",
detail: stdout
dismissable: yes
else
atom.notifications.addSuccess "npm run #{script} (#{pkg.name or pkg.wd})",
detail: stdout
dismissable: yes

pkg.run script
.then ({stdout, stderr}) ->
info.dismiss()
atom.notifications.addSuccess "npm run #{script} @ #{pkg.name or pkg.wd}",
detail: stdout
dismissable: yes
.catch ({code, stdout, stderr}) ->
info.dismiss()
atom.notifications.addError "npm run #{script} @ #{pkg.name or pkg.wd}",
detail: stderr
dismissable: yes
return
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"dependencies": {
"atom-npm-client-api": "^0.1.0",
"atom-space-pen-views": "^2.2.0",
"lodash": "^4.15.0",
"promise": "^7.1.1"
"lodash": "^4.15.0"
}
}

0 comments on commit 0670df0

Please sign in to comment.