import yargs from 'yargs'; import { applyTemplates } from '../commands/apply-templates/index.js'; import { createExtensionConfigCommand, getExtensions, } from '../commands/create-extension-config/index.js'; import { createSolutionCommand } from '../commands/create/command.js'; import { getAccessToken } from '../commands/get-access-token/index.js'; import { graphqlDiff } from '../commands/graphql-diff.js'; import { hosting } from '../commands/hosting/index.js'; import { msgCodegen } from '../commands/msg-codegen/index.js'; import { msgDiff } from '../commands/msg-diff/index.js'; import { pgDump } from '../commands/pg-dump/index.js'; import { publishSchemaToDb } from '../commands/publish-schema-to-db/index.js'; import { service } from '../commands/service/index.js'; import { unpublishPilet } from '../commands/unpublish-pilet/index.js'; import { getCliExtensionFactory } from '../common/index.js'; export const run = async (): Promise => { const cli = yargs(process.argv.slice(2)); cli .scriptName('mosaic') .env() .command(applyTemplates) .command(getAccessToken) .command(publishSchemaToDb) .command(pgDump) .command(msgCodegen) .command(msgDiff) .command(createExtensionConfigCommand) .command(graphqlDiff) .command(hosting) .command(unpublishPilet) .command(service) .command(createSolutionCommand); //adding cli extensions: await Promise.all( getExtensions().map(async (library) => { try { const cliExtension = getCliExtensionFactory(await import(library)); if (cliExtension) { cliExtension().forEach((cmd) => { cli.command(cmd); }); } } catch (error) { //package is either not installed, or doesn't have cli extension } }), ); cli .demandCommand() .help() .epilog(`For more information, visit https://portal.axinom.com.`).argv; };