UNPKG

@nativescript/doctor

Version:

Library that helps identifying if the environment can be used for development of {N} apps.

62 lines (61 loc) 2.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FileSystem = void 0; var fs = require("fs"); var path = require("path"); var yauzl = require("yauzl"); var shelljs = require("shelljs"); var FileSystem = (function () { function FileSystem() { } FileSystem.prototype.exists = function (filePath) { return fs.existsSync(path.resolve(filePath)); }; FileSystem.prototype.extractZip = function (pathToZip, outputDir) { return new Promise(function (resolve, reject) { yauzl.open(pathToZip, { autoClose: true, lazyEntries: true }, function (openError, zipFile) { if (openError) { return reject(openError); } zipFile.on("entry", function (entry) { var fn = entry.fileName; if (/\/$/.test(fn)) { return zipFile.readEntry(); } zipFile.openReadStream(entry, function (openStreamError, stream) { if (openStreamError) { return reject(openStreamError); } var filePath = "".concat(outputDir, "/").concat(fn); return createParentDirsIfNeeded(filePath) .catch(function (createParentDirError) { return reject(createParentDirError); }) .then(function () { var outfile = fs.createWriteStream(filePath); stream.once("end", function () { zipFile.readEntry(); }); stream.pipe(outfile); }); }); }); zipFile.once("end", function () { return resolve(); }); zipFile.readEntry(); }); }); }; FileSystem.prototype.readDirectory = function (directoryPath) { return fs.readdirSync(directoryPath); }; FileSystem.prototype.readJson = function (filePath, options) { var content = fs.readFileSync(filePath, options); return JSON.parse(content.toString()); }; FileSystem.prototype.deleteEntry = function (filePath) { shelljs.rm("-rf", filePath); }; return FileSystem; }()); exports.FileSystem = FileSystem; function createParentDirsIfNeeded(filePath) { return fs.promises.mkdir(path.dirname(filePath), { recursive: true }); }