UNPKG

@blockfrost/blockfrost-cardano-cli

Version:

Drop-in(ish) replacement for cardano-cli powered by Blockfrost

37 lines (36 loc) 1.72 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const child_process_1 = require("child_process"); const parsing_1 = require("../utils/parsing"); const hook = async function (options) { var _a; const argv = (_a = options.argv) !== null && _a !== void 0 ? _a : []; // Commands (basically args that are not options) are joined into options.id, separated by ":" const command = options.id.split(':'); const args = [...command, ...argv]; // first run cardano-cli --version just to figure out if it is available let cardanoCliVersionOutput = ''; try { cardanoCliVersionOutput = (0, child_process_1.execSync)('cardano-cli --version', { // won't show error message on fail stdio: 'pipe', }).toString(); } catch (error) { // cardano-cli not available if (process.env.NODE_ENV === 'development') { // Shown only during development console.debug(`Cannot find cardano-cli binary.`, error.message); } // In case of error we need to show original command not found msg. // For some reason Oclif itself won't show it after defining this hook this.error(`Command ${args.join(' ')} not found in blockfrost-cardano-cli.`); } const version = (0, parsing_1.parseCardanoCliVersion)(cardanoCliVersionOutput); console.log(`Command ${args.join(' ')} not found in blockfrost-cardano-cli. Using installed cardano-cli version ${version.join('.')} instead.`); // Looks like Oclif will wait until cardano-cli exits which is perfect (0, child_process_1.spawn)('cardano-cli', args, { stdio: 'inherit', }); }; exports.default = hook;