Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sisilicon
GitHub Repository: sisilicon/worldedit-be
Path: blob/master/tools/utils.mjs
1780 views
1
/* global console */
2
import process from "process";
3
import path from "path";
4
import fs from "fs";
5
6
export function exitMessage(message) {
7
console.error(message);
8
process.exit(1);
9
}
10
11
export function copyDir(src, dest) {
12
if (!fs.existsSync(src)) return;
13
fs.mkdirSync(dest, { recursive: true });
14
for (const entry of fs.readdirSync(src)) {
15
const srcPath = path.join(src, entry);
16
const destPath = path.join(dest, entry);
17
if (fs.statSync(srcPath).isDirectory()) copyDir(srcPath, destPath);
18
else fs.copyFileSync(srcPath, destPath);
19
}
20
}
21
22
export function ensureDir(dir) {
23
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
24
}
25
26
export function removeDirIfExists(dir) {
27
if (fs.existsSync(dir)) fs.rmSync(dir, { recursive: true, force: true });
28
}
29
30