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

Create Plugin: Allow setting feature flags via cli args #984

Merged
merged 11 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 15 additions & 0 deletions packages/create-plugin/src/utils/tests/utils.config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DEFAULT_FEATURE_FLAGS } from '../../constants.js';
const mocks = vi.hoisted(() => {
return {
commandName: 'generate',
argv: {},
};
});

Expand All @@ -25,6 +26,7 @@ describe('getConfig', () => {
describe('Command: Generate', () => {
beforeEach(() => {
mocks.commandName = 'generate';
mocks.argv = {};
});

it('should give back a default config', async () => {
Expand All @@ -35,6 +37,19 @@ describe('getConfig', () => {
features: DEFAULT_FEATURE_FLAGS,
});
});

it('should override default feature flags via cli args', async () => {
mocks.argv = {
useReactRouterV6: false,
bundleGrafanaUI: true,
};
const config = getConfig(tmpDir);

expect(config).toEqual({
version: getVersion(),
features: { ...DEFAULT_FEATURE_FLAGS, useReactRouterV6: false, bundleGrafanaUI: true },
jackw marked this conversation as resolved.
Show resolved Hide resolved
});
});
});

describe('Command: Update', () => {
Expand Down
14 changes: 11 additions & 3 deletions packages/create-plugin/src/utils/utils.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs';
import path from 'node:path';
import { getVersion } from './utils.version.js';
import { commandName } from './utils.cli.js';
import { argv, commandName } from './utils.cli.js';
import { DEFAULT_FEATURE_FLAGS } from '../constants.js';

export type FeatureFlags = {
Expand Down Expand Up @@ -84,9 +84,17 @@ function readRCFileSync(path: string): CreatePluginConfig | undefined {
}

function createFeatureFlags(flags?: FeatureFlags): FeatureFlags {
// Default values for new scaffoldings
// For new scaffolds override any defaults with args passed in the CLI.
if (commandName === 'generate') {
return DEFAULT_FEATURE_FLAGS;
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;
leventebalogh marked this conversation as resolved.
Show resolved Hide resolved
}

return flags ?? {};
Expand Down
Loading