UNPKG

liveperson-functions-cli

Version:
51 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.nodeVersion = void 0; const semver = require("semver"); const chalk = require("chalk"); const faasFactory_service_1 = require("../../service/faasFactory.service"); /** * Hook which will run if the invoke command was triggered. * Will display the difference of the remote and local node.js version * @param {*} opts - passed options from the oclif framework * @returns {Promise<void>} - update version hint */ async function nodeVersion(opts, /* istanbul ignore next */ version = process.version) { /* istanbul ignore else */ if (opts.id === 'invoke') { try { const faasService = await faasFactory_service_1.factory.get(); const runtime = await faasService.getRuntime(); const userNodeVersion = semver.major(semver.clean(version)); const remoteVersion = runtime.name.replace('Node.js ', ''); /* istanbul ignore else */ if (userNodeVersion > Number.parseInt(remoteVersion, 10)) { // eslint-disable-next-line no-console console.log(`Please be aware that your Node.js (${chalk.yellowBright(`v${userNodeVersion}`)}) version is higher than the one on the LivePerson functions platform (${chalk.green(`v${remoteVersion}`)})! ${chalk.yellowBright('This can cause unexpected behaviour!')} `); } } catch { /* eslint-disable no-console */ /* istanbul ignore next */ console.log('Could not fetch runtime version from LivePerson Functions platform'); /* eslint-enable no-console */ } } } exports.nodeVersion = nodeVersion; /** * Runs the a hook every time the CLI gets initialised * @param { config } - oclif configuration */ /* istanbul ignore next */ const hook = async function nodeVersionHook(opts) { // need to separate the function for the test, // because there is no context for the init command during the test /* istanbul ignore next */ await nodeVersion(opts); }; exports.default = hook; //# sourceMappingURL=nodeVersion.js.map