Class: Scaffold
- Inherits:
-
Object
- Object
- Scaffold
- Extended by:
- FileUtils
- Defined in:
- lib/glimmer/scaffold.rb
Overview
TODO refactor to nest under RakeTask namespace
Constant Summary collapse
- VERSION =
File.read(File.('../../../VERSION', __FILE__)).strip
- RUBY_VERSION =
File.read(File.('../../../RUBY_VERSION', __FILE__)).strip
- GITIGNORE =
TODO externalize all constants into scaffold/files
"*.gem\n*.rbc\n/.config\n/coverage/\n/InstalledFiles\n/pkg/\n/spec/reports/\n/spec/examples.txt\n/test/tmp/\n/test/version_tmp/\n/tmp/\n \n# Used by dotenv library to load environment variables.\n# .env\n \n## Specific to RubyMotion:\n.dat*\n.repl_history\nbuild/\n*.bridgesupport\nbuild-iPhoneOS/\nbuild-iPhoneSimulator/\n \n## Specific to RubyMotion (use of CocoaPods):\n#\n# We recommend against adding the Pods directory to your .gitignore. However\n# you should judge for yourself, the pros and cons are mentioned at:\n# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control\n#\n# vendor/Pods/\n \n## Documentation cache and generated files:\n/.yardoc/\n/_yardoc/\n/doc/\n/rdoc/\n \n## Environment normalization:\n/.bundle/\n/vendor/bundle\n/lib/bundler/man/\n \n# for a library or gem, you might want to ignore these files since the code is\n# intended to run in multiple environments; otherwise, check them in:\n# Gemfile.lock\n# .ruby-version\n# .ruby-gemset\n \n# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:\n.rvmrc\n \n# Mac\n.DS_Store\n \n# Gladiator (Glimmer Editor)\n.gladiator\n \n# Glimmer\ndist\npackages \n"- GEMFILE_APP =
"# frozen_string_literal: true\n \nsource 'https://rubygems.org'\n \ngit_source(:github) {|repo_name| \"https://github.com/\\\#{repo_name}\" }\n \ngem 'glimmer-dsl-swt', '~> \#{VERSION}'\n \ngroup :test do\n gem 'rspec'\nend\n"- GEMFILE_GEM =
"# frozen_string_literal: true\n \nsource 'https://rubygems.org'\n \ngit_source(:github) {|repo_name| \"https://github.com/\\\#{repo_name}\" }\n \ngem 'glimmer-dsl-swt', '~> \#{VERSION}'\n \ngroup :development do\n gem 'rspec', '~> 3.5.0'\n gem 'jeweler', '2.3.9'\n gem 'simplecov', '>= 0'\nend\n"- RAKEFILE =
"require 'glimmer/rake_task'\n \n## Use the following configuration if you would like to customize javapackager\n## arguments for `glimmer package` command.\n#\n# Glimmer::Package.javapackager_extra_args =\n# \" -BlicenseType=\" +\n# \" -Bmac.CFBundleIdentifier=\" +\n# \" -Bmac.category=\" +\n# \" -Bmac.signing-key-developer-id-app=\"\n"- RVM_FUNCTION =
"# Load RVM into a shell session *as a function*\nif [[ -s \"$HOME/.rvm/scripts/rvm\" ]] ; then\n \n # First try to load from a user install\n source \"$HOME/.rvm/scripts/rvm\"\n \nelif [[ -s \"/usr/local/rvm/scripts/rvm\" ]] ; then\n \n # Then try to load from a root install\n source \"/usr/local/rvm/scripts/rvm\"\n \nfi\n"
Class Method Summary collapse
- .app(app_name) ⇒ Object
- .custom_shell(custom_shell_name, namespace, shell_type = nil) ⇒ Object
- .custom_shell_gem(custom_shell_name, namespace) ⇒ Object
- .custom_widget(custom_widget_name, namespace) ⇒ Object
- .custom_widget_gem(custom_widget_name, namespace) ⇒ Object
Class Method Details
.app(app_name) ⇒ Object
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 |
# File 'lib/glimmer/scaffold.rb', line 137 def app(app_name) mkdir app_name cd app_name 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_APP write 'Rakefile', RAKEFILE 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) if OS.mac? mkdir_p 'package/macosx' icon_file = "package/macosx/#{human_name(app_name)}.icns" cp File.('../../../icons/scaffold_app.icns', __FILE__), icon_file puts "Created #{current_dir_name}/#{icon_file}" end mkdir 'bin' write "bin/#{file_name(app_name)}", app_bin_file(app_name) system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'" system "open packages/bundles/#{human_name(app_name).gsub(' ', '\ ')}.app" # TODO generate rspec test suite end |
.custom_shell(custom_shell_name, namespace, shell_type = nil) ⇒ Object
165 166 167 168 169 170 171 |
# File 'lib/glimmer/scaffold.rb', line 165 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
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 |
# File 'lib/glimmer/scaffold.rb', line 181 def custom_shell_gem(custom_shell_name, namespace) return puts('Namespace is required! Usage: glimmer scaffold:custom_shell_gem[custom_shell_name,namespace]') unless `git config --get github.user`.to_s.strip == 'AndyObtiva' 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 namespace = 'glimmer' end system "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_GEM 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)}" if OS.mac? mkdir_p 'package/macosx' icon_file = "package/macosx/#{human_name(custom_shell_name)}.icns" cp File.('../../../icons/scaffold_app.icns', __FILE__), icon_file puts "Created #{current_dir_name}/#{icon_file}" end system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n glimmer package\n'" system "open packages/bundles/#{human_name(custom_shell_name).gsub(' ', '\ ')}.app" 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
173 174 175 176 177 178 179 |
# File 'lib/glimmer/scaffold.rb', line 173 def (, 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", (, namespace) end |
.custom_widget_gem(custom_widget_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 |
# File 'lib/glimmer/scaffold.rb', line 221 def (, 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 "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_GEM write 'Rakefile', gem_rakefile write 'spec/spec_helper.rb', spec_helper_file append "lib/#{gem_name}.rb", gem_main_file(, namespace) mkdir 'lib/views' (, namespace) system "bash -c '#{RVM_FUNCTION}\n cd .\n bundle\n'" 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 |