-
Notifications
You must be signed in to change notification settings - Fork 14
/
build.js
68 lines (54 loc) · 1.55 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
/* eslint no-console: off */
var fs = require("fs");
var copy = require("ncp").ncp;
var browserify = require("browserify");
var normalizePath = require("path").normalize;
var indexFile = normalizePath("index.js");
var outputFile = normalizePath("build/WebStoryEngine.js");
mkdirSync('./build');
mkdirSync('./export');
mkdirSync('./export/engine');
var info = JSON.parse("" + fs.readFileSync("package.json"));
var bundle = browserify({debug: true}).
add(indexFile).
//transform({global: true}, "uglifyify").
bundle();
bundle.on("end", done).
pipe(fs.createWriteStream(outputFile)).
write(
"/*\n" +
" WebStory Engine (v" + info.version + ")\n" +
" Build time: " + (new Date().toUTCString()) +
"\n*/\n"
);
function mkdirSync (path) {
try {
fs.mkdirSync(path);
}
catch (e) {
if (e.code != 'EEXIST') {
throw e;
}
}
}
function done (error) {
var content;
if (error) {
console.error(error);
return;
}
/*
content = "" + fs.readFileSync(outputFile);
content = content.split("%%%version%%%").join(info.version);
fs.writeFileSync(outputFile, content);
*/
console.log("WebStory Engine v" + info.version + " built and written to: " + outputFile);
exportFiles();
}
function exportFiles () {
copy("./build", "./export/engine", function () {
copy("./story", "./export", function () {
console.log("Exported WebStory Engine skeleton to export folder.");
});
});
}