UNPKG

scryptlib

Version:

Javascript SDK for integration of Bitcoin SV Smart Contracts written in sCrypt language.

72 lines 2.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.findCompiler = exports.getPlatformScryptc = void 0; const child_process_1 = require("child_process"); const fs_1 = require("fs"); const minimist = require("minimist"); const os = require("os"); const path_1 = require("path"); const showerror_1 = require("../util/showerror"); function getPlatformScryptc() { switch (os.platform()) { case 'win32': return 'compiler/scryptc/win32/scryptc.exe'; case 'linux': return 'compiler/scryptc/linux/scryptc'; case 'darwin': return 'compiler/scryptc/mac/scryptc'; default: throw `sCrypt doesn't support ${os.platform()}`; } } exports.getPlatformScryptc = getPlatformScryptc; function find_compiler_local(directory = __dirname) { const compiler = (0, path_1.resolve)(directory, 'compiler'); if ((0, fs_1.existsSync)(compiler) && (0, fs_1.statSync)(compiler).isDirectory()) { const scryptc = (0, path_1.join)(compiler, '..', getPlatformScryptc()); return (0, fs_1.existsSync)(scryptc) ? scryptc : undefined; } const parent = (0, path_1.resolve)(directory, '..'); if (parent === directory) { return undefined; } return find_compiler_local(parent); } function find_compiler_PATH() { const isWin = os.platform().indexOf('win') > -1; const where = isWin ? 'where' : 'which'; try { const scryptc = (0, child_process_1.execSync)(`${where} scryptc`, { stdio: [] }).toString(); return scryptc.replace(/\r\n/g, ''); } catch (error) { return undefined; } } // Searches known directories for a specific platform and returns Path object of the sCrypt compiler binary if found. function findCompiler() { const argv = minimist(process.argv.slice(2)); let scryptc = argv.scryptc; if (scryptc && scryptc.startsWith('"') && scryptc.endsWith('"')) { scryptc = scryptc.substring(1, scryptc.length - 1); } // If a special compiler is specified on the command line, the specified compiler is used if (scryptc && (0, fs_1.existsSync)(scryptc)) { return scryptc; } // special compiler by Enviroment Variables if (process.env.SCRYPTC && (0, fs_1.existsSync)(process.env.SCRYPTC)) { return process.env.SCRYPTC; } scryptc = find_compiler_local(); if (scryptc && (0, fs_1.existsSync)(scryptc)) { return scryptc; } scryptc = find_compiler_PATH(); if (scryptc && (0, fs_1.existsSync)(scryptc)) { return scryptc; } (0, showerror_1.showNoCompilerFound)(); } exports.findCompiler = findCompiler; //# sourceMappingURL=findCompiler.js.map