From f37dda16c2845309332ef7811c0f272da0923334 Mon Sep 17 00:00:00 2001 From: Pujit Mehrotra Date: Mon, 13 Jan 2025 10:26:38 -0500 Subject: [PATCH] fix(api): slow init of unraid-api cli (#1022) * lazy load debug stuff * refactor(api): lazy load cli help command --- api/src/cli/index.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/api/src/cli/index.ts b/api/src/cli/index.ts index f45bc6960..7695d630a 100755 --- a/api/src/cli/index.ts +++ b/api/src/cli/index.ts @@ -1,22 +1,25 @@ -import { parse } from 'ts-command-line-args'; -import { cliLogger } from '@app/core/log'; -import { type Flags, mainOptions, options, args } from '@app/cli/options'; -import { setEnv } from '@app/cli/set-env'; -import { getters } from '@app/store'; import { execSync } from 'child_process'; + +import type { Flags } from '@app/cli/options'; +import { args, mainOptions, options } from '@app/cli/options'; +import { setEnv } from '@app/cli/set-env'; import { PM2_PATH } from '@app/consts'; -import * as ENVIRONMENT from '@app/environment'; const command = mainOptions.command as unknown as string; export const main = async (...argv: string[]) => { - // Set envs - cliLogger.debug({ paths: getters.paths(), environment: ENVIRONMENT }, 'Starting CLI'); + if (mainOptions.debug) { + const { cliLogger } = await import('@app/core/log'); + const { getters } = await import('@app/store'); + const ENVIRONMENT = await import('@app/environment'); + cliLogger.debug({ paths: getters.paths(), environment: ENVIRONMENT }, 'Starting CLI'); + } setEnv('PORT', process.env.PORT ?? mainOptions.port ?? '9000'); if (!command) { // Run help command + const { parse } = await import('ts-command-line-args'); parse(args, { ...options, partial: true,