Class: Xnlogic::CLI::Application
- Defined in:
- lib/xnlogic/cli/application.rb
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
-
#base_name ⇒ Object
readonly
Returns the value of attribute base_name.
-
#existing ⇒ Object
readonly
Returns the value of attribute existing.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Attributes inherited from Core
#app, #ignore_options, #options, #thor
Instance Method Summary collapse
- #_generate_templates(template_src_to_dst, template_folder, opts, ui_message = nil) ⇒ Object
- #application ⇒ Object
- #check_arguments ⇒ Object
- #datomic_license ⇒ Object
- #datomic_pro? ⇒ Boolean
- #generate_application ⇒ Object
- #generate_vm_config ⇒ Object
- #in_existing_project ⇒ Object
-
#initialize(options, thor) ⇒ Application
constructor
A new instance of Application.
- #install_vagrant_note ⇒ Object
- #options_file ⇒ Object
- #options_filename ⇒ Object
- #require_key ⇒ Object
- #set_name(app_name) ⇒ Object
- #show_source(source) ⇒ Object
- #template_options ⇒ Object
- #update_key(xn_key) ⇒ Object
- #vm_config ⇒ Object
Methods inherited from Core
Constructor Details
#initialize(options, thor) ⇒ Application
Returns a new instance of Application.
7 8 9 10 |
# File 'lib/xnlogic/cli/application.rb', line 7 def initialize(, thor) super @ignore_options = ['up', 'provision'] end |
Instance Attribute Details
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
5 6 7 |
# File 'lib/xnlogic/cli/application.rb', line 5 def app_name @app_name end |
#base_name ⇒ Object (readonly)
Returns the value of attribute base_name.
5 6 7 |
# File 'lib/xnlogic/cli/application.rb', line 5 def base_name @base_name end |
#existing ⇒ Object (readonly)
Returns the value of attribute existing.
5 6 7 |
# File 'lib/xnlogic/cli/application.rb', line 5 def existing @existing end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/xnlogic/cli/application.rb', line 5 def name @name end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
5 6 7 |
# File 'lib/xnlogic/cli/application.rb', line 5 def root @root end |
Instance Method Details
#_generate_templates(template_src_to_dst, template_folder, opts, ui_message = nil) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/xnlogic/cli/application.rb', line 192 def _generate_templates(template_src_to_dst, template_folder, opts, =nil) if(not .nil?) Xnlogic.ui.info "" Xnlogic.ui.info Xnlogic.ui.info "" end template_src_to_dst.each do |src, dst| thor.template("#{template_folder}/#{src}", app.join(dst), opts) end end |
#application ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/xnlogic/cli/application.rb', line 59 def application require_key generate_vm_config if ['vm_config'] generate_application ['application_version'] = Xnlogic::VERSION Xnlogic.ui.info "Initializing git repo in #{app}" Dir.chdir(app) { system 'git init' and system 'git add .' } unless existing install_vagrant_note if ['up'] Dir.chdir(app) { system 'vagrant up' } else Xnlogic.ui.info "" Xnlogic.ui.info "To start your VM, run the following:" Xnlogic.ui.info "" Xnlogic.ui.info "cd #{root}" Xnlogic.ui.info "xnlogic up" end if ['provision'] Dir.chdir(app) { system 'vagrant provision' } end Xnlogic.ui.info "To begin working with your VM, ssh into it with the following command:" Xnlogic.ui.info "" Xnlogic.ui.info "cd #{root}" Xnlogic.ui.info "xnlogic ssh" Xnlogic.ui.info "" Xnlogic.ui.info "Once logged in to the server, try the xn-console and xn-server commands" end |
#check_arguments ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/xnlogic/cli/application.rb', line 144 def check_arguments if datomic_pro? if ['datomic_license'] unless datomic_license Xnlogic.ui.warn "[WARN] Datomic license file '#{ ['datomic_license'] }' not found." end else Xnlogic.ui.warn "[WARN] No datomic-license specified. Pro transacter will not start." end unless ['datomic_username'] and ['datomic_key'] Xnlogic.ui.warn "[WARN] No datomic-username or datomic-key. Will not be able to fetch datomic pro jar dependencies." end end end |
#datomic_license ⇒ Object
159 160 161 162 163 |
# File 'lib/xnlogic/cli/application.rb', line 159 def datomic_license if ['datomic_license'] and File.exist? ['datomic_license'] File.read(['datomic_license']).sub(/^license-key=/, '') end end |
#datomic_pro? ⇒ Boolean
140 141 142 |
# File 'lib/xnlogic/cli/application.rb', line 140 def datomic_pro? .fetch('datomic_pro', ['datomic_mysql']) end |
#generate_application ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/xnlogic/cli/application.rb', line 246 def generate_application opts = namespaced_path = opts[:namespaced_path] templates = { "gitignore.tt" => ".gitignore", ".rspec.tt" => ".rspec", "gemspec.tt" => "#{namespaced_path}.gemspec", "Rakefile.tt" => "Rakefile", "Readme.md.tt" => "Readme.md", "logback.xml.tt" => "logback.xml", "config.ru.tt" => "config.ru", "dev/console.rb.tt" => "dev/console.rb", "config/mcfly_config.yml.tt" => "config/mcfly_config.yml", "tasks/deploy.rb.tt" => "tasks/deploy.rb", "torquebox.yml.tt" => "torquebox.yml", "torquebox_init.rb.tt" => "torquebox_init.rb", "lib/gemname.rb.tt" => "lib/#{namespaced_path}.rb", "lib/gemname/version.rb.tt" => "lib/#{namespaced_path}/version.rb", "lib/gemname/initializers/inflections.rb.tt" => "lib/#{namespaced_path}/initializers/inflections.rb", "lib/gemname/parts/has_notes.rb.tt" => "lib/#{namespaced_path}/parts/has_notes.rb", "lib/gemname/parts/note.rb.tt" => "lib/#{namespaced_path}/parts/note.rb", "lib/gemname/type/url.rb.tt" => "lib/#{namespaced_path}/type/url.rb", "lib/gemname/fixtures.rb.tt" => "lib/#{namespaced_path}/fixtures.rb", "lib/gemname/models.rb.tt" => "lib/#{namespaced_path}/models.rb", "lib/gemname/permissions.rb.tt" => "lib/#{namespaced_path}/permissions.rb", "lib/gemname/type.rb.tt" => "lib/#{namespaced_path}/type.rb", "lib/fixtures/sample_fixtures.rb.tt" => "lib/fixtures/sample_fixtures.rb", "assets/index.html.tt" => "assets/index.html", "assets/images/xnlogic-logo-site.png" => "assets/images/xnlogic-logo-site.png", "assets/images/xnlogic-logo-site-x2.png" => "assets/images/xnlogic-logo-site-x2.png", "spec/spec_helper.rb.tt" => "spec/spec_helper.rb", "spec/gemname/gemname_spec.rb.tt" => "spec/#{namespaced_path}/#{name}_spec.rb", } _generate_templates(templates, 'application', opts, 'Creating application templates') end |
#generate_vm_config ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/xnlogic/cli/application.rb', line 205 def generate_vm_config transactor_properties = if ['datomic_mysql'] "datomic/mysql.properties.tt" elsif ['datomic_pro'] "datomic/pro.properties.tt" else "datomic/free.properties.tt" end datomic_installer = if datomic_pro? 'datomic/install_pro_transactor.sh.tt' else 'datomic/install_free_transactor.sh.tt' end base_templates = { "Vagrantfile.tt" => "Vagrantfile", "Gemfile.tt" => "Gemfile", "config/vagrant.provision.tt" => "config/vagrant.provision", "config/vagrant.up.tt" => "config/vagrant.up", "config/datomic.conf" => "config/datomic.conf", "config/start.sh" => "config/start.sh", "config/diagnostics.sh" => "config/diagnostics.sh", transactor_properties => "config/transactor.properties", "config/xnlogic.conf.tt" => "config/xnlogic.conf", datomic_installer => 'script/install_transactor.sh', } if datomic_pro? base_templates['datomic/m2_settings.xml.tt'] = 'config/m2_settings.xml' base_templates['datomic/pom.xml.tt'] = 'config/pom.xml' base_templates['datomic/get_datomic_jar.sh.tt'] = 'script/get_datomic_jar.sh' if ['datomic_mysql'] base_templates['datomic/mysql/db.sql'] = 'config/mysql/db.sql' base_templates['datomic/mysql/table.sql'] = 'config/mysql/table.sql' base_templates['datomic/mysql/user.sql'] = 'config/mysql/user.sql' end end _generate_templates(base_templates, 'vagrant', , 'Creating Vagrant configuration') end |
#in_existing_project ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/xnlogic/cli/application.rb', line 32 def in_existing_project @existing = true @root = .fetch('root', '.') @app = Pathname.pwd.join(root) super() @name ||= ['name'] self end |
#install_vagrant_note ⇒ Object
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/xnlogic/cli/application.rb', line 109 def install_vagrant_note ver = `vagrant --version` rescue '' if ver == '' Xnlogic.ui.info "" Xnlogic.ui.info "Please ensure that the following dependencies are installed on your computer" Xnlogic.ui.info "to continue." Xnlogic.ui.info " - Vagrant: https://www.vagrantup.com/" Xnlogic.ui.info " - VirtualBox: https://www.virtualbox.org/wiki/Downloads" end end |
#options_file ⇒ Object
28 29 30 |
# File 'lib/xnlogic/cli/application.rb', line 28 def app + end |
#options_filename ⇒ Object
24 25 26 |
# File 'lib/xnlogic/cli/application.rb', line 24 def 'config/app_options.yaml' end |
#require_key ⇒ Object
52 53 54 55 56 57 |
# File 'lib/xnlogic/cli/application.rb', line 52 def require_key unless ['key'] Xnlogic.ui.info 'You must specify a --key option to generate an application.' exit 1 end end |
#set_name(app_name) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/xnlogic/cli/application.rb', line 12 def set_name(app_name) if File.exists?() Xnlogic.ui.info "Can not create an application within an application." exit 1 end @name = app_name.chomp("/").tr('-', '_') # remove trailing slash if present @root = .fetch('root', @name) @app = Pathname.pwd.join(root) ['name'] = @name self end |
#show_source(source) ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/xnlogic/cli/application.rb', line 41 def show_source(source) case ['format'] when 'bundler' Xnlogic.ui.info "source \"#{source}\"" when 'rubygems' Xnlogic.ui.info "gem sources -a #{source}" else Xnlogic.ui.info source end end |
#template_options ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/xnlogic/cli/application.rb', line 165 def namespaced_path = name constant_name = namespaced_path.split('_').map{|p| p[0..0].upcase + p[1..-1] }.join git_user_name = `git config user.name`.chomp git_user_email = `git config user.email`.chomp check_arguments { :name => name, :namespaced_path => namespaced_path, :constant_name => constant_name, :author => git_user_name.empty? ? "TODO: Write your name" : git_user_name, :email => git_user_email.empty? ? "TODO: Write your email address" : git_user_email, :vm_cpus => ['cpus'], :vm_memory => ['memory'], :xn_key => ['key'], :datomic_pro => datomic_pro?, :datomic_license => datomic_license, :datomic_mysql => ['datomic_mysql'], :datomic_optional_version => ['datomic_version'], :datomic_version => (['datomic_version'] || "0.9.5130"), :mysql_version => '5.1.35', :datomic_username => .fetch('datomic_username', '[username from my.datomic.com]'), :datomic_key => .fetch('datomic_key', '[key from my.datomic.com]'), } end |
#update_key(xn_key) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/xnlogic/cli/application.rb', line 121 def update_key(xn_key) # Set the option ['key'] = xn_key # Check that we are in an existing project folder in_existing_project # Gemerate the necessary templates templates = { "Gemfile.tt" => "Gemfile", "config/vagrant.provision.tt" => "config/vagrant.provision", "config/xnlogic.conf.tt" => "config/xnlogic.conf", } _generate_templates(templates, 'vagrant', , 'Updating configuration') # Write the options YAML file end |
#vm_config ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/xnlogic/cli/application.rb', line 91 def vm_config generate_vm_config ['vm_config_version'] = Xnlogic::VERSION install_vagrant_note if ['provision'] or ['up'] Dir.chdir(app) { system 'vagrant up' } if ['up'] Dir.chdir(app) { system 'vagrant provision' } if ['provision'] else Xnlogic.ui.info "" Xnlogic.ui.info "If you have an existing VM that you are updating, run 'xnlogic provision'," Xnlogic.ui.info "otherwise, run 'xnlogic up'" Xnlogic.ui.info "" end Xnlogic.ui.info "Once that is done, run 'xnlogic ssh' to log in to the VM." end |