-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.js
132 lines (126 loc) · 3.07 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
// REQUIRES
const compile = require('google-closure-compiler-js').compile;
const fs = require('fs');
const path = require('path');
const spawn = require('child_process').spawnSync;
// FUNCTIONS
const Minify = function () {
console.log("Minifying JS code...");
try
{
stats = fs.statSync('build/sage.js');
fs.unlinkSync('build/sage.js');
}
catch (e) { }
try
{
stats = fs.statSync('build/sage.min.js');
fs.unlinkSync('build/sage.min.js');
}
catch (e) { }
let js = ConcatFiles("engine");
fs.writeFileSync("build/sage.js", js);
let out = compile({
jsCode: [{ src: js }]
});
fs.writeFileSync("build/sage.min.js", out.compiledCode);
};
const CreateDoc = function () {
console.log("Creating Documentation...");
try
{
stats = fs.statSync('build/doc');
DeleteFolder('build/doc');
}
catch (e) { }
fs.writeFileSync("conf.js", "{\"templates\":{\"default\":{\"outputSourceFiles\":false}}}");
fs.mkdirSync("build/doc");
if (process.platform == "win32")
{
spawn("cmd.exe", ["/c", "call", "node_modules\\.bin\\jsdoc", "engine", "-r", "-d", "build/doc", "-c", "conf.js", "-t", "node_modules/namis", "-R", "README.md"]);
}
else
{
spawn("./node_modules/.bin/jsdoc", ["engine", "-r", "-d", "build/doc", "-c", "conf.js", "-t", "node_modules/namis", "-R", "README.md"]);
}
fs.unlinkSync('conf.js');
};
const CreateDocset = function () {
console.log("Creating Docset...");
try
{
stats = fs.statSync('build/SAGE.docset');
DeleteFolder('build/SAGE.docset');
}
catch (e) { }
try
{
stats = fs.statSync('build/SAGE');
DeleteFolder('build/SAGE');
}
catch (e) { }
if (process.platform == "win32")
{
spawn("cmd.exe", ["/c", "call", "node_modules\\.bin\\jsdoc", "engine", "-r", "-d", "build\\SAGE", "-t", "node_modules\\jsdoc-dash-template", "-R", "README.md"]);
}
else
{
spawn("./node_modules/.bin/jsdoc", ["engine", "-r", "-d", "build/SAGE", "-t", "node_modules/jsdoc-dash-template", "-R", "README.md"]);
}
fs.renameSync("build/SAGE/SAGE.docset", "build/SAGE.docset");
DeleteFolder("build/SAGE");
};
const DeleteFolder = function (folder) {
let contains = fs.readdirSync(folder);
contains.forEach(function (element) {
let curr = path.join(folder, element);
let stats = fs.statSync(curr);
if (stats.isFile())
{
fs.unlinkSync(curr);
}
else if (stats.isDirectory())
{
DeleteFolder(curr);
}
});
fs.rmdirSync(folder);
};
const ConcatFiles = function (folder) {
let contains = fs.readdirSync(folder);
let result = "";
contains.forEach(function (element) {
let curr = path.join(folder, element);
let stats = fs.statSync(curr);
if (stats.isFile())
{
result += fs.readFileSync(curr);
}
else if (stats.isDirectory())
{
result += ConcatFiles(curr);
}
});
return result;
};
// EXECUTE
try
{
stats = fs.statSync('build');
}
catch (e)
{
fs.mkdirSync("build");
}
if (process.argv[2] == "compile")
{
Minify();
}
else if (process.argv[2] == "doc")
{
CreateDoc();
}
else if (process.argv[2] == "docset")
{
CreateDocset();
}