UNPKG

pascal-utils

Version:

Utility functions for compilation of simple pascal programs, with the Free Pascal compiler, in Node.js.

54 lines 2.35 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const childProcess = __importStar(require("child_process")); const compilerNotFoundError_1 = __importDefault(require("./errors/compilerNotFoundError")); const isVersionString_1 = __importDefault(require("./utils/validation/isVersionString")); /** * Checks whether the Free Pascal compiler is present in the system path. * @category Compiler Detection * @param {string} compilerName - The name of the compiler executable. * @returns {Promise<{version: string}>} * @throws {@link CompilerNotFoundError} if no compiler is found. */ function checkCompiler(compilerName = 'fpc') { return new Promise((resolve, reject) => { childProcess.exec(`${compilerName} -iV`, (error, stdout) => { if (error) { reject(new compilerNotFoundError_1.default()); } const version = stdout.trim(); if ((0, isVersionString_1.default)(version)) { resolve({ version }); } reject(new compilerNotFoundError_1.default()); }); }); } exports.default = checkCompiler; //# sourceMappingURL=checkCompiler.js.map