UNPKG

perlnavigator-server

Version:

Perl language server

63 lines 2.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.cleanupTemporaryAssetPath = exports.getPerlAssetsPath = void 0; require("process"); const os_1 = require("os"); const fs_1 = require("fs"); const path_1 = require("path"); let haveExtractedAssets = false; let pkgAssetPath; async function extractAssetsIfNecessary() { if (!haveExtractedAssets) { pkgAssetPath = (0, fs_1.mkdtempSync)((0, path_1.join)((0, os_1.tmpdir)(), "perl-navigator")); let assets = [ "src/perl/lib_bs22/ModHunter.pl", "src/perl/Inquisitor.pm", "src/perl/criticWrapper.pl", "src/perl/lib_bs22/Class/Inspector.pm", "src/perl/lib_bs22/Devel/Symdump.pm", "src/perl/lib_bs22/Devel/Symdump/Export.pm", "src/perl/lib_bs22/Inspectorito.pm", "src/perl/lib_bs22/SubUtilPP.pm", "src/perl/lib_bs22/SourceStash.pm", "src/perl/lib_bs22/pltags.pm", "src/perl/defaultCriticProfile", "src/perl/tidyWrapper.pl", "src/perl/perlimportsWrapper.pl", ]; assets.forEach((asset) => { let source = (0, path_1.join)((0, path_1.dirname)(__dirname), asset); let dest = (0, path_1.join)(pkgAssetPath, asset); (0, fs_1.mkdirSync)((0, path_1.dirname)(dest), { recursive: true }); // Create all parent folders (0, fs_1.createReadStream)(source).pipe((0, fs_1.createWriteStream)(dest)); }); haveExtractedAssets = true; // Allow time to copy. TODO: Change writeStreams to be async and just wait on them return new Promise(resolve => setTimeout(() => resolve(pkgAssetPath), 50)); } return pkgAssetPath; } async function getAssetsPath() { let anyProcess = process; if (anyProcess.pkg) { // When running inside of a pkg built executable, the assets // are available via the snapshot filesystem. That file // system is only available through the node API, so the // assets need to be extracted in order to be accessible by // the perl command return extractAssetsIfNecessary(); } return (0, path_1.dirname)(__dirname); } async function getPerlAssetsPath() { return (0, path_1.join)(await getAssetsPath(), "src", "perl"); } exports.getPerlAssetsPath = getPerlAssetsPath; function cleanupTemporaryAssetPath() { if (haveExtractedAssets) { (0, fs_1.rmSync)(pkgAssetPath, { recursive: true }); // Create all parent folders haveExtractedAssets = false; } } exports.cleanupTemporaryAssetPath = cleanupTemporaryAssetPath; //# sourceMappingURL=assets.js.map