-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
65 lines (54 loc) · 2.1 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
const fs = require('fs-extra');
const fsPromises = require('fs/promises');
const path = require('path');
// Output folder
var outputDir = './output';
// Before starting, we have to make sure the output folder is removed
if (fs.existsSync(outputDir)) {
console.log(`Deleting past output folder`);
fs.rmSync(outputDir, { recursive: true });
console.log(`Deleted past output folder`);
}
// Function to copy all the dirs but not REALLY all of them.
async function copyDir(sourceDir, newDir) {
// Get dirs in the project folder.
var dirs = await fsPromises.readdir(sourceDir, { withFileTypes: true });
await fsPromises.mkdir(newDir);
// now we finna do something with all of these dirs
for (let entry of dirs) {
// Folders & files that we AIN'T ALLOWIN'!
if (
entry.name === '.git' ||
entry.name === '.github' ||
entry.name === 'psds' ||
entry.name === 'node_modules' ||
entry.name === 'build.js' ||
entry.name === 'package-lock.json' ||
entry.name === 'package.json'
) continue;
// If the files passed the vibe check, we go.
const sourcePath = path.join(sourceDir, entry.name);
const newPath = path.join(newDir, entry.name);
if (entry.isDirectory()) {
await copyDir(sourcePath, newPath);
} else {
await fsPromises.copyFile(sourcePath, newPath);
}
}
}
// Here's we build.
// We'll output everything to the output/ folder
copyDir('./', outputDir).then(async () => {
console.log(`Copied the repo folder to "output/"`);
console.log(`-------------`);
// MultiTTV
var multiTTVDir = `${outputDir}/multittv`;
// Replace current "config.js" with "config-retail.js"
fs.removeSync(`${multiTTVDir}/src/config.js`)
fs.renameSync(`${multiTTVDir}/src/config-retail.js`, `${multiTTVDir}/src/config.js`);
console.log(`Removed local config & replaced it with retail config`);
console.log(`-------------`);
// Finish
console.log(`Everything should be done!`);
console.log(`-------------`);
});