shag 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +25 -0
- data/Rakefile +7 -0
- data/bin/shag +19 -0
- data/lib/shag.rb +2 -0
- data/lib/shag/generator.rb +72 -0
- data/lib/shag/version.rb +3 -0
- data/shag.gemspec +24 -0
- data/spec/generator.rb +118 -0
- data/spec/spec_helper.rb +21 -0
- metadata +126 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Robert J Samson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Shag
|
2
|
+
|
3
|
+
SHAG - Sinatra Heroku App Generator
|
4
|
+
|
5
|
+
Shag is a stupidly simple, single purpose CLI for generating a scaffold for Sinatra apps on heroku. `shag new [APP_NAME]` creates a new directory for APP_NAME along with an appropriate Procfile, Gemfile and bare Sinatra application.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Install from the command line as:
|
10
|
+
|
11
|
+
$ gem install shag
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
$ shag new [APP_NAME]
|
16
|
+
|
17
|
+
Generates a shell project for APP_NAME.
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
1. Fork it
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bin/shag
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'shag'
|
4
|
+
|
5
|
+
USAGE = <<-TEXT
|
6
|
+
shag (Sinatra Heroku App Generator) version #{Shag::VERSION}
|
7
|
+
|
8
|
+
Usage: shag new [APP_NAME]
|
9
|
+
|
10
|
+
TEXT
|
11
|
+
|
12
|
+
if (ARGV[0] == 'new') && (ARGV.length == 2)
|
13
|
+
gen = Shag::Generator.new(ARGV[1])
|
14
|
+
gen.run
|
15
|
+
elsif (ARGV[0] == '-v') || (ARGV[0] == '--version')
|
16
|
+
puts "shag (Sinatra Heroku App Generator) version #{Shag::VERSION}"
|
17
|
+
else
|
18
|
+
puts USAGE
|
19
|
+
end
|
data/lib/shag.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
module Shag
|
2
|
+
class Generator
|
3
|
+
attr_reader :app_name
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@app_name = name
|
7
|
+
@app_dir = File.join(Dir.pwd, name)
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
puts "Creating directory"
|
12
|
+
Dir.mkdir(@app_dir)
|
13
|
+
Dir.chdir(@app_dir)
|
14
|
+
generate_gemfile
|
15
|
+
generate_procfile
|
16
|
+
generate_sinatra_file
|
17
|
+
bundle
|
18
|
+
git_init
|
19
|
+
puts "Project #{@app_name} has been created"
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
def generate_gemfile
|
24
|
+
puts "Writing Gemfile"
|
25
|
+
File.open('Gemfile', 'w') { |f| f.write(gemfile_content) }
|
26
|
+
end
|
27
|
+
|
28
|
+
def generate_procfile
|
29
|
+
puts "Writing Procfile"
|
30
|
+
File.open('Procfile', 'w') { |f| f.write(procfile_content) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def generate_sinatra_file
|
34
|
+
puts "Writing #{@app_name}.rb"
|
35
|
+
File.open("#{@app_name}.rb", 'w') { |f| f.write(sinatra_file_content) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def bundle
|
39
|
+
puts 'Running bundle install'
|
40
|
+
puts `bundle install`
|
41
|
+
end
|
42
|
+
|
43
|
+
def git_init
|
44
|
+
puts 'Initializing git repo'
|
45
|
+
puts `git init`
|
46
|
+
end
|
47
|
+
|
48
|
+
def gemfile_content
|
49
|
+
<<-GEMFILE
|
50
|
+
source :rubygems
|
51
|
+
|
52
|
+
gem 'sinatra'
|
53
|
+
GEMFILE
|
54
|
+
end
|
55
|
+
|
56
|
+
def procfile_content
|
57
|
+
<<-PROCFILE
|
58
|
+
web: bundle exec ruby #{@app_name}.rb -p $PORT
|
59
|
+
PROCFILE
|
60
|
+
end
|
61
|
+
|
62
|
+
def sinatra_file_content
|
63
|
+
<<-SINATRA_FILE
|
64
|
+
require 'sinatra'
|
65
|
+
|
66
|
+
get '/' do
|
67
|
+
puts "Hello world!"
|
68
|
+
end
|
69
|
+
SINATRA_FILE
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/shag/version.rb
ADDED
data/shag.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'shag/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "shag"
|
8
|
+
gem.version = Shag::VERSION
|
9
|
+
gem.authors = ["Robert J Samson"]
|
10
|
+
gem.email = ["rjsamson@me.com"]
|
11
|
+
gem.description = %q{SHAG - Sinatra Heroku App Generator - A stupidly simple, single purpose CLI for generating a scaffold for Sinatra apps on heroku.}
|
12
|
+
gem.summary = %q{A stupidly simple, single purpose CLI for generating a scaffold for Sinatra apps on heroku.}
|
13
|
+
gem.homepage = "https://github.com/rjsamson/shag"
|
14
|
+
|
15
|
+
gem.add_runtime_dependency "thor"
|
16
|
+
gem.add_development_dependency "rspec"
|
17
|
+
gem.add_development_dependency "fakefs"
|
18
|
+
gem.add_development_dependency "stub_shell"
|
19
|
+
|
20
|
+
gem.files = `git ls-files`.split($/)
|
21
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
22
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
23
|
+
gem.require_paths = ["lib"]
|
24
|
+
end
|
data/spec/generator.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Generator" do
|
4
|
+
include FakeFS::SpecHelpers
|
5
|
+
|
6
|
+
before do
|
7
|
+
@gen = Shag::Generator.new("test_app")
|
8
|
+
@app_name = "test_app"
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "private methods" do
|
12
|
+
include FakeFS::SpecHelpers
|
13
|
+
describe "#bundle" do
|
14
|
+
it "runs bundle install" do
|
15
|
+
stub_shell do
|
16
|
+
command "bundle install" do
|
17
|
+
stdout <<-HERE
|
18
|
+
Using thor (0.16.0)
|
19
|
+
Using shag (0.0.1)
|
20
|
+
Using bundler (1.2.3)
|
21
|
+
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
|
22
|
+
HERE
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
output = capture_stdout { @gen.send(:bundle) }
|
27
|
+
output.should eq <<-HERE
|
28
|
+
Running bundle install
|
29
|
+
Using thor (0.16.0)
|
30
|
+
Using shag (0.0.1)
|
31
|
+
Using bundler (1.2.3)
|
32
|
+
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
|
33
|
+
HERE
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#git_init" do
|
38
|
+
it "runs git init" do
|
39
|
+
stub_shell do
|
40
|
+
command "git init" do
|
41
|
+
stdout <<-HERE
|
42
|
+
Initialized empty Git repository in /#{@app_name}/.git/
|
43
|
+
HERE
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
output = capture_stdout { @gen.send(:git_init) }
|
48
|
+
output.should eq <<-HERE
|
49
|
+
Initializing git repo
|
50
|
+
Initialized empty Git repository in /#{@test_app}/.git/
|
51
|
+
HERE
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#generate_gemfile" do
|
56
|
+
before { @output = capture_stdout { @gen.send(:generate_gemfile) } }
|
57
|
+
|
58
|
+
it "creates a Gemfile" do
|
59
|
+
File.exists?("Gemfile")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "prints status to STDOUT" do
|
63
|
+
@output.should eq "Writing Gemfile\n"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "generates a Gemfile with the correct content" do
|
67
|
+
contents = File.read("Gemfile")
|
68
|
+
contents.should eq <<-CONTENTS
|
69
|
+
source :rubygems
|
70
|
+
|
71
|
+
gem 'sinatra'
|
72
|
+
CONTENTS
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "#generate_procfile" do
|
77
|
+
before { @output = capture_stdout { @gen.send(:generate_procfile) } }
|
78
|
+
|
79
|
+
it "creates a Procfile" do
|
80
|
+
File.exists?("Procfile")
|
81
|
+
end
|
82
|
+
|
83
|
+
it "prints status to STDOUT" do
|
84
|
+
@output.should eq "Writing Procfile\n"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "generates a Procfile with the correct content" do
|
88
|
+
contents = File.read("Procfile")
|
89
|
+
contents.should eq <<-CONTENTS
|
90
|
+
web: bundle exec ruby #{@app_name}.rb -p $PORT
|
91
|
+
CONTENTS
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#generate_sinatra_file" do
|
96
|
+
before { @output = capture_stdout { @gen.send(:generate_sinatra_file) } }
|
97
|
+
|
98
|
+
it "creates a .rb file named after the @app_name" do
|
99
|
+
File.exists?("#{@app_name}.rb")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "prints status to STDOUT" do
|
103
|
+
@output.should eq "Writing #{@app_name}.rb\n"
|
104
|
+
end
|
105
|
+
|
106
|
+
it "generates a Sinatra application file with the correct content" do
|
107
|
+
contents = File.read("#{@app_name}.rb")
|
108
|
+
contents.should eq <<-CONTENTS
|
109
|
+
require 'sinatra'
|
110
|
+
|
111
|
+
get '/' do
|
112
|
+
puts "Hello world!"
|
113
|
+
end
|
114
|
+
CONTENTS
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'shag'
|
2
|
+
require 'fakefs/spec_helpers'
|
3
|
+
require 'stub_shell'
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.include StubShell::TestHelpers
|
7
|
+
end
|
8
|
+
|
9
|
+
# Credit to cldwalker for capture_stdout
|
10
|
+
# From https://github.com/cldwalker/hirb/blob/master/test/test_helper.rb
|
11
|
+
|
12
|
+
def capture_stdout(&block)
|
13
|
+
original_stdout = $stdout
|
14
|
+
$stdout = fake = StringIO.new
|
15
|
+
begin
|
16
|
+
yield
|
17
|
+
ensure
|
18
|
+
$stdout = original_stdout
|
19
|
+
end
|
20
|
+
fake.string
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Robert J Samson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: thor
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: fakefs
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: stub_shell
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: SHAG - Sinatra Heroku App Generator - A stupidly simple, single purpose
|
79
|
+
CLI for generating a scaffold for Sinatra apps on heroku.
|
80
|
+
email:
|
81
|
+
- rjsamson@me.com
|
82
|
+
executables:
|
83
|
+
- shag
|
84
|
+
extensions: []
|
85
|
+
extra_rdoc_files: []
|
86
|
+
files:
|
87
|
+
- .gitignore
|
88
|
+
- Gemfile
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.md
|
91
|
+
- Rakefile
|
92
|
+
- bin/shag
|
93
|
+
- lib/shag.rb
|
94
|
+
- lib/shag/generator.rb
|
95
|
+
- lib/shag/version.rb
|
96
|
+
- shag.gemspec
|
97
|
+
- spec/generator.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
homepage: https://github.com/rjsamson/shag
|
100
|
+
licenses: []
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.8.24
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: A stupidly simple, single purpose CLI for generating a scaffold for Sinatra
|
123
|
+
apps on heroku.
|
124
|
+
test_files:
|
125
|
+
- spec/generator.rb
|
126
|
+
- spec/spec_helper.rb
|