[update] update tool scripts

This commit is contained in:
PrinOrange
2024-08-12 13:53:28 +08:00
parent a3d4cd5a1d
commit 95d119bbc9
9 changed files with 320 additions and 162 deletions

25
lib/file.ts Normal file
View File

@@ -0,0 +1,25 @@
import * as fs from "fs";
export function checkAndCreateDirectory(dirPath: string) {
try {
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, { recursive: true });
}
fs.accessSync(dirPath, fs.constants.R_OK | fs.constants.W_OK);
return true;
} catch (err) {
throw err;
}
}
export function isDirectoryEmptySync(directory: string) {
try {
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory, { recursive: true });
}
const files = fs.readdirSync(directory);
return files.length === 0;
} catch (err) {
throw err;
}
}