Class: Scaffold

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

Overview

TODO refactor to nest under RakeTask namespace

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
  /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
  
  # Glimmer
  dist
  packages
  vendor/jars
MULTI_LINE_STRING
GEMFILE =
<<~MULTI_LINE_STRING
  # frozen_string_literal: true
  
  source 'https://rubygems.org'
  
  git_source(:github) {|repo_name| "https://github.com/\#{repo_name}" }
  
  gem 'glimmer-dsl-swt', '~> #{VERSION}'
  
  group :development do
    gem 'rspec', '~> 3.5.0'
    gem 'git-glimmer', '1.7.0'
    gem 'jeweler', '2.3.9'
    gem 'simplecov', '>= 0'
  end
MULTI_LINE_STRING
RVM_FUNCTION =
<<~MULTI_LINE_STRING
  # Load RVM into a shell session *as a function*
  if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
  
    # First try to load from a user install
    source "$HOME/.rvm/scripts/rvm"
  
  elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
  
    # Then try to load from a root install
    source "/usr/local/rvm/scripts/rvm"
  
  fi
MULTI_LINE_STRING

Class Method Summary collapse

Class Method Details

.app(app_name) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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
# File 'lib/glimmer/scaffold.rb', line 112

def app(app_name)
  gem_name = file_name(app_name)
  gem_summary = human_name(app_name)
  system "jruby -r git-glimmer -S jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}" 
  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
  write 'Rakefile', gem_rakefile(app_name, nil, gem_name)
  mkdir 'app'
  write "app/#{file_name(app_name)}.rb", app_main_file(app_name)
  mkdir 'app/models'
  mkdir 'app/views'
  custom_shell('AppView', current_dir_name, :app)
    
  mkdir_p 'package/windows'
  icon_file = "package/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 'package/macosx'
  icon_file = "package/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 'package/linux'
  icon_file = "package/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 'bin'
  write "bin/#{file_name(app_name)}", app_bin_file(app_name)
  write 'spec/spec_helper.rb', spec_helper_file
  if OS.windows?
    system "bundle"
    system "glimmer package[image]"
    system "\"packages/bundles/#{human_name(app_name)}/#{human_name(app_name)}.exe\""
  else
    system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
    if OS.mac?
      system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app"
    else
      system "glimmer bin/#{file_name(app_name)}"
    end
  end
end

.custom_shell(custom_shell_name, namespace, shell_type = nil) ⇒ Object



163
164
165
166
167
168
169
# File 'lib/glimmer/scaffold.rb', line 163

def custom_shell(custom_shell_name, namespace, shell_type = nil)
  namespace ||= current_dir_name
  root_dir = File.exists?('app') ? 'app' : 'lib'
  parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
  mkdir_p parent_dir unless File.exists?(parent_dir)
  write "#{parent_dir}/#{file_name(custom_shell_name)}.rb", custom_shell_file(custom_shell_name, namespace, shell_type)
end

.custom_shell_gem(custom_shell_name, namespace) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
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
# File 'lib/glimmer/scaffold.rb', line 179

