Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 9108016a50d78f55d331396be031c3ebdc57f2fb @swalkinshaw swalkinshaw committed Jun 6, 2013
Showing with 101 additions and 0 deletions.
  1. +4 −0 .gitignore
  2. +4 −0 Gemfile
  3. +56 −0 README.md
  4. +1 −0 Rakefile
  5. +20 −0 capistrano-npm.gemspec
  6. +11 −0 lib/capistrano/npm.rb
  7. +5 −0 lib/capistrano/npm/version.rb
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+
+# Specify your gem's dependencies in capistrano-composer.gemspec
+gemspec
@@ -0,0 +1,56 @@
+# capistrano-npm
+
+capistrano-npm is a [Capistrano](https://github.com/capistrano/capistrano) extension that will let you run [npm](https://npmjs.org/) during your deploy process.
+
+## Installation
+
+1. Install the Gem
+
+```bash
+gem install capistrano-npm
+```
+
+Or if you're using Bundler, add it to your `Gemfile`:
+
+```ruby
+gem 'capistrano-npm', github: 'swalkinshaw/npm'
+```
+
+2. Add to `Capfile` or `config/deploy.rb`:
+
+```ruby
+require 'capistrano/npm'
+```
+
+## Usage
+
+Add the task to your `deploy.rb`:
+
+```ruby
+after 'deploy:finalize_update', 'npm:install'
+```
+
+To speed up your deployments, you should also add `node_modules` to Capistrano's `shared_children` variable:
+
+```ruby
+set :shared_children, shared_children + %w{node_modules}
+```
+
+This will symlink `node_modules` from the `shared` directory so it isn't re-created from scratch each deploy.
+
+Ideally when using npm, you should add `node_modules` to your `.gitignore` file to keep them out of your repository.
+
+Since `npm install` does not guarantee that you will get the same package versions when deploying, you should use `npm shrinkwrap` (https://npmjs.org/doc/shrinkwrap.html) first.
+
+Running `npm shrinkwrap` will created a `npm-shrinkwrap.json` file that locks down the dependency versions. Check this file into your repository.
+
+Now when deploying, `npm install` will detect the `npm-shrinkwrap.json` file and use that to install the packages.
+
+### Tasks
+
+* `npm:install`: Runs `npm install`.
+
+### Configuration
+
+* `npm_path`: Path to npm bin on the remote server. Defaults to just `npm` as its assumed to be in your `$PATH`.
+* `npm_options`: Options for `npm` command. Defaults to an empty string.
@@ -0,0 +1 @@
+require 'bundler/gem_tasks'
@@ -0,0 +1,20 @@
+# coding: utf-8
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+
+require 'capistrano/npm/version'
+
+Gem::Specification.new do |s|
+ s.name = 'capistrano-npm'
+ s.version = Capistrano::Npm::VERSION
+ s.authors = ['Scott Walkinshaw']
+ s.email = ['scott.walkinshaw@gmail.com']
+ s.homepage = 'https://github.com/swalkinshaw/capistrano-npm'
+ s.summary = %q{Capistrano extension for npm (Node Packaged Modules)}
+ s.license = 'MIT'
+
+ s.files = `git ls-files`.split($/)
+ s.require_paths = %w(lib)
+
+ s.add_dependency 'capistrano', '>= 2.5.5'
+end
@@ -0,0 +1,11 @@
+Capistrano::Configuration.instance(true).load do
+ set :npm_path, 'npm'
+ set :npm_options, nil
+
+ namespace :npm do
+ desc 'Runs npm install.'
+ task :install, :roles => :app, :except => { :no_release => true } do
+ try_sudo "cd #{latest_release} && #{npm_path} #{npm_options} install"
+ end
+ end
+end
@@ -0,0 +1,5 @@
+module Capistrano
+ module Npm
+ VERSION = '0.0.1'
+ end
+end

0 comments on commit 9108016

Please sign in to comment.