import semver from 'semver';
import chalk from 'chalk';
import { packageJson } from '../../../lib/index.js';
const isNodeVersionCompliantWithRequirement = (gatheredFromEnvironment, requiredVersion) => {
    return !semver.satisfies(gatheredFromEnvironment, requiredVersion);
};
const getNodeReleaseFromCurrentProcess = () => {
    return process.release || {};
};
const isNodeLTS = release => {
    return release.lts;
};
const getNodeVersionFromCurrentProcess = () => {
    return process.version;
};
const requiredEngineFromPackageJson = () => {
    return packageJson.engines.node;
};
const checkNode = (logger, requiredNodeVersion = requiredEngineFromPackageJson(), currentNodeVersion = getNodeVersionFromCurrentProcess()) => {
    if (isNodeVersionCompliantWithRequirement(currentNodeVersion, requiredNodeVersion)) {
        logger.warn(`Your NodeJS version is too old (${currentNodeVersion}). You should use at least NodeJS ${chalk.bold(requiredNodeVersion)}`);
    }
    if (!isNodeLTS(getNodeReleaseFromCurrentProcess())) {
        logger.warn('Your Node version is not LTS (Long Term Support), use it at your own risk! Begcode does not support non-LTS releases, so if you encounter a bug, please use a LTS version first.');
    }
};
export default checkNode;
