-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·37 lines (28 loc) · 991 Bytes
/
index.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
#!/usr/bin/env node
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const templateFolderPath = path.join(__dirname, "template");
function copyFolderRecursiveSync(source, target) {
const files = fs.readdirSync(source);
if (!fs.existsSync(target)) {
fs.mkdirSync(target);
}
files.forEach((file) => {
const currentSource = path.join(source, file);
const currentTarget = path.join(target, file);
if (fs.statSync(currentSource).isDirectory()) {
copyFolderRecursiveSync(currentSource, currentTarget);
} else {
fs.copyFileSync(currentSource, currentTarget);
}
});
}
function execute() {
console.log(`Copying files to react-app/...`);
copyFolderRecursiveSync(templateFolderPath, "./react-app");
console.log(`Copying to react-app/ complete.`);
}
execute();