UNPKG

@berenddeboer/nx-aws-cdk

Version:

Nx self-inferring plugin for AWS CDK stacks

68 lines 3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TempFs = void 0; const node_fs_1 = require("node:fs"); const promises_1 = require("node:fs/promises"); const path_1 = require("path"); const os_1 = require("os"); const path_2 = require("./path"); const workspace_root_1 = require("./workspace-root"); class TempFs { constructor(dirname, overrideWorkspaceRoot = true) { this.dirname = dirname; this.tempDir = (0, node_fs_1.realpathSync)((0, node_fs_1.mkdtempSync)((0, path_1.join)((0, os_1.tmpdir)(), this.dirname))); this.previousWorkspaceRoot = workspace_root_1.workspaceRoot; if (overrideWorkspaceRoot) { (0, workspace_root_1.setWorkspaceRoot)(this.tempDir); } } async createFiles(fileObject) { await Promise.all(Object.keys(fileObject).map(async (path) => { await this.createFile(path, fileObject[path]); })); } createFilesSync(fileObject) { for (const path of Object.keys(fileObject)) { this.createFileSync(path, fileObject[path]); } } async createFile(filePath, content) { const dir = (0, path_2.joinPathFragments)(this.tempDir, (0, path_1.dirname)(filePath)); if (!(0, node_fs_1.existsSync)(dir)) { await (0, promises_1.mkdir)(dir, { recursive: true }); } await (0, promises_1.writeFile)((0, path_2.joinPathFragments)(this.tempDir, filePath), content); } createFileSync(filePath, content) { const dir = (0, path_2.joinPathFragments)(this.tempDir, (0, path_1.dirname)(filePath)); if (!(0, node_fs_1.existsSync)(dir)) { (0, node_fs_1.mkdirSync)(dir, { recursive: true }); } (0, node_fs_1.writeFileSync)((0, path_2.joinPathFragments)(this.tempDir, filePath), content); } async readFile(filePath) { return await (0, promises_1.readFile)((0, path_2.joinPathFragments)(this.tempDir, filePath), "utf-8"); } removeFileSync(filePath) { (0, node_fs_1.unlinkSync)((0, path_2.joinPathFragments)(this.tempDir, filePath)); } appendFile(filePath, content) { (0, node_fs_1.appendFileSync)((0, path_2.joinPathFragments)(this.tempDir, filePath), content); } writeFile(filePath, content) { (0, node_fs_1.writeFileSync)((0, path_2.joinPathFragments)(this.tempDir, filePath), content); } renameFile(oldPath, newPath) { (0, node_fs_1.renameSync)((0, path_2.joinPathFragments)(this.tempDir, oldPath), (0, path_2.joinPathFragments)(this.tempDir, newPath)); } cleanup() { (0, node_fs_1.rmSync)(this.tempDir, { recursive: true, force: true }); (0, workspace_root_1.setWorkspaceRoot)(this.previousWorkspaceRoot); } reset() { (0, node_fs_1.rmSync)(this.tempDir, { recursive: true, force: true }); (0, node_fs_1.mkdirSync)(this.tempDir, { recursive: true }); } } exports.TempFs = TempFs; //# sourceMappingURL=temp-fs.js.map