├── README.md └── script.py /README.md: -------------------------------------------------------------------------------- 1 | local-npm-launch-agent 2 | ==== 3 | 4 | Script to set up [local-npm](https://github.com/nolanlawson/local-npm/) as a LaunchAgent on OS X, so that you can get up and running with `local-npm` in no time. 5 | 6 | Usage 7 | --- 8 | 9 | Run this command (**without sudo!**): 10 | 11 | curl -sL https://raw.githubusercontent.com/nolanlawson/local-npm-launch-agent/master/script.py | python - 12 | 13 | ### What this does 14 | 15 | 1. Installs `local-npm`, `pm2`, and `npmrc` globally. 16 | 2. Creates a LaunchAgent to run `pm2` and `local-npm`. 17 | 3. Creates an `npmrc` called `local` that points to local-npm. 18 | 4. Starts it up. 19 | 20 | When you restart your machine, `local-npm` will already be up and running. 21 | 22 | To see the output logs, you can run: 23 | 24 | pm2 logs all 25 | 26 | To switch back to regular npm, you can run: 27 | 28 | npmrc default 29 | 30 | You can also visit [http://localhost:5080/_browse](http://localhost:5080/_browse) in a browser to confirm that `local-npm` is up and running. 31 | 32 | Uninstall 33 | ---- 34 | 35 | If at any point you want to uninstall all this stuff, just do: 36 | 37 | launchctl unload ~/Library/LaunchAgents/com.nolanlawson.localnpm.plist 38 | rm -fr ~/.local-npm ~/.npmrcs/local ~/Library/LaunchAgents/com.nolanlawson.localnpm.plist 39 | npmrc default -------------------------------------------------------------------------------- /script.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # Creates a LaunchAgent for local-npm, or does nothing 4 | # if it's already installed. 5 | 6 | import os, sys, getpass, commands 7 | 8 | def command(cmd): 9 | print cmd 10 | os.system(cmd) 11 | 12 | def finished(): 13 | print "\nIf you want to switch back to normal npm, run:\n\n npmrc default\n" 14 | print "If you want to see replication progress, run:\n\n pm2 logs all\n" 15 | print "If you want to uninstall, run:\n\n launchctl unload ~/Library/LaunchAgents/com.nolanlawson.localnpm.plist\n" 16 | 17 | install_dir = os.path.expanduser('~/.local-npm') 18 | if not os.path.exists(install_dir): 19 | os.mkdir(install_dir) 20 | 21 | done_file = os.path.join(install_dir, 'done') 22 | if os.path.exists(done_file): 23 | print "\nLooks like local-npm is already installed! Exiting." 24 | finished() 25 | sys.exit(1) 26 | 27 | command('npm install -g local-npm pm2 npmrc') 28 | 29 | plist = ''' 30 | 31 | 32 | 33 | Label 34 | com.nolanlawson.localnpm 35 | ProgramArguments 36 | 37 | %s 38 | %s 39 | start 40 | %s 41 | -- 42 | %s 43 | 44 | RunAtLoad 45 | 46 | KeepAlive 47 | 48 | StandardErrorPath 49 | /tmp/localnpm.err 50 | StandardOutPath 51 | /tmp/localnpm.out 52 | UserName 53 | %s 54 | WorkingDirectory 55 | %s 56 | 57 | ''' 58 | 59 | plist = plist % (\ 60 | commands.getoutput('which node'), \ 61 | commands.getoutput('which pm2'), \ 62 | commands.getoutput('which node'), \ 63 | commands.getoutput('which local-npm'), \ 64 | getpass.getuser(), \ 65 | install_dir) 66 | 67 | out_file = open(os.path.expanduser('~/Library/LaunchAgents/com.nolanlawson.localnpm.plist'), 'w') 68 | out_file.write(plist) 69 | out_file.close() 70 | 71 | command('launchctl load -w ~/Library/LaunchAgents/com.nolanlawson.localnpm.plist') 72 | 73 | command('npmrc -c local') 74 | os.system('npm set registry http://127.0.0.1:5080') 75 | 76 | open(done_file, 'a').close() 77 | 78 | print "\nDone! You now have local-npm running at 127.0.0.1:5080" 79 | print "You also have an npmrc called \"local\" configured to point to it." 80 | print "All offline data is stored in ~/.local-npm" 81 | finished() 82 | --------------------------------------------------------------------------------