-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmove_output.js
53 lines (42 loc) · 1.21 KB
/
move_output.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
const path = require("path");
const fs = require("fs");
const { exec } = require("child_process");
const buildDir = path.join(__dirname, "build");
const outputDir = path.join(__dirname, "docs");
const cname = path.join(__dirname, "CNAME");
const cnameOutput = path.join(outputDir, "CNAME");
if (!fs.existsSync(buildDir)) {
console.log(`${buildDir} does not exist, exiting`);
process.exit(-1);
}
async function a() {
if (fs.existsSync(outputDir)) {
// NOTE: requires nodejs 13+
fs.rmdirSync(outputDir, {
recursive: true,
});
}
// Wait a few seconds for some reason
await new Promise((resolve, reject) => {
setTimeout(resolve, 1000);
});
fs.renameSync(buildDir, outputDir);
console.log(cnameOutput);
fs.copyFileSync(cname, cnameOutput);
exec("git add .", (err, stdout, stderr) => {
if (err) {
console.log(err);
return;
}
// the *entire* stdout and stderr (buffered)
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});
}
a();
// Finally: remove build dir
/*if (fs.existsSync(buildDir)) {
fs.rmdirSync(buildDir, {
recursive: true,
});
}*/