1+ #!/usr/bin/env node
2+
3+ import semverSatisfies = require ( "semver/functions/satisfies" ) ;
4+ import { Command } from "commander" ;
5+ import { Configurator , ModuleHandler } from "./core/command/module-handler" ;
6+ import { Context } from "./core/command/cli-context" ;
7+ import { VersionUtils } from "./core/utils/version" ;
8+ import { logger } from "./core/utils/logger" ;
9+
10+ /**
11+ * Celonis Content CLI.
12+ *
13+ * This is the main entry point for the CLI.
14+ */
15+
16+ // Check if the Node.js version satisfies the minimum requirements
17+ const requiredVersion = ">=10.10.0" ;
18+ if ( ! semverSatisfies ( process . version , requiredVersion ) ) {
19+ logger . error (
20+ `Node version ${ process . version } not supported. Please upgrade your node version to ${ requiredVersion } `
21+ ) ;
22+ process . exit ( 1 ) ;
23+ }
24+
25+ // Global configuration options
26+ const program : Command = new Command ( ) ;
27+ program . version ( VersionUtils . getCurrentCliVersion ( ) ) ;
28+ program . option ( "-q, --quietmode" , "Reduce output to a minimum" , false ) ;
29+ program . option ( "-p, --profile [profile]" ) ;
30+ program . option ( "--debug" , "Print debug messages" , false ) ;
31+ program . parseOptions ( process . argv ) ;
32+
33+ if ( ! program . opts ( ) . quietmode ) {
34+ console . log ( `Content CLI - (C) Copyright 2025 - Celonis SE - Version ${ VersionUtils . getCurrentCliVersion ( ) } ` ) ;
35+ console . log ( ) ;
36+ }
37+
38+ if ( program . opts ( ) . debug ) {
39+ logger . transports . forEach ( t => {
40+ t . level = 'debug' ;
41+ } ) ;
42+ }
43+
44+ /**
45+ * To support the legacy command structure, we have to configure some root commands
46+ * that the individual modules will extend.
47+ */
48+ function configureRootCommands ( configurator : Configurator ) {
49+ configurator . command ( "list" )
50+ . description ( "Commands to list content." )
51+ . alias ( "ls" )
52+ . action ( ( ) => program . outputHelp ( ) ) ;
53+ }
54+
55+ async function run ( ) {
56+ let context = new Context ( program . opts ( ) ) ;
57+ await context . init ( ) ;
58+
59+ let moduleHandler = new ModuleHandler ( program , context ) ;
60+
61+ configureRootCommands ( moduleHandler . configurator ) ;
62+
63+ moduleHandler . discoverAndRegisterModules ( __dirname ) ;
64+
65+ if ( ! process . argv . slice ( 2 ) . length ) {
66+ program . outputHelp ( ) ;
67+ }
68+
69+ try {
70+ program . parse ( process . argv ) ;
71+ } catch ( error ) {
72+ logger . error ( `An unexpected error occured: ${ error } ` ) ;
73+ }
74+ }
75+
76+ run ( ) ;
77+
78+ // catch uncaught exceptions
79+ process . on ( 'uncaughtException' , ( error : Error , origin : NodeJS . UncaughtExceptionOrigin ) => {
80+ console . error ( `\n💥 UNCAUGHT EXCEPTION!\n` ) ;
81+ console . error ( 'Error:' , error ) ;
82+ console . error ( 'Origin:' , origin ) ;
83+ process . exit ( 1 ) ;
84+ } ) ;
0 commit comments