@grafana/create-plugin 6.2.0-canary.2233.18936261925.0 → 6.2.0-canary.2233.18946416008.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
- var defaultAdditions = {
2
- additions: {
3
- i18n: {
4
- name: "i18n",
5
- description: "Add internationalization (i18n) support to your plugin",
6
- scriptPath: "./scripts/add-i18n.js"
7
- }
1
+ const additions = {
2
+ i18n: {
3
+ name: "i18n",
4
+ description: "Add internationalization (i18n) support to your plugin",
5
+ scriptPath: "./scripts/add-i18n.js",
6
+ featureName: "i18nEnabled"
8
7
  }
9
8
  };
9
+ var defaultAdditions = { additions };
10
10
 
11
11
  export { defaultAdditions as default };
@@ -1,5 +1,6 @@
1
1
  import { additionsDebug, printChanges } from './utils.js';
2
2
  import defaultAdditions from './additions.js';
3
+ import { getConfig, isFeatureEnabled, setFeatureFlag } from '../utils/utils.config.js';
3
4
  import { Context } from '../migrations/context.js';
4
5
  import { gitCommitNoVerify } from '../utils/utils.git.js';
5
6
  import { output } from '../utils/utils.console.js';
@@ -70,6 +71,14 @@ Available additions: ${additionsList.join(", ")}`);
70
71
  }
71
72
  async function runAddition(addition, additionOptions = {}, runOptions = {}) {
72
73
  const basePath = process.cwd();
74
+ const config = getConfig();
75
+ if (isFeatureEnabled(config.features, addition.featureName)) {
76
+ output.log({
77
+ title: `Addition '${addition.name}' is already enabled`,
78
+ body: [`The feature flag '${addition.featureName}' is already set to true in .cprc.json.`, "No changes needed."]
79
+ });
80
+ return;
81
+ }
73
82
  output.log({
74
83
  title: `Running addition: ${addition.name}`,
75
84
  body: [addition.description]
@@ -84,6 +93,8 @@ async function runAddition(addition, additionOptions = {}, runOptions = {}) {
84
93
  flushChanges(updatedContext);
85
94
  printChanges(updatedContext, addition.name, addition);
86
95
  installNPMDependencies(updatedContext);
96
+ await setFeatureFlag(addition.featureName, true);
97
+ additionsDebug(`Set feature flag '${addition.featureName}' to true in .cprc.json`);
87
98
  if (shouldCommit) {
88
99
  await gitCommitNoVerify(`chore: add ${addition.name} support via create-plugin`);
89
100
  }
@@ -1,13 +1,16 @@
1
1
  import { argv, commandName } from './utils.cli.js';
2
2
  import { CURRENT_APP_VERSION } from './utils.version.js';
3
3
  import { DEFAULT_FEATURE_FLAGS } from '../constants.js';
4
+ import { EOL } from 'node:os';
4
5
  import fs from 'node:fs';
5
6
  import { output } from './utils.console.js';
6
7
  import { partitionArr } from './utils.helpers.js';
7
8
  import path from 'node:path';
8
9
  import { writeFile } from 'node:fs/promises';
9
- import { EOL } from 'node:os';
10
10
 
11
+ function isFeatureEnabled(features, featureName) {
12
+ return features[featureName] === true;
13
+ }
11
14
  let hasShownConfigWarnings = false;
12
15
  function getConfig(workDir = process.cwd()) {
13
16
  const rootConfig = getRootConfig(workDir);
@@ -92,5 +95,17 @@ async function setRootConfig(configOverride = {}) {
92
95
  await writeFile(rootConfigPath, JSON.stringify(updatedConfig, null, 2) + EOL);
93
96
  return updatedConfig;
94
97
  }
98
+ async function setFeatureFlag(featureName, enabled = true) {
99
+ const userConfig = getUserConfig() || { features: {} };
100
+ const userConfigPath = path.resolve(process.cwd(), ".cprc.json");
101
+ const updatedConfig = {
102
+ ...userConfig,
103
+ features: {
104
+ ...userConfig.features,
105
+ [featureName]: enabled
106
+ }
107
+ };
108
+ await writeFile(userConfigPath, JSON.stringify(updatedConfig, null, 2) + EOL);
109
+ }
95
110
 
96
- export { getConfig, setRootConfig };
111
+ export { getConfig, isFeatureEnabled, setFeatureFlag, setRootConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "6.2.0-canary.2233.18936261925.0",
3
+ "version": "6.2.0-canary.2233.18946416008.0",
4
4
  "repository": {
5
5
  "directory": "packages/create-plugin",
6
6
  "url": "https://github.com/grafana/plugin-tools"
@@ -61,5 +61,5 @@
61
61
  "engines": {
62
62
  "node": ">=20"
63
63
  },
64
- "gitHead": "4fe983e6dd98bd64f3cb807b5a44906de0ec8603"
64
+ "gitHead": "7f8486188da11dbb73a5abd43c4f1db50fdc937c"
65
65
  }
@@ -1,15 +1,22 @@
1
- export type AdditionMeta = {
1
+ export type AdditionMeta<TFeatureName extends string = string> = {
2
2
  name: string;
3
3
  description: string;
4
4
  scriptPath: string;
5
+ featureName: TFeatureName;
5
6
  };
6
7
 
7
- export default {
8
- additions: {
9
- i18n: {
10
- name: 'i18n',
11
- description: 'Add internationalization (i18n) support to your plugin',
12
- scriptPath: './scripts/add-i18n.js',
13
- },
8
+ const additions = {
9
+ i18n: {
10
+ name: 'i18n',
11
+ description: 'Add internationalization (i18n) support to your plugin',
12
+ scriptPath: './scripts/add-i18n.js',
13
+ featureName: 'i18nEnabled',
14
14
  },
15
15
  };
16
+
17
+ export default { additions };
18
+
19
+ type AdditionValues = (typeof additions)[keyof typeof additions];
20
+ export type AdditionFeatureName = AdditionValues['featureName'];
21
+
22
+ export type TypedAdditionMeta = AdditionMeta<AdditionFeatureName>;
@@ -1,5 +1,6 @@
1
1
  import { additionsDebug, flushChanges, formatFiles, installNPMDependencies, printChanges } from './utils.js';
2
2
  import defaultAdditions, { AdditionMeta } from './additions.js';
3
+ import { getConfig, isFeatureEnabled, setFeatureFlag } from '../utils/utils.config.js';
3
4
 
4
5
  import { Context } from '../migrations/context.js';
5
6
  import { gitCommitNoVerify } from '../utils/utils.git.js';
@@ -100,6 +101,16 @@ export async function runAddition(
100
101
  ): Promise<void> {
101
102
  const basePath = process.cwd();
102
103
 
104
+ // Check if the feature is already enabled
105
+ const config = getConfig();
106
+ if (isFeatureEnabled(config.features, addition.featureName)) {
107
+ output.log({
108
+ title: `Addition '${addition.name}' is already enabled`,
109
+ body: [`The feature flag '${addition.featureName}' is already set to true in .cprc.json.`, 'No changes needed.'],
110
+ });
111
+ return;
112
+ }
113
+
103
114
  output.log({
104
115
  title: `Running addition: ${addition.name}`,
105
116
  body: [addition.description],
@@ -119,6 +130,9 @@ export async function runAddition(
119
130
 
120
131
  installNPMDependencies(updatedContext);
121
132
 
133
+ await setFeatureFlag(addition.featureName, true);
134
+ additionsDebug(`Set feature flag '${addition.featureName}' to true in .cprc.json`);
135
+
122
136
  if (shouldCommit) {
123
137
  await gitCommitNoVerify(`chore: add ${addition.name} support via create-plugin`);
124
138
  }
@@ -1,24 +1,36 @@
1
1
  import { argv, commandName } from './utils.cli.js';
2
2
 
3
+ import type { AdditionFeatureName } from '../additions/additions.js';
3
4
  import { CURRENT_APP_VERSION } from './utils.version.js';
4
5
  import { DEFAULT_FEATURE_FLAGS } from '../constants.js';
6
+ import { EOL } from 'node:os';
5
7
  import fs from 'node:fs';
6
8
  import { output } from './utils.console.js';
7
9
  import { partitionArr } from './utils.helpers.js';
8
10
  import path from 'node:path';
9
11
  import { writeFile } from 'node:fs/promises';
10
- import { EOL } from 'node:os';
11
12
 
12
- export type FeatureFlags = {
13
+ type CoreFeatureFlags = {
13
14
  bundleGrafanaUI?: boolean;
14
15
 
15
16
  // If set to true, the plugin will be scaffolded with React Router v6. Defaults to true.
16
17
  // (Attention! We always scaffold new projects with React Router v6, so if you are changing this to `false` manually you will need to make changes to the React code as well.)
17
18
  useReactRouterV6?: boolean;
19
+ usePlaywright?: boolean;
18
20
  useExperimentalRspack?: boolean;
19
21
  useExperimentalUpdates?: boolean;
20
22
  };
21
23
 
24
+ type AdditionFeatureFlags = {
25
+ [K in AdditionFeatureName]?: boolean;
26
+ };
27
+
28
+ export type FeatureFlags = CoreFeatureFlags & AdditionFeatureFlags;
29
+
30
+ export function isFeatureEnabled(features: FeatureFlags, featureName: string): boolean {
31
+ return features[featureName as AdditionFeatureName] === true;
32
+ }
33
+
22
34
  export type CreatePluginConfig = UserConfig & {
23
35
  version: string;
24
36
  };
@@ -132,3 +144,18 @@ export async function setRootConfig(configOverride: Partial<CreatePluginConfig>
132
144
 
133
145
  return updatedConfig;
134
146
  }
147
+
148
+ export async function setFeatureFlag(featureName: string, enabled = true): Promise<void> {
149
+ const userConfig = getUserConfig() || { features: {} };
150
+ const userConfigPath = path.resolve(process.cwd(), '.cprc.json');
151
+
152
+ const updatedConfig = {
153
+ ...userConfig,
154
+ features: {
155
+ ...userConfig.features,
156
+ [featureName]: enabled,
157
+ },
158
+ };
159
+
160
+ await writeFile(userConfigPath, JSON.stringify(updatedConfig, null, 2) + EOL);
161
+ }