forked from Katello/bastion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
60 lines (47 loc) · 1.35 KB
/
Rakefile
1
2
3
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'open3'
require 'bastion/engine'
namespace :bastion do
desc 'Run linting and tests for the plugin'
task 'ci' do
success = grunt('ci')
exit!(1) if !success
end
desc 'Run any grunt task by specifying the argument'
task 'grunt', [:task] do |task, args|
success = grunt(args[:task])
exit!(1) if !success
end
desc 'Setup development environment'
task 'setup' do
puts "Setting up development environment"
setup_npm
end
end
def grunt(command)
syscall("grunt #{command}")
end
def bastion_core?
Dir.pwd.split('/').last == 'bastion'
end
def setup_npm
syscall('sudo yum install -y nodejs npm') if !system('rpm -q nodejs') || !system('rpm -q npm')
syscall('sudo npm -g install grunt-cli bower yo phantomjs')
puts "Installing NPM dependencies"
syscall("npm install #{Bastion::Engine.root} grunt") if !bastion_core?
syscall("npm install") if File.exist?('package.json')
syscall("bower install") if bastion_core?
end
def syscall(*cmd)
Open3.popen3(*cmd) do |stdin, stdout, stderr, thread|
# read each stream from a new thread
{ :out => stdout, :err => stderr }.each do |key, stream|
Thread.new do
until (raw_line = stream.gets).nil? do
puts raw_line
end
end
end
thread.join # don't exit until the external process is done
thread.value.success?
end
end