Class: GoScript::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/go_script/template.rb

Class Method Summary collapse

Class Method Details

.endObject

rubocop:enable MethodLength



69
70
71
# File 'lib/go_script/template.rb', line 69

def self.end
  "execute_command ARGV\n"
end

.preambleObject

rubocop:disable MethodLength



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/go_script/template.rb', line 4

def self.preamble
  <<END_OF_PREAMBLE
#! /usr/bin/env ruby

require 'English'

Dir.chdir File.dirname(__FILE__)

def try_command_and_restart(command)
  exit $CHILD_STATUS.exitstatus unless system command
  exec({ 'RUBYOPT' => nil }, RbConfig.ruby, *[$PROGRAM_NAME].concat(ARGV))
end

begin
  require 'bundler/setup' if File.exist? 'Gemfile'
rescue LoadError
  try_command_and_restart 'gem install bundler'
rescue SystemExit
  try_command_and_restart 'bundle install'
end

begin
  require 'go_script'
rescue LoadError
  try_command_and_restart 'gem install go_script' unless File.exist? 'Gemfile'
  abort "Please add \\\"gem 'go_script'\\\" to your Gemfile"
end

extend GoScript
check_ruby_version '#{RUBY_VERSION}'

END_OF_PREAMBLE
end

.standard_dev_commandsObject

rubocop:disable MethodLength



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/go_script/template.rb', line 40

def self.standard_dev_commands
  <<END_STANDARD_DEV_COMMANDS
command_group :dev, 'Development commands'

def_command :init, 'Set up the development environment' do
end

def_command :update_gems, 'Update Ruby gems' do |gems|
  update_gems gems
end

def_command :update_js, 'Update JavaScript components' do
  update_node_modules
end

def_command :test, 'Execute automated tests' do |args|
  exec_cmd "bundle exec rake test \#{args.join ' '}"
end

def_command :lint, 'Run style-checking tools' do |files|
  files = files.group_by { |f| File.extname f }
  lint_ruby files['.rb']  # uses rubocop
  lint_javascript Dir.pwd, files['.js']  # uses node_modules/jshint
end

END_STANDARD_DEV_COMMANDS
end