Open
Description
With meteor I dearly miss the simplicity of npm install {pkg}
and npm uninstall {pkg}
My OCD brain was hating having to look up the latest version of packages and manually add them to my packages.json file, so I made a little CLI so I can ./cli install {pkg}
and ./cli uninstall {pkg}
but this is not the most elegant of solutions
Any thoughts on a possible better solution that can be worked into this package? My quick and dirty CLI tool below
#!/usr/bin/env coffee
# USAGE:
# ./cli install chalk
# ./cli uninstall chalk
exec = require('child_process').exec
fs = require 'fs'
argv = process.argv
handleError = (error) ->
throw error if error
command = argv[2]
switch command
when 'install'
pkg = argv[3]
exec "npm show #{pkg} version", (error, output) ->
handleError error
latestVersion = output.trim()
fs.readFile 'packages.json', 'utf8', (error, contents) ->
handleError error
json = JSON.parse contents
json[pkg] = latestVersion
newString = JSON.stringify json, null, 2
newString += '\n'
fs.writeFile 'packages.json', newString, (error) ->
handleError error
console.info "Latest #{pkg} added to ./packages.json"
when 'uninstall'
pkg = argv[3]
fs.readFile 'packages.json', 'utf8', (error, contents) ->
handleError error
json = JSON.parse contents
if json[pkg]
delete json[pkg]
else
console.warn "Huh? #{pkg} is not in your packages.json"
return
newString = JSON.stringify json, null, 2
newString += '\n'
fs.writeFile 'packages.json', newString, (error) ->
handleError error
console.info "#{pkg} removed from packages.json"
Metadata
Metadata
Assignees
Labels
No labels