From daf548df1d153409998213ca11914212a1d036b6 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Fri, 13 Oct 2023 11:51:40 +0200 Subject: [PATCH] refactor(cli): rename configPath to config (#109) --- examples/cli-e2e/tests/cli.spec.ts | 6 +-- packages/cli/project.json | 2 +- .../src/lib/collect/command-object.spec.ts | 2 +- .../implementation/config-middleware.spec.ts | 38 +++++++++---------- .../lib/implementation/config-middleware.ts | 4 +- .../src/lib/implementation/global-options.ts | 2 +- .../cli/src/lib/upload/command-object.spec.ts | 2 +- packages/cli/src/lib/yargs-cli.spec.ts | 6 +-- packages/models/src/lib/global-options.ts | 2 +- 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/examples/cli-e2e/tests/cli.spec.ts b/examples/cli-e2e/tests/cli.spec.ts index 83b0333bd..f99659220 100644 --- a/examples/cli-e2e/tests/cli.spec.ts +++ b/examples/cli-e2e/tests/cli.spec.ts @@ -20,14 +20,14 @@ const execCli = (argObj: Partial) => describe('cli', () => { it('should load .js config file', async () => { - await execCli({ configPath: configFile('js') }); + await execCli({ config: configFile('js') }); }); it('should load .mjs config file', async () => { - await execCli({ configPath: configFile('mjs') }); + await execCli({ config: configFile('mjs') }); }); it('should load .ts config file', async () => { - await execCli({ configPath: configFile('ts') }); + await execCli({ config: configFile('ts') }); }); }); diff --git a/packages/cli/project.json b/packages/cli/project.json index 4844d3cd2..bcb6a610e 100644 --- a/packages/cli/project.json +++ b/packages/cli/project.json @@ -20,7 +20,7 @@ "dependsOn": ["build"] }, "exec": { - "command": "npx dist/packages/cli --configPath=./packages/cli/code-pushup.config.ts", + "command": "npx dist/packages/cli --config=./packages/cli/code-pushup.config.ts", "dependsOn": ["build"] }, "lint": { diff --git a/packages/cli/src/lib/collect/command-object.spec.ts b/packages/cli/src/lib/collect/command-object.spec.ts index a0d9f0d53..ec7f5d438 100644 --- a/packages/cli/src/lib/collect/command-object.spec.ts +++ b/packages/cli/src/lib/collect/command-object.spec.ts @@ -9,7 +9,7 @@ import { yargsCollectCommandObject } from './command-object'; const baseArgs = [ ...objectToCliArgs({ verbose: true, - configPath: join( + config: join( fileURLToPath(dirname(import.meta.url)), '..', '..', diff --git a/packages/cli/src/lib/implementation/config-middleware.spec.ts b/packages/cli/src/lib/implementation/config-middleware.spec.ts index 0b46a928a..056bd4806 100644 --- a/packages/cli/src/lib/implementation/config-middleware.spec.ts +++ b/packages/cli/src/lib/implementation/config-middleware.spec.ts @@ -6,42 +6,42 @@ import { getDirname } from './helper.mock'; const __dirname = getDirname(import.meta.url); const withDirName = (path: string) => join(__dirname, path); -const configPath = (ext: string) => +const config = (ext: string) => `${withDirName('../../../test/config.mock.')}${ext}`; describe('applyConfigMiddleware', () => { it('should load valid .mjs config', async () => { - const configPathMjs = configPath('mjs'); - const config = await configMiddleware({ configPath: configPathMjs }); - expect(config.upload.project).toContain('mjs'); - expect(config.persist.outputDir).toContain('tmp'); + const configPathMjs = config('mjs'); + const _config = await configMiddleware({ config: configPathMjs }); + expect(_config.upload.project).toContain('mjs'); + expect(_config.persist.outputDir).toContain('tmp'); }); it('should load valid .cjs config', async () => { - const configPathCjs = configPath('cjs'); - const config = await configMiddleware({ configPath: configPathCjs }); - expect(config.upload.project).toContain('cjs'); - expect(config.persist.outputDir).toContain('tmp'); + const configPathCjs = config('cjs'); + const _config = await configMiddleware({ config: configPathCjs }); + expect(_config.upload.project).toContain('cjs'); + expect(_config.persist.outputDir).toContain('tmp'); }); it('should load valid .js config', async () => { - const configPathJs = configPath('js'); - const config = await configMiddleware({ configPath: configPathJs }); - expect(config.upload.project).toContain('js'); - expect(config.persist.outputDir).toContain('tmp'); + const configPathJs = config('js'); + const _config = await configMiddleware({ config: configPathJs }); + expect(_config.upload.project).toContain('js'); + expect(_config.persist.outputDir).toContain('tmp'); }); - it('should throw with invalid configPath', async () => { - const configPath = 'wrong/path/to/config'; + it('should throw with invalid config', async () => { + const config = 'wrong/path/to/config'; let error: Error = new Error(); - await configMiddleware({ configPath }).catch(e => (error = e)); - expect(error?.message).toContain(configPath); + await configMiddleware({ config }).catch(e => (error = e)); + expect(error?.message).toContain(config); }); - it('should provide default configPath', async () => { + it('should provide default config', async () => { const defaultConfigPath = 'code-pushup.config.js'; let error: Error = new Error(); - await configMiddleware({ configPath: undefined }).catch(e => (error = e)); + await configMiddleware({ config: undefined }).catch(e => (error = e)); expect(error?.message).toContain(defaultConfigPath); }); }); diff --git a/packages/cli/src/lib/implementation/config-middleware.ts b/packages/cli/src/lib/implementation/config-middleware.ts index f6582044e..750008e64 100644 --- a/packages/cli/src/lib/implementation/config-middleware.ts +++ b/packages/cli/src/lib/implementation/config-middleware.ts @@ -4,9 +4,9 @@ import { ArgsCliObj, CommandBase } from './model'; export async function configMiddleware(processArgs: T) { const args = processArgs as T; - const { configPath, ...cliOptions }: GlobalOptions = + const { config, ...cliOptions }: GlobalOptions = globalOptionsSchema.parse(args); - const importedRc = await readCodePushupConfig(configPath); + const importedRc = await readCodePushupConfig(config); const cliConfigArgs = readCoreConfigFromCliArgs(processArgs); const parsedProcessArgs: CommandBase = { ...cliOptions, diff --git a/packages/cli/src/lib/implementation/global-options.ts b/packages/cli/src/lib/implementation/global-options.ts index b2916f28a..00bccaf9c 100644 --- a/packages/cli/src/lib/implementation/global-options.ts +++ b/packages/cli/src/lib/implementation/global-options.ts @@ -17,7 +17,7 @@ export function yargsGlobalOptionsDefinition(): Record< type: 'boolean', default: false, }, - configPath: { + config: { describe: 'Path the the config file, e.g. code-pushup.config.js', type: 'string', default: 'code-pushup.config.js', diff --git a/packages/cli/src/lib/upload/command-object.spec.ts b/packages/cli/src/lib/upload/command-object.spec.ts index 89df97747..436e6492b 100644 --- a/packages/cli/src/lib/upload/command-object.spec.ts +++ b/packages/cli/src/lib/upload/command-object.spec.ts @@ -31,7 +31,7 @@ const baseArgs = [ 'upload', '--verbose', ...objectToCliArgs({ - configPath: join( + config: join( fileURLToPath(dirname(import.meta.url)), '..', '..', diff --git a/packages/cli/src/lib/yargs-cli.spec.ts b/packages/cli/src/lib/yargs-cli.spec.ts index 03963a010..a583eee83 100644 --- a/packages/cli/src/lib/yargs-cli.spec.ts +++ b/packages/cli/src/lib/yargs-cli.spec.ts @@ -14,7 +14,7 @@ const demandCommand: [number, string] = [0, 'no command required']; function middleware>(processArgs: T) { return { ...processArgs, - configPath: '42', + config: '42', }; } @@ -41,7 +41,7 @@ describe('yargsCli', () => { it('global options and middleware handle argument overrides correctly', async () => { const args: string[] = objectToCliArgs({ - configPath: 'validConfigPath', + config: 'validConfigPath', }); const parsedArgv = await yargsCli(args, { options, @@ -52,6 +52,6 @@ describe('yargsCli', () => { }, ], }).parseAsync(); - expect(parsedArgv.configPath).toContain(42); + expect(parsedArgv.config).toContain(42); }); }); diff --git a/packages/models/src/lib/global-options.ts b/packages/models/src/lib/global-options.ts index cf0905dbf..e971f2dd8 100644 --- a/packages/models/src/lib/global-options.ts +++ b/packages/models/src/lib/global-options.ts @@ -7,7 +7,7 @@ export const globalOptionsSchema = z.object({ description: 'Outputs additional information for a run', }) .default(false), - configPath: filePathSchema( + config: filePathSchema( "Path to config file in format `ts` or `mjs`. defaults to 'code-pushup.config.js'", ) .optional()