-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbuild.js
218 lines (178 loc) · 6.48 KB
/
build.js
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* See license.txt for terms of usage */
// ********************************************************************************************* //
// Dryice Build File
var copy = require("dryice").copy;
var fs = require("fs");
var os = require("os");
var spawn = require("child_process").spawn;
var shell = require("shelljs");
// ********************************************************************************************* //
// Command Line Arguments
var args = process.argv;
var autoInstall = (args.length == 3 && args[2] === "install");
// ********************************************************************************************* //
// Setup Common JS
// Common JS project dependency tracking.
var project = copy.createCommonJsProject({
roots: [ __dirname + "/content" ]
});
// Munge define lines to add module names
function moduleDefines(input, source)
{
input = (typeof input !== "string") ? input.toString() : input;
var deps = source.deps ? Object.keys(source.deps) : [];
deps = deps.length ? (", '" + deps.join("', '") + "'") : "";
var module = source.isLocation ? source.path : source;
module = module.replace(/\.js$/, "");
return input.replace(/define\(\[/, "define('" + module + "', [");
}
moduleDefines.onRead = true;
// ********************************************************************************************* //
// Special firefox build
if (args.length == 3 && args[2] == "firefox")
{
buildFirefox();
process.exit(0);
}
// ********************************************************************************************* //
// Clean Up
// Helper for the target release directory.
var release = __dirname + "/release";
// Remove target release directory (if there is one left from the last time)
shell.rm("-rf", "release");
// ********************************************************************************************* //
// Initial File Copy
// Create target content directory.
copy.mkdirSync(release + "/content", 0755);
// Copy all html, XUL and JS files into the target dir.
copy({
source: {
root: __dirname + "/content",
include: [/.*\.html$/, /.*\.xul$/, /.*\.js$/]
},
dest: release + "/content"
});
// Copy Dryice mini-loader.
copy({
source: [ copy.getMiniRequire() ],
dest: release + "/content/loader.js"
});
// ********************************************************************************************* //
// Build Main Module
// Copy all modules into one big module file -> /content/main.js
// Use 'moduleDefines' filter that provides module ID for define functions
copy({
source: [
{
project: project,
require: ["httpmonitor/app/httpMonitor"]
},
__dirname + "/content/httpmonitor/app/main.js"
],
filter: moduleDefines,
dest: release + "/content/httpmonitor/app/main.js"
});
// Helper log of module dependencies
//console.log(project.report());
// Compress main.js file (all extension modules)
//xxxHonza: uncomment for now (the stack trace is not much useful if there is just one line.
/*copy({
source: release + "/content/httpmonitor/app/main.js",
filter: copy.filter.uglifyjs,
dest: release + "/content/httpmonitor/app/main.js"
});*/
// ********************************************************************************************* //
// Copy Skin
// Create target skin dir and copy all styles and images files.
copy.mkdirSync(release + "/skin", 0755);
copy({
source: {
root: __dirname + "/skin",
include: [/.*\.css$/, /.*\.gif$/, /.*\.png$/]
},
dest: release + "/skin"
});
// ********************************************************************************************* //
// Copy Locale
// Create target skin dir and copy all styles and images files.
copy.mkdirSync(release + "/locale", 0755);
copy({
source: {
root: __dirname + "/locale",
include: [/.*\.properties$/]
},
dest: release + "/locale"
});
// ********************************************************************************************* //
// Copy JS Modules
// Create target 'modules' dir and copy all files.
copy.mkdirSync(release + "/modules", 0755);
copy({
source: {
root: __dirname + "/modules",
include: [/.*\.js$/]
},
dest: release + "/modules"
});
// ********************************************************************************************* //
// Copy Installation Files
// Copy other files that are not part of the content dir.
copy({
source: ["bootstrap.js", "chrome.manifest", "license.txt", "README.md",],
dest: release
});
// Read version number from package.json file and update install.rdf
var packageFile = fs.readFileSync(__dirname + "/package.json", "utf8");
var version = JSON.parse(packageFile).version;
copy({
source: ["install.rdf"],
filter: function(data)
{
return data.toString().replace(/@VERSION@/, version);
},
dest: release
});
// ********************************************************************************************* //
// Build XPI
// Compute name of the XPI package
var xpiFileName = "httpmonitor-" + version + ".xpi";
// Create final XPI package.
var zip;
if (os.platform() === "win32")
{
var params = "a -tzip ../" + xpiFileName + " content locale modules skin " +
"bootstrap.js chrome.manifest install.rdf license.txt README.md";
zip = spawn("7z.exe", params.split(" "), { cwd: release });
}
else
{
zip = spawn("zip", [ "-r", __dirname + "/" + xpiFileName, release ]);
}
// As soon as the XPI is created (asynchronously) remove the release directory.
zip.on("exit", function()
{
shell.rm("-rf", "release");
console.log(xpiFileName + " is ready");
// This feature requires 'Extension Auto-Installer' extension installed
// on the server side. It sends the xpi to the server, which installs it
// and automatically restarts the browser if necessary.
// https://addons.mozilla.org/cs/firefox/addon/autoinstaller/
// You also need 'wget' in your path.
if (autoInstall)
{
var params = "--post-file=httpmonitor-0.5.0.xpi http://127.0.0.1:8888/";
zip = spawn("wget", params.split(" "), {});
console.log(xpiFileName + " auto installed");
}
});
// ********************************************************************************************* //
function buildFirefox() {
copy({
source: [
"mozilla/module-prefix.jsm",
{ project: project, require: [ "httpmonitor/app/httpMonitor" ] }
],
filter: moduleDefines,
dest: __dirname + "/monitor.jsm"
});
}