Skip to content

Commit

Permalink
feat(create-plugin): allow cli arg feature flag overrides for all com…
Browse files Browse the repository at this point in the history
…mands
  • Loading branch information
jackw committed Jul 3, 2024
1 parent dbba404 commit 9ef654f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
23 changes: 10 additions & 13 deletions packages/create-plugin/src/utils/utils.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,16 @@ function readRCFileSync(path: string): CreatePluginConfig | undefined {
}
}

// This function creates feature flags based on the defaults for generate command else flags read from config.
// In both cases it will override the flags if any cli args with the same name are passed in.
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);
const featureFlags = commandName === 'generate' ? DEFAULT_FEATURE_FLAGS : flags ?? {};

return flags;
}

return 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);
}

0 comments on commit 9ef654f

Please sign in to comment.