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



90
91
92
# File 'lib/go_script/template.rb', line 90

def self.end
  "execute_command ARGV\n"
end

.preambleObject

rubocop:disable MethodLength



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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/go_script/template.rb', line 6

def self.preamble
  <<END_OF_PREAMBLE
#! /usr/bin/env ruby
#
# The preamble down to the check_ruby_version line was generated by version
# #{VERSION} of the go_script gem. This preamble tries to load bundler state
# from Gemfile.lock if present, then the go_script gem for core functionality.
#
# This means the ./go script will run `gem install` or `bundle install` as
# necessary when invoked for the first time, or when dependencies change. It
# also means that commands invoked within the ./go script do not need to be
# prefixed with `bundle exec`.

require 'English'

Dir.chdir File.dirname(__FILE__)

# If a require statement fails, the script calls try_command_and_restart to
# try to install the necessary gems before re-executing itself with the
# original arguments.
def try_command_and_restart(command)
  exit $CHILD_STATUS.exitstatus unless system command

  # If the RUBYOPT environment variable is set, bundler will presume that it
  # has already run. Hence, filtering out RUBYOPT forces bundler to load its
  # state during the re-execution.
  env = {}.merge(ENV)
  env.delete('RUBYOPT')
  exec(env, 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 go_script #{VERSION} GENERATED CONTENT

END_OF_PREAMBLE
end

.standard_dev_commandsObject

rubocop:disable MethodLength



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
# File 'lib/go_script/template.rb', line 62

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 "rake test \#{args_to_string args}"
end

def_command :lint, 'Run style-checking tools' do |files|
  lint_ruby files  # uses rubocop
  lint_javascript Dir.pwd, files  # uses node_modules/eslint
end

END_STANDARD_DEV_COMMANDS
end