@grafana/create-plugin 6.2.0-canary.2233.18936706437.0 → 6.2.0-canary.2233.18946524692.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.
- package/README.md +0 -39
- package/dist/additions/additions.js +7 -7
- package/dist/additions/manager.js +11 -0
- package/dist/utils/utils.config.js +17 -2
- package/package.json +2 -2
- package/src/additions/additions.ts +15 -8
- package/src/additions/manager.ts +14 -0
- package/src/utils/utils.config.ts +29 -2
package/README.md
CHANGED
|
@@ -122,45 +122,6 @@ For more information see our [documentation](https://grafana.com/developers/plug
|
|
|
122
122
|
|
|
123
123
|
---
|
|
124
124
|
|
|
125
|
-
## Add optional features to your existing plugin
|
|
126
|
-
|
|
127
|
-
You can add optional features to your plugin using the `add` command. This allows you to enhance your plugin with additional capabilities without starting from scratch.
|
|
128
|
-
|
|
129
|
-
### Add internationalization (i18n) support
|
|
130
|
-
|
|
131
|
-
Add translation support to make your plugin available in multiple languages:
|
|
132
|
-
|
|
133
|
-
```bash
|
|
134
|
-
# Run this command from the root of your plugin
|
|
135
|
-
cd ./my-plugin
|
|
136
|
-
|
|
137
|
-
npx @grafana/create-plugin@latest add i18n
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
This will:
|
|
141
|
-
|
|
142
|
-
- Update your `plugin.json` with the selected languages
|
|
143
|
-
- Create locale folders and translation files
|
|
144
|
-
- Add the necessary dependencies to `package.json`
|
|
145
|
-
- Configure your docker-compose.yaml with the required feature toggle
|
|
146
|
-
- Add i18n imports to your module file
|
|
147
|
-
- Set up the i18n extraction script
|
|
148
|
-
|
|
149
|
-
The command will prompt you to select which locales you want to support. You can choose from common locales like:
|
|
150
|
-
|
|
151
|
-
- English (US) - `en-US`
|
|
152
|
-
- Spanish (Spain) - `es-ES`
|
|
153
|
-
- French (France) - `fr-FR`
|
|
154
|
-
- German (Germany) - `de-DE`
|
|
155
|
-
- Swedish (Sweden) - `sv-SE`
|
|
156
|
-
- And more...
|
|
157
|
-
|
|
158
|
-
You can also add custom locale codes during the interactive prompt.
|
|
159
|
-
|
|
160
|
-
For more information about plugin internationalization, see our [documentation](https://grafana.com/developers/plugin-tools/how-to-guides/plugin-internationalization).
|
|
161
|
-
|
|
162
|
-
---
|
|
163
|
-
|
|
164
125
|
## Contributing
|
|
165
126
|
|
|
166
127
|
We are always grateful for contributions! See [CONTRIBUTING.md](../../CONTRIBUTING.md) for more information.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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.
|
|
3
|
+
"version": "6.2.0-canary.2233.18946524692.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": "
|
|
64
|
+
"gitHead": "66533b5a682753ffda37f33a185e8fa2fe2c8383"
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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>;
|
package/src/additions/manager.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
+
}
|