-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
106 lines (93 loc) · 3.01 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
const { stringify } = require("querystring");
const System = function() {
return {
out: {
println: function(msg) {
console.log(msg);
},
print: function(msg) {
process.stdout.write(msg);
}
}
};
}();
const program = function() {
let imports = {}
let exports = {
importModules : function() {
imports = {
fs : require("fs"),
childprocess: require("child_process")
}
},
filesToCompile : "",
listFiles : function(folder) {
let files = imports.fs.readdirSync(folder);
files.forEach(elm => {
let fl = folder + "/" + elm;
if (imports.fs.statSync(fl).isDirectory()) {
this.listFiles(fl);
} else {
this.filesToCompile += fl + " ";
}
});
},
main : async function() {
let runProgram = process.argv.includes("run");
System.out.println("Building...");
let line = "ldc2";
let isDebug = false;
process.argv.forEach((elm) =>{
if (elm.startsWith("/use:")) {
let cc = elm.substring(5, elm.length);
line = cc;
}
if (elm == "/debug") {
isDebug = true;
}
});
System.out.println("Using compiler: " + line);
if (isDebug) {
System.out.println("Debug Mode!");
}
// for DMD
if (line == "dmd") {
if (isDebug)
line += " -debug";
line += " -version=GL_33";
}
// for LDC2
else if (line == "ldc2") {
if (isDebug)
line += " -d-debug -g";
line += " --d-version=GL_33";
}
this.listFiles("lib/vendor");
this.listFiles("src");
line += " " + this.filesToCompile;
line += " -od=bin";
if (process.platform == "win32") {
line += " -of=murasaki-win32.exe";
} else {
line += " -of=murasaki-linux";
}
imports.childprocess.exec(line, function(err) {
if (err != null) {
System.out.println("########## Build Failed!!! ##########");
System.out.println(err);
System.out.println("########## Build Failed!!! ##########");
} else {
System.out.println("########## BUILD SUCCESS #########");
}
});
if (runProgram) {
System.out.println("Executing..");
imports.childprocess.exec("main.exe");
}
}
}
return exports;
};
let pm = program();
pm.importModules();
pm.main();