Class: Glimmer::RakeTask::Scaffold

Inherits:
Object
  • Object
show all
Extended by:
FileUtils
Defined in:
lib/glimmer/rake_task/scaffold.rb

Constant Summary collapse

VERSION =
File.read(File.expand_path('../../../../VERSION', __FILE__)).strip
RUBY_VERSION =
File.read(File.expand_path('../../../../RUBY_VERSION', __FILE__)).strip
GITIGNORE =

TODO externalize all constants into scaffold/files

<<~MULTI_LINE_STRING
  *.gem
  *.rbc
  /.config
  /.mvn/
  /coverage/
  /InstalledFiles
  /pkg/
  /spec/reports/
  /spec/examples.txt
  /test/tmp/
  /test/version_tmp/
  /tmp/
  
  # Used by dotenv library to load environment variables.
  # .env
  
  ## Specific to RubyMotion:
  .dat*
  .repl_history
  build/
  *.bridgesupport
  build-iPhoneOS/
  build-iPhoneSimulator/
  
  ## Specific to RubyMotion (use of CocoaPods):
  #
  # We recommend against adding the Pods directory to your .gitignore. However
  # you should judge for yourself, the pros and cons are mentioned at:
  # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
  #
  # vendor/Pods/
  
  ## Documentation cache and generated files:
  /.yardoc/
  /_yardoc/
  /doc/
  /rdoc/
  
  ## Environment normalization:
  /.bundle/
  /vendor/bundle
  /lib/bundler/man/
  
  # for a library or gem, you might want to ignore these files since the code is
  # intended to run in multiple environments; otherwise, check them in:
  # Gemfile.lock
  # .ruby-version
  # .ruby-gemset
  
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
  .rvmrc
  
  # Mac
  .DS_Store
  
  # Gladiator (Glimmer Editor)
  .gladiator
  .gladiator-scratchpad
  
  # Glimmer
  /dist/
  /packages/
MULTI_LINE_STRING
GEMFILE_PREFIX =
<<~MULTI_LINE_STRING
  # frozen_string_literal: true
  
  source 'https://rubygems.org'
  
  git_source(:github) {|repo_name| "https://github.com/\#{repo_name}" }
MULTI_LINE_STRING
GEMFILE_APP_MIDFIX =
<<~MULTI_LINE_STRING

  gem 'glimmer-dsl-libui', '~> #{VERSION}'
MULTI_LINE_STRING
GEMFILE_GEM_MIDFIX =
<<~MULTI_LINE_STRING

  gem 'glimmer-dsl-libui', '~> #{VERSION.split('.')[0...2].join('.')}'
MULTI_LINE_STRING
GEMFILE_SUFFIX =
<<~MULTI_LINE_STRING

  group :development do
    gem 'rspec', '~> 3.5.0'
    gem 'juwelier', '2.4.9'
    gem 'simplecov', '>= 0'
  end
MULTI_LINE_STRING
APP_GEMFILE =
GEMFILE_PREFIX + GEMFILE_APP_MIDFIX + GEMFILE_SUFFIX
GEM_GEMFILE =
GEMFILE_PREFIX + GEMFILE_GEM_MIDFIX + GEMFILE_SUFFIX

Class Method Summary collapse

Class Method Details

.app(app_name) ⇒ Object



132
133
134
# File 'lib/glimmer/rake_task/scaffold.rb', line 132

def app(app_name)
  common_app(app_name)
end

.app_model(current_dir_name, namespace = nil) ⇒ Object



372
373
374
375
376
377
378
379
380
# File 'lib/glimmer/rake_task/scaffold.rb', line 372

def app_model(current_dir_name, namespace = nil)
  model_name = 'Greeting'
  namespace ||= current_dir_name
  root_dir = File.exist?('app') ? 'app' : 'lib'
  parent_dir = "#{root_dir}/#{file_name(namespace)}/model"
  return puts("The file '#{parent_dir}/#{file_name(model_name)}.rb' already exists. Please either remove or pick a different name.") if File.exist?("#{parent_dir}/#{file_name(model_name)}.rb")
  mkdir_p parent_dir unless File.exist?(parent_dir)
  write "#{parent_dir}/#{file_name(model_name)}.rb", model_file(model_name, namespace)
end

.common_app(app_name, window_type = :app, window_options = {}) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
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
190
191
192
# File 'lib/glimmer/rake_task/scaffold.rb', line 136

def common_app(app_name, window_type = :app, window_options = {})
  gem_name = file_name(app_name)
  gem_summary = human_name(app_name)
  return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
