diff --git a/scripts/utils/cliContextUtils.spec.ts b/scripts/utils/cliContextUtils.spec.ts deleted file mode 100644 index e112a91f..00000000 --- a/scripts/utils/cliContextUtils.spec.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { describe, expect, it } from 'vitest' -import { getArgs } from './cliContextUtils.js' - -describe('getArgs', () => { - it('parses long arguments with values', () => { - process.argv = ['node', 'script.js', '--key=value'] - const args = getArgs() - expect(args).toEqual({ key: 'value' }) - }) - - it('parses long arguments without values', () => { - process.argv = ['node', 'script.js', '--flag'] - const args = getArgs() - expect(args).toEqual({ flag: true }) - }) - - it('parses short arguments', () => { - process.argv = ['node', 'script.js', '-abc'] - const args = getArgs() - expect(args).toEqual({ a: true, b: true, c: true }) - }) - - it('parses mixed arguments', () => { - process.argv = ['node', 'script.js', '--key=value', '-abc', '--flag'] - const args = getArgs() - expect(args).toEqual({ key: 'value', a: true, b: true, c: true, flag: true }) - }) - - it('handles no arguments', () => { - process.argv = ['node', 'script.js'] - const args = getArgs() - expect(args).toEqual({}) - }) - - it('handles empty long argument', () => { - process.argv = ['node', 'script.js', '--'] - const args = getArgs() - console.info(args) - expect(args).toEqual({}) - }) - - it('handles empty short argument', () => { - process.argv = ['node', 'script.js', '-'] - const args = getArgs() - expect(args).toEqual({}) - }) -}) diff --git a/scripts/utils/cliContextUtils.ts b/scripts/utils/cliContextUtils.ts deleted file mode 100644 index 82fbadce..00000000 --- a/scripts/utils/cliContextUtils.ts +++ /dev/null @@ -1,57 +0,0 @@ -import { type ParseArgsConfig, parseArgs } from 'node:util' -import type { RequestContext } from '@lokalise/fastify-extras' -import { generateMonotonicUuid } from '@lokalise/id-utils' -import type { CommonLogger } from '@lokalise/node-core' -import type z from 'zod' -import { type AppInstance, getApp } from '../../src/app.js' - -export const getArgs = (config: Partial = {}) => { - const { values } = parseArgs({ - ...config, - args: process.argv, - strict: false, - } satisfies ParseArgsConfig) - - return values -} - -export const createCliContext = async ( - // biome-ignore lint/suspicious/noExplicitAny: This is a generic schema - ARGUMENTS_SCHEMA: z.ZodObject, - origin: string, -): Promise<{ - app: AppInstance - logger: CommonLogger - args: Arguments -}> => { - const app = await getApp({ - queuesEnabled: false, - jobsEnabled: false, - healthchecksEnabled: false, - monitoringEnabled: false, - }) - - const requestId = generateMonotonicUuid() - const reqContext: RequestContext = { - reqId: requestId, - logger: (app.diContainer.cradle.logger as CommonLogger).child({ - origin, - 'x-request-id': requestId, - }), - } - - const res = ARGUMENTS_SCHEMA.safeParse(getArgs()) - if (!res.success) { - reqContext.logger.error(res.error.errors, 'Invalid arguments') - await app.close() - process.exit(1) - } - const args = res.data as Arguments - - return { app, logger: reqContext.logger, args } -} - -export const destroyCliContext = async (app: AppInstance, failure = false) => { - await app.close() - process.exit(failure ? 1 : 0) -}