class GoScript::Template

Public Class Methods

end() click to toggle source

rubocop:enable MethodLength

# File lib/go_script/template.rb, line 90
def self.end
  "execute_command ARGV\n"
end
preamble() click to toggle source

rubocop:disable MethodLength

# 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_commands() click to toggle source

rubocop:disable MethodLength

# 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