#           system "ruby -S gem install bundler --no-document" if OS.windows? # resolves freezing issue with warbler and bundler 2.2.29 included in JRuby
  system "ruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exist?
  system "ruby -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
  return puts('Your Git user.name and/or github.user are missing! Please add in for Juwelier to help Glimmer with Scaffolding.') if `git config --get github.user`.strip.empty? || `git config --get user.name`.strip.empty?
  cd gem_name
  rm_rf 'lib'
  write '.gitignore', GITIGNORE
  write '.ruby-version', RUBY_VERSION
  write '.ruby-gemset', app_name
  write 'VERSION', '1.0.0'
  write 'LICENSE.txt', "Copyright (c) #{Time.now.year} #{app_name}"
  write 'Gemfile', gemfile(window_type)
  write 'Rakefile', gem_rakefile(app_name, nil, gem_name)
  mkdir 'app'
  write "app/#{file_name(app_name)}.rb", app_main_file(app_name)
  mkdir_p "app/#{file_name(app_name)}/model"
  mkdir_p "app/#{file_name(app_name)}/view"
  custom_window(class_name(app_name), current_dir_name, window_type, custom_window_class_name: 'Application')
  app_model(current_dir_name)
    
  mkdir_p 'icons/windows'
  icon_file = "icons/windows/#{human_name(app_name)}.ico"
  cp File.expand_path('../../../../icons/scaffold_app.ico', __FILE__), icon_file
  puts "Created #{current_dir_name}/#{icon_file}"
  
  mkdir_p 'icons/macosx'
  icon_file = "icons/macosx/#{human_name(app_name)}.icns"
  cp File.expand_path('../../../../icons/scaffold_app.icns', __FILE__), icon_file
  puts "Created #{current_dir_name}/#{icon_file}"

  mkdir_p 'icons/linux'
  icon_file = "icons/linux/#{human_name(app_name)}.png"
  cp File.expand_path('../../../../icons/scaffold_app.png', __FILE__), icon_file
  puts "Created #{current_dir_name}/#{icon_file}"
  
  mkdir_p "app/#{file_name(app_name)}"
  write "app/#{file_name(app_name)}/launch.rb", app_launch_file(app_name)
  mkdir_p 'bin'
  write "bin/#{file_name(app_name)}", app_bin_command_file(app_name)
  FileUtils.chmod 0755, "bin/#{file_name(app_name)}"
  if OS.windows?
    system "bundle"
    system "rspec --init"
  else
    system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n rspec --init\n'"
  end
  write 'spec/spec_helper.rb', spec_helper_file
  if OS.mac? || OS.linux?
    system "bash -c '#{RVM_FUNCTION}\n cd .\n glimmer run\n'"
  else
    system "glimmer run"
  end
end

.custom_control(custom_control_name, namespace) ⇒ Object



203
204
205
206
207
208
209
210
# File 'lib/glimmer/rake_task/scaffold.rb', line 203

def custom_control(custom_control_name, namespace)
  namespace ||= current_dir_name
  root_dir = File.exist?('app') ? 'app' : 'lib'
  parent_dir = "#{root_dir}/#{file_name(namespace)}/view"
  return puts("The file '#{parent_dir}/#{file_name(custom_control_name)}.rb' already exists. Please either remove or pick a different name.") if File.exist?("#{parent_dir}/#{file_name(custom_control_name)}.rb")
  mkdir_p parent_dir unless File.exist?(parent_dir)
  write "#{parent_dir}/#{file_name(custom_control_name)}.rb", custom_control_file(custom_control_name, namespace)
end

.custom_control_gem(custom_control_name, namespace) ⇒ Object



294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/glimmer/rake_task/scaffold.rb', line 294

