-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathcopy.js
36 lines (29 loc) · 914 Bytes
/
copy.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
// recursively copy files from /src to /tsc while ignoring all .ts files
const fs = require('fs');
const path = require('path');
const sourceDir = 'src';
const buildDir = 'tsc';
if (!fs.existsSync(buildDir)) {
fs.mkdirSync(buildDir, { recursive: true });
}
function copyRecursiveSync(src, dest) {
const exists = fs.existsSync(src);
const stats = exists && fs.statSync(src);
const isDirectory = exists && stats.isDirectory();
if (exists && isDirectory) {
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest);
}
fs.readdirSync(src).forEach((childItemName) => {
copyRecursiveSync(
path.join(src, childItemName),
path.join(dest, childItemName)
);
});
} else {
if (!src.endsWith('.ts')) {
fs.copyFileSync(src, dest);
}
}
}
copyRecursiveSync(sourceDir, buildDir);