Module: GoScript
- Defined in:
- lib/go_script/version.rb,
lib/go_script/go.rb,
lib/go_script/command_group.rb
Overview
Defined Under Namespace
Classes: Command, CommandGroup, Version
Constant Summary
collapse
- JEKYLL_BUILD_CMD =
'bundle exec jekyll build --trace'
- JEKYLL_SERVE_CMD =
'bundle exec jekyll serve -w --trace'
- VERSION =
'0.1.5'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Instance Attribute Details
#current_group ⇒ Object
Returns the value of attribute current_group.
8
9
10
|
# File 'lib/go_script/go.rb', line 8
def current_group
@current_group
end
|
Instance Method Details
#args_to_string(args) ⇒ Object
71
72
73
74
|
# File 'lib/go_script/go.rb', line 71
def args_to_string(args)
args ||= ''
(args.instance_of? Array) ? args.join(' ') : args
end
|
#build_jekyll(extra_args = '') ⇒ Object
89
90
91
|
# File 'lib/go_script/go.rb', line 89
def build_jekyll( = '')
exec_cmd "#{JEKYLL_BUILD_CMD} #{args_to_string extra_args}"
end
|
#check_ruby_version(min_version) ⇒ Object
10
11
12
|
# File 'lib/go_script/go.rb', line 10
def check_ruby_version(min_version)
Version.check_ruby_version min_version
end
|
#command_group(group_symbol, description) ⇒ Object
14
15
16
17
18
19
|
# File 'lib/go_script/go.rb', line 14
def command_group(group_symbol, description)
location = caller_locations(1, 1).first
CommandGroup.add_group(group_symbol, description,
location.path, location.lineno)
@current_group = group_symbol
end
|
#def_command(id, description, &command_block) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/go_script/go.rb', line 21
def def_command(id, description, &command_block)
abort "#{$PROGRAM_NAME}: No command_groups defined" unless current_group
abort "Command ID must be a symbol: #{id}" unless id.instance_of? Symbol
self.class.send :define_method, id, ->(*argv) { command_block.call(*argv) }
path, lineno = command_block.source_location
CommandGroup.add_command id, @current_group, description, path, lineno
end
|
#exec_cmd(cmd) ⇒ Object
42
43
44
|
# File 'lib/go_script/go.rb', line 42
def exec_cmd(cmd)
exit $CHILD_STATUS.exitstatus unless system cmd
end
|
#execute_command(argv) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/go_script/go.rb', line 29
def execute_command(argv)
command = argv.shift
CommandGroup.usage exitstatus: 1 if command.nil?
CommandGroup.usage if ['-h', '--help', '-help', 'help'].include? command
send :version if ['-v', '--version', 'version'].include? command
send CommandGroup.command(command.to_sym), argv
end
|
#file_args_by_extension(file_args, extension) ⇒ Object
76
77
78
79
80
81
82
83
|
# File 'lib/go_script/go.rb', line 76
def file_args_by_extension(file_args, extension)
if file_args.instance_of? Array
files_by_extension = file_args.group_by { |f| File.extname f }
args_to_string files_by_extension[extension]
else
args_to_string file_args
end
end
|
#git_sync_and_deploy(commands, branch: nil) ⇒ Object
93
94
95
96
97
98
99
|
# File 'lib/go_script/go.rb', line 93
def git_sync_and_deploy(commands, branch: nil)
exec_cmd 'git stash'
exec_cmd "git checkout -b #{branch}" unless branch.nil?
exec_cmd 'git pull'
exec_cmd 'bundle install' if File.exist? 'Gemfile'
commands.each { |command| exec_cmd command }
end
|
#install_bundle ⇒ Object
46
47
48
49
50
51
52
53
|
# File 'lib/go_script/go.rb', line 46
def install_bundle
begin
require 'bundler'
rescue LoadError
exec_cmd 'gem install bundler'
end
exec_cmd 'bundle install'
end
|
#lint_javascript(basedir, files) ⇒ Object
105
106
107
108
|
# File 'lib/go_script/go.rb', line 105
def lint_javascript(basedir, files)
files = file_args_by_extension files, '.js'
exec_cmd "#{basedir}/node_modules/jshint/bin/jshint #{files}"
end
|
#lint_ruby(files) ⇒ Object
101
102
103
|
# File 'lib/go_script/go.rb', line 101
def lint_ruby(files)
exec_cmd "bundle exec rubocop #{file_args_by_extension files, '.rb'}"
end
|
#serve_jekyll(extra_args = '') ⇒ Object
85
86
87
|
# File 'lib/go_script/go.rb', line 85
def serve_jekyll( = '')
exec "#{JEKYLL_SERVE_CMD} #{args_to_string extra_args}"
end
|
#update_gems(gems = '') ⇒ Object
55
56
57
58
|
# File 'lib/go_script/go.rb', line 55
def update_gems(gems = '')
exec_cmd "bundle update #{args_to_string gems}"
exec_cmd 'git add Gemfile.lock'
end
|
#update_node_modules ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/go_script/go.rb', line 60
def update_node_modules
abort 'Install npm to update JavaScript components: ' \
'http://nodejs.org/download/' unless system 'which npm > /dev/null'
exec_cmd 'npm update'
exec_cmd 'npm install'
end
|
#version ⇒ Object
37
38
39
40
|
# File 'lib/go_script/go.rb', line 37
def version
puts "go_script version #{VERSION}"
exit 0
end
|