def custom_control_gem(custom_control_name, namespace)
  gem_name = "glimmer-libui-cc-#{custom_control_name.underscore}"
  gem_summary = "#{human_name(custom_control_name)} - Glimmer Custom Control"
  if namespace
    gem_name += "-#{namespace.underscore}"
    gem_summary += " (#{human_name(namespace)})"
  else
    return puts('Namespace is required! Usage: glimmer scaffold:custom_control_gem[custom_control_name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
    namespace = 'glimmer'
  end
  
  return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
#           system "ruby -S gem install bundler --no-document" if OS.windows? # resolves freezing issue with warbler and bundler 2.2.29 included in JRuby
  system "ruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exist?
  system "ruby -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
  return puts('Your Git user.name and/or github.user are missing! Please add in for Juwelier to help Glimmer with Scaffolding.') if `git config --get github.user`.strip.empty? && `git config --get user.name`.strip.empty?
  cd gem_name
  write '.gitignore', GITIGNORE
  write '.ruby-version', RUBY_VERSION
  write '.ruby-gemset', gem_name
  write 'VERSION', '1.0.0'
  write 'Gemfile', GEM_GEMFILE
  write 'Rakefile', gem_rakefile
  append "lib/#{gem_name}.rb", gem_main_file(custom_control_name, namespace)
  custom_control(custom_control_name, namespace)
  if OS.windows?
    system "bundle"
    system "rspec --init"
  else
    system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n rspec --init\n'"
  end
  write 'spec/spec_helper.rb', spec_helper_file
  puts "Finished creating #{gem_name} Ruby gem."
  puts 'Edit Rakefile to configure gem details.'
  puts 'Run `rake` to execute specs.'
  puts 'Run `rake build` to build gem.'
  puts 'Run `rake release` to release into rubygems.org once ready.'
end

.custom_shape(custom_shape_name, namespace) ⇒ Object



212
213
214
215
216
217
218
219
# File 'lib/glimmer/rake_task/scaffold.rb', line 212

def custom_shape(custom_shape_name, namespace)
  namespace ||= current_dir_name
  root_dir = File.exist?('app') ? 'app' : 'lib'
  parent_dir = "#{root_dir}/#{file_name(namespace)}/view"
  return puts("The file '#{parent_dir}/#{file_name(custom_shape_name)}.rb' already exists. Please either remove or pick a different name.") if File.exist?("#{parent_dir}/#{file_name(custom_shape_name)}.rb")
  mkdir_p parent_dir unless File.exist?(parent_dir)
  write "#{parent_dir}/#{file_name(custom_shape_name)}.rb", custom_shape_file(custom_shape_name, namespace)
end

.custom_shape_gem(custom_shape_name, namespace) ⇒ Object



333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
# File 'lib/glimmer/rake_task/scaffold.rb', line 333

def custom_shape_gem(custom_shape_name, namespace)
  gem_name = "glimmer-libui-cs-#{custom_shape_name.underscore}"
  gem_summary = "#{human_name(custom_shape_name)} - Glimmer Custom Shape"
  if namespace
    gem_name += "-#{namespace.underscore}"
    gem_summary += " (#{human_name(namespace)})"
  else
    return puts('Namespace is required! Usage: glimmer scaffold:custom_shape_gem[custom_shape_name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
    namespace = 'glimmer'
  end
  
  return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
#           system "ruby -S gem install bundler --no-document" if OS.windows? # resolves freezing issue with warbler and bundler 2.2.29 included in JRuby
  system "ruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exist?
  system "ruby -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
  return puts('Your Git user.name and/or github.user are missing! Please add in for Juwelier to help Glimmer with Scaffolding.') if `git config --get github.user`.strip.empty? && `git config --get user.name`.strip.empty?
  cd gem_name
  write '.gitignore', GITIGNORE
  write '.ruby-version', RUBY_VERSION
  write '.ruby-gemset', gem_name
  write 'VERSION', '1.0.0'
  write 'Gemfile', GEM_GEMFILE
  write 'Rakefile', gem_rakefile
  append "lib/#{gem_name}.rb", gem_main_file(custom_shape_name, namespace)
  custom_shape(custom_shape_name, namespace)
  if OS.windows?
    system "bundle"
    system "rspec --init"
  else
    system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n rspec --init\n'"
  end
  write 'spec/spec_helper.rb', spec_helper_file
  puts "Finished creating #{gem_name} Ruby gem."
  puts 'Edit Rakefile to configure gem details.'
  puts 'Run `rake` to execute specs.'
  puts 'Run `rake build` to build gem.'
  puts 'Run `rake release` to release into rubygems.org once ready.'
end

.custom_window(custom_window_name, namespace, window_type = nil, window_options = {}) ⇒ Object



194
195
196
197
198
199
200
201
# File 'lib/glimmer/rake_task/scaffold.rb', line 194

def custom_window(custom_window_name, namespace, window_type = nil, window_options = {})
  namespace ||= current_dir_name
  root_dir = File.exist?('app') ? 'app' : 'lib'
  parent_dir = "#{root_dir}/#{file_name(namespace)}/view"
  return puts("The file '#{parent_dir}/#{file_name(custom_window_name)}.rb' already exists. Please either remove or pick a different name.") if File.exist?("#{parent_dir}/#{file_name(custom_window_name)}.rb")
  mkdir_p parent_dir unless File.exist?(parent_dir)
  write "#{parent_dir}/#{file_name(custom_window_name)}.rb", custom_window_file(custom_window_name, namespace, window_type, window_options)
end

.custom_window_gem(custom_window_name, namespace) ⇒ Object



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
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
283
284
285
286
287
288
289
290
291
292
# File 'lib/glimmer/rake_task/scaffold.rb', line 221

def custom_window_gem(custom_window_name, namespace)
  gem_name = "glimmer-libui-cw-#{custom_window_name.underscore}"
  gem_summary = "#{human_name(custom_window_name)} - Glimmer Custom Window"
  begin
    custom_window_keyword = dsl_control_name(custom_window_name)
    MAIN_OBJECT.method(custom_window_keyword)
    return puts("CustomWindow keyword `#{custom_window_keyword}` is unavailable (occupied by a built-in Ruby method)! Please pick a different name.")
  rescue NameError
    # No Op (keyword is not taken by a built in Ruby method)
  end
  if namespace
    gem_name += "-#{namespace.underscore}"
    gem_summary += " (#{human_name(namespace)})"
  else
    return puts('Namespace is required! Usage: glimmer scaffold:gem:customwindow[name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
    namespace = 'glimmer'
  end
  return puts("The directory '#{gem_name}' already exists. Please either remove or pick a different name.") if Dir.exist?(gem_name)
#           system "ruby -S gem install bundler --no-document" if OS.windows? # resolves freezing issue with warbler and bundler 2.2.29 included in JRuby
  system "ruby -S gem install juwelier -v2.4.9 --no-document" unless juwelier_exist?
  system "ruby -S juwelier --markdown --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}"
  return puts('Your Git user.name and/or github.user are missing! Please add in for Juwelier to help Glimmer with Scaffolding.') if `git config --get github.user`.strip.empty? && `git config --get user.name`.strip.empty?
  cd gem_name
  write '.gitignore', GITIGNORE
  write '.ruby-version', RUBY_VERSION
  write '.ruby-gemset', gem_name
  write 'VERSION', '1.0.0'
  write 'Gemfile', GEM_GEMFILE
  write 'Rakefile', gem_rakefile(custom_window_name, namespace, gem_name)
  append "lib/#{gem_name}.rb", gem_main_file(custom_window_name, namespace)
  custom_window(custom_window_name, namespace, :gem)
  app_model(current_dir_name, namespace)
  
  mkdir_p "lib/#{gem_name}"
  write "lib/#{gem_name}/launch.rb", gem_launch_file(gem_name, custom_window_name, namespace)
  mkdir_p 'bin'
  write "bin/#{file_name(custom_window_name)}", app_bin_command_file(gem_name, custom_window_name, namespace)
  FileUtils.chmod 0755, "bin/#{file_name(custom_window_name)}"
  if OS.windows?
    system "bundle"
    system "rspec --init"
  else
    system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n rspec --init\n'"
  end
  write 'spec/spec_helper.rb', spec_helper_file
    
  mkdir_p 'icons/windows'
  icon_file = "icons/windows/#{human_name(gem_name)}.ico"
  cp File.expand_path('../../../../icons/scaffold_app.ico', __FILE__), icon_file
  puts "Created #{current_dir_name}/#{icon_file}"
    
  mkdir_p 'icons/macosx'
  icon_file = "icons/macosx/#{human_name(gem_name)}.icns"
  cp File.expand_path('../../../../icons/scaffold_app.icns', __FILE__), icon_file
  puts "Created #{current_dir_name}/#{icon_file}"
  
  mkdir_p 'icons/linux'
  icon_file = "icons/linux/#{human_name(gem_name)}.png"
  cp File.expand_path('../../../../icons/scaffold_app.png', __FILE__), icon_file
  puts "Created #{current_dir_name}/#{icon_file}"
  
  if OS.mac? || OS.linux?
    system "bash -c '#{RVM_FUNCTION}\n cd .\n glimmer run\n'"
  else
    system "glimmer run"
  end
  puts "Finished creating #{gem_name} Ruby gem."
  puts 'Edit Rakefile to configure gem details.'
  puts 'Run `rake` to execute specs.'
  puts 'Run `rake build` to build gem.'
  puts 'Run `rake release` to release into rubygems.org once ready.'
end