Module: GoScript
- Defined in:
- lib/go_script/version.rb,
lib/go_script/go.rb,
lib/go_script/template.rb,
lib/go_script/command_group.rb
Overview
Defined Under Namespace
Classes: Command, CommandGroup, Template, Version
Constant Summary
collapse
- JEKYLL_BUILD_CMD =
'jekyll build --trace'
- JEKYLL_SERVE_CMD =
'jekyll serve -w --trace'
- VERSION =
'0.1.9'
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
69
70
71
72
|
# File 'lib/go_script/go.rb', line 69
def args_to_string(args)
args ||= ''
(args.instance_of? Array) ? args.join(' ') : args
end
|
#build_jekyll(extra_args = '') ⇒ Object
87
88
89
|
# File 'lib/go_script/go.rb', line 87
def build_jekyll( = '')
exec_cmd "#{JEKYLL_BUILD_CMD} #{args_to_string }"
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
45
46
47
48
49
50
51
|
# File 'lib/go_script/go.rb', line 42
def exec_cmd(cmd)
status = system(cmd, err: :out)
if $CHILD_STATUS.exitstatus.nil?
$stderr.puts "could not run command: #{cmd}"
$stderr.puts '(Check syslog for possible `Out of memory` error?)'
exit 1
else
exit $CHILD_STATUS.exitstatus unless status
end
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
74
75
76
77
78
79
80
81
|
# File 'lib/go_script/go.rb', line 74
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
91
92
93
94
95
96
97
98
|
# File 'lib/go_script/go.rb', line 91
def git_sync_and_deploy(commands, branch: nil)
exec_cmd 'git fetch origin #{branch}'
exec_cmd 'git clean -f'
exec_cmd "git reset --hard #{branch.nil? ? 'HEAD' : 'origin/' + branch}"
exec_cmd 'git submodule --sync --recursive'
exec_cmd 'git submodule update --init --recursive'
commands.each { |command| exec_cmd command }
end
|
#lint_javascript(basedir, files) ⇒ Object
104
105
106
107
|
# File 'lib/go_script/go.rb', line 104
def lint_javascript(basedir, files)
files = file_args_by_extension files, '.js'
exec_cmd "#{basedir}/node_modules/.bin/eslint #{files}"
end
|
#lint_ruby(files) ⇒ Object
100
101
102
|
# File 'lib/go_script/go.rb', line 100
def lint_ruby(files)
exec_cmd "rubocop #{file_args_by_extension files, '.rb'}"
end
|
#serve_jekyll(extra_args = '') ⇒ Object
83
84
85
|
# File 'lib/go_script/go.rb', line 83
def serve_jekyll( = '')
exec "#{JEKYLL_SERVE_CMD} #{args_to_string }"
end
|
#update_gems(gems = '') ⇒ Object
53
54
55
56
|
# File 'lib/go_script/go.rb', line 53
def update_gems(gems = '')
exec_cmd "bundle update #{args_to_string gems}"
exec_cmd 'git add Gemfile.lock'
end
|
#update_node_modules ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/go_script/go.rb', line 58
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
|