jumpstart 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (168) hide show
  1. data/.bundle/config +2 -0
  2. data/.document +5 -0
  3. data/.gitignore +28 -0
  4. data/Gemfile +8 -0
  5. data/LICENSE +20 -0
  6. data/README.rdoc +19 -0
  7. data/Rakefile +54 -0
  8. data/VERSION +1 -0
  9. data/bin/jumpstart +5 -0
  10. data/config/jumpstart_setup.yml +2 -0
  11. data/jumpstart.gemspec +222 -0
  12. data/jumpstart_templates/i0n_rails_3/.gitignore +11 -0
  13. data/jumpstart_templates/i0n_rails_3/_._Gemfile +5 -0
  14. data/jumpstart_templates/i0n_rails_3/app/views/home/index.haml +4 -0
  15. data/jumpstart_templates/i0n_rails_3/app/views/layouts/application.haml +32 -0
  16. data/jumpstart_templates/i0n_rails_3/config/_2._routes.rb +1 -0
  17. data/jumpstart_templates/i0n_rails_3/config/_L._database.yml +1 -0
  18. data/jumpstart_templates/i0n_rails_3/config/deploy.rb +62 -0
  19. data/jumpstart_templates/i0n_rails_3/config/environments/_18._development.rb +5 -0
  20. data/jumpstart_templates/i0n_rails_3/config/environments/_27._test.rb +1 -0
  21. data/jumpstart_templates/i0n_rails_3/config/environments/_41._production.rb +3 -0
  22. data/jumpstart_templates/i0n_rails_3/config/initializers/setup_mail.rb +14 -0
  23. data/jumpstart_templates/i0n_rails_3/jumpstart_config/i0n_rails_3.yml +40 -0
  24. data/jumpstart_templates/i0n_rails_3/jumpstart_config/nginx.local.conf +11 -0
  25. data/jumpstart_templates/i0n_rails_3/jumpstart_config/nginx.remote.conf +37 -0
  26. data/jumpstart_templates/i0n_rails_3/lib/development_mail_interceptor.rb +8 -0
  27. data/jumpstart_templates/i0n_rails_3/lib/generators/authlogic.rb +11 -0
  28. data/jumpstart_templates/i0n_rails_3/lib/generators/authlogic/session/session_generator.rb +18 -0
  29. data/jumpstart_templates/i0n_rails_3/lib/generators/authlogic/session/templates/session.rb +2 -0
  30. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper.rb +80 -0
  31. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/migration/migration_generator.rb +26 -0
  32. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/migration/templates/migration.rb +21 -0
  33. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/model/model_generator.rb +29 -0
  34. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/model/templates/migration.rb +17 -0
  35. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/model/templates/model.rb +10 -0
  36. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/observer/observer_generator.rb +15 -0
  37. data/jumpstart_templates/i0n_rails_3/lib/generators/datamapper/observer/templates/observer.rb +5 -0
  38. data/jumpstart_templates/i0n_rails_3/lib/generators/factory_girl.rb +11 -0
  39. data/jumpstart_templates/i0n_rails_3/lib/generators/factory_girl/model/model_generator.rb +14 -0
  40. data/jumpstart_templates/i0n_rails_3/lib/generators/factory_girl/model/templates/fixtures.rb +7 -0
  41. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb.rb +9 -0
  42. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/USAGE +8 -0
  43. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/controller/controller_generator.rb +24 -0
  44. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/controller/templates/view.html.erb +0 -0
  45. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/scaffold_generator.rb +27 -0
  46. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/_form.html.erb +12 -0
  47. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/edit.html.erb +6 -0
  48. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/index.html.erb +27 -0
  49. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/layout.html.erb +16 -0
  50. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/new.html.erb +5 -0
  51. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_erb/scaffold/templates/show.html.erb +10 -0
  52. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml.rb +9 -0
  53. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/USAGE +8 -0
  54. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/controller/controller_generator.rb +24 -0
  55. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/controller/templates/view.html.haml +0 -0
  56. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/scaffold_generator.rb +23 -0
  57. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/_form.haml.erb +9 -0
  58. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/edit.haml.erb +7 -0
  59. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/index.haml.erb +23 -0
  60. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/layout.haml.erb +9 -0
  61. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/new.haml.erb +5 -0
  62. data/jumpstart_templates/i0n_rails_3/lib/generators/formtastic_haml/scaffold/templates/show.haml.erb +9 -0
  63. data/jumpstart_templates/i0n_rails_3/lib/generators/haml.rb +9 -0
  64. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/controller/controller_generator.rb +24 -0
  65. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/controller/templates/view.html.haml +0 -0
  66. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/scaffold_generator.rb +26 -0
  67. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/_form.haml.erb +9 -0
  68. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/edit.haml.erb +7 -0
  69. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/index.haml.erb +23 -0
  70. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/layout.haml.erb +9 -0
  71. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/new.haml.erb +5 -0
  72. data/jumpstart_templates/i0n_rails_3/lib/generators/haml/scaffold/templates/show.haml.erb +9 -0
  73. data/jumpstart_templates/i0n_rails_3/lib/generators/machinist.rb +11 -0
  74. data/jumpstart_templates/i0n_rails_3/lib/generators/machinist/model/model_generator.rb +19 -0
  75. data/jumpstart_templates/i0n_rails_3/lib/generators/machinist/model/templates/blueprint.rb +5 -0
  76. data/jumpstart_templates/i0n_rails_3/lib/generators/machinist/model/templates/machinist_initializer.rb +19 -0
  77. data/jumpstart_templates/i0n_rails_3/lib/generators/mongomapper.rb +80 -0
  78. data/jumpstart_templates/i0n_rails_3/lib/generators/mongomapper/model/model_generator.rb +29 -0
  79. data/jumpstart_templates/i0n_rails_3/lib/generators/mongomapper/model/templates/model.rb +24 -0
  80. data/jumpstart_templates/i0n_rails_3/lib/generators/mongomapper/observer/observer_generator.rb +15 -0
  81. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda.rb +11 -0
  82. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda/controller/controller_generator.rb +16 -0
  83. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda/controller/templates/controller.rb +84 -0
  84. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda/model/model_generator.rb +16 -0
  85. data/jumpstart_templates/i0n_rails_3/lib/generators/shoulda/model/templates/model.rb +7 -0
  86. data/jumpstart_templates/i0n_rails_3/lib/tasks/populate.rake +91 -0
  87. data/jumpstart_templates/i0n_rails_3/public/javascripts/init.js +6 -0
  88. data/jumpstart_templates/i0n_rails_3/public/javascripts/jquery-1.4.2.min.js +154 -0
  89. data/jumpstart_templates/i0n_rails_3/public/javascripts/jquery-ui-1.8.custom.min.js +404 -0
  90. data/jumpstart_templates/i0n_rails_3/public/javascripts/rails.js +126 -0
  91. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/_setup.sass +86 -0
  92. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/global.sass +58 -0
  93. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/handheld.sass +7 -0
  94. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/ie.sass +40 -0
  95. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/print.sass +57 -0
  96. data/jumpstart_templates/i0n_rails_3/public/stylesheets/sass/screen.sass +170 -0
  97. data/lib/jumpstart.rb +71 -0
  98. data/lib/jumpstart/base.rb +547 -0
  99. data/lib/jumpstart/doc/JumpStart.html +139 -0
  100. data/lib/jumpstart/doc/JumpStart/Base.html +1566 -0
  101. data/lib/jumpstart/doc/base_rb.html +52 -0
  102. data/lib/jumpstart/doc/created.rid +2 -0
  103. data/lib/jumpstart/doc/index.html +101 -0
  104. data/lib/jumpstart/doc/rdoc.css +706 -0
  105. data/lib/jumpstart/filetools.rb +270 -0
  106. data/source_templates/template_config.yml +77 -0
  107. data/test/fake_nginx_path/local_nginx_1.conf +81 -0
  108. data/test/fake_nginx_path/remote_nginx_1.conf +54 -0
  109. data/test/helper.rb +31 -0
  110. data/test/jumpstart/test_base.rb +422 -0
  111. data/test/jumpstart/test_filetools.rb +350 -0
  112. data/test/test_jumpstart.rb +9 -0
  113. data/test/test_jumpstart_templates/test_base/_._test_file.txt +0 -0
  114. data/test/test_jumpstart_templates/test_base/_._test_file_.txt +0 -0
  115. data/test/test_jumpstart_templates/test_base/_1._test_file1.txt +0 -0
  116. data/test/test_jumpstart_templates/test_base/_1._test_file1_.txt +0 -0
  117. data/test/test_jumpstart_templates/test_base/_10._test_file2.txt +0 -0
  118. data/test/test_jumpstart_templates/test_base/_99999._test_file3.txt +0 -0
  119. data/test/test_jumpstart_templates/test_base/_a._test_file4.txt +0 -0
  120. data/test/test_jumpstart_templates/test_base/test_file +0 -0
  121. data/test/test_jumpstart_templates/test_base/test_file5.txt +0 -0
  122. data/test/test_jumpstart_templates/test_base/test_file_.6txt +0 -0
  123. data/test/test_jumpstart_templates/test_fileutils/append_after_line_test.txt +6 -0
  124. data/test/test_jumpstart_templates/test_fileutils/append_to_end_of_file_source.txt +1 -0
  125. data/test/test_jumpstart_templates/test_fileutils/append_to_end_of_file_test.txt +5 -0
  126. data/test/test_jumpstart_templates/test_fileutils/check_source_type +5 -0
  127. data/test/test_jumpstart_templates/test_fileutils/check_source_type.txt +10 -0
  128. data/test/test_jumpstart_templates/test_fileutils/config_capistrano_source.rb +62 -0
  129. data/test/test_jumpstart_templates/test_fileutils/config_capistrano_test.rb +62 -0
  130. data/test/test_jumpstart_templates/test_fileutils/config_nginx_source.txt +1 -0
  131. data/test/test_jumpstart_templates/test_fileutils/config_nginx_test.txt +82 -0
  132. data/test/test_jumpstart_templates/test_fileutils/hosts_test +11 -0
  133. data/test/test_jumpstart_templates/test_fileutils/insert_text_at_line_number_source.txt +1 -0
  134. data/test/test_jumpstart_templates/test_fileutils/insert_text_at_line_number_test.txt +4 -0
  135. data/test/test_jumpstart_templates/test_fileutils/remove_files_test_2.txt +0 -0
  136. data/test/test_jumpstart_templates/test_fileutils/remove_files_test_3.txt +0 -0
  137. data/test/test_jumpstart_templates/test_fileutils/remove_lines_test.txt +10 -0
  138. data/test/test_jumpstart_templates/test_fileutils/replace_strings_test.rb +62 -0
  139. data/test/test_jumpstart_templates/test_template_1/_._test_append_file_with_extension.txt +1 -0
  140. data/test/test_jumpstart_templates/test_template_1/_._test_append_file_without_extension +1 -0
  141. data/test/test_jumpstart_templates/test_template_1/_20._test_line_file_without_extension +1 -0
  142. data/test/test_jumpstart_templates/test_template_1/_5._test_line_file_with_extension.txt +1 -0
  143. data/test/test_jumpstart_templates/test_template_1/_L._test_append_to_end_of_file_remove_last_line_1.txt +1 -0
  144. data/test/test_jumpstart_templates/test_template_1/_l._test_append_to_end_of_file_remove_last_line_2.txt +1 -0
  145. data/test/test_jumpstart_templates/test_template_1/folder with spaces/_._test_append_file_with_extension.txt +1 -0
  146. data/test/test_jumpstart_templates/test_template_1/folder with spaces/_._test_append_file_without_extension +1 -0
  147. data/test/test_jumpstart_templates/test_template_1/folder with spaces/_5._test_line_file_with_extension.txt +1 -0
  148. data/test/test_jumpstart_templates/test_template_1/folder with spaces/_50._test_line_file_without_extension +1 -0
  149. data/test/test_jumpstart_templates/test_template_1/folder with spaces/test_whole_file_with_extension.txt +1 -0
  150. data/test/test_jumpstart_templates/test_template_1/folder with spaces/test_whole_file_without_extension +1 -0
  151. data/test/test_jumpstart_templates/test_template_1/jumpstart_config/test_template_1.yml +31 -0
  152. data/test/test_jumpstart_templates/test_template_1/normal_folder_name/_._test_append_file_with_extension.txt +1 -0
  153. data/test/test_jumpstart_templates/test_template_1/normal_folder_name/_._test_append_file_without_extension +1 -0
  154. data/test/test_jumpstart_templates/test_template_1/normal_folder_name/_5._test_line_file_with_extension.txt +1 -0
  155. data/test/test_jumpstart_templates/test_template_1/normal_folder_name/_50._test_line_file_without_extension +1 -0
  156. data/test/test_jumpstart_templates/test_template_1/normal_folder_name/test_whole_file_with_extension.txt +1 -0
  157. data/test/test_jumpstart_templates/test_template_1/normal_folder_name/test_whole_file_without_extension +1 -0
  158. data/test/test_jumpstart_templates/test_template_1/test_append_to_end_of_file_remove_last_line_1.txt +10 -0
  159. data/test/test_jumpstart_templates/test_template_1/test_append_to_end_of_file_remove_last_line_2.txt +10 -0
  160. data/test/test_jumpstart_templates/test_template_1/test_remove_files/file_with_extension.txt +1 -0
  161. data/test/test_jumpstart_templates/test_template_1/test_remove_files/file_without_extension +1 -0
  162. data/test/test_jumpstart_templates/test_template_1/test_replace_strings/replace_strings_1.rb +62 -0
  163. data/test/test_jumpstart_templates/test_template_1/test_replace_strings/replace_strings_2.txt +23 -0
  164. data/test/test_jumpstart_templates/test_template_1/test_whole_file_with_extension.txt +1 -0
  165. data/test/test_jumpstart_templates/test_template_1/test_whole_file_without_extension +1 -0
  166. data/test/test_jumpstart_templates/test_template_2/jumpstart_config/test_template_2.yml +8 -0
  167. data/test/test_jumpstart_templates/test_template_3/jumpstart_config/test_template_3.yml +22 -0
  168. metadata +254 -0