def custom_shell_gem(custom_shell_name, namespace)
  gem_name = "glimmer-cs-#{compact_name(custom_shell_name)}"
  gem_summary = "#{human_name(custom_shell_name)} - Glimmer Custom Shell"
  if namespace
    gem_name += "-#{compact_name(namespace)}"
    gem_summary += " (#{human_name(namespace)})"
  else
    return puts('Namespace is required! Usage: glimmer scaffold:gem:customshell[name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
    namespace = 'glimmer'
  end
  system "jruby -r git-glimmer -S jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}" 
  cd gem_name
  write '.gitignore', GITIGNORE
  write '.ruby-version', RUBY_VERSION        
  write '.ruby-gemset', gem_name
  write 'VERSION', '1.0.0'
  write 'Gemfile', GEMFILE
  write 'Rakefile', gem_rakefile(custom_shell_name, namespace, gem_name)
  append "lib/#{gem_name}.rb", gem_main_file(custom_shell_name, namespace)
  mkdir 'lib/views'
  custom_shell(custom_shell_name, namespace, :gem)
  mkdir 'bin'
  write "bin/#{gem_name}", gem_bin_file(gem_name, custom_shell_name, namespace)
  write "bin/#{file_name(custom_shell_name)}", gem_bin_command_file(gem_name)
  FileUtils.chmod 0755, "bin/#{file_name(custom_shell_name)}"
  write 'spec/spec_helper.rb', spec_helper_file

  mkdir_p 'package/windows'
  icon_file = "package/windows/#{human_name(custom_shell_name)}.ico"
  cp File.expand_path('../../../icons/scaffold_app.ico', __FILE__), icon_file
  puts "Created #{current_dir_name}/#{icon_file}"
    
  mkdir_p 'package/macosx'
  icon_file = "package/macosx/#{human_name(custom_shell_name)}.icns"
  cp File.expand_path('../../../icons/scaffold_app.icns', __FILE__), icon_file
  puts "Created #{current_dir_name}/#{icon_file}"
  
  mkdir_p 'package/linux'
  icon_file = "package/linux/#{human_name(custom_shell_name)}.png"
  cp File.expand_path('../../../icons/scaffold_app.png', __FILE__), icon_file
  puts "Created #{current_dir_name}/#{icon_file}"
  
  if OS.windows?
    system "bundle"
    system "glimmer package[image]"
    system "\"packages/bundles/#{human_name(custom_shell_name)}/#{human_name(custom_shell_name)}.exe\""
  else
    system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'"
    if OS.mac?
      system "open packages/bundles/#{human_name(custom_shell_name).gsub(' ', '\ ')}.app" if OS.mac?
    else
      system "bin/#{file_name(custom_shell_name)}"
    end        
  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

.custom_widget(custom_widget_name, namespace) ⇒ Object



171
172
173
174
175
176
177
# File 'lib/glimmer/scaffold.rb', line 171

def custom_widget(custom_widget_name, namespace)
  namespace ||= current_dir_name
  root_dir = File.exists?('app') ? 'app' : 'lib'
  parent_dir = "#{root_dir}/views/#{file_name(namespace)}"
  mkdir_p parent_dir unless File.exists?(parent_dir)
  write "#{parent_dir}/#{file_name(custom_widget_name)}.rb", custom_widget_file(custom_widget_name, namespace)
end

.custom_widget_gem(custom_widget_name, namespace) ⇒ Object



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
# File 'lib/glimmer/scaffold.rb', line 240

def custom_widget_gem(custom_widget_name, namespace)
  return puts('Namespace is required! Usage: glimmer scaffold:custom_widget_gem[custom_widget_name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva'
  gem_name = "glimmer-cw-#{compact_name(custom_widget_name)}"
  gem_summary = "#{human_name(custom_widget_name)} - Glimmer Custom Widget"
  if namespace
    gem_name += "-#{compact_name(namespace)}"
    gem_summary += " (#{human_name(namespace)})"
  else
    namespace = 'glimmer'
  end
  system "jruby -r git-glimmer -S jeweler --rspec --summary '#{gem_summary}' --description '#{gem_summary}' #{gem_name}" 
  cd gem_name
  write '.gitignore', GITIGNORE
  write '.ruby-version', RUBY_VERSION        
  write '.ruby-gemset', gem_name
  write 'VERSION', '1.0.0'
  write 'Gemfile', GEMFILE
  write 'Rakefile', gem_rakefile
  write 'spec/spec_helper.rb', spec_helper_file
  append "lib/#{gem_name}.rb", gem_main_file(custom_widget_name, namespace)
  mkdir 'lib/views'
  custom_widget(custom_widget_name, namespace)
  if OS.windows?
    system "bundle"
  else
    system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n'"
  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