-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple-build.js
48 lines (37 loc) · 1.18 KB
/
simple-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
const path = require("path");
const fs = require("fs");
const ignoreFiles = [
"package.json",
"node_modules",
"turbo.json",
".turbo",
"dist",
];
(function () {
const root = path.resolve(process.cwd());
const outDir = path.resolve(root, "dist");
function getAllFiles(dirPath, arrayOfFiles) {
const files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach((file) => {
if (fs.statSync(path.join(dirPath, file)).isDirectory()) {
arrayOfFiles = getAllFiles(path.join(dirPath, file), arrayOfFiles);
} else {
arrayOfFiles.push(path.join(dirPath, file));
}
});
return arrayOfFiles;
}
const files = getAllFiles(root).filter((file) => {
return !ignoreFiles.find((ignoreFile) => file.includes(ignoreFile));
});
// Copy files to outDir
fs.mkdirSync(outDir, { recursive: true });
files.forEach((filePath) => {
const relativePath = path.relative(root, filePath);
const destinationPath = path.resolve(outDir, relativePath);
const destinationDir = path.dirname(destinationPath);
fs.mkdirSync(destinationDir, { recursive: true });
fs.copyFileSync(filePath, destinationPath);
});
})();