data/lib/jumpstart.rb ADDED
@@ -0,0 +1,71 @@
1
+ require 'rubygems'
2
+ require 'find'
3
+ require 'fileutils'
4
+ require 'yaml'
5
+
6
+ # TODO Test this under Windows, and look into conditionally including this dependency with bundler.
7
+ begin
8
+ require 'Win32/Console/ANSI' if RUBY_PLATFORM =~ /win32/
9
+ rescue LoadError
10
+ raise 'You must gem install win32console to use colored output on Windows'
11
+ end
12
+
13
+ module JumpStart
14
+
15
+ ROOT_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..'))
16
+ LIB_PATH = File.expand_path(File.dirname(__FILE__))
17
+ CONFIG_PATH = File.expand_path(File.join(File.dirname(__FILE__), '../config'))
18
+ IGNORE_DIRS = ['.','..']
19
+
20
+ require 'jumpstart/base'
21
+ require 'jumpstart/filetools'
22
+
23
+ end
24
+
25
+ module FileUtils
26
+ class << self
27
+ include JumpStart::FileTools
28
+ end
29
+ end
30
+
31
+ class String
32
+
33
+ def red; colourise(self, "\e[31m"); end
34
+ def red_bold; colourise(self, "\e[1m\e[31m"); end
35
+ def green; colourise(self, "\e[32m"); end
36
+ def green_bold; colourise(self, "\e[1m\e[32m"); end
37
+ def yellow; colourise(self, "\e[1m\e[33m"); end
38
+ def blue; colourise(self, "\e[34m"); end
39
+ def blue_bold; colourise(self, "\e[1m\e[34m"); end
40
+ def purple; colourise(self, "\e[1m\e[35m"); end
41
+
42
+ def colourise(text, colour_code) "#{colour_code}#{text}\e[0m" end
43
+
44
+ # Codes for changing output text:
45
+
46
+ # 0 Turn off all attributes
47
+ # 1 Set bright mode
48
+ # 4 Set underline mode
49
+ # 5 Set blink mode
50
+ # 7 Exchange foreground and background colors
51
+ # 8 Hide text (foreground colour would be the same as background)
52
+ # 30 Black text
53
+ # 31 Red text
54
+ # 32 Green text
55
+ # 33 Yellow text
56
+ # 34 Blue text
57
+ # 35 Magenta text
58
+ # 36 Cyan text
59
+ # 37 White text
60
+ # 39 Default text colour
61
+ # 40 Black background
62
+ # 41 Red background
63
+ # 42 Green background
64
+ # 43 Yellow background
65
+ # 44 Blue background
66
+ # 45 Magenta background
67
+ # 46 Cyan background
68
+ # 47 White background
69
+ # 49 Default background colour
70
+
71
+ end
@@ -0,0 +1,547 @@
1
+ module JumpStart
2
+ class Base
3
+
4
+ # Accessor methods to make testing input or output easier.
5
+ attr_accessor :input
6
+ attr_reader :output
7
+
8
+ # Monkeypatch puts to make testing easier.
9
+ def puts(*args)
10
+ @output.puts(*args)
11
+ end
12
+
13
+ # Monkeypatch gets to make testing easier.
14
+ def gets(*args)
15
+ @input.gets(*args)
16
+ end
17
+
18
+ # TODO initialize needs more tests
19
+ def initialize(args)
20
+ # setup for testing input
21
+ @input = $stdin
22
+ # setup for testing output
23
+ @output = $stdout
24
+ # The path to the jumpstart templates directory
25
+ @jumpstart_templates_path = YAML.load_file("#{CONFIG_PATH}/jumpstart_setup.yml")[:jumpstart_templates_path]
26
+ # sets the default template to use if it has not been passed as an argument.
27
+ @default_template_name = YAML.load_file("#{CONFIG_PATH}/jumpstart_setup.yml")[:default_template_name]
28
+ # set the name of the project from the first argument passed, or from the constant @default_template_name if no argument passed.
29
+ @project_name = args.shift.dup if args[0] != nil
30
+ if args[0] != nil
31
+ @template_name = args.shift.dup
32
+ elsif @default_template_name != nil
33
+ @template_name = @default_template_name
34
+ end
35
+ # set instance variable @template_path as the directory to read templates from.
36
+ @template_path = FileUtils.join_paths(@jumpstart_templates_path, @template_name)
37
+ # set up instance variable containing an array that will be populated with existing jumpstart templates
38
+ end
39
+
40
+ # TODO Refactor startup so that if one argument is passed to the jumpstart command it will assume that it is the projects name.
41
+ # If a default template has been set, jumpstart should create the project.
42
+ # If a default template has not been set then the user should be asked to select an existing template. This could be the same menu as displayed for option 1 above.
43
+
44
+ # TODO Ensure that if jumpstart is launched with two arguments they are parsed as @project_name and @template_name, and the command is launched without any menu display.
45
+ # TODO Ensure that if jumpstart is launched with one argument it is parsed as @project_name, and if @default_template_name exists then the command is launched without any menu display.
46
+ # TODO Document methods for RDOC
47
+ # Finish README etc for github
48
+
49
+ # TODO set_config_file_options needs tests
50
+ def set_config_file_options
51
+ if File.exists?(FileUtils.join_paths(@jumpstart_templates_path, @template_name, "/jumpstart_config/", "#{@template_name}.yml"))
52
+ @config_file = YAML.load_file(FileUtils.join_paths(@jumpstart_templates_path, @template_name, "/jumpstart_config/", "#{@template_name}.yml"))
53
+ @install_command ||= @config_file[:install_command]
54
+ @install_command_args ||= @config_file[:install_command_args]
55
+ @replace_strings ||= @config_file[:replace_strings].each {|x| x}
56
+ @install_path ||= FileUtils.join_paths(@config_file[:install_path])
57
+ else
58
+ jumpstart_menu
59
+ end
60
+ end
61
+
62
+ # TODO check_setup needs tests
63
+ def check_setup
64
+ set_config_file_options
65
+ lookup_existing_templates
66
+ check_project_name
67
+ check_template_name
68
+ check_template_path
69
+ check_install_path
70
+ end
71
+
72
+ # TODO lookup_existing_templates needs tests
73
+ def lookup_existing_templates
74
+ @existing_templates = []
75
+ template_dirs = Dir.entries(@jumpstart_templates_path) - IGNORE_DIRS
76
+ template_dirs.each do |x|
77
+ if Dir.entries(FileUtils.join_paths(@jumpstart_templates_path, x)).include? "jumpstart_config"
78
+ if File.exists?(FileUtils.join_paths(@jumpstart_templates_path, x, '/jumpstart_config/', "#{x}.yml"))
79
+ @existing_templates << x
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ def start
86
+ puts "\n******************************************************************************************************************************************\n\n"
87
+ puts "JumpStarting....\n".purple
88
+ check_setup
89
+ execute_install_command
90
+ run_scripts_from_yaml(:run_after_install_command)
91
+ parse_template_dir
92
+ # makes folders for the project
93
+ @dir_list.each {|dir| FileUtils.mkdir_p(FileUtils.join_paths(@install_path, @project_name, dir)) }
94
+ # create files from whole templates
95
+ @whole_templates.each {|x| FileUtils.cp(FileUtils.join_paths(@template_path, x), FileUtils.join_paths(@install_path, @project_name, x)) }
96
+ populate_files_from_append_templates
97
+ populate_files_from_line_templates
98
+ remove_unwanted_files
99
+ run_scripts_from_yaml(:run_after_jumpstart)
100
+ check_for_strings_to_replace
101
+ check_local_nginx_configuration
102
+ exit_with_success
103
+ end
104
+
105
+ def check_replace_string_pairs_for_project_name_sub(hash)
106
+ unless @project_name.nil?
107
+ hash.each do |key, value|
108
+ if key == :project_name
109
+ hash[key] = @project_name
110
+ end
111
+ end
112
+ end
113
+ hash
114
+ end
115
+
116
+ private
117
+
118
+ # TODO check_project_name needs extra tests for the match elsif
119
+ def check_project_name
120
+ if @project_name.nil? || @project_name.empty?
121
+ puts "\n Enter a name for your project.".yellow
122
+ @project_name = gets.chomp.strip
123
+ check_project_name
124
+ elsif @project_name.length < 3
125
+ puts "\n The name #{@project_name} is too short. Please enter a name at least 3 characters long.".red
126
+ @project_name = gets.chomp.strip
127
+ check_project_name
128
+ elsif @project_name.match(/^\W/)
129
+ puts "\n #{@project_name} begins with an invalid character. Please enter a name thats starts with a letter or a number.".red
130
+ check_project_name
131
+ else
132
+ @project_name
133
+ end
134
+ end
135
+
136
+ # TODO check_template_name needs tests.
137
+ def check_template_name
138
+ if @template_name.nil? || @template_name.empty?
139
+ jumpstart_menu
140
+ end
141
+ end
142
+
143
+ # TODO check_template_path needs tests
144
+ def check_template_path
145
+ begin
146
+ Dir.chdir(@template_path)
147
+ rescue
148
+ puts "\nThe directory #{x.red} could not be found, or you do not have the correct permissions to access it."
149
+ exit_normal
150
+ end
151
+ end
152
+
153
+ # TODO check_install_path needs tests
154
+ def check_install_path
155
+ @install_path = FileUtils.pwd if @install_path.nil?
156
+ if Dir.exists?(FileUtils.join_paths(@install_path, @project_name))
157
+ puts
158
+ puts "The 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."
159
+ exit_normal
160
+ end
161
+ end
162
+
163
+ # TODO create_template needs tests
164
+ def create_template
165
+ if Dir.exists?(FileUtils.join_paths(@jumpstart_templates_path, @template_name))
166
+ puts "\nThe directory #{FileUtils.join_paths(@jumpstart_templates_path, @template_name).red} already exists. The template will not be created."
167
+ exit_normal
168
+ else
169
+ FileUtils.mkdir_p(FileUtils.join_paths(@jumpstart_templates_path, @template_name, "/jumpstart_config"))
170
+ yaml = IO.read(FileUtils.join_paths(ROOT_PATH, "/source_templates/template_config.yml"))
171
+ File.open(FileUtils.join_paths(@jumpstart_templates_path, @template_name, "/jumpstart_config", "#{@template_name}.yml"), 'w') do |file|
172
+ file.puts yaml
173
+ end
174
+ puts "The template #{@template_name.green} has been generated.\n"
175
+ end
176
+ end
177
+
178
+ # TODO jumpstart_menu needs tests
179
+ def jumpstart_menu
180
+ puts "\n\n******************************************************************************************************************************************\n\n"
181
+ puts " JUMPSTART MENU\n".purple
182
+ puts " Here are your options:\n\n"
183
+ puts " 1".yellow + " Create a new project from an existing template.\n"
184
+ puts " 2".yellow + " Create a new template.\n"
185
+ puts " 3".yellow + " Set the default template.\n"
186
+ puts " 4".yellow + " Set the templates directory.\n\n"
187
+ puts " x".yellow + " Exit jumpstart\n\n"
188
+ puts "******************************************************************************************************************************************\n\n"
189
+ jumpstart_menu_options
190
+ end
191
+
192
+ # TODO jumpstart_menu_options needs tests
193
+ def jumpstart_menu_options
194
+ lookup_existing_templates
195
+ input = gets.chomp.strip
196
+ case
197
+ when input == "1"
198
+ new_project_from_template_menu
199
+ when input == "2"
200
+ new_template_menu
201
+ when input == "3"
202
+ set_default_template_menu
203
+ when input == "4"
204
+ templates_dir_menu
205
+ when input == "x"
206
+ exit_normal
207
+ else
208
+ puts "That command hasn't been understood. Try again!".red
209
+ jumpstart_menu_options
210
+ end
211
+ end
212
+
213
+ # TODO Check/finish methods for creating a new project through the menu
214
+ # TODO new_project_from_template_menu needs tests
215
+ def new_project_from_template_menu
216
+ puts "\n\n******************************************************************************************************************************************\n\n"
217
+ puts " CREATE A NEW JUMPSTART PROJECT FROM AN EXISTING TEMPLATE\n\n".purple
218
+ puts " Type a number for the template that you want.\n\n"
219
+ count = 0
220
+ @existing_templates.each do |t|
221
+ count += 1
222
+ puts " #{count.to_s.yellow} #{t}"
223
+ end
224
+ puts "\n b".yellow + " Back to main menu."
225
+ puts "\n x".yellow + " Exit jumpstart\n\n"
226
+ puts "******************************************************************************************************************************************\n\n"
227
+ new_project_from_template_options
228
+ end
229
+
230
+ # TODO new_project_from_template_options needs tests
231
+ def new_project_from_template_options
232
+ input = gets.chomp.strip
233
+ case
234
+ when input.to_i <= @existing_templates.count && input.to_i > 0
235
+ @template_name = @existing_templates[(input.to_i - 1)]
236
+ check_project_name
237
+ project = JumpStart::Base.new([@project_name, @template_name])
238
+ project.check_setup
239
+ project.start
240
+ when input == "b"
241
+ jumpstart_menu
242
+ when input == "x"
243
+ exit_normal
244
+ else
245
+ puts "That command hasn't been understood. Try again!".red
246
+ end
247
+ end
248
+
249
+ # TODO write tests for new_template_menu
250
+ def new_template_menu
251
+ puts "\n\n******************************************************************************************************************************************\n\n"
252
+ puts " CREATE A NEW JUMPSTART TEMPLATE\n".purple
253
+ puts " Existing templates:\n"
254
+ lookup_existing_templates
255
+ @existing_templates.each do |x|
256
+ puts " #{x.green}\n"
257
+ end
258
+ new_template_options
259
+ end
260
+
261
+ # TODO write tests for new_template_options
262
+ def new_template_options
263
+ puts "\n Enter a unique name for the new template.\n".yellow
264
+ input = gets.chomp.strip
265
+ if @existing_templates.include?(input)
266
+ puts " A template of the name ".red + input.red_bold + " already exists.".red
267
+ new_template_options
268
+ elsif input.length < 3
269
+ puts " 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
+ elsif input.match(/^\W/)
272
+ puts " The template name ".red + input.red_bold + " begins 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 " 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
+ # TODO Write method(s) for setting the default template
283
+ def set_default_template_menu
284
+ puts "\n\n******************************************************************************************************************************************\n\n"
285
+ puts " JUMPSTART DEFAULT TEMPLATE OPTIONS\n\n".purple
286
+ count = 0
287
+ @existing_templates.each do |t|
288
+ count += 1
289
+ puts " #{count.to_s.yellow} #{t}"
290
+ end
291
+ puts "\n b".yellow + " Back to main menu.\n\n"
292
+ puts " x".yellow + " Exit jumpstart\n\n"
293
+ puts "******************************************************************************************************************************************\n\n"
294
+ set_default_template_options
295
+ end
296
+
297
+ # Sets the default template to be used by JumpStart.
298
+ def set_default_template_options
299
+ input = gets.chomp.strip
300
+ case
301
+ when input.to_i <= @existing_templates.count && input.to_i > 0
302
+ @default_template_name = @existing_templates[(input.to_i - 1)]
303
+ dump_global_yaml
304
+ puts " The default jumpstart template has been set to: #{@default_template_name.green}"
305
+ jumpstart_menu
306
+ when input == "b"
307
+ jumpstart_menu
308
+ when input == "x"
309
+ exit_normal
310
+ else
311
+ puts "That command hasn't been understood. Try again!".red
312
+ set_default_template_options
313
+ end
314
+ end
315
+
316
+ # TODO write tests for templates_dir_menu
317
+ def templates_dir_menu
318
+ puts "\n\n******************************************************************************************************************************************\n\n"
319
+ puts " JUMPSTART TEMPLATES DIRECTORY OPTIONS\n\n".purple
320
+ puts " 1".yellow + " Set templates directory.\n"
321
+ puts " 2".yellow + " Reset templates directory to default\n\n"
322
+ puts " b".yellow + " Back to main menu.\n\n"
323
+ puts " x".yellow + " Exit jumpstart\n\n"
324
+ puts "******************************************************************************************************************************************\n\n"
325
+ templates_dir_options
326
+ end
327
+
328
+ # TODO templates_dir_options needs tests
329
+ def templates_dir_options
330
+ input = gets.chomp.strip
331
+ case
332
+ when input == "1"
333
+ set_templates_dir
334
+ when input == "2"
335
+ reset_templates_dir_to_default
336
+ when input == "b"
337
+ jumpstart_menu
338
+ when input == "x"
339
+ exit_normal
340
+ else
341
+ puts "That command hasn't been understood. Try again!".red
342
+ templates_dir_options
343
+ end
344
+ end
345
+
346
+ # TODO set_templates_dir needs tests
347
+ # Sets the path for templates to be used by JumpStart.
348
+ def set_templates_dir
349
+ puts "Please enter the absolute path for the directory that you would like to contain your jumpstart templates."
350
+ input = gets.chomp.strip
351
+ root_path = input.sub(/\/\w*\/*$/, '')
352
+ case
353
+ when Dir.exists?(input)
354
+ puts "A directory of that name already exists, please choose a directory that does not exist."
355
+ set_template_dir
356
+ when Dir.exists?(root_path)
357
+ begin
358
+ Dir.chdir(root_path)
359
+ Dir.mkdir(input)
360
+ files_and_dirs = FileUtils.sort_contained_files_and_dirs(@jumpstart_templates_path)
361
+ puts "\nCopying existing templates to #{input}"
362
+ files_and_dirs[:dirs].each {|x| FileUtils.mkdir_p(FileUtils.join_paths(input, x))}
363
+ files_and_dirs[:files].each {|x| FileUtils.cp(FileUtils.join_paths(@jumpstart_templates_path, x), FileUtils.join_paths(input, x)) }
364
+ @jumpstart_templates_path = input.to_s
365
+ dump_global_yaml
366
+ puts "\nTransfer complete!".green
367
+ jumpstart_menu
368
+ rescue
369
+ puts "It looks like you do not have the correct permissions to create a directory in #{root_path.red}"
370
+ end
371
+ end
372
+ end
373
+
374
+ # TODO reset_templates_dir_to_default needs tests
375
+ # Resets the JumpStart template directory to the default location. (within the gem.)
376
+ def reset_templates_dir_to_default
377
+ if @jumpstart_templates_path == "#{ROOT_PATH}/jumpstart_templates"
378
+ puts " You do not need to reset the jumpstart templates directory, it is already set to: #{ROOT_PATH}/jumpstart_templates\n\n".red
379
+ else
380
+ puts " Resetting the jumpstart templates directory to the default: #{ROOT_PATH}/jumpstart_templates\n\n"
381
+ current_files_and_dirs = FileUtils.sort_contained_files_and_dirs(@jumpstart_templates_path)
382
+ puts " Moving your jumpstart templates back to the default directory will delete any templates that are currently there. Proceed?\n".yellow
383
+ puts " Type yes (" + "y".yellow + ") or no (" + "n".yellow + ")\n\n"
384
+ input = gets.chomp.strip
385
+ if input == "yes" || input == "y"
386
+ FileUtils.delete_dir_contents(FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates'))
387
+ current_files_and_dirs[:dirs].each {|x| FileUtils.mkdir_p(FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates', x))}
388
+ current_files_and_dirs[:files].each {|x| FileUtils.cp(FileUtils.join_paths(@jumpstart_templates_path, x), FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates', x)) }
389
+ @jumpstart_templates_path = FileUtils.join_paths(ROOT_PATH, '/jumpstart_templates')
390
+ dump_global_yaml
391
+ puts "\n SUCCESS! the jumpstart templates directory has been set to the default: #{ROOT_PATH}/jumpstart_templates".green
392
+ end
393
+ end
394
+ templates_dir_menu
395
+ end
396
+
397
+ # TODO execute_install_command needs tests
398
+ def execute_install_command
399
+ Dir.chdir(@install_path)
400
+ unless @install_command.nil?
401
+ puts "Executing command: #{@install_command.green} #{@project_name.green} #{@install_command_args.green}"
402
+ system "#{@install_command} #{@project_name} #{@install_command_args}"
403
+ end
404
+ end
405
+
406
+ # TODO parse_template_dir needs tests
407
+ def parse_template_dir
408
+ @dir_list = []
409
+ file_list = []
410
+ @whole_templates = []
411
+ @append_templates = []
412
+ @line_templates = []
413
+ Find.find(@template_path) do |x|
414
+ case
415
+ when File.file?(x) && x !~ /\/jumpstart_config/ then
416
+ file_list << x.sub!(@template_path, '')
417
+ when File.directory?(x) && x !~ /\/jumpstart_config/ then
418
+ @dir_list << x.sub!(@template_path, '')
419
+ when File.file?(x) && x =~ /\/jumpstart_config\/nginx.local.conf/ then
420
+ @nginx_local_template = x
421
+ when File.file?(x) && x =~ /\/jumpstart_config\/nginx.remote.conf/ then
422
+ @nginx_remote_template = x
423
+ end
424
+ end
425
+ file_list.each do |file|
426
+ if file =~ /_([lL]?)\._{1}\w*/
427
+ @append_templates << file
428
+ elsif file =~ /_(\d+)\._{1}\w*/
429
+ @line_templates << file
430
+ else
431
+ @whole_templates << file
432
+ end
433
+ end
434
+ end
435
+
436
+ #TODO populate_files_from_append_templates needs tests
437
+ def populate_files_from_append_templates
438
+ @append_templates.each do |x|
439
+ new_name = x.sub(/_([lL]?)\._{1}/, '')
440
+ FileUtils.touch(FileUtils.join_paths(@install_path, @project_name, new_name))
441
+ 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))
442
+ end
443
+ end
444
+
445
+ # TODO populate_files_from_line_templates needs tests
446
+ def populate_files_from_line_templates
447
+ @line_templates.each do |x|
448
+ new_name = x.sub(/_(\d+)\._{1}/, '')
449
+ FileUtils.touch(FileUtils.join_paths(@install_path, @project_name, new_name))
450
+ 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))
451
+ end
452
+ end
453
+
454
+ # TODO check_local_nginx_configuration needs tests
455
+ def check_local_nginx_configuration
456
+ unless @nginx_local_template.nil? && @config_file[:local_nginx_conf].nil?
457
+ FileUtils.config_nginx(@nginx_local_template, @config_file[:local_nginx_conf], @project_name)
458
+ FileUtils.config_hosts("/etc/hosts", @project_name)
459
+ end
460
+ end
461
+
462
+ def remove_unwanted_files
463
+ file_array = []
464
+ root_path = FileUtils.join_paths(@install_path, @project_name)
465
+ @config_file[:remove_files].each do |file|
466
+ file_array << FileUtils.join_paths(root_path, file)
467
+ end
468
+ FileUtils.remove_files(file_array)
469
+ end
470
+
471
+ def run_scripts_from_yaml(script_name)
472
+ unless @config_file[script_name].nil? || @config_file[script_name].empty?
473
+ begin
474
+ Dir.chdir(FileUtils.join_paths(@install_path, @project_name))
475
+ @config_file[script_name].each do |x|
476
+ puts "\nExecuting command: #{x.green}"
477
+ system "#{x}"
478
+ end
479
+ rescue
480
+ 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."
481
+ end
482
+ end
483
+ end
484
+
485
+ def check_for_strings_to_replace
486
+ if @replace_strings.nil? || @replace_strings.empty?
487
+ false
488
+ else
489
+ puts "\nChecking for strings to replace inside files...\n\n"
490
+ @replace_strings.each do |file|
491
+ puts "Target file: #{file[:target_path].green}\n"
492
+ puts "Strings to replace:\n\n"
493
+ check_replace_string_pairs_for_project_name_sub(file[:symbols])
494
+ file[:symbols].each do |x,y|
495
+ puts "Key: #{x.to_s.green}"
496
+ puts "Value: #{y.to_s.green}\n\n"
497
+ end
498
+ puts "\n"
499
+ path = FileUtils.join_paths(@install_path, @project_name, file[:target_path])
500
+ FileUtils.replace_strings(path, file[:symbols])
501
+ end
502
+ end
503
+ end
504
+
505
+ def dump_global_yaml
506
+ File.open( "#{CONFIG_PATH}/jumpstart_setup.yml", 'w' ) do |out|
507
+ YAML.dump( {:jumpstart_templates_path => @jumpstart_templates_path, :default_template_name => @default_template_name}, out )
508
+ end
509
+ end
510
+
511
+ def exit_with_success
512
+ puts "\n\n Exiting JumpStart...".purple
513
+ 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
514
+ puts "******************************************************************************************************************************************\n"
515
+ exit
516
+ end
517
+
518
+ def exit_normal
519
+ puts "\n\n Exiting JumpStart...".purple
520
+ puts "\n Goodbye!\n\n"
521
+ puts "******************************************************************************************************************************************\n"
522
+ exit
523
+ end
524
+
525
+ class << self
526
+
527
+ def get_line_number(file_name)
528
+ if file_name.match(/_(\d+)\._\w*/)
529
+ number = file_name.match(/_(\d+)\._\w*/)[1]
530
+ number.to_i
531
+ else
532
+ false
533
+ end
534
+ end
535
+
536
+ def remove_last_line?(file_name)
537
+ if file_name.match(/_([lL]{1})\._{1}\w*/)
538
+ true
539
+ else
540
+ false
541
+ end
542
+ end
543
+
544
+ end
545
+
546
+ end
547
+ end