UNPKG

react-native-node-api

Version:
30 lines (29 loc) 1.32 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.setupTempDirectory = setupTempDirectory; const node_os_1 = __importDefault(require("node:os")); const node_fs_1 = __importDefault(require("node:fs")); const node_path_1 = __importDefault(require("node:path")); function writeFiles(fromPath, files) { for (const [filePath, content] of Object.entries(files)) { const fullPath = node_path_1.default.join(fromPath, filePath); node_fs_1.default.mkdirSync(node_path_1.default.dirname(fullPath), { recursive: true }); if (typeof content === "string") { node_fs_1.default.writeFileSync(fullPath, content, "utf8"); } else { writeFiles(fullPath, content); } } } function setupTempDirectory(context, files) { const tempDirectoryPath = node_fs_1.default.realpathSync(node_fs_1.default.mkdtempSync(node_path_1.default.join(node_os_1.default.tmpdir(), "react-native-node-api-test-"))); context.after(() => { node_fs_1.default.rmSync(tempDirectoryPath, { recursive: true, force: true }); }); writeFiles(tempDirectoryPath, files); return tempDirectoryPath; }