Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
swalkinshaw committed Jun 7, 2013
0 parents commit 9108016
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in capistrano-composer.gemspec
gemspec
56 changes: 56 additions & 0 deletions README.md
@@ -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.
1 change: 1 addition & 0 deletions Rakefile
@@ -0,0 +1 @@
require 'bundler/gem_tasks'
20 changes: 20 additions & 0 deletions capistrano-npm.gemspec
@@ -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
11 changes: 11 additions & 0 deletions lib/capistrano/npm.rb
@@ -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
5 changes: 5 additions & 0 deletions lib/capistrano/npm/version.rb
@@ -0,0 +1,5 @@
module Capistrano
module Npm
VERSION = '0.0.1'
end
end

0 comments on commit 9108016

Please sign in to comment.