rails-new 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rails-new +5 -80
- data/lib/rails_new.rb +2 -0
- data/lib/rails_new/cli.rb +89 -0
- data/lib/rails_new/command.rb +24 -0
- data/lib/rails_new/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2574d8e6e14dafba2a540d34dcea2ae52e6f7614
|
4
|
+
data.tar.gz: 915ba3662d5a33c03121bcf74b1a0be4103c3c80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 626a7cb24ebb747869b6fc4a68726da8e0f013cc834872629b04ad4e5c6ffe8f2e56aef9f4da0a681657a8af3c307ad953be2a7c00d8d389f36c1d89fb172999
|
7
|
+
data.tar.gz: 30319c83146979c7ec93e8a27df8302ed1a77c41ac8534b6c35e232e23cfe9e63449b7069a51018eb64f86bcc62d902c02362b0630d814395ac2aae274ae3538
|
data/bin/rails-new
CHANGED
@@ -1,85 +1,10 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "thor"
|
4
|
-
require "thor/group"
|
5
|
-
require 'httparty'
|
6
|
-
require 'tmpdir'
|
7
|
-
|
8
2
|
require_relative '../lib/rails_new'
|
9
3
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
:type => :string,
|
15
|
-
:desc => "The template key in the format user/template",
|
16
|
-
:required => true
|
17
|
-
|
18
|
-
argument :app_name,
|
19
|
-
:type => :string,
|
20
|
-
:desc => "The application name to pass to Rails",
|
21
|
-
:required => true
|
22
|
-
|
23
|
-
def request_template_data
|
24
|
-
url = RailsNew::Api.template_url_for(template_key)
|
25
|
-
|
26
|
-
say "Fetching template data from ", :green, false
|
27
|
-
say url, :blue
|
28
|
-
|
29
|
-
@response = HTTParty.get(url)
|
30
|
-
if @response.code != 200
|
31
|
-
raise "The response of the server to #{@response.request.uri} was not 200."
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def parse_template_data
|
36
|
-
@template_data = JSON.parse(@response.body)['template']
|
37
|
-
@git_repository = @template_data['git_repository']
|
38
|
-
@git_branch = @template_data['git_branch']
|
39
|
-
@main_file_location = @template_data["main_file_location"]
|
40
|
-
@arguments = build_arguments_array(@template_data['arguments'])
|
41
|
-
end
|
42
|
-
|
43
|
-
def run_template
|
44
|
-
Dir.mktmpdir do |temp_dir|
|
45
|
-
template_location = Pathname.new(temp_dir).join(@main_file_location).to_s
|
46
|
-
|
47
|
-
say "Cloning git repository ", :green, false
|
48
|
-
say @git_repository, :blue
|
49
|
-
Kernel.system %w{git clone -b #{@git_branch} #{@git_repository} #{temp_dir}}
|
50
|
-
|
51
|
-
command = [
|
52
|
-
"rails", "new", @app_name, "-m", template_location, *@arguments, *extra_rails_arguments
|
53
|
-
]
|
54
|
-
|
55
|
-
say "The following command will be executed:", :green, false
|
56
|
-
|
57
|
-
puts "\n\n"
|
58
|
-
say command.join(' '), :blue
|
59
|
-
puts
|
60
|
-
|
61
|
-
if yes? "Is this command safe?"
|
62
|
-
say "Executing template", :green
|
63
|
-
Kernel.system *command
|
64
|
-
else
|
65
|
-
say "Aborted command. Please review the template #{template_key}.", :red
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
private
|
71
|
-
|
72
|
-
def build_arguments_array(arguments)
|
73
|
-
arguments.map do |arg|
|
74
|
-
tokens = [arg['key']]
|
75
|
-
tokens << [arg['value']] if arg['has_value']
|
76
|
-
tokens
|
77
|
-
end.flatten
|
78
|
-
end
|
79
|
-
|
80
|
-
def extra_rails_arguments
|
81
|
-
@extra_rails_arguments ||= ARGV[2..-1]
|
82
|
-
end
|
4
|
+
if ['-v', '--version'].include?(ARGV.first)
|
5
|
+
require_relative '../lib/rails_new/version'
|
6
|
+
puts RailsNew::VERSION
|
7
|
+
exit(0)
|
83
8
|
end
|
84
9
|
|
85
|
-
|
10
|
+
RailsNew::CLI.start(ARGV)
|
data/lib/rails_new.rb
CHANGED
@@ -0,0 +1,89 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "thor/group"
|
3
|
+
require "httparty"
|
4
|
+
require "tmpdir"
|
5
|
+
|
6
|
+
module RailsNew
|
7
|
+
class CLI < Thor::Group
|
8
|
+
desc "run `rails new` with the requirements of the template"
|
9
|
+
|
10
|
+
argument :template_key,
|
11
|
+
:type => :string,
|
12
|
+
:desc => "The template key in the format user/template",
|
13
|
+
:required => true
|
14
|
+
|
15
|
+
argument :app_name,
|
16
|
+
:type => :string,
|
17
|
+
:desc => "The application name to pass to Rails",
|
18
|
+
:required => true
|
19
|
+
|
20
|
+
class_option :version, :type => :string, :required => false
|
21
|
+
|
22
|
+
def request_template_data
|
23
|
+
url = RailsNew::Api.template_url_for(template_key)
|
24
|
+
|
25
|
+
say "Fetching template data from ", :green, false
|
26
|
+
say url, :blue
|
27
|
+
|
28
|
+
@response = HTTParty.get(url)
|
29
|
+
if @response.code != 200
|
30
|
+
raise "The response of the server to #{@response.request.uri} was not 200."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def parse_template_data
|
35
|
+
@template_data = JSON.parse(@response.body)['template']
|
36
|
+
@git_repository = @template_data['git_repository']
|
37
|
+
@git_branch = @template_data['git_branch']
|
38
|
+
@main_file_location = @template_data["main_file_location"]
|
39
|
+
@arguments = build_arguments_array(@template_data['arguments'])
|
40
|
+
end
|
41
|
+
|
42
|
+
def run_template
|
43
|
+
Dir.mktmpdir do |temp_dir|
|
44
|
+
template_location = Pathname.new(temp_dir).join(@main_file_location).to_s
|
45
|
+
|
46
|
+
say "Cloning git repository ", :green, false
|
47
|
+
say @git_repository, :blue
|
48
|
+
clone_command = RailsNew::Command.new("git", "clone", "-b", @git_branch, @git_repository, temp_dir)
|
49
|
+
clone_command.run
|
50
|
+
|
51
|
+
rails_command = RailsNew::Command.new(
|
52
|
+
"rails", "new", @app_name, "-m", template_location, *@arguments, *extra_rails_arguments
|
53
|
+
)
|
54
|
+
|
55
|
+
say "The following command will be executed:", :green, false
|
56
|
+
|
57
|
+
puts "\n\n"
|
58
|
+
say rails_command.to_s, :blue
|
59
|
+
puts
|
60
|
+
|
61
|
+
if yes? "Is this command safe?"
|
62
|
+
say "Executing template", :green
|
63
|
+
rails_command.run
|
64
|
+
else
|
65
|
+
say "Aborted command. Please review the template #{template_key}.", :red
|
66
|
+
exit(1)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def exit_on_failure?
|
72
|
+
true
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def build_arguments_array(arguments)
|
78
|
+
arguments.map do |arg|
|
79
|
+
tokens = [arg['key']]
|
80
|
+
tokens << [arg['value']] if arg['has_value']
|
81
|
+
tokens
|
82
|
+
end.flatten
|
83
|
+
end
|
84
|
+
|
85
|
+
def extra_rails_arguments
|
86
|
+
@extra_rails_arguments ||= ARGV[2..-1]
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RailsNew
|
2
|
+
class Command
|
3
|
+
attr_reader :command
|
4
|
+
|
5
|
+
def initialize(*command)
|
6
|
+
self.command = command
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
result = Kernel.system *command
|
11
|
+
unless result
|
12
|
+
raise "Command #{to_s} failed."
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
command.join(' ')
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_writer :command
|
23
|
+
end
|
24
|
+
end
|
data/lib/rails_new/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-new
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- juliogarciag
|
@@ -83,6 +83,8 @@ files:
|
|
83
83
|
- lib/rails_new.rb
|
84
84
|
- lib/rails_new/.DS_Store
|
85
85
|
- lib/rails_new/api.rb
|
86
|
+
- lib/rails_new/cli.rb
|
87
|
+
- lib/rails_new/command.rb
|
86
88
|
- lib/rails_new/version.rb
|
87
89
|
- rails-new.gemspec
|
88
90
|
homepage: ''
|