-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackExtension.rb
More file actions
78 lines (60 loc) · 1.81 KB
/
Copy pathpackExtension.rb
File metadata and controls
78 lines (60 loc) · 1.81 KB
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
#!/usr/bin/ruby
require 'fileutils'
require 'open3'
def syscall(*cmd)
begin
# puts "Syscall: #{cmd}"
stdout, stderr, status = Open3.capture3(*cmd)
if status.success?
return
else
return stdout.slice!(0..-(1 + $/.size)) # strip trailing eol
end
rescue
return "Error with command: #{cmd}"
end
end
chromeCLI = "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
currentDirectory = File.expand_path(File.dirname(__FILE__))
chromeBuildDirectory = File.expand_path(currentDirectory + "/src")
crxPath = chromeBuildDirectory + ".crx"
buildsFolder = File.expand_path(currentDirectory + "/build")
if File.exists?(crxPath)
puts "Removing old CRX build."
FileUtils.rm(crxPath)
end
if File.exists?(buildsFolder) == false
puts "Creating builds folder #{buildsFolder}."
FileUtils.mkdir_p(buildsFolder)
end
pemPath = File.expand_path(currentDirectory + "/tabulater.pem")
command = "\"#{chromeCLI}\" --pack-extension=\"#{chromeBuildDirectory}\" --pack-extension-key=\"#{pemPath}\" --no-message-box";
puts "Building CRX file"
status = syscall(command);
if status
puts "Failed to generate Chrome Extension crx: #{status}"
exit;
end
if File.exists?(crxPath) == false
puts "CRX build failed"
exit;
end
timeLabel = Time.now.strftime("%Y%m%d_%H%M%S")
baseName = "tabulater_chrome"
# zip
zipFilepath = File.expand_path(buildsFolder + "/#{baseName}.zip");
puts "Building zip #{zipFilepath}"
Dir.chdir(chromeBuildDirectory) do
system "zip -rq \"#{zipFilepath}\" ./ -x \"*/.*\""
end
filename = "#{baseName}.crx"
destinationFilepath = File.expand_path(buildsFolder + "/#{filename}");
puts "Moving CRX file to #{destinationFilepath}";
FileUtils.mv crxPath, destinationFilepath
if File.exists?(destinationFilepath)
puts "Finished build"
system "open -R \"#{destinationFilepath}\""
else
puts "Build error!"
exit;
end