Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9108016
Showing
7 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
*.gem | |||
.bundle | |||
Gemfile.lock | |||
pkg/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,4 @@ | |||
source 'https://rubygems.org' | |||
|
|||
# Specify your gem's dependencies in capistrano-composer.gemspec | |||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
require 'bundler/gem_tasks' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
module Capistrano | |||
module Npm | |||
VERSION = '0.0.1' | |||
end | |||
end |