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

Install, uninstall CLI #72

Open
steve8708 opened this issue Feb 17, 2015 · 1 comment
Open

Install, uninstall CLI #72

steve8708 opened this issue Feb 17, 2015 · 1 comment

Comments

@steve8708
Copy link

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"
@steve8708
Copy link
Author

This is probably not possible without this - MeteorCommunity/discussions#9

But who knows if there is a workaround anyone can think of in the interim?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant