From 80756feb11314c9e08a12c2a14911589a4903992 Mon Sep 17 00:00:00 2001 From: Jonathan Hutchinson <86778615+Djontleman@users.noreply.github.com> Date: Fri, 12 Jan 2024 14:27:38 +0000 Subject: [PATCH] feat: Read rest of options from custom configuration file (#391) ## Problem Not all of the options that can be set through CLI flags are able to be read in from the custom config file. These being: - `useMaintainers` - `useRootMaintainers` - `preserveBlockPosition` It would improve dev experience to also set these in the custom config and have them be respected like the other options. ## Changes - Update `generate` to read in the options mentioned above from custom config - Connect the `CustomConfig`, `GlobalOptions` and `Options` types - Small refactors --- src/commands/generate.ts | 24 ++++++++---------------- src/utils/getCustomConfiguration.ts | 4 +++- src/utils/getGlobalOptions.ts | 10 +++------- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/commands/generate.ts b/src/commands/generate.ts index 06bcfb44..d4635489 100644 --- a/src/commands/generate.ts +++ b/src/commands/generate.ts @@ -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, @@ -21,7 +21,6 @@ const debug = logger('generate'); type Generate = (options: GenerateInput) => Promise; type GenerateInput = { rootDir: string; - verifyPaths?: boolean; useMaintainers?: boolean; useRootMaintainers?: boolean; includes?: string[]; @@ -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 => { 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; 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, diff --git a/src/utils/getCustomConfiguration.ts b/src/utils/getCustomConfiguration.ts index 61be93eb..a7625cac 100644 --- a/src/utils/getCustomConfiguration.ts +++ b/src/utils/getCustomConfiguration.ts @@ -6,12 +6,14 @@ import packageJSON from '../../package.json'; import { logger } from './debug'; const debug = logger('customConfiguration'); + export type CustomConfig = { includes?: string[]; + output?: string; useMaintainers?: boolean; useRootMaintainers?: boolean; groupSourceComments?: boolean; - output?: string; + preserveBlockPosition?: boolean; customRegenerationCommand?: string; }; diff --git a/src/utils/getGlobalOptions.ts b/src/utils/getGlobalOptions.ts index 23a63f8c..0ee670d3 100644 --- a/src/utils/getGlobalOptions.ts +++ b/src/utils/getGlobalOptions.ts @@ -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; }