@ts-dev-tools/core
Version:
TS dev tools Core
31 lines (30 loc) • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getTestDirPath = void 0;
exports.createTestDir = createTestDir;
exports.removeTestDir = removeTestDir;
var fs_1 = require("fs");
var os_1 = require("os");
var path_1 = require("path");
var file_system_1 = require("./file-system");
var getTestDirPath = function (dirName, filename) {
return (0, path_1.join)((0, os_1.tmpdir)(), dirName + "-" + (0, path_1.basename)(filename).split(".")[0]);
};
exports.getTestDirPath = getTestDirPath;
function createTestDir(testDirPath, removeIfExists) {
if (removeIfExists === void 0) { removeIfExists = false; }
if ((0, fs_1.existsSync)(testDirPath)) {
if (!removeIfExists) {
return testDirPath;
}
(0, file_system_1.deleteFolderRecursive)(testDirPath);
}
(0, fs_1.mkdirSync)(testDirPath);
return testDirPath;
}
function removeTestDir(testDirPath) {
if (!(0, fs_1.existsSync)(testDirPath)) {
throw new Error("Test project dir \"".concat(testDirPath, "\" does not exist"));
}
(0, file_system_1.deleteFolderRecursive)(testDirPath);
}