forked from rails/web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
121 lines (96 loc) · 3.18 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
61
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
require 'socket'
require 'rake/testtask'
require 'tmpdir'
require 'securerandom'
require 'json'
require 'web_console/testing/erb_precompiler'
EXPANDED_CWD = File.expand_path(File.dirname(__FILE__))
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = false
end
namespace :test do
desc "Run tests for templates"
task templates: "templates:all"
namespace :templates do
task all: [ :daemonize, :npm, :rackup, :mocha, :kill ]
task serve: [ :npm, :rackup ]
work_dir = Pathname(__FILE__).dirname.join("test/templates")
pid_file = Pathname(Dir.tmpdir).join("web_console.#{SecureRandom.uuid}.pid")
server_port = 29292
rackup_opts = "-p #{server_port}"
task :daemonize do
rackup_opts += " -D -P #{pid_file}"
end
task :npm do
Dir.chdir(work_dir) { system "npm install --silent" }
end
task :rackup do
Dir.chdir(work_dir) { system "bundle exec rackup #{rackup_opts}" }
end
task :mocha do
Dir.chdir(work_dir) { system "$(npm bin)/mocha-phantomjs http://localhost:#{server_port}/html/spec_runner.html" }
end
task :kill do
system "kill #{File.read pid_file}"
end
end
end
namespace :ext do
rootdir = Pathname('extensions')
desc 'Build Chrome Extension'
task chrome: 'chrome:build'
namespace :chrome do
dist = Pathname('dist/crx')
extdir = rootdir.join(dist)
manifest_json = rootdir.join('chrome/manifest.json')
directory extdir
task build: [ extdir, 'lib:templates' ] do
cd rootdir do
cp_r [ 'img/', 'tmp/lib/' ], dist
`cd chrome && git ls-files`.split("\n").each do |src|
dest = dist.join(src)
mkdir_p dest.dirname
cp Pathname('chrome').join(src), dest
end
end
end
# Generate a .crx file.
task crx: [ :build, :npm ] do
out = "crx-web-console-#{JSON.parse(File.read(manifest_json))["version"]}.crx"
cd(extdir) { sh "node \"$(npm bin)/crx\" pack ./ -p ../crx-web-console.pem -o ../#{out}" }
end
# Generate a .zip file for Chrome Web Store.
task zip: [ :build ] do
version = JSON.parse(File.read(manifest_json))["version"]
cd(extdir) { sh "zip -r ../crx-web-console-#{version}.zip ./" }
end
desc 'Launch a browser with the chrome extension.'
task run: [ :build ] do
cd(rootdir) { sh "sh ./script/run_chrome.sh --load-extension=#{dist}" }
end
end
task :npm do
cd(rootdir) { sh "npm install --silent" }
end
namespace :lib do
templates = Pathname('lib/web_console/templates')
tmplib = rootdir.join('tmp/lib/')
js_erb = FileList.new(templates.join('**/*.js.erb'))
dirs = js_erb.pathmap("%{^#{templates},#{tmplib}}d")
task templates: dirs + js_erb.pathmap("%{^#{templates},#{tmplib}}X")
dirs.each { |d| directory d }
rule '.js' => [ "%{^#{tmplib},#{templates}}X.js.erb" ] do |t|
File.write(t.name, WebConsole::Testing::ERBPrecompiler.new(t.source).build)
end
end
end
Bundler::GemHelper.install_tasks
task default: :test