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

feat: Read rest of options from custom configuration file #391

Merged
merged 4 commits into from
Jan 12, 2024
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
24 changes: 8 additions & 16 deletions src/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ora from 'ora';
import { posix as path } from 'path';
import fs from 'fs';
import { sync } from 'fast-glob';
import { Command, getGlobalOptions } from '../utils/getGlobalOptions';
import { Command, GlobalOptions, getGlobalOptions } from '../utils/getGlobalOptions';
import {
OUTPUT,
INCLUDES,
Expand All @@ -21,7 +21,6 @@ const debug = logger('generate');
type Generate = (options: GenerateInput) => Promise<ownerRule[]>;
type GenerateInput = {
rootDir: string;
verifyPaths?: boolean;
useMaintainers?: boolean;
useRootMaintainers?: boolean;
includes?: string[];
Expand Down Expand Up @@ -97,45 +96,38 @@ export const generate: Generate = async ({ rootDir, includes, useMaintainers = f
}
};

interface Options {
output?: string;
verifyPaths?: boolean;
useMaintainers?: boolean;
useRootMaintainers?: boolean;
groupSourceComments?: boolean;
preserveBlockPosition?: boolean;
includes?: string[];
customRegenerationCommand?: string;
interface Options extends GlobalOptions {
check?: boolean;
}

export const command = async (options: Options, command: Command): Promise<void> => {
const globalOptions = await getGlobalOptions(command);

const { verifyPaths, useMaintainers, useRootMaintainers, check, preserveBlockPosition } = options;
const { check } = options;

const { output = globalOptions.output || OUTPUT } = options;
const output = options.output || globalOptions.output || OUTPUT;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this syntax more readable as it only uses one technique


const loader = ora('generating codeowners...').start();

const useMaintainers = globalOptions.useMaintainers || options.useMaintainers;
const useRootMaintainers = globalOptions.useRootMaintainers || options.useRootMaintainers;
const groupSourceComments = globalOptions.groupSourceComments || options.groupSourceComments;

const preserveBlockPosition = globalOptions.preserveBlockPosition || options.preserveBlockPosition;
const customRegenerationCommand = globalOptions.customRegenerationCommand || options.customRegenerationCommand;

debug('Options:', {
...globalOptions,
output,
useMaintainers,
useRootMaintainers,
groupSourceComments,
preserveBlockPosition,
customRegenerationCommand,
output,
});

try {
const ownerRules = await generate({
rootDir: __dirname,
verifyPaths,
useMaintainers,
useRootMaintainers,
...globalOptions,
Expand Down
4 changes: 3 additions & 1 deletion src/utils/getCustomConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import packageJSON from '../../package.json';
import { logger } from './debug';

const debug = logger('customConfiguration');

export type CustomConfig = {
includes?: string[];
output?: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-ordering in some places so the options are in the same order as in the documentation for consistency and readability.

useMaintainers?: boolean;
useRootMaintainers?: boolean;
groupSourceComments?: boolean;
output?: string;
preserveBlockPosition?: boolean;
customRegenerationCommand?: string;
};

Expand Down
10 changes: 3 additions & 7 deletions src/utils/getGlobalOptions.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { getCustomConfiguration } from './getCustomConfiguration';
interface GlobalOptions {
includes?: string[];
output?: string;
customRegenerationCommand?: string;
groupSourceComments?: boolean;
}
import { CustomConfig, getCustomConfiguration } from './getCustomConfiguration';

export type GlobalOptions = CustomConfig;
export interface Command {
parent: Partial<GlobalOptions>;
}
Expand Down
Loading