Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added commander.js for help and version number #7

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
"url": "https://github.com/hci-lab/vispack/blob/master/LICENSE-MIT"
}
],
"main": "src/vispack",
"bin": {
"vispack": "dist/vispack.js"
},
"main": "dist/vispack",
"engines": {
"node": ">=5.1.0"
},
"preferGlobal": "true",
"scripts": {
"preinstall": "coffee --bare --no-header --output dist --compile src",
"test": "grunt test"
},
"devDependencies": {
Expand All @@ -43,6 +48,7 @@
},
"keywords": [],
"dependencies": {
"commander": "^2.9.0",
"extfs": "0.0.7",
"fs-extra": "^0.26.2",
"jethro": "^2.6.3"
Expand Down
81 changes: 49 additions & 32 deletions src/vispack.coffee
Original file line number Diff line number Diff line change
@@ -1,43 +1,60 @@
`#!/usr/bin/env node
`
###
project | vispack
url | https://github.com/hci-lab/vispack/blob/master/src/vispack.coffee
module |
module | vispack
author | YusufMohamed
description |
description | a cli utility to install and remove plugins.

Copyright (c) 2015 HCI Lab. Licensed under the MIT license.
###
exec = require 'child_process'
logger = require 'jethro'
fs = require 'extfs'
fse = require 'fs-extra'

commands = process.argv.slice 2

if commands[0] is 'remove'
plugin_name = commands[1]
fs.getDirs process.cwd() + '\\plugins\\node_modules\\' + plugin_name, (err, dirs) ->
if err
console.log 'directory not found'
else
plugin_dir = process.cwd() + '\\plugins\\node_modules\\' + plugin_name
fse.remove plugin_dir, (err)->
if err
logger 'Error', 'Remove', err
logger 'Info' , 'Remove' , 'Success'





if commands[0] is 'install'
github_url = commands[1]
prefix = './plugins'
str = 'npm install --prefix ' + prefix + ' ' + github_url
exec.exec str, (error,stdout,stderr) ->
logger 'Info' , 'stdout' , stdout
exec = require 'child_process'
logger = require 'jethro'
fs = require 'extfs'
fse = require 'fs-extra'
program = require 'commander'
pjson = require '../package.json'


program
.version pjson.version
.option '-I, --install [plugin]', 'add a new plugin'
.option '-R, --remove [plugin]', 'remove installed plugin'

program.on '--help', ()->
console.log ' Examples:'
console.log ''
console.log ' $ vispack install underscore'
console.log ' $ vispack remove underscore'
console.log ''

program.parse(process.argv);



if program.install is true
logger 'Error', 'vispack', 'missing arguments. [vispack -h] for more help.'
else if program.remove is true
logger 'Error', 'vispack', 'missing arguments. [vispack -h] for more help.'
else if program.install isnt true and program.remove is undefined and program.install isnt undefined
package_name = program.install
install_dir = process.env.APPDATA + '/npm/node_modules/vispack' || (process.platform == 'darwin' ? process.env.HOME + 'Library/Preference/npm/node_modules/vispack' : '/usr/lib/node_modules/vispack')
prefix = install_dir + '/plugins'
str = 'npm install --prefix ' + prefix + ' ' + package_name
exec.exec str ,(error,stdout,stderr) ->
logger 'Info' , 'vispack installer' , stdout
if error isnt null
logger 'Error', 'vispack installer' , 'something wrong happened. try again later.'
else if program.remove isnt true and program.install is undefined and program.remove isnt undefined
package_name = program.remove
install_dir = process.env.APPDATA + '/npm/node_modules/vispack' || (process.platform == 'darwin' ? process.env.HOME + 'Library/Preference/npm/node_modules/vispack' : '/var/local/npm/node_modules/vispack')
prefix = install_dir + '/plugins'
str = 'npm remove --prefix ' + prefix + ' ' + package_name
exec.exec str ,(error,stdout,stderr) ->
logger 'Info' , 'vispack removal' , stdout
if error isnt null
logger 'Error', 'exec error' , error
logger 'Error', 'vispack removal' , 'something wrong happened. try again later.'

#exports.awesome = ->
# "awesome"
2 changes: 1 addition & 1 deletion test/vispack_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ sinonChai = require('sinon-chai')

chai.use(sinonChai)

vispack = require('../src/vispack.coffee')
#vispack = require('../src/vispack.coffee')

describe "test", ->
beforeEach (done) ->
Expand Down