-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo_01.ts
64 lines (48 loc) · 1.61 KB
/
demo_01.ts
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
import * as chokidar from 'chokidar';
import { exec, spawn, execSync } from "child_process";
const windowsBashPath = "C:\\Program Files\\Git\\bin\\bash.exe"
const isWin = process.platform === "win32";
const localDir = process.cwd().replace(/["\\\\"]/g, "/");
function executeCommand(args: string[]) {
const [command, ...vars] = args;
if (isWin) {
const bashInput = args.join(" ");
console.log(bashInput);
return spawn(windowsBashPath, ["-c", bashInput], {
stdio: "inherit",
});
} else {
console.log(vars);
return spawn(command, vars, {
stdio: "inherit",
});
}
}
function getFiles(path: string) {
chokidar.watch(path).on('all', (event, path) => {
console.log(event, path);
});
}
function compile(files: string[]) {
// gcc -c a.c b.c b.h c.c c.h d.c d.h
return executeCommand([
"gcc",
"-working-directory", localDir + "/examples/build",
"-c", ...files])
.on("error", (err) => { console.log(`Compiler error: ${err}`); });
}
function link(files: string[]) {
// gcc -o myApp -Wl a.o b.o c.o d.o
return executeCommand([
"gcc", "-v",
"-working-directory", localDir + "/examples/build",
"-o", "myApp",
"-Wl", ...files])
.on("error", (err) => { console.log(`Linker error: ${err}`); });
}
// watches the folder and files inside the folder
//getFiles('./src');
// compile the C files in ./examples/build
compile(["a.c", "b.c", "b.h", "c.c", "c.h", "d.c", "d.h"]);
// link the C files in ./examples/build
//link(["a.o", "b.o", "c.o", "d.o"]);