capistrano-node 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'term-ansicolor'
4
+ gem 'capistrano', '>= 2.11'
5
+
6
+ group :development do
7
+ gem 'rspec', '~> 2.8.0'
8
+ gem 'yard', '~> 0.7'
9
+ gem 'rdoc', '~> 3.12'
10
+ gem 'bundler', '~> 1.1'
11
+ gem 'jeweler', '~> 1.8.3'
12
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Flowdock Ltd.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "capistrano-node"
18
+ gem.homepage = "https://github.com/flowdock/capistrano-node"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Capistrano scripts for Node deployment}
21
+ gem.description = %Q{Capistrano scripts to handle Node deployment}
22
+ gem.email = "lautis@gmail.com"
23
+ gem.authors = ["Ville Lautanala"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ task :default => :spec
35
+
36
+ require 'yard'
37
+ YARD::Rake::YardocTask.new
@@ -0,0 +1,27 @@
1
+ # capistrano-node
2
+
3
+ Capistrano tasks for deploying Node projects.
4
+
5
+ ## What does it do?
6
+
7
+ * Skips migrations
8
+ * Installs NPM packages on deploy
9
+ * Manages multiple node versions
10
+
11
+ ## Usage
12
+
13
+ In your deploy.rb
14
+
15
+ ```ruby
16
+
17
+ require 'capistrano/node'
18
+
19
+ set :multi_node, true # To use multiple node versions
20
+ set :node_dir, '/opt/nodejs/versions' # Node dirs
21
+ set :version_prefix, 'v'
22
+ ```
23
+
24
+ ## Copyright
25
+
26
+ Copyright (c) 2012 Flowdock Ltd. See LICENSE.txt for
27
+ further details.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,68 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "capistrano-node"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Ville Lautanala"]
12
+ s.date = "2012-03-26"
13
+ s.description = "Capistrano scripts to handle Node deployment"
14
+ s.email = "lautis@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ ".rspec",
21
+ "Gemfile",
22
+ "LICENSE.txt",
23
+ "Rakefile",
24
+ "Readme.md",
25
+ "VERSION",
26
+ "capistrano-node.gemspec",
27
+ "lib/capistrano-node.rb",
28
+ "lib/capistrano/node.rb",
29
+ "spec/capistrano-node_spec.rb",
30
+ "spec/spec_helper.rb"
31
+ ]
32
+ s.homepage = "https://github.com/flowdock/capistrano-node"
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = "1.8.11"
36
+ s.summary = "Capistrano scripts for Node deployment"
37
+
38
+ if s.respond_to? :specification_version then
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<term-ansicolor>, [">= 0"])
43
+ s.add_runtime_dependency(%q<capistrano>, [">= 2.11"])
44
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
45
+ s.add_development_dependency(%q<yard>, ["~> 0.7"])
46
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.1"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
49
+ else
50
+ s.add_dependency(%q<term-ansicolor>, [">= 0"])
51
+ s.add_dependency(%q<capistrano>, [">= 2.11"])
52
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
53
+ s.add_dependency(%q<yard>, ["~> 0.7"])
54
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
+ s.add_dependency(%q<bundler>, ["~> 1.1"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<term-ansicolor>, [">= 0"])
60
+ s.add_dependency(%q<capistrano>, [">= 2.11"])
61
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
62
+ s.add_dependency(%q<yard>, ["~> 0.7"])
63
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
64
+ s.add_dependency(%q<bundler>, ["~> 1.1"])
65
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
66
+ end
67
+ end
68
+
@@ -0,0 +1,42 @@
1
+ require 'json'
2
+
3
+ module Capistrano
4
+ module Node
5
+ extend self
6
+ # Internal: Parse node version from string
7
+ #
8
+ # string - version string
9
+ # prefix - prefix used in node versions, e.g. 'v', (default: '')
10
+ #
11
+ # Returns Gem::Version object
12
+ def version(string, prefix = '')
13
+ Gem::Version.create(string[prefix.length..-1])
14
+ end
15
+
16
+ # Internal: Choose best matching version for given requirement
17
+ #
18
+ # requirement - Gem::Requirement object
19
+ # versions - Array of Gem::Versions
20
+ #
21
+ # Returns latest matching version
22
+ def choose_version(requirement, versions = [])
23
+ versions.sort.reduce(nil) do |used, candidate|
24
+ if requirement.satisfied_by? candidate
25
+ candidate
26
+ else
27
+ used
28
+ end
29
+ end
30
+ end
31
+
32
+ # Internal: Parse requirement from package.json
33
+ #
34
+ # file - package.json file object
35
+ #
36
+ # Returns Gem::Requirement
37
+ def requirement(file)
38
+ json = JSON.parse(File.open('package.json', 'r:utf-8').read)
39
+ Gem::Requirement.create(json['engines']['node'])
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,82 @@
1
+ require 'capistrano-node'
2
+ require 'term/ansicolor'
3
+ include Term::ANSIColor
4
+
5
+ def local_versions(path, prefix)
6
+ Dir.entries(path).select do |n|
7
+ n[0] != '.'
8
+ end.map do |ver|
9
+ Capistrano::Node.version ver, prefix
10
+ end
11
+ end
12
+
13
+ def remote_versions(path, prefix)
14
+ capture("ls #{path}").chomp.split("\n").map do |ver|
15
+ Capistrano::Node.version ver, prefix
16
+ end
17
+ end
18
+
19
+ Capistrano::Configuration.instance(:must_exist).load do |configuration|
20
+ after :'deploy:finalize_update', :'deploy:symlink_node'
21
+ after :'deploy:update_code', :'deploy:npm'
22
+
23
+ set :multi_node, false unless defined? multi_node
24
+ set :local, false unless defined? local
25
+ set :node_dir, '/opt/nodejs/versions' unless defined? node_dir
26
+ set :version_prefix, 'v' unless defined? version_prefix
27
+ set :available_node_versions do
28
+ if local
29
+ local_versions node_dir, version_prefix
30
+ else
31
+ remote_versions node_dir, version_prefix
32
+ end.sort
33
+ end
34
+
35
+ set :node_version do
36
+ requirement = Capistrano::Node.requirement 'package.json'
37
+ Capistrano::Node.choose_version requirement, available_node_versions
38
+ end
39
+
40
+ namespace :node do
41
+ desc 'List available node versions'
42
+ task :versions do
43
+ puts available_node_versions
44
+ end
45
+
46
+ desc 'Used Node version'
47
+ task :used do
48
+ if node_version
49
+ puts node_version
50
+ else
51
+ puts red('No suitable node version found')
52
+ end
53
+ end
54
+ end
55
+
56
+ namespace :deploy do
57
+ task :migrate do
58
+ # Skip migrations
59
+ end
60
+
61
+ desc 'Symlink node version'
62
+ task :symlink_node do
63
+ return unless multi_node
64
+
65
+ unless node_version
66
+ puts red('No suitable node version found')
67
+ exit
68
+ end
69
+
70
+ if local
71
+ run_locally "ln -snf #{node_dir}/#{version_prefix}#{node_version}/bin bin"
72
+ else
73
+ run "ln -snf #{node_dir}/#{version_prefix}#{node_version}/bin #{release_path}/bin"
74
+ end
75
+ end
76
+
77
+ desc 'Build NPM packages'
78
+ task :npm do
79
+ run "export PATH=#{release_path}/bin:$PATH && cd #{release_path} && npm install && npm rebuild"
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,47 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'tempfile'
3
+
4
+ describe 'Capistrano::Node' do
5
+ describe '.version' do
6
+ it 'parses version' do
7
+ Capistrano::Node.version('0.6.11').should == Gem::Version.new('0.6.11')
8
+ end
9
+
10
+ it 'ignores prefix' do
11
+ Capistrano::Node.version('v0.4.3', 'v').should == Gem::Version.new('0.4.3')
12
+ end
13
+ end
14
+
15
+ describe '.choose_version' do
16
+ before :each do
17
+ @versions = [
18
+ Gem::Version.new('0.6.3'),
19
+ Gem::Version.new('0.6.4'),
20
+ Gem::Version.new('0.4.2')
21
+ ]
22
+ end
23
+ it 'chooses the matching version' do
24
+ requirement = Gem::Requirement.create('0.6.3')
25
+ Capistrano::Node.choose_version(requirement, @versions).to_s.should == '0.6.3'
26
+ end
27
+
28
+ it 'prefers newest version' do
29
+ requirement = Gem::Requirement.create('~>0.6.3')
30
+ Capistrano::Node.choose_version(requirement, @versions).to_s.should == '0.6.4'
31
+ end
32
+
33
+ it 'returns nil if no version matches to requirement' do
34
+ requirement = Gem::Requirement.create('~>0.4.3')
35
+ Capistrano::Node.choose_version(requirement, @versions).should be_nil
36
+ end
37
+ end
38
+
39
+ describe '.requirement' do
40
+ it 'parses node requirement from package.json file' do
41
+ Tempfile.new('package.json') do |t|
42
+ t.write('{"node":{"version":">=0.6.11"}}')
43
+ Capistano::Node.requirement(t.path).should == Gem::Requirement.create(">=0.6.11")
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'capistrano-node'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-node
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ville Lautanala
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: term-ansicolor
16
+ requirement: &70108179190900 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70108179190900
25
+ - !ruby/object:Gem::Dependency
26
+ name: capistrano
27
+ requirement: &70108179189520 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '2.11'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70108179189520
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70108179188160 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.8.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70108179188160
47
+ - !ruby/object:Gem::Dependency
48
+ name: yard
49
+ requirement: &70108179211800 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.7'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70108179211800
58
+ - !ruby/object:Gem::Dependency
59
+ name: rdoc
60
+ requirement: &70108179211220 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '3.12'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70108179211220
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: &70108179210480 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: '1.1'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *70108179210480
80
+ - !ruby/object:Gem::Dependency
81
+ name: jeweler
82
+ requirement: &70108179209780 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 1.8.3
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *70108179209780
91
+ description: Capistrano scripts to handle Node deployment
92
+ email: lautis@gmail.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files:
96
+ - LICENSE.txt
97
+ files:
98
+ - .document
99
+ - .rspec
100
+ - Gemfile
101
+ - LICENSE.txt
102
+ - Rakefile
103
+ - Readme.md
104
+ - VERSION
105
+ - capistrano-node.gemspec
106
+ - lib/capistrano-node.rb
107
+ - lib/capistrano/node.rb
108
+ - spec/capistrano-node_spec.rb
109
+ - spec/spec_helper.rb
110
+ homepage: https://github.com/flowdock/capistrano-node
111
+ licenses:
112
+ - MIT
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ segments:
124
+ - 0
125
+ hash: 4423601583990083914
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 1.8.11
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Capistrano scripts for Node deployment
138
+ test_files: []