import { Runner } from 'oo-cli'; import * as path from 'path'; import { showEnvironment } from './lib/EnvironmentalOutput'; import { checkForUpdate } from './lib/checkForUpdate'; import { checkDeprecation } from './lib/checkDeprecation'; import * as os from 'os'; import * as fs from 'fs'; import {formatError} from './lib/formatError'; import {migrateOptiCli} from './lib/migrateOptiCli'; import {die} from './lib/die'; import * as chalk from 'chalk'; async function run() { const args = process.argv.slice(2); const noPrompt = args.includes('--noPrompt'); if (Number(process.versions.node.split('.')[0]) < 18) { console.log( chalk.redBright('Node version 18 or higher is recommended. OCP CLI is not tested on versions lower than 18.') ); } await migrateOptiCli(noPrompt); const configFolder = path.join(os.homedir(), '.ocp'); if (!fs.existsSync(configFolder)) { die( 'No ~/.ocp config folder found. ' + 'Follow the instruction in ' + 'https://docs.developers.optimizely.com/optimizely-connect-platform/docs/configure-your-development-environment-ocp2 ' + 'to set up your development environment.' ); } showEnvironment(); checkDeprecation(); const manifest = require(path.join(__dirname, './oo-cli.manifest.json')); await checkForUpdate(manifest, noPrompt); new Runner(__dirname, manifest).run(); } // catch does not work here sadly for async functions as oo-cli lib does not wait for the promise to resolve // use try/catch instead in every command run().catch((e) => die(formatError(e)));