From 51417fd3ac0acd28582cf5f049e3522a147f6825 Mon Sep 17 00:00:00 2001 From: Jack Westbrook Date: Tue, 2 Jul 2024 14:02:10 +0200 Subject: [PATCH] feat(create-plugin): allow feature flag cli arg overrides in both generate and update commands --- .../src/utils/tests/utils.config.test.ts | 1 + .../create-plugin/src/utils/utils.config.ts | 35 ++++++++++++------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/create-plugin/src/utils/tests/utils.config.test.ts b/packages/create-plugin/src/utils/tests/utils.config.test.ts index 50e2f8614c..84d374d620 100644 --- a/packages/create-plugin/src/utils/tests/utils.config.test.ts +++ b/packages/create-plugin/src/utils/tests/utils.config.test.ts @@ -55,6 +55,7 @@ describe('getConfig', () => { describe('Command: Update', () => { beforeEach(() => { mocks.commandName = 'update'; + mocks.argv = {}; }); it('should give back the correct config when there are no config files at all', async () => { diff --git a/packages/create-plugin/src/utils/utils.config.ts b/packages/create-plugin/src/utils/utils.config.ts index eee9bd3bd7..8237c449fe 100644 --- a/packages/create-plugin/src/utils/utils.config.ts +++ b/packages/create-plugin/src/utils/utils.config.ts @@ -85,17 +85,28 @@ function readRCFileSync(path: string): CreatePluginConfig | undefined { function createFeatureFlags(flags?: FeatureFlags): FeatureFlags { // For new scaffolds override any defaults with args passed in the CLI. - if (commandName === 'generate') { - const flags = Object.entries(DEFAULT_FEATURE_FLAGS).reduce((acc, [flag, value]) => { - if (argv.hasOwnProperty(flag)) { - return { ...acc, [flag]: argv[flag] }; - } else { - return { ...acc, [flag]: value }; - } - }, {} as FeatureFlags); - - return flags; - } - return flags ?? {}; + const featureFlags = commandName === 'generate' ? DEFAULT_FEATURE_FLAGS : flags ?? {}; + + return Object.entries(featureFlags).reduce((acc, [flag, value]) => { + if (argv.hasOwnProperty(flag)) { + return { ...acc, [flag]: argv[flag] }; + } else { + return { ...acc, [flag]: value }; + } + }, {} as FeatureFlags); + + // if (commandName === 'generate') { + // const flags = Object.entries(DEFAULT_FEATURE_FLAGS).reduce((acc, [flag, value]) => { + // if (argv.hasOwnProperty(flag)) { + // return { ...acc, [flag]: argv[flag] }; + // } else { + // return { ...acc, [flag]: value }; + // } + // }, {} as FeatureFlags); + + // return flags; + // } + + // return flags ?? {}; }