This repository has been archived on 2026-05-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
GitBlog.md/test/test_utils.js
T
2019-06-20 14:24:34 +02:00

20 lines
597 B
JavaScript

const fs = require('fs');
const path = require('path');
const deleteFolderSync = (dir) => {
if (!fs.existsSync(dir))
return;
fs.readdirSync(dir, {withFileTypes: true}).forEach((item) => {
if (item.isDirectory())
deleteFolderSync(path.join(dir, item.name));
else
fs.unlinkSync(path.join(dir, item.name));
});
fs.rmdirSync(dir);
};
module.exports = {
deleteFolderSync: deleteFolderSync,
createEmptyDirs: (list) => list.forEach((path) => fs.mkdirSync(path, {recursive: true})),
createEmptyFiles: (list) => list.forEach((file) => fs.writeFileSync(file, '')),
};