import { dirname, join, relative } from 'path';
import { fileURLToPath } from 'url';
import { existsSync } from 'fs';
import semver from 'semver';
import chalk from 'chalk';
import { packageJson } from '../lib/index.js';
import { runJHipster } from './program.mjs';
import { done, logger } from './utils.mjs';
import process from "node:process";
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const currentNodeVersion = process.versions.node;
const minimumNodeVersion = packageJson.engines.node;
if (!process.argv.includes('--skip-checks') && !semver.satisfies(currentNodeVersion, minimumNodeVersion)) {
    logger.fatal(`You are running Node version ${currentNodeVersion}.\nBegCode requires Node version ${minimumNodeVersion}.\nPlease update your version of Node.`);
}
const appFolderOrWorkspaceRoot = existsSync('../node_modules') ? join(process.cwd(), '..') : process.cwd();
if (relative(appFolderOrWorkspaceRoot, __dirname).startsWith('..') &&
    existsSync(join(appFolderOrWorkspaceRoot, 'node_modules/.bin/jhipster'))) {
    logger.warn(`Since BegCode v8, the begcode command will not use the locally installed generator-begcode.
    If you want to execute the locally installed generator-begcode, run: ${chalk.yellow('npx begcode')}`);
}
export default runJHipster().catch(done);
process.on('unhandledRejection', (reason, promise) => {
    logger.error('Unhandled promise rejection at:', promise);
    logger.fatal(reason);
});
