forked from janodvarko/ccdump
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
135 lines (112 loc) · 3.72 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
/* 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");
// ********************************************************************************************* //
// 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");
// Create target content directory.
copy.mkdirSync(release + "/content", 0755);
// Copy all html files into the target dir.
copy({
source: {
root: __dirname + "/content",
include: [/.*\.html$/]
},
dest: release + "/content"
});
// Copy Dryice mini-loader.
copy({
source: [ copy.getMiniRequire() ],
dest: release + "/content/loader.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;
// Copy all modules into one big module file -> /content/main.js
// Use 'moduleDefins' filter that provides module ID for define functions
copy({
source: [
{
project: project,
require: [
"lib/tabView", "lib/lib", "lib/trace", "tabs/homeTab", "tabs/aboutTab",
"app/analyzer", "app/tabNavigator", "lib/options",
]
},
__dirname + "/content/main.js"
],
filter: moduleDefines,
dest: release + "/content/main.js"
});
// Helper log of module dependencies
console.log(project.report());
// Compress main.js file (all extension modules)
copy({
source: release + "/content/main.js",
filter: copy.filter.uglifyjs,
dest: release + "/content/main.js"
});
// 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 other files that are not part of the content dir.
copy({
source: ["bootstrap.js", "license.txt", "README.md", "app.properties"],
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
});
// Compute name of the XPI package
var xpiFileName = "ccdump-" + version + ".xpi";
// Create final XPI package.
var zip;
if (os.platform() === "win32")
{
var params = "a -tzip ../" + xpiFileName + " skin content bootstrap.js license.txt " +
"README.md install.rdf app.properties";
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");
});
// ********************************************************************************************* //