Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cli): rename configPath to config #109

Merged
merged 3 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/cli-e2e/tests/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ const execCli = (argObj: Partial<CliArgsObject>) =>

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') });
});
});
2 changes: 1 addition & 1 deletion packages/cli/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/collect/command-object.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { yargsCollectCommandObject } from './command-object';
const baseArgs = [
...objectToCliArgs({
verbose: true,
configPath: join(
config: join(
fileURLToPath(dirname(import.meta.url)),
'..',
'..',
Expand Down
38 changes: 19 additions & 19 deletions packages/cli/src/lib/implementation/config-middleware.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
4 changes: 2 additions & 2 deletions packages/cli/src/lib/implementation/config-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { ArgsCliObj, CommandBase } from './model';

export async function configMiddleware<T extends ArgsCliObj>(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,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/implementation/global-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/upload/command-object.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const baseArgs = [
'upload',
'--verbose',
...objectToCliArgs({
configPath: join(
config: join(
fileURLToPath(dirname(import.meta.url)),
'..',
'..',
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/lib/yargs-cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const demandCommand: [number, string] = [0, 'no command required'];
function middleware<T extends Record<string, unknown>>(processArgs: T) {
return {
...processArgs,
configPath: '42',
config: '42',
};
}

Expand All @@ -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,
Expand All @@ -52,6 +52,6 @@ describe('yargsCli', () => {
},
],
}).parseAsync();
expect(parsedArgv.configPath).toContain(42);
expect(parsedArgv.config).toContain(42);
});
});
2 changes: 1 addition & 1 deletion packages/models/src/lib/global-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down