-
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.
- Loading branch information
Showing
12 changed files
with
226 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
npm-debug.log | ||
node_modules |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
## 0.1.0 - First Release |
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 +1,3 @@ | ||
# atom-npm-run | ||
# atom-npm | ||
|
||
NPM integration for Atom. |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{CompositeDisposable} = require 'atom' | ||
|
||
ScriptsListView = require './views/scripts-list-view' | ||
OutdatedView = require './views/outdated-view' | ||
InstallView = require './views/install-view' | ||
UpdateView = require './views/update-view' | ||
npm = require './npm' | ||
|
||
module.exports = | ||
subscriptions: null | ||
|
||
activate: (state) -> | ||
# Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable | ||
@subscriptions = new CompositeDisposable() | ||
|
||
# Register command that toggles this view | ||
@subscriptions.add atom.commands.add 'atom-workspace', 'atom-npm:run': () -> | ||
npm.getPackage().then (pkg) -> | ||
(new ScriptsListView(pkg)).show() | ||
@subscriptions.add atom.commands.add 'atom-workspace', 'atom-npm:outdated': () -> new OutdatedView() | ||
@subscriptions.add atom.commands.add 'atom-workspace', 'atom-npm:install': () -> new InstallView() | ||
@subscriptions.add atom.commands.add 'atom-workspace', 'atom-npm:update': () -> new UpdateView() | ||
|
||
return | ||
|
||
deactivate: () -> | ||
@subscriptions.dispose() | ||
return |
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
path = require 'path' | ||
{execSync} = require 'child_process' | ||
|
||
npm = require 'npm/lib/npm' | ||
npmconf = require 'npm/lib/config/core' | ||
{makeEnv} = require 'npm/lib/utils/lifecycle' | ||
Promise = require 'promise' | ||
readJson = require 'read-package-json' | ||
nopt = require 'nopt' | ||
|
||
configDefs = npmconf.defs | ||
shorthands = configDefs.shorthands | ||
types = configDefs.types | ||
conf = nopt types, shorthands | ||
|
||
getNpm = () -> | ||
new Promise (resolve, reject) -> | ||
npm.load conf, (err) -> | ||
if err then reject err | ||
npm.localPrefix = atom.project.getDirectories()[0].path | ||
resolve npm | ||
return | ||
|
||
getPackage = (npm) -> | ||
pkgdir = npm.localPrefix | ||
|
||
new Promise (resolve, reject) -> | ||
readJson path.resolve(pkgdir, 'package.json'), (err, pkg) -> | ||
if err then reject err | ||
resolve pkg | ||
return | ||
|
||
exec = (wd, pkg, script) -> | ||
env = makeEnv pkg | ||
|
||
conf = cwd: wd, env: env | ||
|
||
if process.platform is 'win32' then conf.windowsVerbatimArguments = true | ||
|
||
out = execSync "npm #{script}", conf | ||
|
||
module.exports = | ||
getPackage: () -> getNpm().then (npm) -> getPackage npm | ||
|
||
run: (wd, pkg, script) -> exec wd, pkg, "run #{script}" | ||
|
||
outdated: (wd, pkg) -> exec wd, pkg, 'outdated' | ||
|
||
install: (wd, pkg) -> exec wd, pkg, 'install' | ||
|
||
update: (wd, pkg) -> exec wd, pkg, 'update' |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
npm = require '../npm' | ||
|
||
module.exports = class InstallView | ||
constructor: () -> | ||
atom.notifications.addInfo 'Run "npm install"' | ||
npm.getPackage().done (pkg) => | ||
out = npm.install atom.project.getDirectories()[0].path, pkg | ||
@show out.toString() | ||
return | ||
|
||
show: (txt) -> | ||
atom.notifications.addSuccess "npm install", detail: txt, dismissable: yes | ||
return |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
npm = require '../npm' | ||
|
||
module.exports = class OutdatedView | ||
constructor: () -> | ||
atom.notifications.addInfo 'Run "npm outdated"' | ||
npm.getPackage().done (pkg) => | ||
out = npm.outdated atom.project.getDirectories()[0].path, pkg | ||
@show out.toString() | ||
return | ||
|
||
show: (txt) -> | ||
atom.notifications.addSuccess "npm outdated", detail: txt, dismissable: yes | ||
return |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{$$, SelectListView} = require 'atom-space-pen-views' | ||
keys = require 'lodash/keys' | ||
{makeEnv} = require 'npm/lib/utils/lifecycle' | ||
{execSync} = require 'child_process' | ||
npm = require '../npm' | ||
|
||
module.exports = | ||
class ScriptsListView extends SelectListView | ||
initialize: (@pkg) -> | ||
super | ||
@data = pkg.scripts or {} | ||
@setItems @parseData @data | ||
@focusFilterEditor() | ||
|
||
parseData: (scripts) -> keys(scripts).map (script, content) -> | ||
label: "Run #{script}" | ||
script: script | ||
|
||
getFilterKey: () -> 'name' | ||
|
||
show: () -> | ||
@panel ?= atom.workspace.addModalPanel(item: this) | ||
@panel.show() | ||
@focusFilterEditor() | ||
|
||
cancelled: () -> @hide() | ||
|
||
hide: () -> @panel?.destroy() | ||
|
||
viewForItem: ({label}) -> | ||
$$ -> | ||
@li => | ||
@span label | ||
|
||
confirmed: ({script}) -> | ||
@cancel() | ||
out = npm.run atom.project.getDirectories()[0].path, @pkg, script | ||
|
||
atom.notifications.addSuccess "npm run #{script}", detail: out.toString(), dismissable: yes |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
npm = require '../npm' | ||
|
||
module.exports = class UpdateView | ||
constructor: () -> | ||
atom.notifications.addInfo 'Run "npm update"' | ||
npm.getPackage().done (pkg) => | ||
out = npm.update atom.project.getDirectories()[0].path, pkg | ||
@show out.toString() | ||
return | ||
|
||
show: (txt) -> | ||
atom.notifications.addSuccess "npm update", detail: txt, dismissable: yes | ||
return |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
"menu": [ | ||
"label": "Packages" | ||
"submenu": [ | ||
"label": "Atom NPM" | ||
"submenu": [ | ||
"label": "Run" | ||
"command": "atom-npm:run" | ||
, | ||
"label": "Outdated" | ||
"command": "atom-npm:outdated" | ||
, | ||
"label": "Install" | ||
"command": "atom-npm:install" | ||
, | ||
"label": "Update" | ||
"command": "atom-npm:update" | ||
] | ||
] | ||
] |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"name": "atom-npm", | ||
"main": "./lib/atom-npm", | ||
"version": "0.1.0", | ||
"description": "NPM integration for Atom", | ||
"keywords": [ | ||
"atom", | ||
"npm" | ||
], | ||
"scripts": { | ||
"q": "echo \"Test\" && echo \"Line 2\"" | ||
}, | ||
"activationCommands": { | ||
"atom-workspace": [ | ||
"atom-npm:run", | ||
"atom-npm:outdated", | ||
"atom-npm:install", | ||
"atom-npm:update" | ||
] | ||
}, | ||
"repository": "https://github.com/atom/atom-npm", | ||
"license": "MIT", | ||
"engines": { | ||
"atom": ">=1.0.0 <2.0.0" | ||
}, | ||
"dependencies": { | ||
"atom-space-pen-views": "^2.2.0", | ||
"graceful-fs": "^4.1.6", | ||
"lodash": "^4.15.0", | ||
"nopt": "^3.0.6", | ||
"npm": "^3.10.7", | ||
"promise": "^7.1.1", | ||
"read-package-json": "^2.0.4" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// The ui-variables file is provided by base themes provided by Atom. | ||
// | ||
// See https://github.com/atom/atom-dark-ui/blob/master/styles/ui-variables.less | ||
// for a full listing of what's available. | ||
@import "ui-variables"; | ||
|
||
.atom-npm { | ||
} |