vigetlabs-provisional 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,59 @@
1
+ = Provisional
2
+
3
+ == Description
4
+
5
+ Provisional creates a new Rails project, using a standard Rails 2.3 application template, and checks it into a new SCM repository.
6
+
7
+ In the future, Provisional may be expanded to create production and staging environments, set up continuous integration, and automate other tasks that are usually performed at the beginning of a project.
8
+
9
+ == Requirements
10
+
11
+ Provisional requires Rails 2.3.0 or greater.
12
+
13
+ Provisional is only tested on Mac OS X. It should also work on Linux. It is not tested or supported on Windows.
14
+
15
+ == Installation
16
+
17
+ sudo gem install provisional
18
+
19
+ == Usage
20
+
21
+ Options:
22
+ --name, -n <s>: Name of the project
23
+ --scm, -s <s>: SCM to use (default: git)
24
+ --rails, -r <s>: Path to rails generator script (default: first occurrence of rails in $PATH)
25
+ --template, -t <s>: Rails template to use (default: viget)
26
+ --version, -v: Print version and exit
27
+ --help, -h: Show this message
28
+
29
+ The SCM option can be one of the following ("project_name" refers to the value of the --name option):
30
+
31
+ * git: creates a git repository in the project_name directory
32
+ * github: creates a git repository in the project_name directory, creates project_name on GitHub using the specified credentials, and adds it as origin (see section below about required Git configuration)
33
+
34
+ (Subversion and Viget-specific SCM's were removed in Provisional 2.0.0. They may return at a later date.)
35
+
36
+ The template option can be either a literal path to a template file, a URL for a template on a remote server, or the name of one of the templates found in lib/provisional/templates (without the .rb suffix.) The default viget template does the following:
37
+
38
+ * freezes rails from currently installed gems
39
+ * installs gems: mocha, factory_girl, shoulda
40
+ * installs plugins: hoptoad_notifier, jrails, model_generator_with_factories, viget_deployment, vl_cruise_control
41
+ * installs a .gitignore file to ignore logs, temp files, sqlite3 databases, rcov reports, and database.yml
42
+ * generates Capistrano configuration with viget_deployment
43
+ * copies database.yml to database.yml-sample
44
+ * removes public/index.html, test/fixtures, prototype, and script.aculo.us
45
+ * creates a SCM repository and checks the application in (pushing to origin if the github SCM is used)
46
+
47
+ == GitHub
48
+
49
+ To use GitHub, you will need to place your GitHub username and token in your Git configuration as described here: http://github.com/guides/local-github-config
50
+
51
+ == License
52
+
53
+ Copyright (c) 2009 Mark Cornick of Viget Labs <mark@viget.com>
54
+
55
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
56
+
57
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
58
+
59
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 2
3
+ :minor: 0
4
+ :patch: 2
data/bin/provisional ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'provisional'
5
+ require 'trollop'
6
+
7
+ options = Trollop::options do
8
+ # version "1.2.4"
9
+ opt :name, "Name of the project", :type => String
10
+ opt :scm, "SCM to use", :type => String, :default => 'git'
11
+ opt :rails, "Path to rails generator script", :type => String, :default => `which rails`.chomp
12
+ opt :template, "Rails template to use", :type => String, :default => 'viget'
13
+ end
14
+
15
+ Provisional::Project.new(options)
@@ -0,0 +1,17 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'provisional/project'
4
+
5
+ module Provisional
6
+ IGNORE_FILES = [
7
+ ['coverage'],
8
+ ['config/database.yml'],
9
+ ['db/*.sqlite3'],
10
+ ['log/*.log'],
11
+ ['tmp/restart.txt'],
12
+ ['tmp/cache/*'],
13
+ ['tmp/pids/*'],
14
+ ['tmp/sessions/*'],
15
+ ['tmp/sockets/*']
16
+ ]
17
+ end
@@ -0,0 +1,51 @@
1
+ require 'active_support'
2
+ require 'uri'
3
+
4
+ module Provisional
5
+ class Project
6
+ attr_reader :options
7
+
8
+ def initialize(options)
9
+ @options = options
10
+
11
+ unless is_valid_url?(@options[:template])
12
+ if File.exist?(File.expand_path(@options[:template]))
13
+ @options[:template_path] = File.expand_path(@options[:template])
14
+ else
15
+ @options[:template_path] = File.expand_path(File.join(File.dirname(__FILE__),'templates',"#{@options[:template]}.rb"))
16
+ end
17
+ raise ArgumentError, "is not valid: #{@options[:template]}" unless File.exist?(@options[:template_path])
18
+ else
19
+ @options[:template_path] = @options[:template]
20
+ end
21
+
22
+ raise ArgumentError, "must be specified" unless @options[:name]
23
+ raise ArgumentError, "already exists: #{@options[:name]}" if File.exist?(@options[:name])
24
+ raise ArgumentError, "already exists: #{@options[:name]}.repo" if @options[:scm] == 'svn' && File.exist?("#{@options[:name]}.repo")
25
+
26
+ begin
27
+ require "provisional/scm/#{@options[:scm]}"
28
+ rescue MissingSourceFile
29
+ raise ArgumentError, "is not supported: #{@options[:scm]}"
30
+ end
31
+
32
+ raise ArgumentError, "must be specified" if @options[:rails].to_s.empty?
33
+ raise ArgumentError, "is not valid: #{@options[:rails]}" unless File.exist?(@options[:rails]) && File.executable?(@options[:rails])
34
+
35
+ scm_class = "Provisional::SCM::#{@options[:scm].classify}".constantize
36
+ scm = scm_class.new(@options)
37
+ scm.init
38
+ scm.generate_rails
39
+ scm.checkin
40
+ end
41
+
42
+ def is_valid_url?(url)
43
+ begin
44
+ [URI::HTTP, URI::HTTPS].include?(URI.parse(url).class)
45
+ rescue URI::InvalidURIError
46
+ false
47
+ end
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,44 @@
1
+ require 'fileutils'
2
+ require 'git'
3
+ require 'rails/version'
4
+ require 'rails_generator'
5
+ require 'rails_generator/scripts/generate'
6
+
7
+ module Provisional
8
+ module SCM
9
+ class Git
10
+ def initialize(options)
11
+ @options = options
12
+ end
13
+
14
+ def gitignore
15
+ Provisional::IGNORE_FILES.join("\n")
16
+ end
17
+
18
+ def init
19
+ FileUtils.mkdir_p @options[:name]
20
+ Dir.chdir @options[:name]
21
+ @options[:path] = Dir.getwd
22
+ ::Git.init
23
+ end
24
+
25
+ def generate_rails
26
+ generator_options = ['.', '-m', @options[:template_path]]
27
+ Dir.chdir @options[:path]
28
+ Rails::Generator::Base.use_application_sources!
29
+ Rails::Generator::Scripts::Generate.new.run generator_options, :generator => 'app'
30
+ end
31
+
32
+ def checkin
33
+ repo = ::Git.open @options[:path]
34
+ Dir.chdir @options[:path]
35
+ File.open('.gitignore', 'w') do |f|
36
+ f.puts gitignore
37
+ end
38
+ repo.add '.'
39
+ repo.commit 'Initial commit by Provisional'
40
+ repo
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,21 @@
1
+ require 'provisional/scm/git'
2
+ require 'net/http'
3
+
4
+ module Provisional
5
+ module SCM
6
+ class Github < Provisional::SCM::Git
7
+ def checkin
8
+ repo = super
9
+ github_user = repo.config 'github.user'
10
+ github_token = repo.config 'github.token'
11
+ Net::HTTP.post_form URI.parse('http://github.com/api/v2/yaml/repos/create'), {
12
+ 'login' => github_user,
13
+ 'token' => github_token,
14
+ 'name' => @options[:name]
15
+ }
16
+ repo.add_remote('origin', "git@github.com:#{github_user}/#{@options[:name]}.git")
17
+ repo.push
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ # rails new_app_name -m viget.rb
2
+
3
+ # freeze rails
4
+ rake 'rails:freeze:gems'
5
+
6
+ # install gems
7
+ gem 'mocha', :version => '>= 0.9.5'
8
+ gem 'thoughtbot-factory_girl', :lib => 'factory_girl', :source => 'http://gems.github.com', :version => '>= 1.2.0'
9
+ gem 'thoughtbot-shoulda', :lib => 'shoulda', :source => 'http://gems.github.com', :version => '>= 2.10.1'
10
+ rake 'gems:install gems:unpack'
11
+
12
+ # install plugins
13
+ plugin 'hoptoad_notifier', :git => 'git://github.com/thoughtbot/hoptoad_notifier.git'
14
+ plugin 'jrails', :git => 'git://github.com/aaronchi/jrails.git'
15
+ plugin 'model_generator_with_factories', :git => 'git://github.com/vigetlabs/model_generator_with_factories.git'
16
+ plugin 'viget_deployment', :git => 'git://github.com/vigetlabs/viget_deployment.git'
17
+ plugin 'vl_cruise_control', :git => 'git://github.com/vigetlabs/vl_cruise_control.git'
18
+
19
+ # generate viget_deployment stuff
20
+ generate :viget_deployment
21
+
22
+ # clean up
23
+ run 'rm -rf public/index.html log/* test/fixtures config/database.yml'
24
+ inside ('public/javascripts') do
25
+ run 'rm -f dragdrop.js controls.js effects.js prototype.js'
26
+ end
27
+ rake 'jrails:install:javascripts'
@@ -0,0 +1,7 @@
1
+ # http://sneaq.net/textmate-wtf
2
+ $:.reject! { |e| e.include? 'TextMate' }
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'mocha'
7
+ require File.dirname(__FILE__) + '/../lib/provisional'
@@ -0,0 +1,47 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require File.dirname(__FILE__) + '/../../lib/provisional/scm/git'
3
+
4
+ class GitTest < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @scm = Provisional::SCM::Git.new(
8
+ {
9
+ :name => 'name',
10
+ :template_path => 'template_path',
11
+ :rails => 'rails'
12
+ }
13
+ )
14
+ end
15
+
16
+ def test_gitignore
17
+ assert_equal Provisional::IGNORE_FILES.join("\n"), @scm.gitignore
18
+ end
19
+
20
+ def test_init
21
+ FileUtils.expects(:mkdir_p).with('name')
22
+ Dir.expects(:chdir).with('name')
23
+ Git.expects(:init)
24
+ @scm.init
25
+ end
26
+
27
+ def test_generate_rails
28
+ Dir.expects(:chdir)
29
+ Rails::Generator::Base.expects(:use_application_sources!)
30
+ generator_stub = stub()
31
+ generator_stub.expects(:run).with(%w(. -m template_path), :generator => 'app')
32
+ Rails::Generator::Scripts::Generate.expects(:new).returns(generator_stub)
33
+ @scm.generate_rails
34
+ end
35
+
36
+ def test_checkin
37
+ repo_stub = stub()
38
+ repo_stub.expects(:add).with('.')
39
+ repo_stub.expects(:commit).with('Initial commit by Provisional')
40
+ Git.expects(:open).returns(repo_stub)
41
+ Dir.expects(:chdir)
42
+ gitignore_file = stub()
43
+ gitignore_file.expects(:puts).with(@scm.gitignore)
44
+ File.expects(:open).with('.gitignore', 'w').yields(gitignore_file)
45
+ @scm.checkin
46
+ end
47
+ end
@@ -0,0 +1,52 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require File.dirname(__FILE__) + '/../../lib/provisional/scm/github'
3
+
4
+ class GithubTest < Test::Unit::TestCase
5
+ def setup
6
+ @scm = Provisional::SCM::Github.new(
7
+ {
8
+ :name => 'name',
9
+ :template_path => 'template_path',
10
+ :rails => 'rails'
11
+ }
12
+ )
13
+ end
14
+
15
+ def test_gitignore
16
+ assert_equal Provisional::IGNORE_FILES.join("\n"), @scm.gitignore
17
+ end
18
+
19
+ def test_init
20
+ FileUtils.expects(:mkdir_p).with('name')
21
+ Dir.expects(:chdir).with('name')
22
+ Git.expects(:init)
23
+ @scm.init
24
+ end
25
+
26
+ def test_generate_rails
27
+ Dir.expects(:chdir)
28
+ Rails::Generator::Base.expects(:use_application_sources!)
29
+ generator_stub = stub()
30
+ generator_stub.expects(:run).with(%w(. -m template_path), :generator => 'app')
31
+ Rails::Generator::Scripts::Generate.expects(:new).returns(generator_stub)
32
+ @scm.generate_rails
33
+ end
34
+
35
+ def test_checkin
36
+ repo_stub = stub()
37
+ repo_stub.expects(:add).with('.')
38
+ repo_stub.expects(:commit).with('Initial commit by Provisional')
39
+ repo_stub.expects(:config).with('github.user').returns('user')
40
+ repo_stub.expects(:config).with('github.token').returns('token')
41
+ repo_stub.expects(:add_remote)
42
+ repo_stub.expects(:push)
43
+
44
+ Git.expects(:open).returns(repo_stub)
45
+ Dir.expects(:chdir)
46
+ gitignore_file = stub()
47
+ gitignore_file.expects(:puts).with(@scm.gitignore)
48
+ File.expects(:open).with('.gitignore', 'w').yields(gitignore_file)
49
+
50
+ @scm.checkin
51
+ end
52
+ end
@@ -0,0 +1,130 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+ require File.dirname(__FILE__) + '/../../lib/provisional/scm/git'
3
+
4
+ class ProjectTest < Test::Unit::TestCase
5
+
6
+ RAILS = `which rails`.chomp
7
+ DEFAULT_TEMPLATE_PATH = File.expand_path(File.join(File.dirname(__FILE__), '../../lib/provisional/templates/viget.rb'))
8
+
9
+ def stub_git
10
+ git_stub = stub()
11
+ git_stub.expects(:init).returns('true')
12
+ git_stub.expects(:generate_rails).returns('true')
13
+ git_stub.expects(:checkin).returns('true')
14
+ Provisional::SCM::Git.expects(:new).returns(git_stub)
15
+ end
16
+
17
+ def new_project(opts = {})
18
+ opts = {:name => 'name', :template => 'viget', :rails => RAILS, :scm => 'git'}.merge(opts)
19
+ Provisional::Project.new(opts)
20
+ end
21
+
22
+ def test_new_project_should_call_init_generate_rails_and_checkin
23
+ stub_git
24
+ new_project
25
+ end
26
+
27
+ def test_should_be_able_to_use_a_literal_template_path
28
+ stub_git
29
+ path_to_my_template = File.expand_path('my_template.rb')
30
+ File.expects(:exist?).with(path_to_my_template).times(2).returns(true)
31
+ File.expects(:exist?).with('name').returns(false)
32
+ File.expects(:exist?).with(RAILS).returns(true)
33
+ project = new_project(:template => 'my_template.rb')
34
+ assert_equal path_to_my_template, project.options[:template_path]
35
+ end
36
+
37
+ def test_should_find_the_template_path_based_on_the_template_option
38
+ stub_git
39
+ assert_equal DEFAULT_TEMPLATE_PATH, new_project.options[:template_path]
40
+ end
41
+
42
+ def test_should_raise_argumenterror_if_invalid_template_url_is_specified
43
+ bogus_url = 'bagel://pants/wizard'
44
+ URI.expects(:parse).with(bogus_url).raises(URI::InvalidURIError)
45
+ assert_raise ArgumentError do
46
+ project = new_project(:template => bogus_url)
47
+ end
48
+ end
49
+
50
+ def test_should_raise_argumenterror_if_name_is_not_specified
51
+ assert_raise ArgumentError do
52
+ new_project(:name => nil)
53
+ end
54
+ end
55
+
56
+ def test_should_raise_argumenterror_if_name_already_exists
57
+ File.expects(:exist?).with('name').returns(true)
58
+ File.expects(:exist?).with(File.expand_path('viget')).returns(false)
59
+ File.expects(:exist?).with(DEFAULT_TEMPLATE_PATH).returns(true)
60
+ assert_raise ArgumentError do
61
+ new_project
62
+ end
63
+ end
64
+
65
+ def test_should_raise_argumenterror_if_namedotrepo_already_exists_and_scm_is_svn
66
+ File.expects(:exist?).with('name').returns(false)
67
+ File.expects(:exist?).with('name.repo').returns(true)
68
+ File.expects(:exist?).with(DEFAULT_TEMPLATE_PATH).returns(true)
69
+ File.expects(:exist?).with(File.expand_path('viget')).returns(false)
70
+ assert_raise ArgumentError do
71
+ new_project(:scm => 'svn')
72
+ end
73
+ end
74
+
75
+ def test_should_raise_argumenterror_if_unsupported_scm_is_specified
76
+ assert_raise ArgumentError do
77
+ new_project(:scm => 'bogus')
78
+ end
79
+ end
80
+
81
+ def test_should_raise_argumenterror_if_no_scm_is_specified
82
+ assert_raise ArgumentError do
83
+ new_project(:scm => nil)
84
+ end
85
+ end
86
+
87
+ def test_should_raise_argumenterror_if_no_rails_is_specified
88
+ assert_raise ArgumentError do
89
+ new_project(:rails => nil)
90
+ end
91
+ end
92
+
93
+ def test_should_raise_argumenterror_if_invalid_rails_is_specified
94
+ assert_raise ArgumentError do
95
+ new_project(:rails => 'bogus')
96
+ end
97
+ end
98
+
99
+ def test_should_raise_argumenterror_if_invalid_template_is_specified
100
+ assert_raise ArgumentError do
101
+ new_project(:template => 'bogus')
102
+ end
103
+ end
104
+
105
+ def test_should_not_raise_argumenterror_if_a_valid_http_template_url_is_specified
106
+ stub_git
107
+ assert_nothing_raised do
108
+ new_project(:template => 'http://example.com/')
109
+ end
110
+ end
111
+
112
+ def test_should_not_raise_argumenterror_if_a_valid_https_template_url_is_specified
113
+ stub_git
114
+ assert_nothing_raised do
115
+ new_project(:template => 'https://example.com/')
116
+ end
117
+ end
118
+
119
+ def test_should_raise_argumenterror_if_a_valid_other_template_url_is_specified
120
+ assert_raise ArgumentError do
121
+ new_project(:template => 'ftp://example.com/')
122
+ end
123
+ end
124
+
125
+ def test_should_raise_argumenterror_if_an_invalid_url_is_specified
126
+ assert_raise ArgumentError do
127
+ new_project(:template => 'bogus://awesome.pants/')
128
+ end
129
+ end
130
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vigetlabs-provisional
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Mark Cornick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-21 00:00:00 -07:00
13
+ default_executable: provisional
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: trollop
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.10.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.3.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: git
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.5
44
+ version:
45
+ description:
46
+ email: mark@viget.com
47
+ executables:
48
+ - provisional
49
+ extensions: []
50
+
51
+ extra_rdoc_files:
52
+ - README.rdoc
53
+ files:
54
+ - README.rdoc
55
+ - VERSION.yml
56
+ - bin/provisional
57
+ - lib/provisional
58
+ - lib/provisional/project.rb
59
+ - lib/provisional/scm
60
+ - lib/provisional/scm/git.rb
61
+ - lib/provisional/scm/github.rb
62
+ - lib/provisional/templates
63
+ - lib/provisional/templates/viget.rb
64
+ - lib/provisional.rb
65
+ - test/test_helper.rb
66
+ - test/unit
67
+ - test/unit/git_test.rb
68
+ - test/unit/github_test.rb
69
+ - test/unit/project_test.rb
70
+ has_rdoc: true
71
+ homepage: http://github.com/vigetlabs/provisional
72
+ post_install_message:
73
+ rdoc_options:
74
+ - --inline-source
75
+ - --charset=UTF-8
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ requirements: []
91
+
92
+ rubyforge_project: viget
93
+ rubygems_version: 1.2.0
94
+ signing_key:
95
+ specification_version: 2
96
+ summary: Automation for new Rails Projects
97
+ test_files: []
98
+