jumpstart 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +30 -3
- data/config/jumpstart_version.yml +1 -1
- data/lib/jumpstart.rb +21 -22
- data/lib/jumpstart/base.rb +505 -481
- data/lib/jumpstart/filetools.rb +11 -11
- data/test/jumpstart/test_base.rb +362 -280
- data/test/test_jumpstart.rb +50 -30
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
=JumpStart
|
2
2
|
|
3
|
-
|
3
|
+
JumpStart is a gem for quickly creating projects.
|
4
4
|
It does this by running options from a YAML file that you can create, or you can let the gem do it for you.
|
5
5
|
It's dead easy to do.
|
6
6
|
|
7
|
+
==Use Case
|
8
|
+
Despite the many cool generators etc for a typical framework based project, there are always things that I wanted set up differently when starting a new Rails/Sinatra/(other cool framework) project. I figured that the way that these tools create code, and what that code is, will constantly change. With that in mind, the only way to be able to control the creation of genuinely unique project configurations would be to manipulate the files that these processes create. This is what JumpStart does. As well as some other cool stuff to avoid doing the same tedious setup dance over and over again.
|
9
|
+
|
10
|
+
My main use case is Rails. Application templates weren't adjustable or broad enough in scope for me, and I wanted a way of automatically configuring my local Nginx setup to include the new project, make a collection of changes to the files generated by Rails (for example changing the path of the Production MySQL database) as well as running a bunch of other stuff that needs to happen at a projects inception (Like running Capistrano and creating a custom deploy.rb file or checking the project in to source control. Git in my case.) I also wanted one place to keep my setup templates for all kinds of different projects. I might want to create a Ruby Gem in a certain way, or a Sinatra app. So that's why I wrote this gem. That, and it being fun :-) Give it a try, I think you'll like it.
|
11
|
+
|
12
|
+
Finally, if you think that anything isn't clear in this README or you have other ideas about improving JumpStart, give me a shout!
|
13
|
+
|
7
14
|
==Features
|
8
15
|
With jumpstart you can:
|
9
16
|
|
@@ -26,6 +33,15 @@ Build jumpstart from the git repo's gemspec:
|
|
26
33
|
gem build jumpstart.gemspec
|
27
34
|
Install the newly created gem:
|
28
35
|
gem install jumpstart-WHATEVER_THE_CURRENT_VERSION_IS.gem
|
36
|
+
|
37
|
+
I've tested JumpStart with Ruby 1.8.7 and Ruby 1.9.2-head
|
38
|
+
|
39
|
+
If you're on a Unix based system, you're good to go!
|
40
|
+
|
41
|
+
If you are using Windows, what were you thinking! ;-)
|
42
|
+
You'll need the win32console gem to use JumpStart
|
43
|
+
gem install win32console
|
44
|
+
I can't figure a good way to get this dependancy to install automatically for Windows users without disturbing their Unix bashing friends. If anyone knows how I might achieve this (with Bundler or otherwise) just let me know and I'll implement it.
|
29
45
|
|
30
46
|
====NOTE! If you install jumpstart using sudo then you will probably need to run jumpstart with it as well to grant writes to the YAML files in the gem.
|
31
47
|
|
@@ -38,10 +54,20 @@ If you have a template and you would like to create a new project with it, pass
|
|
38
54
|
If you have already created a template and set it as the default jumpstart template (you can do this in the jumpstart menu), you can create a new project using it by passing just the new projects name to jumpstart. e.g.
|
39
55
|
jumpstart my_new_project
|
40
56
|
|
41
|
-
If you haven't created any templates yet, or you want to change one of
|
57
|
+
If you haven't created any templates yet, or you want to change one of JumpStarts configuration options, just call:
|
42
58
|
jumpstart
|
43
59
|
This will launch the jumpstart menu.
|
44
60
|
|
61
|
+
== The JumpStart menu
|
62
|
+
JumpStart has a handy menu interface which will start up if you don't pass the jumpstart command any (or enough) arguments.
|
63
|
+
From the menu you can:
|
64
|
+
* Create a new project from a list of existing templates
|
65
|
+
* Create a new template from scratch (the config file and directory structure will be created for you.)
|
66
|
+
* Create a new template by duplicating an existing one. (Everything the except the name.)
|
67
|
+
* Set the default template. (The template that will be used if you invoke the jumpstart command with only a project name)
|
68
|
+
* Set the directory that JumpStart looks in for templates. This means you can have your own folder anywhere on your dev machine for templates. By default templates get created inside the JumpStart gems directory structure.
|
69
|
+
* Easily reset the default template directory back to the original default (All of the templates in your current default templates directory will be copied back inside the gem.)
|
70
|
+
|
45
71
|
== Template File Syntax
|
46
72
|
One of the core ideas behind jumpstart is the notion of generating files in a new project automatically from template files. The idea being that you specify a generator of some kind in the jumpstart YAML (the install command), which sets up a generic project (for example rails). Once this has happened the jumpstart template will be parsed for template files to apply to the new project. Anything inside the jumpstart_config directory will not be copied to the project, this is where the templates configuration YAML lives. Everything else is evaluated from the root of the template directory and applied to the new project, again with the projects containing folder treated as the beginning of file paths. So as an example, a jumpstart template called "my_template" containing the path /folder1/folder2/file.txt when parsed would generate the same path in the new project. e.g. my_project/folder1/folder2/file.txt The template files contained in a jumpstart template come in three flavours:
|
47
73
|
|
@@ -76,7 +102,8 @@ e.g.
|
|
76
102
|
===:install_command_args:
|
77
103
|
Can be omitted or left blank.
|
78
104
|
The arguments for :install_command. Broken into it's own value to allow the project name to be inserted between the two values.
|
79
|
-
e.g.
|
105
|
+
e.g.
|
106
|
+
:install_command_args: -d mysql -J -T
|
80
107
|
|
81
108
|
===:run_after_install_command:
|
82
109
|
Can be omitted or left blank.
|
data/lib/jumpstart.rb
CHANGED
@@ -25,13 +25,13 @@ if RbConfig::CONFIG['host_os'] =~ /mswin|windows|cygwin|mingw32/
|
|
25
25
|
end
|
26
26
|
|
27
27
|
module JumpStart
|
28
|
-
|
28
|
+
|
29
29
|
ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
30
30
|
LIB_PATH = File.expand_path(File.dirname(__FILE__))
|
31
31
|
CONFIG_PATH = File.expand_path(File.join(File.dirname(__FILE__), '../config'))
|
32
32
|
IGNORE_DIRS = ['.','..']
|
33
33
|
LAUNCH_PATH = FileUtils.pwd
|
34
|
-
|
34
|
+
|
35
35
|
@jumpstart_setup_yaml = YAML.load_file("#{JumpStart::CONFIG_PATH}/jumpstart_setup.yml")
|
36
36
|
@jumpstart_version_yaml = YAML.load_file("#{JumpStart::CONFIG_PATH}/jumpstart_version.yml")
|
37
37
|
|
@@ -40,9 +40,9 @@ module JumpStart
|
|
40
40
|
@version_patch = @jumpstart_version_yaml[:jumpstart_version_patch]
|
41
41
|
|
42
42
|
class << self
|
43
|
-
|
43
|
+
|
44
44
|
attr_accessor :default_template_name, :version_major, :version_minor, :version_patch
|
45
|
-
|
45
|
+
|
46
46
|
# Set the jumpstart templates path back to default if it has not been set
|
47
47
|
def templates_path
|
48
48
|
if @templates_path.nil? || @templates_path.empty?
|
@@ -51,11 +51,11 @@ module JumpStart
|
|
51
51
|
@templates_path
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
def templates_path=(value)
|
56
56
|
@templates_path = value
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
# TODO JumpStart#lookup_existing_templates class instance method needs tests
|
60
60
|
def existing_templates
|
61
61
|
templates = []
|
@@ -71,23 +71,23 @@ module JumpStart
|
|
71
71
|
end
|
72
72
|
templates
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
# Method for writing to config/jumpstart_setup.yml
|
76
76
|
def dump_jumpstart_setup_yaml
|
77
77
|
File.open( "#{JumpStart::CONFIG_PATH}/jumpstart_setup.yml", 'w' ) do |out|
|
78
78
|
YAML.dump( {:jumpstart_templates_path => @templates_path, :jumpstart_default_template_name => @default_template_name}, out )
|
79
|
-
end
|
79
|
+
end
|
80
80
|
end
|
81
|
-
|
81
|
+
|
82
82
|
# Method for writing to config/jumpstart_version.yml
|
83
83
|
def dump_jumpstart_version_yaml
|
84
84
|
File.open( "#{JumpStart::CONFIG_PATH}/jumpstart_version.yml", 'w' ) do |out|
|
85
85
|
YAML.dump( {:jumpstart_version_major => @version_major, :jumpstart_version_minor => @version_minor, :jumpstart_version_patch => @version_patch}, out )
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
# Looks up the current version of JumpStart
|
90
|
-
def version
|
90
|
+
def version
|
91
91
|
"#{version_major}.#{version_minor}.#{version_patch}"
|
92
92
|
end
|
93
93
|
|
@@ -104,7 +104,7 @@ module JumpStart
|
|
104
104
|
end
|
105
105
|
dump_jumpstart_version_yaml
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
# Handles calls to JumpStart::Setup.bump_version_major, JumpStart::Setup.bump_version_minor and JumpStart::Setup.bump_version_patch class methods.
|
109
109
|
def method_missing(method, *args)
|
110
110
|
if method.to_s.match(/^bump_version_(major|minor|patch)$/)
|
@@ -114,29 +114,28 @@ module JumpStart
|
|
114
114
|
super
|
115
115
|
end
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
# Handles calls to missing constants in the JumpStart module. Calls JumpStart.version if JumpStart::VERSION is recognised.
|
119
119
|
def const_missing(name)
|
120
|
-
if name.to_s =~ /^VERSION$/
|
120
|
+
if name.to_s =~ /^VERSION$/
|
121
121
|
version
|
122
122
|
else
|
123
123
|
super
|
124
124
|
end
|
125
125
|
end
|
126
|
-
|
126
|
+
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
# sets the default template to use if it has not been passed as an argument.
|
130
130
|
# Set as a module instance variable.
|
131
131
|
if !@jumpstart_setup_yaml[:jumpstart_default_template_name].nil?
|
132
132
|
@default_template_name = @jumpstart_setup_yaml[:jumpstart_default_template_name] if existing_templates.include?(@jumpstart_setup_yaml[:jumpstart_default_template_name])
|
133
133
|
end
|
134
|
-
|
135
|
-
# The path to the jumpstart templates directory.
|
136
|
-
# Set as a module instance variable.
|
134
|
+
|
135
|
+
# The path to the jumpstart templates directory.
|
136
|
+
# Set as a module instance variable.
|
137
137
|
if !@jumpstart_setup_yaml[:jumpstart_templates_path].nil?
|
138
|
-
@templates_path = @jumpstart_setup_yaml[:jumpstart_templates_path] if Dir.exists?(@jumpstart_setup_yaml[:jumpstart_templates_path])
|
138
|
+
@templates_path = @jumpstart_setup_yaml[:jumpstart_templates_path] if Dir.exists?(@jumpstart_setup_yaml[:jumpstart_templates_path])
|
139
139
|
end
|
140
|
-
|
141
|
-
end
|
142
140
|
|
141
|
+
end
|
data/lib/jumpstart/base.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module JumpStart
|
2
2
|
class Base
|
3
|
-
|
3
|
+
|
4
4
|
# Accessor methods to make testing input or output easier.
|
5
5
|
attr_accessor :input, :output
|
6
6
|
|
@@ -8,12 +8,12 @@ module JumpStart
|
|
8
8
|
def gets(*args)
|
9
9
|
@input.gets(*args)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
# Monkeypatch puts to make testing easier.
|
13
13
|
def puts(*args)
|
14
|
-
@output.puts(*args)
|
14
|
+
@output.puts(*args)
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
# Sets up JumpStart::Base object with preliminary instance variables.
|
18
18
|
def initialize(args)
|
19
19
|
# setup for testing input
|
@@ -33,7 +33,7 @@ module JumpStart
|
|
33
33
|
# set instance variable @template_path as the directory to read templates from.
|
34
34
|
@template_path = FileUtils.join_paths(JumpStart.templates_path, @template_name)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
# Sets up instance variables from YAML file
|
38
38
|
def set_config_file_options
|
39
39
|
if @template_name.nil? || @template_path.nil?
|
@@ -48,7 +48,7 @@ module JumpStart
|
|
48
48
|
jumpstart_menu
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
|
52
52
|
# Pre-install project configuration checking.
|
53
53
|
def check_setup
|
54
54
|
set_config_file_options
|
@@ -57,7 +57,7 @@ module JumpStart
|
|
57
57
|
check_template_path
|
58
58
|
check_install_path
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
# Runs the configuration, generating the new project from the chosen template.
|
62
62
|
def start
|
63
63
|
puts "\n******************************************************************************************************************************************\n\n"
|
@@ -76,7 +76,7 @@ module JumpStart
|
|
76
76
|
check_local_nginx_configuration
|
77
77
|
exit_with_success
|
78
78
|
end
|
79
|
-
|
79
|
+
|
80
80
|
# Checks replace string values for :project_name and replaces these with the value of @project_name if found. This enables PROJECT_NAME entries in projects to be dynamically populated with the current project name.
|
81
81
|
def check_replace_string_pairs_for_project_name_sub(hash)
|
82
82
|
unless @project_name.nil?
|
@@ -88,534 +88,558 @@ module JumpStart
|
|
88
88
|
end
|
89
89
|
hash
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
private
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
93
|
+
|
94
|
+
# Makes sure that the chosen project name is suitable. (Not nil or empty, at least 3 characters long, and starts with a letter or a number.)
|
95
|
+
# Returns with the value of @project_name
|
96
|
+
def check_project_name
|
97
|
+
if @project_name == "b"
|
98
|
+
@project_name = nil
|
99
|
+
jumpstart_menu
|
100
|
+
elsif @project_name == "x"
|
101
|
+
@project_name = nil
|
102
|
+
exit_normal
|
103
|
+
elsif @project_name.nil? || @project_name.empty?
|
104
|
+
puts "\n Enter a name for your project.".yellow
|
105
|
+
@project_name = gets.chomp.strip
|
106
|
+
check_project_name
|
107
|
+
elsif @project_name.length < 3
|
108
|
+
puts "\n The name #{@project_name} is too short. Please enter a name at least 3 characters long.".red
|
109
|
+
@project_name = gets.chomp.strip
|
110
|
+
check_project_name
|
111
|
+
elsif @project_name.match(/^\W/)
|
112
|
+
puts "\n #{@project_name} begins with an invalid character. Please enter a name thats starts with a letter or a number.".red
|
113
|
+
@project_name = gets.chomp.strip
|
114
|
+
check_project_name
|
115
|
+
else
|
116
|
+
@project_name
|
117
|
+
end
|
117
118
|
end
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
119
|
+
|
120
|
+
# Launches the JumpStart menu system if a template has not been specified.
|
121
|
+
def check_template_name
|
122
|
+
if @template_name.nil? || @template_name.empty?
|
123
|
+
jumpstart_menu
|
124
|
+
end
|
124
125
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
126
|
+
|
127
|
+
# Ensures that the template path specified exists and can be accessed. Exits if an error occurs.
|
128
|
+
def check_template_path
|
129
|
+
begin
|
130
|
+
Dir.chdir(@template_path)
|
131
|
+
rescue
|
132
|
+
puts "\nThe directory #{@template_path.red} could not be found, or you do not have the correct permissions to access it."
|
133
|
+
exit_normal
|
134
|
+
end
|
134
135
|
end
|
135
|
-
end
|
136
136
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
137
|
+
# Sets the install path to executing directory if @install_path varibale is nil or empty. This should result in projects being created in directory from which the jumpstart command was called, if the template specified does not set this option.
|
138
|
+
# Checks the install path set in @install_path.
|
139
|
+
# Checks that a directory with the same name as the project does not already exist in the install path.
|
140
|
+
def check_install_path
|
141
|
+
@install_path = JumpStart::LAUNCH_PATH if @install_path.nil? || @install_path.empty?
|
142
|
+
if File.directory?(FileUtils.join_paths(@install_path, @project_name))
|
143
|
+
puts "\nThe directory #{FileUtils.join_paths(@install_path, @project_name).red} already exists.\nAs this is the location you have specified for creating your new project jumpstart will now exit to avoid overwriting anything."
|
144
|
+
exit_normal
|
145
|
+
end
|
146
|
+
return true
|
145
147
|
end
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
148
|
+
|
149
|
+
# Creates a new blank template in whichever directory the default templates directory has been set to.
|
150
|
+
def create_template
|
151
|
+
if File.directory?(FileUtils.join_paths(JumpStart.templates_path, @template_name))
|
152
|
+
puts "\nThe directory #{FileUtils.join_paths(JumpStart.templates_path, @template_name).red} already exists. The template will not be created."
|
153
|
+
exit_normal
|
154
|
+
else
|
155
|
+
FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, @template_name, "/jumpstart_config"))
|
156
|
+
yaml = IO.read(FileUtils.join_paths(ROOT_PATH, "/source_templates/template_config.yml"))
|
157
|
+
File.open(FileUtils.join_paths(JumpStart.templates_path, @template_name, "/jumpstart_config", "#{@template_name}.yml"), 'w') do |file|
|
158
|
+
file.puts yaml
|
159
|
+
end
|
160
|
+
puts "The template #{@template_name.green} has been generated.\n"
|
159
161
|
end
|
160
|
-
puts "The template #{@template_name.green} has been generated.\n"
|
161
162
|
end
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
puts "******************************************************************************************************************************************\n\n"
|
175
|
-
jumpstart_menu_options
|
176
|
-
end
|
177
|
-
|
178
|
-
# Captures user input for the main jumpstart menu and calls the appropriate method
|
179
|
-
def jumpstart_menu_options
|
180
|
-
input = gets.chomp.strip
|
181
|
-
case
|
182
|
-
when input == "1"
|
183
|
-
new_project_from_template_menu
|
184
|
-
when input == "2"
|
185
|
-
new_template_menu
|
186
|
-
when input == "3"
|
187
|
-
set_default_template_menu
|
188
|
-
when input == "4"
|
189
|
-
templates_dir_menu
|
190
|
-
when input == "x"
|
191
|
-
exit_normal
|
192
|
-
else
|
193
|
-
puts "That command hasn't been understood. Try again!".red
|
163
|
+
|
164
|
+
# Displays options for the main jumpstart menu.
|
165
|
+
def jumpstart_menu
|
166
|
+
puts "\n\n******************************************************************************************************************************************\n\n"
|
167
|
+
puts " JUMPSTART MENU\n".purple
|
168
|
+
puts " Here are your options:\n\n"
|
169
|
+
puts " 1".yellow + " Create a new project from an existing template.\n"
|
170
|
+
puts " 2".yellow + " Create a new template.\n"
|
171
|
+
puts " 3".yellow + " Set the default template.\n"
|
172
|
+
puts " 4".yellow + " Set the templates directory.\n\n"
|
173
|
+
puts " x".yellow + " Exit jumpstart\n\n"
|
174
|
+
puts "******************************************************************************************************************************************\n\n"
|
194
175
|
jumpstart_menu_options
|
195
176
|
end
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
177
|
+
|
178
|
+
# Captures user input for the main jumpstart menu and calls the appropriate method
|
179
|
+
def jumpstart_menu_options
|
180
|
+
input = gets.chomp.strip.downcase
|
181
|
+
case
|
182
|
+
when input == "1"
|
183
|
+
new_project_from_template_menu
|
184
|
+
when input == "2"
|
185
|
+
new_template_menu
|
186
|
+
when input == "3"
|
187
|
+
set_default_template_menu
|
188
|
+
when input == "4"
|
189
|
+
templates_dir_menu
|
190
|
+
when input == "x"
|
191
|
+
exit_normal
|
192
|
+
else
|
193
|
+
puts "That command hasn't been understood. Try again!".red
|
194
|
+
jumpstart_menu_options
|
204
195
|
end
|
205
196
|
end
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
@template_name = JumpStart.existing_templates[(input.to_i - 1)]
|
227
|
-
check_project_name
|
228
|
-
project = JumpStart::Base.new([@project_name, @template_name])
|
229
|
-
project.check_setup
|
230
|
-
project.start
|
231
|
-
when input == "b"
|
232
|
-
jumpstart_menu
|
233
|
-
when input == "x"
|
234
|
-
exit_normal
|
235
|
-
else
|
236
|
-
puts "That command hasn't been understood. Try again!".red
|
197
|
+
|
198
|
+
def display_existing_templates
|
199
|
+
unless JumpStart.existing_templates.empty?
|
200
|
+
count = 0
|
201
|
+
JumpStart.existing_templates.each do |x|
|
202
|
+
count += 1
|
203
|
+
puts " #{count.to_s.yellow} #{x.green}\n"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
# Displays options for the "create a new jumpstart project from an existing template" menu
|
209
|
+
def new_project_from_template_menu
|
210
|
+
puts "\n\n******************************************************************************************************************************************\n\n"
|
211
|
+
puts " CREATE A NEW JUMPSTART PROJECT FROM AN EXISTING TEMPLATE\n\n".purple
|
212
|
+
puts " Type a number for the template that you want.\n\n"
|
213
|
+
display_existing_templates
|
214
|
+
puts "\n b".yellow + " Back to main menu."
|
215
|
+
puts "\n x".yellow + " Exit jumpstart\n\n"
|
216
|
+
puts "******************************************************************************************************************************************\n\n"
|
237
217
|
new_project_from_template_options
|
238
218
|
end
|
239
|
-
end
|
240
|
-
|
241
|
-
# Displays output for the "create a new jumpstart template" menu
|
242
|
-
def new_template_menu
|
243
|
-
puts "\n\n******************************************************************************************************************************************\n\n"
|
244
|
-
puts " CREATE A NEW JUMPSTART TEMPLATE\n".purple
|
245
|
-
puts " Existing templates:\n"
|
246
|
-
display_existing_templates
|
247
|
-
puts "\n b".yellow + " Back to main menu."
|
248
|
-
puts "\n x".yellow + " Exit jumpstart\n"
|
249
|
-
new_template_options
|
250
|
-
end
|
251
219
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
220
|
+
# Captures user input for the "create a new jumpstart project from an existing template" menu and calls the appropriate method.
|
221
|
+
# When the input matches a template number a project will be created from that template
|
222
|
+
def new_project_from_template_options
|
223
|
+
input = gets.chomp.strip.downcase
|
224
|
+
case
|
225
|
+
when input.to_i <= JumpStart.existing_templates.count && input.to_i > 0
|
226
|
+
@template_name = JumpStart.existing_templates[(input.to_i - 1)]
|
227
|
+
check_project_name
|
228
|
+
project = JumpStart::Base.new([@project_name, @template_name])
|
229
|
+
project.check_setup
|
230
|
+
project.start
|
231
|
+
when input == "b"
|
232
|
+
jumpstart_menu
|
233
|
+
when input == "x"
|
234
|
+
exit_normal
|
235
|
+
else
|
236
|
+
puts "That command hasn't been understood. Try again!".red
|
237
|
+
new_project_from_template_options
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
# Displays output for the "create a new jumpstart template" menu
|
242
|
+
def new_template_menu
|
243
|
+
puts "\n\n******************************************************************************************************************************************\n\n"
|
244
|
+
puts " CREATE A NEW JUMPSTART TEMPLATE\n".purple
|
245
|
+
puts " Existing templates:\n"
|
246
|
+
display_existing_templates
|
247
|
+
puts "\n b".yellow + " Back to main menu."
|
248
|
+
puts "\n x".yellow + " Exit jumpstart\n"
|
274
249
|
new_template_options
|
275
|
-
else
|
276
|
-
FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config"))
|
277
|
-
FileUtils.cp(FileUtils.join_paths(ROOT_PATH, "source_templates/template_config.yml"), FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config", "#{input}.yml"))
|
278
|
-
puts "\n The template ".green + input.green_bold + " has been created in your default jumpstart template directory ".green + JumpStart.templates_path.green_bold + " ready for editing.".green
|
279
|
-
jumpstart_menu
|
280
250
|
end
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
251
|
+
|
252
|
+
# Captures user input for "create a new jumpstart template" menu and calls the appropriate action.
|
253
|
+
# If the template name provided meets the methods requirements then a directory of that name containing a jumpstart_config dir and matching yaml file are created.
|
254
|
+
def new_template_options
|
255
|
+
puts "\n Enter a unique name to create a new template, or enter an existing templates name (or number) to duplicate it.".yellow
|
256
|
+
input = gets.chomp.strip
|
257
|
+
case
|
258
|
+
when input.downcase == "b"
|
259
|
+
jumpstart_menu
|
260
|
+
when input.downcase == "x"
|
261
|
+
exit_normal
|
262
|
+
when JumpStart.existing_templates.include?(input)
|
263
|
+
puts "\n You have chosen to duplicate the " + input.green + " template." + "\n Please enter a name for the duplicate.".yellow
|
264
|
+
duplicate_template(input)
|
265
|
+
when input.to_i != 0 && input.to_i <= JumpStart.existing_templates.count
|
266
|
+
puts "\n You have chosen to duplicate the " + JumpStart.existing_templates[(input.to_i - 1)].green + " template." + "\n Please enter a name for the duplicate.".yellow
|
267
|
+
duplicate_template(JumpStart.existing_templates[(input.to_i - 1)])
|
268
|
+
when input.length < 3
|
269
|
+
puts "\n The template name ".red + input.red_bold + " is too short. Please enter a name that is at least 3 characters long.".red
|
270
|
+
new_template_options
|
271
|
+
when input.match(/^\W|\W$/)
|
272
|
+
puts "\n The template name ".red + input.red_bold + " begins or ends with an invalid character. Please enter a name that begins with a letter or a number.".red
|
273
|
+
new_template_options
|
274
|
+
else
|
275
|
+
FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config"))
|
276
|
+
FileUtils.cp(FileUtils.join_paths(ROOT_PATH, "source_templates/template_config.yml"), FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config", "#{input}.yml"))
|
277
|
+
puts "\n The template ".green + input.green_bold + " has been created in your default jumpstart template directory ".green + JumpStart.templates_path.green_bold + " ready for editing.".green
|
278
|
+
jumpstart_menu
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
# Duplicates an existing template, changing the name of the config YAML file to the name of the new project.
|
283
|
+
def duplicate_template(template)
|
284
|
+
input = gets.chomp.strip
|
285
|
+
case
|
286
|
+
when input.downcase == "b"
|
287
|
+
jumpstart_menu
|
288
|
+
when input.downcase == "x"
|
289
|
+
exit_normal
|
290
|
+
when JumpStart.existing_templates.include?(input)
|
291
|
+
puts " The template ".red + input.red_bold + " already exists. Please enter a unique name for the duplicate.".red
|
292
|
+
duplicate_template(template)
|
293
|
+
when input.length < 3
|
294
|
+
puts " The template name ".red + input.red_bold + " is too short. Please enter a name that is at least 3 characters long.".red
|
295
|
+
duplicate_template(template)
|
296
|
+
when input.match(/^\W|\W$/)
|
297
|
+
puts " The template name ".red + input.red_bold + " begins or ends with an invalid character. Please enter a name that begins with a letter or a number.".red
|
298
|
+
duplicate_template(template)
|
299
|
+
else
|
300
|
+
files_and_dirs = FileUtils.sort_contained_files_and_dirs(FileUtils.join_paths(JumpStart.templates_path, template))
|
301
|
+
FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config"))
|
302
|
+
FileUtils.touch(FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config", "#{input}.yml"))
|
303
|
+
files_and_dirs[:dirs].each {|x| FileUtils.mkdir_p(FileUtils.join_paths(JumpStart.templates_path, input, x))}
|
304
|
+
files_and_dirs[:files].each do |x|
|
305
|
+
if x.match(/\/jumpstart_config\/#{template}\.yml/)
|
306
|
+
FileUtils.copy_file(FileUtils.join_paths(JumpStart.templates_path, template, x), FileUtils.join_paths(JumpStart.templates_path, input, "jumpstart_config", "#{input}.yml") )
|
307
|
+
else
|
308
|
+
FileUtils.cp(FileUtils.join_paths(JumpStart.templates_path, template, x), FileUtils.join_paths(JumpStart.templates_path, input, x))
|
309
|
+
end
|
310
310
|
end
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
# Displays output for the "jumpstart default template options menu"
|
319
|
-
def set_default_template_menu
|
320
|
-
puts "\n\n******************************************************************************************************************************************\n\n"
|
321
|
-
puts " SELECT A DEFAULT JUMPSTART TEMPLATE\n\n".purple
|
322
|
-
display_existing_templates
|
323
|
-
puts "\n b".yellow + " Back to main menu.\n\n"
|
324
|
-
puts " x".yellow + " Exit jumpstart\n\n"
|
325
|
-
puts "******************************************************************************************************************************************\n\n"
|
326
|
-
set_default_template_options
|
327
|
-
end
|
328
|
-
|
329
|
-
# Sets the default template to be used by JumpStart and writes it to a YAML file.
|
330
|
-
def set_default_template_options
|
331
|
-
input = gets.chomp.strip
|
332
|
-
case
|
333
|
-
when input.to_i <= JumpStart.existing_templates.count && input.to_i > 0
|
334
|
-
JumpStart.default_template_name = JumpStart.existing_templates[(input.to_i - 1)]
|
335
|
-
JumpStart.dump_jumpstart_setup_yaml
|
336
|
-
puts " The default jumpstart template has been set to: ".green + JumpStart.default_template_name.green_bold
|
337
|
-
jumpstart_menu
|
338
|
-
when input == "b"
|
339
|
-
jumpstart_menu
|
340
|
-
when input == "x"
|
341
|
-
exit_normal
|
342
|
-
else
|
343
|
-
puts "That command hasn't been understood. Try again!".red
|
344
|
-
set_default_template_options
|
311
|
+
puts "\n Duplication complete!".green_bold
|
312
|
+
puts " Template " + template.green + " has been duplicated to " + input.green
|
313
|
+
jumpstart_menu
|
314
|
+
end
|
345
315
|
end
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
puts "******************************************************************************************************************************************\n\n"
|
357
|
-
templates_dir_options
|
358
|
-
end
|
359
|
-
|
360
|
-
# Captures user input for the "jumpstart templates directory options" menu and calls the appropriate method.
|
361
|
-
def templates_dir_options
|
362
|
-
input = gets.chomp.strip
|
363
|
-
case
|
364
|
-
when input == "1"
|
365
|
-
puts "Please enter the absolute path for the directory that you would like to contain your jumpstart templates.\n".yellow
|
366
|
-
set_templates_dir
|
367
|
-
when input == "2"
|
368
|
-
reset_templates_dir_to_default_check
|
369
|
-
when input == "b"
|
370
|
-
jumpstart_menu
|
371
|
-
when input == "x"
|
372
|
-
exit_normal
|
373
|
-
else
|
374
|
-
puts "That command hasn't been understood. Try again!".red
|
375
|
-
templates_dir_options
|
316
|
+
|
317
|
+
# Displays output for the "jumpstart default template options menu"
|
318
|
+
def set_default_template_menu
|
319
|
+
puts "\n\n******************************************************************************************************************************************\n\n"
|
320
|
+
puts " SELECT A DEFAULT JUMPSTART TEMPLATE\n\n".purple
|
321
|
+
display_existing_templates
|
322
|
+
puts "\n b".yellow + " Back to main menu.\n\n"
|
323
|
+
puts " x".yellow + " Exit jumpstart\n\n"
|
324
|
+
puts "******************************************************************************************************************************************\n\n"
|
325
|
+
set_default_template_options
|
376
326
|
end
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
root_path = input.sub(/\/\w*\/*$/, '')
|
385
|
-
case
|
386
|
-
when input == "b"
|
387
|
-
jumpstart_menu
|
388
|
-
when input == "x"
|
389
|
-
exit_normal
|
390
|
-
when File.directory?(input)
|
391
|
-
puts "A directory of that name already exists, please choose a directory that does not exist.".red
|
392
|
-
set_templates_dir
|
393
|
-
when File.directory?(root_path)
|
394
|
-
begin
|
395
|
-
Dir.chdir(root_path)
|
396
|
-
Dir.mkdir(input)
|
397
|
-
files_and_dirs = FileUtils.sort_contained_files_and_dirs(JumpStart.templates_path)
|
398
|
-
puts "\nCopying existing templates to #{input}"
|
399
|
-
files_and_dirs[:dirs].each {|x| FileUtils.mkdir_p(FileUtils.join_paths(input, x))}
|
400
|
-
files_and_dirs[:files].each {|x| FileUtils.cp(FileUtils.join_paths(JumpStart.templates_path, x), FileUtils.join_paths(input, x)) }
|
401
|
-
JumpStart.templates_path = input.to_s
|
327
|
+
|
328
|
+
# Sets the default template to be used by JumpStart and writes it to a YAML file.
|
329
|
+
def set_default_template_options
|
330
|
+
input = gets.chomp.strip
|
331
|
+
case
|
332
|
+
when input.to_i <= JumpStart.existing_templates.count && input.to_i > 0
|
333
|
+
JumpStart.default_template_name = JumpStart.existing_templates[(input.to_i - 1)]
|
402
334
|
JumpStart.dump_jumpstart_setup_yaml
|
403
|
-
puts "
|
335
|
+
puts " The default jumpstart template has been set to: ".green + JumpStart.default_template_name.green_bold
|
404
336
|
jumpstart_menu
|
405
|
-
|
406
|
-
|
337
|
+
when input.downcase == "b"
|
338
|
+
jumpstart_menu
|
339
|
+
when input.downcase == "x"
|
340
|
+
exit_normal
|
341
|
+
else
|
342
|
+
puts "That command hasn't been understood. Try again!".red
|
343
|
+
set_default_template_options
|
407
344
|
end
|
408
|
-
else
|
409
|
-
puts "Couldn't find a directory of that name. Try again.".red
|
410
|
-
set_templates_dir
|
411
345
|
end
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
puts "
|
418
|
-
|
419
|
-
|
420
|
-
puts "
|
421
|
-
|
422
|
-
|
423
|
-
puts " Type yes (" + "y".yellow + ") or no (" + "n".yellow + ")\n\n"
|
424
|
-
reset_templates_dir_to_default_set
|
346
|
+
|
347
|
+
# Displays output for the "jumpstart templates directory options" menu.
|
348
|
+
def templates_dir_menu
|
349
|
+
puts "\n\n******************************************************************************************************************************************\n\n"
|
350
|
+
puts " JUMPSTART TEMPLATES DIRECTORY OPTIONS\n\n".purple
|
351
|
+
puts " 1".yellow + " Set templates directory.\n"
|
352
|
+
puts " 2".yellow + " Reset templates directory to default\n\n"
|
353
|
+
puts " b".yellow + " Back to main menu.\n\n"
|
354
|
+
puts " x".yellow + " Exit jumpstart\n\n"
|
355
|
+
puts "******************************************************************************************************************************************\n\n"
|
356
|
+
templates_dir_options
|
425
357
|
end
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
reset_templates_dir_to_default_set
|
358
|
+
|
359
|
+
# Captures user input for the "jumpstart templates directory options" menu and calls the appropriate method.
|
360
|
+
def templates_dir_options
|
361
|
+
input = gets.chomp.strip.downcase
|
362
|
+
case
|
363
|
+
when input == "1"
|
364
|
+
puts " Please enter the absolute path for the directory that you would like to contain your jumpstart templates.".yellow
|
365
|
+
puts " e.g. /Users/your_name/projects/jumpstart_templates\n\n"
|
366
|
+
set_templates_dir
|
367
|
+
when input == "2"
|
368
|
+
reset_templates_dir_to_default_check
|
369
|
+
when input == "b"
|
370
|
+
jumpstart_menu
|
371
|
+
when input == "x"
|
372
|
+
exit_normal
|
373
|
+
else
|
374
|
+
puts " That command hasn't been understood. Try again!".red
|
375
|
+
templates_dir_options
|
376
|
+
end
|
446
377
|
end
|
447
|
-
end
|
448
378
|
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
379
|
+
# Sets the path for templates to be used by JumpStart.
|
380
|
+
# Copies templates in the existing template dir to the new location.
|
381
|
+
# The folder specified must not exist yet, but it's parent should.
|
382
|
+
def set_templates_dir
|
383
|
+
input = gets.chomp.strip
|
384
|
+
root_path = input.sub(/\/\w*\/*$/, '')
|
385
|
+
case
|
386
|
+
when input.downcase == "b"
|
387
|
+
jumpstart_menu
|
388
|
+
when input.downcase == "x"
|
389
|
+
exit_normal
|
390
|
+
when File.directory?(input)
|
391
|
+
puts "\n A directory of that name already exists, would you like to set it as your template directory anyway? (Nothing will be copied or removed.)".yellow
|
392
|
+
puts " Yes (" + "y".yellow + ") or No (" + "n".yellow + ")?"
|
393
|
+
set_templates_dir_to_existing_dir(input)
|
394
|
+
when File.directory?(root_path)
|
395
|
+
begin
|
396
|
+
Dir.chdir(root_path)
|
397
|
+
Dir.mkdir(input)
|
398
|
+
files_and_dirs = FileUtils.sort_contained_files_and_dirs(JumpStart.templates_path)
|
399
|
+
puts "\nCopying existing templates to #{input}"
|
400
|
+
files_and_dirs[:dirs].each {|x| FileUtils.mkdir_p(FileUtils.join_paths(input, x))}
|
401
|
+
files_and_dirs[:files].each {|x| FileUtils.cp(FileUtils.join_paths(JumpStart.templates_path, x), FileUtils.join_paths(input, x)) }
|
402
|
+
JumpStart.templates_path = input.to_s
|
403
|
+
JumpStart.dump_jumpstart_setup_yaml
|
404
|
+
puts "\n Transfer complete!".green
|
405
|
+
puts "\n The directory " + input.green + " has been set as the JumpStart templates directory."
|
406
|
+
jumpstart_menu
|
407
|
+
rescue
|
408
|
+
puts " It looks like you do not have the correct permissions to create a directory in #{root_path.red}"
|
409
|
+
end
|
410
|
+
else
|
411
|
+
puts " Couldn't find a directory of that name. Try again.".red
|
412
|
+
set_templates_dir
|
413
|
+
end
|
455
414
|
end
|
456
|
-
end
|
457
415
|
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
file_list = []
|
462
|
-
@append_templates = []
|
463
|
-
@line_templates = []
|
464
|
-
@whole_templates = []
|
465
|
-
Find.find(@template_path) do |x|
|
416
|
+
# TOOD set_templates_dir_to_existing_dir Needs tests
|
417
|
+
def set_templates_dir_to_existing_dir(dir)
|
418
|
+
input = gets.chomp.strip.downcase
|
466
419
|
case
|
467
|
-
when
|
468
|
-
|
469
|
-
when
|
470
|
-
|
471
|
-
when
|
472
|
-
|
473
|
-
|
474
|
-
|
420
|
+
when input == "b"
|
421
|
+
jumpstart_menu
|
422
|
+
when input == "x"
|
423
|
+
exit_normal
|
424
|
+
when input == "y" || input == "yes"
|
425
|
+
JumpStart.templates_path = dir
|
426
|
+
JumpStart.dump_jumpstart_setup_yaml
|
427
|
+
puts "\n The directory ".green + dir.green_bold + " has been set as the JumpStart templates directory.".green
|
428
|
+
jumpstart_menu
|
429
|
+
when input == "n" || input == "no"
|
430
|
+
puts "\n The JumpStart templates directory has not been altered".yellow
|
431
|
+
jumpstart_menu
|
432
|
+
else
|
433
|
+
puts "\n The command has not been understood, try again!".red
|
434
|
+
set_templates_dir_to_existing_dir(dir)
|
475
435
|
end
|
476
436
|
end
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
437
|
+
|
438
|
+
# Checks to see if the JumpStart template directory should be reset to the default location. (within the gem.)
|
439
|
+
def reset_templates_dir_to_default_check
|
440
|
+
if JumpStart.templates_path == "#{ROOT_PATH}/jumpstart_templates"
|
441
|
+
puts " You do not need to reset the jumpstart templates directory, it is already set to: #{ROOT_PATH}/jumpstart_templates".red
|
442
|
+
templates_dir_menu
|
482
443
|
else
|
483
|
-
|
444
|
+
puts " Resetting the jumpstart templates directory to the default: #{ROOT_PATH}/jumpstart_templates\n\n"
|
445
|
+
@current_files_and_dirs = FileUtils.sort_contained_files_and_dirs(JumpStart.templates_path)
|
446
|
+
puts " Moving your jumpstart templates back to the default directory will delete any templates that are currently there. Proceed?\n".yellow
|
447
|
+
puts " Type yes (" + "y".yellow + ") or no (" + "n".yellow + ")\n\n"
|
448
|
+
reset_templates_dir_to_default_set
|
484
449
|
end
|
485
450
|
end
|
486
|
-
end
|
487
|
-
|
488
|
-
# Makes folders for the project
|
489
|
-
def create_dirs
|
490
|
-
@dir_list.each {|dir| FileUtils.mkdir_p(FileUtils.join_paths(@install_path, @project_name, dir)) } unless @dir_list.nil?
|
491
|
-
end
|
492
|
-
|
493
|
-
# Create files from whole templates
|
494
|
-
def populate_files_from_whole_templates
|
495
|
-
@whole_templates.each {|x| FileUtils.cp(FileUtils.join_paths(@template_path, x), FileUtils.join_paths(@install_path, @project_name, x)) } unless @whole_templates.nil?
|
496
|
-
end
|
497
451
|
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
452
|
+
# Resets the JumpStart template directory to the default location. (within the gem.)
|
453
|
+
def reset_templates_dir_to_default_set
|
454
|
+
input = gets.chomp.strip.downcase
|
455
|
+
if input == "yes" || input == "y"
|
456
|
+
FileUtils.delete_dir_contents(FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates'))
|
457
|
+
FileUtils.touch(FileUtils.join_paths(ROOT_PATH, '.gitignore'))
|
458
|
+
@current_files_and_dirs[:dirs].each {|x| FileUtils.mkdir_p(FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates', x))}
|
459
|
+
@current_files_and_dirs[:files].each {|x| FileUtils.cp(FileUtils.join_paths(JumpStart.templates_path, x), FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates', x)) }
|
460
|
+
JumpStart.templates_path = FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates')
|
461
|
+
JumpStart.dump_jumpstart_setup_yaml
|
462
|
+
puts "\n SUCCESS! the jumpstart templates directory has been set to the default: #{ROOT_PATH}/jumpstart_templates".green
|
463
|
+
templates_dir_menu
|
464
|
+
elsif input == "no" || input == "n"
|
465
|
+
puts "\n You have chosen not to move the jumpstart templates directory, nothing has been changed."
|
466
|
+
templates_dir_menu
|
467
|
+
else
|
468
|
+
puts "\n The command you entered could not be understood, please enter yes '" + "y".yellow + "' or no '" + "n".yellow + "'"
|
469
|
+
reset_templates_dir_to_default_set
|
470
|
+
end
|
504
471
|
end
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
472
|
+
|
473
|
+
# Runs the main install command specified in the selected templates YAML file.
|
474
|
+
def execute_install_command
|
475
|
+
Dir.chdir(@install_path)
|
476
|
+
unless @install_command.nil? || @install_command.empty?
|
477
|
+
puts "Executing command: #{@install_command.green} #{@project_name.green} #{@install_command_args.green}"
|
478
|
+
system "#{@install_command} #{@project_name} #{@install_command_args}"
|
479
|
+
end
|
513
480
|
end
|
514
|
-
end
|
515
481
|
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
482
|
+
# Parses the contents of the @template_path and sorts ready for template creation.
|
483
|
+
def parse_template_dir
|
484
|
+
@dir_list = []
|
485
|
+
file_list = []
|
486
|
+
@append_templates = []
|
487
|
+
@line_templates = []
|
488
|
+
@whole_templates = []
|
489
|
+
Find.find(@template_path) do |x|
|
490
|
+
case
|
491
|
+
when File.file?(x) && x !~ /\/jumpstart_config/ then
|
492
|
+
file_list << x.sub!(@template_path, '')
|
493
|
+
when File.directory?(x) && x !~ /\/jumpstart_config/ then
|
494
|
+
@dir_list << x.sub!(@template_path, '')
|
495
|
+
when File.file?(x) && x =~ /\/jumpstart_config\/nginx.local.conf/ then
|
496
|
+
@nginx_local_template = x
|
497
|
+
when File.file?(x) && x =~ /\/jumpstart_config\/nginx.remote.conf/ then
|
498
|
+
@nginx_remote_template = x
|
499
|
+
end
|
500
|
+
end
|
501
|
+
file_list.each do |file|
|
502
|
+
if file =~ /_([lL]?)\._{1}\w*/
|
503
|
+
@append_templates << file
|
504
|
+
elsif file =~ /_(\d+)\._{1}\w*/
|
505
|
+
@line_templates << file
|
506
|
+
else
|
507
|
+
@whole_templates << file
|
508
|
+
end
|
509
|
+
end
|
523
510
|
end
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
511
|
+
|
512
|
+
# Makes folders for the project
|
513
|
+
def create_dirs
|
514
|
+
@dir_list.each {|dir| FileUtils.mkdir_p(FileUtils.join_paths(@install_path, @project_name, dir)) } unless @dir_list.nil?
|
515
|
+
end
|
516
|
+
|
517
|
+
# Create files from whole templates
|
518
|
+
def populate_files_from_whole_templates
|
519
|
+
@whole_templates.each {|x| FileUtils.cp(FileUtils.join_paths(@template_path, x), FileUtils.join_paths(@install_path, @project_name, x)) } unless @whole_templates.nil?
|
520
|
+
end
|
521
|
+
|
522
|
+
# Create files from append (_._ _l._ or _L._) templates
|
523
|
+
def populate_files_from_append_templates
|
524
|
+
@append_templates.each do |x|
|
525
|
+
new_name = x.sub(/_([lL]?)\._{1}/, '')
|
526
|
+
FileUtils.touch(FileUtils.join_paths(@install_path, @project_name, new_name))
|
527
|
+
FileUtils.append_to_end_of_file(FileUtils.join_paths(@template_path, x), FileUtils.join_paths(@install_path, @project_name, new_name), JumpStart::Base.remove_last_line?(x))
|
533
528
|
end
|
534
|
-
FileUtils.remove_files(file_array)
|
535
529
|
end
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
530
|
+
|
531
|
+
# Create files from line number templates (e.g. _12._ or _1._)
|
532
|
+
def populate_files_from_line_templates
|
533
|
+
@line_templates.each do |x|
|
534
|
+
new_name = x.sub(/_(\d+)\._{1}/, '')
|
535
|
+
FileUtils.touch(FileUtils.join_paths(@install_path, @project_name, new_name))
|
536
|
+
FileUtils.insert_text_at_line_number(FileUtils.join_paths(@template_path, x), FileUtils.join_paths(@install_path, @project_name, new_name), JumpStart::Base.get_line_number(x))
|
537
|
+
end
|
538
|
+
end
|
539
|
+
|
540
|
+
# Checks to see if options for configuring a local Nginx environment have been specified in the template. If they have, runs the relevant JumpStart::FileTools class methods (included in FileUtils module.)
|
541
|
+
def check_local_nginx_configuration
|
542
|
+
if @nginx_local_template.nil? || @config_file[:local_nginx_conf].nil?
|
543
|
+
puts " \nNginx will not be configured as options have not been set for this."
|
544
|
+
else
|
545
|
+
FileUtils.config_nginx(@nginx_local_template, @config_file[:local_nginx_conf], @project_name)
|
546
|
+
FileUtils.config_hosts("/etc/hosts", @project_name)
|
547
|
+
end
|
548
|
+
end
|
549
|
+
|
550
|
+
# Removes files specified in templates YAML
|
551
|
+
def remove_unwanted_files
|
552
|
+
file_array = []
|
553
|
+
root_path = FileUtils.join_paths(@install_path, @project_name)
|
554
|
+
unless @config_file[:remove_files].nil?
|
555
|
+
@config_file[:remove_files].each do |file|
|
556
|
+
file_array << FileUtils.join_paths(root_path, file)
|
546
557
|
end
|
547
|
-
|
548
|
-
puts "\nCould not access the directory #{FileUtils.join_paths(@install_path, @project_name).red}.\nIn the interest of safety JumpStart will NOT run any YAML scripts from #{script_name.to_s.red_bold} until it can change into the new projects home directory."
|
558
|
+
FileUtils.remove_files(file_array)
|
549
559
|
end
|
550
560
|
end
|
551
|
-
end
|
552
561
|
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
return false
|
562
|
-
else
|
563
|
-
puts "Target file: #{file[:target_path].green}\n"
|
564
|
-
puts "Strings to replace:\n\n"
|
565
|
-
check_replace_string_pairs_for_project_name_sub(file[:symbols])
|
566
|
-
file[:symbols].each do |x,y|
|
567
|
-
puts "Key: #{x.to_s.green}"
|
568
|
-
puts "Value: #{y.to_s.green}\n\n"
|
562
|
+
# Runs additional scripts specified in YAML. Runs one set after the install command has executed, and another after the templates have been generated.
|
563
|
+
def run_scripts_from_yaml(script_name)
|
564
|
+
unless @config_file[script_name].nil? || @config_file[script_name].empty?
|
565
|
+
begin
|
566
|
+
Dir.chdir(FileUtils.join_paths(@install_path, @project_name))
|
567
|
+
@config_file[script_name].each do |x|
|
568
|
+
puts "\nExecuting command: #{x.green}"
|
569
|
+
system "#{x}"
|
569
570
|
end
|
570
|
-
|
571
|
-
|
572
|
-
FileUtils.replace_strings(path, file[:symbols])
|
571
|
+
rescue
|
572
|
+
puts "\nCould not access the directory #{FileUtils.join_paths(@install_path, @project_name).red}.\nIn the interest of safety JumpStart will NOT run any YAML scripts from #{script_name.to_s.red_bold} until it can change into the new projects home directory."
|
573
573
|
end
|
574
574
|
end
|
575
575
|
end
|
576
|
-
end
|
577
|
-
|
578
|
-
# Exit after creating a project, dumping current setup information to YAML
|
579
|
-
def exit_with_success
|
580
|
-
puts "\n\n Exiting JumpStart...".purple
|
581
|
-
puts "\n Success! ".green + @project_name.green_bold + " has been created at: ".green + FileUtils.join_paths(@install_path, @project_name).green_bold + "\n\n".green
|
582
|
-
puts "******************************************************************************************************************************************\n"
|
583
|
-
JumpStart.dump_jumpstart_setup_yaml
|
584
|
-
exit
|
585
|
-
end
|
586
576
|
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
puts "\n Goodbye!\n\n"
|
591
|
-
puts "******************************************************************************************************************************************\n"
|
592
|
-
JumpStart.dump_jumpstart_setup_yaml
|
593
|
-
exit
|
594
|
-
end
|
595
|
-
|
596
|
-
class << self
|
597
|
-
|
598
|
-
# Class instance method that returns an integer to be used as the line number for line templates. Returns false if no match is found.
|
599
|
-
def get_line_number(file_name)
|
600
|
-
if file_name.match(/_(\d+)\._\w*/)
|
601
|
-
number = file_name.match(/_(\d+)\._\w*/)[1]
|
602
|
-
number.to_i
|
603
|
-
else
|
577
|
+
# Looks for strings IN_CAPS that are specified for replacement in the templates YAML
|
578
|
+
def check_for_strings_to_replace
|
579
|
+
if @replace_strings.nil? || @replace_strings.empty?
|
604
580
|
return false
|
581
|
+
else
|
582
|
+
puts "\nChecking for strings to replace inside files...\n\n"
|
583
|
+
@replace_strings.each do |file|
|
584
|
+
if file[:target_path].nil? || file[:symbols].nil?
|
585
|
+
return false
|
586
|
+
else
|
587
|
+
puts "Target file: #{file[:target_path].green}\n"
|
588
|
+
puts "Strings to replace:\n\n"
|
589
|
+
check_replace_string_pairs_for_project_name_sub(file[:symbols])
|
590
|
+
file[:symbols].each do |x,y|
|
591
|
+
puts "Key: #{x.to_s.green}"
|
592
|
+
puts "Value: #{y.to_s.green}\n\n"
|
593
|
+
end
|
594
|
+
puts "\n"
|
595
|
+
path = FileUtils.join_paths(@install_path, @project_name, file[:target_path])
|
596
|
+
FileUtils.replace_strings(path, file[:symbols])
|
597
|
+
end
|
598
|
+
end
|
605
599
|
end
|
606
600
|
end
|
607
601
|
|
608
|
-
#
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
602
|
+
# Exit after creating a project, dumping current setup information to YAML
|
603
|
+
def exit_with_success
|
604
|
+
puts "\n\n Exiting JumpStart...".purple
|
605
|
+
puts "\n Success! ".green + @project_name.green_bold + " has been created at: ".green + FileUtils.join_paths(@install_path, @project_name).green_bold + "\n\n".green
|
606
|
+
puts "******************************************************************************************************************************************\n"
|
607
|
+
JumpStart.dump_jumpstart_setup_yaml
|
608
|
+
exit
|
609
|
+
end
|
610
|
+
|
611
|
+
# Exit normally, dumping current setup information to YAML
|
612
|
+
def exit_normal
|
613
|
+
puts "\n\n Exiting JumpStart...".purple
|
614
|
+
puts "\n Goodbye!\n\n"
|
615
|
+
puts "******************************************************************************************************************************************\n"
|
616
|
+
JumpStart.dump_jumpstart_setup_yaml
|
617
|
+
exit
|
618
|
+
end
|
619
|
+
|
620
|
+
class << self
|
621
|
+
|
622
|
+
# Class instance method that returns an integer to be used as the line number for line templates. Returns false if no match is found.
|
623
|
+
def get_line_number(file_name)
|
624
|
+
if file_name.match(/_(\d+)\._\w*/)
|
625
|
+
number = file_name.match(/_(\d+)\._\w*/)[1]
|
626
|
+
number.to_i
|
627
|
+
else
|
628
|
+
return false
|
629
|
+
end
|
630
|
+
end
|
631
|
+
|
632
|
+
# Class instance method that returns true or false for removing the last line of a file.
|
633
|
+
# Append templates with the _l._ or _L._ prefix will return true.
|
634
|
+
def remove_last_line?(file_name)
|
635
|
+
if file_name.match(/_([lL]{1})\._{1}\w*/)
|
636
|
+
return true
|
637
|
+
else
|
638
|
+
return false
|
639
|
+
end
|
615
640
|
end
|
641
|
+
|
616
642
|
end
|
617
|
-
|
618
|
-
end
|
619
|
-
|
643
|
+
|
620
644
|
end
|
621
|
-
end
|
645
|
+
end
|