UNPKG

nativescript

Version:

Command-line interface for building NativeScript projects

38 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TempService = void 0; const fs = require("fs"); const path = require("path"); const os_1 = require("os"); const yok_1 = require("../common/yok"); class TempService { constructor($cleanupService) { this.$cleanupService = $cleanupService; // no-op } async mkdirSync(affixes) { var _a; const opts = typeof affixes === "string" ? { prefix: affixes } : affixes; const baseDir = (opts === null || opts === void 0 ? void 0 : opts.dir) ? opts.dir : (0, os_1.tmpdir)(); const prefix = ((_a = opts === null || opts === void 0 ? void 0 : opts.prefix) !== null && _a !== void 0 ? _a : "ns-").replace(/\s+/g, "-"); // fs.mkdtempSync requires the full path prefix const pathToDir = fs.mkdtempSync(path.join(baseDir, prefix)); await this.$cleanupService.addCleanupDeleteAction(pathToDir); return pathToDir; } async path(options) { var _a, _b; const opts = typeof options === "string" ? { prefix: options } : options; const baseDir = (opts === null || opts === void 0 ? void 0 : opts.dir) ? opts.dir : (0, os_1.tmpdir)(); const prefix = ((_a = opts === null || opts === void 0 ? void 0 : opts.prefix) !== null && _a !== void 0 ? _a : "ns-").replace(/\s+/g, "-"); const suffix = (_b = opts === null || opts === void 0 ? void 0 : opts.suffix) !== null && _b !== void 0 ? _b : ""; const unique = Math.random().toString(36).slice(2); const filePath = path.join(baseDir, `${prefix}${unique}${suffix}`); const pathToFile = filePath; await this.$cleanupService.addCleanupDeleteAction(pathToFile); return pathToFile; } } exports.TempService = TempService; yok_1.injector.register("tempService", TempService); //# sourceMappingURL=temp-service.js.map