@grafana/create-plugin 6.2.0-canary.2233.18586197736.0 → 6.2.0-canary.2233.18936109308.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/CHANGELOG.md CHANGED
@@ -1,3 +1,67 @@
1
+ # v6.1.5 (Tue Oct 28 2025)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - Create Plugin: Include EOF newline when setting root config [#2246](https://github.com/grafana/plugin-tools/pull/2246) ([@MattIPv4](https://github.com/MattIPv4))
6
+
7
+ #### Authors: 1
8
+
9
+ - Matt Cowley ([@MattIPv4](https://github.com/MattIPv4))
10
+
11
+ ---
12
+
13
+ # v6.1.4 (Fri Oct 24 2025)
14
+
15
+ #### 🐛 Bug Fix
16
+
17
+ - Create Plugin: pin swc/core to 1.13.20 [#2243](https://github.com/grafana/plugin-tools/pull/2243) ([@jackw](https://github.com/jackw))
18
+
19
+ #### Authors: 1
20
+
21
+ - Jack Westbrook ([@jackw](https://github.com/jackw))
22
+
23
+ ---
24
+
25
+ # v6.1.3 (Thu Oct 23 2025)
26
+
27
+ #### 🐛 Bug Fix
28
+
29
+ - Create Plugin: Scaffold workflows with versioned actions [#2234](https://github.com/grafana/plugin-tools/pull/2234) ([@jackw](https://github.com/jackw))
30
+
31
+ #### Authors: 1
32
+
33
+ - Jack Westbrook ([@jackw](https://github.com/jackw))
34
+
35
+ ---
36
+
37
+ # v6.1.2 (Tue Oct 21 2025)
38
+
39
+ #### 🐛 Bug Fix
40
+
41
+ - Create Plugin: Remove cypress support [#2232](https://github.com/grafana/plugin-tools/pull/2232) ([@sunker](https://github.com/sunker))
42
+ - Update dependency @grafana/e2e-selectors to v12.2.0 [#2205](https://github.com/grafana/plugin-tools/pull/2205) ([@renovate[bot]](https://github.com/renovate[bot]) [@leventebalogh](https://github.com/leventebalogh) [@mckn](https://github.com/mckn))
43
+
44
+ #### Authors: 4
45
+
46
+ - [@renovate[bot]](https://github.com/renovate[bot])
47
+ - Erik Sundell ([@sunker](https://github.com/sunker))
48
+ - Levente Balogh ([@leventebalogh](https://github.com/leventebalogh))
49
+ - Marcus Andersson ([@mckn](https://github.com/mckn))
50
+
51
+ ---
52
+
53
+ # v6.1.1 (Wed Oct 15 2025)
54
+
55
+ #### 🐛 Bug Fix
56
+
57
+ - Fix: Use proper install command for legacy plugin migrations [#2221](https://github.com/grafana/plugin-tools/pull/2221) ([@sunker]https://github.com/sunker))
58
+
59
+ #### Authors: 1
60
+
61
+ - Erik Sundell ([@sunker](https://github.com/sunker))
62
+
63
+ ---
64
+
1
65
  # v6.1.0 (Wed Oct 08 2025)
2
66
 
3
67
  #### 🚀 Enhancement
@@ -11,6 +11,63 @@ function getAvailableAdditions(additions = defaultAdditions.additions) {
11
11
  function getAdditionByName(name, additions = defaultAdditions.additions) {
12
12
  return additions[name];
13
13
  }
14
+ async function getAdditionFlags(addition) {
15
+ try {
16
+ const module = await import(addition.scriptPath);
17
+ return module.flags || [];
18
+ } catch (error) {
19
+ return [];
20
+ }
21
+ }
22
+ async function parseAdditionFlags(addition, argv) {
23
+ try {
24
+ const module = await import(addition.scriptPath);
25
+ if (module.parseFlags && typeof module.parseFlags === "function") {
26
+ return module.parseFlags(argv);
27
+ }
28
+ return {};
29
+ } catch (error) {
30
+ return {};
31
+ }
32
+ }
33
+ async function validateAdditionOptions(addition, options) {
34
+ const flags = await getAdditionFlags(addition);
35
+ if (!flags || flags.length === 0) {
36
+ return;
37
+ }
38
+ const missingFlags = [];
39
+ for (const flag of flags) {
40
+ if (flag.required) {
41
+ const value = options[flag.name];
42
+ if (value === void 0 || value === null || Array.isArray(value) && value.length === 0) {
43
+ missingFlags.push(flag.name);
44
+ }
45
+ }
46
+ }
47
+ if (missingFlags.length > 0) {
48
+ const flagDocs = flags.filter((f) => missingFlags.includes(f.name)).map((f) => ` --${f.name}: ${f.description}`);
49
+ throw new Error(
50
+ `Missing required flag${missingFlags.length > 1 ? "s" : ""}:
51
+
52
+ ` + flagDocs.join("\n") + `
53
+
54
+ Example: npx @grafana/create-plugin add ${addition.name} --${missingFlags[0]}=value`
55
+ );
56
+ }
57
+ }
58
+ async function runAdditionByName(additionName, argv, runOptions = {}) {
59
+ const addition = getAdditionByName(additionName);
60
+ if (!addition) {
61
+ const availableAdditions = getAvailableAdditions();
62
+ const additionsList = Object.keys(availableAdditions);
63
+ throw new Error(`Unknown addition: ${additionName}
64
+
65
+ Available additions: ${additionsList.join(", ")}`);
66
+ }
67
+ const options = await parseAdditionFlags(addition, argv);
68
+ await validateAdditionOptions(addition, options);
69
+ await runAddition(addition, options, runOptions);
70
+ }
14
71
  async function runAddition(addition, additionOptions = {}, runOptions = {}) {
15
72
  const basePath = process.cwd();
16
73
  output.log({
@@ -45,4 +102,4 @@ async function executeAddition(addition, context, options = {}) {
45
102
  return module.default(context, options);
46
103
  }
47
104
 
48
- export { executeAddition, getAdditionByName, getAvailableAdditions, runAddition };
105
+ export { executeAddition, getAdditionByName, getAdditionFlags, getAvailableAdditions, parseAdditionFlags, runAddition, runAdditionByName };
@@ -0,0 +1,445 @@
1
+ import * as recast from 'recast';
2
+ import { additionsDebug } from '../utils.js';
3
+ import { coerce, gte } from 'semver';
4
+ import { parseDocument, stringify } from 'yaml';
5
+ import { addDependenciesToPackageJson } from '../../migrations/utils.js';
6
+
7
+ const { builders } = recast.types;
8
+ const flags = [
9
+ {
10
+ name: "locales",
11
+ description: "Comma-separated list of locales (e.g., en-US,es-ES)",
12
+ required: true
13
+ }
14
+ ];
15
+ function parseFlags(argv) {
16
+ return {
17
+ locales: argv.locales ? argv.locales.split(",").map((l) => l.trim()) : []
18
+ };
19
+ }
20
+ function migrate(context, options = { locales: ["en-US"] }) {
21
+ const { locales } = options;
22
+ additionsDebug("Adding i18n support with locales:", locales);
23
+ if (isI18nConfigured(context)) {
24
+ additionsDebug("i18n already configured, skipping");
25
+ return context;
26
+ }
27
+ const needsBackwardCompatibility = checkNeedsBackwardCompatibility(context);
28
+ additionsDebug("Needs backward compatibility:", needsBackwardCompatibility);
29
+ if (!needsBackwardCompatibility) {
30
+ updateDockerCompose(context);
31
+ }
32
+ updatePluginJson(context, locales, needsBackwardCompatibility);
33
+ createLocaleFiles(context, locales);
34
+ addI18nDependency(context);
35
+ if (needsBackwardCompatibility) {
36
+ addSemverDependency(context);
37
+ }
38
+ updateEslintConfig(context);
39
+ addI18nInitialization(context, needsBackwardCompatibility);
40
+ if (needsBackwardCompatibility) {
41
+ createLoadResourcesFile(context);
42
+ }
43
+ addI18nextCli(context);
44
+ createI18nextConfig(context);
45
+ return context;
46
+ }
47
+ function isI18nConfigured(context) {
48
+ if (!context.doesFileExist("src/plugin.json")) {
49
+ return false;
50
+ }
51
+ const pluginJsonRaw = context.getFile("src/plugin.json");
52
+ if (!pluginJsonRaw) {
53
+ return false;
54
+ }
55
+ try {
56
+ const pluginJson = JSON.parse(pluginJsonRaw);
57
+ if (pluginJson.languages && Array.isArray(pluginJson.languages) && pluginJson.languages.length > 0) {
58
+ additionsDebug("Found languages in plugin.json, i18n already configured");
59
+ return true;
60
+ }
61
+ } catch (error) {
62
+ additionsDebug("Error parsing plugin.json:", error);
63
+ }
64
+ return false;
65
+ }
66
+ function checkNeedsBackwardCompatibility(context) {
67
+ const pluginJsonRaw = context.getFile("src/plugin.json");
68
+ if (!pluginJsonRaw) {
69
+ return false;
70
+ }
71
+ try {
72
+ const pluginJson = JSON.parse(pluginJsonRaw);
73
+ const currentGrafanaDep = pluginJson.dependencies?.grafanaDependency || ">=11.0.0";
74
+ const minVersion = coerce("12.1.0");
75
+ const currentVersion = coerce(currentGrafanaDep.replace(/^[><=]+/, ""));
76
+ if (currentVersion && minVersion && gte(currentVersion, minVersion)) {
77
+ return false;
78
+ }
79
+ return true;
80
+ } catch (error) {
81
+ additionsDebug("Error checking backward compatibility:", error);
82
+ return true;
83
+ }
84
+ }
85
+ function updateDockerCompose(context) {
86
+ if (!context.doesFileExist("docker-compose.yaml")) {
87
+ additionsDebug("docker-compose.yaml not found, skipping");
88
+ return;
89
+ }
90
+ const composeContent = context.getFile("docker-compose.yaml");
91
+ if (!composeContent) {
92
+ return;
93
+ }
94
+ try {
95
+ const composeDoc = parseDocument(composeContent);
96
+ const currentEnv = composeDoc.getIn(["services", "grafana", "environment"]);
97
+ if (!currentEnv) {
98
+ additionsDebug("No environment section found in docker-compose.yaml, skipping");
99
+ return;
100
+ }
101
+ if (typeof currentEnv === "object") {
102
+ const envMap = currentEnv;
103
+ const toggleValue = envMap.get("GF_FEATURE_TOGGLES_ENABLE");
104
+ if (toggleValue) {
105
+ const toggleStr = toggleValue.toString();
106
+ if (toggleStr.includes("localizationForPlugins")) {
107
+ additionsDebug("localizationForPlugins already in GF_FEATURE_TOGGLES_ENABLE");
108
+ return;
109
+ }
110
+ composeDoc.setIn(
111
+ ["services", "grafana", "environment", "GF_FEATURE_TOGGLES_ENABLE"],
112
+ `${toggleStr},localizationForPlugins`
113
+ );
114
+ } else {
115
+ composeDoc.setIn(["services", "grafana", "environment", "GF_FEATURE_TOGGLES_ENABLE"], "localizationForPlugins");
116
+ }
117
+ context.updateFile("docker-compose.yaml", stringify(composeDoc));
118
+ additionsDebug("Updated docker-compose.yaml with localizationForPlugins feature toggle");
119
+ }
120
+ } catch (error) {
121
+ additionsDebug("Error updating docker-compose.yaml:", error);
122
+ }
123
+ }
124
+ function updatePluginJson(context, locales, needsBackwardCompatibility) {
125
+ if (!context.doesFileExist("src/plugin.json")) {
126
+ additionsDebug("src/plugin.json not found, skipping");
127
+ return;
128
+ }
129
+ const pluginJsonRaw = context.getFile("src/plugin.json");
130
+ if (!pluginJsonRaw) {
131
+ return;
132
+ }
133
+ try {
134
+ const pluginJson = JSON.parse(pluginJsonRaw);
135
+ pluginJson.languages = locales;
136
+ if (!pluginJson.dependencies) {
137
+ pluginJson.dependencies = {};
138
+ }
139
+ const currentGrafanaDep = pluginJson.dependencies.grafanaDependency || ">=11.0.0";
140
+ const targetVersion = needsBackwardCompatibility ? "11.0.0" : "12.1.0";
141
+ const minVersion = coerce(targetVersion);
142
+ const currentVersion = coerce(currentGrafanaDep.replace(/^[><=]+/, ""));
143
+ if (!currentVersion || !minVersion || !gte(currentVersion, minVersion)) {
144
+ pluginJson.dependencies.grafanaDependency = `>=${targetVersion}`;
145
+ additionsDebug(`Updated grafanaDependency to >=${targetVersion}`);
146
+ }
147
+ context.updateFile("src/plugin.json", JSON.stringify(pluginJson, null, 2));
148
+ additionsDebug("Updated src/plugin.json with languages:", locales);
149
+ } catch (error) {
150
+ additionsDebug("Error updating src/plugin.json:", error);
151
+ }
152
+ }
153
+ function createLocaleFiles(context, locales) {
154
+ const pluginJsonRaw = context.getFile("src/plugin.json");
155
+ if (!pluginJsonRaw) {
156
+ additionsDebug("Cannot create locale files without plugin.json");
157
+ return;
158
+ }
159
+ try {
160
+ const pluginJson = JSON.parse(pluginJsonRaw);
161
+ const pluginId = pluginJson.id;
162
+ const pluginName = pluginJson.name || pluginId;
163
+ if (!pluginId) {
164
+ additionsDebug("No plugin ID found in plugin.json");
165
+ return;
166
+ }
167
+ const exampleTranslations = {
168
+ components: {
169
+ exampleComponent: {
170
+ title: `${pluginName} component title`,
171
+ description: "Example description"
172
+ }
173
+ },
174
+ config: {
175
+ title: `${pluginName} configuration`,
176
+ apiUrl: {
177
+ label: "API URL",
178
+ placeholder: "Enter API URL"
179
+ }
180
+ }
181
+ };
182
+ for (const locale of locales) {
183
+ const localePath = `src/locales/${locale}/${pluginId}.json`;
184
+ if (!context.doesFileExist(localePath)) {
185
+ context.addFile(localePath, JSON.stringify(exampleTranslations, null, 2));
186
+ additionsDebug(`Created ${localePath} with example translations`);
187
+ }
188
+ }
189
+ } catch (error) {
190
+ additionsDebug("Error creating locale files:", error);
191
+ }
192
+ }
193
+ function addI18nDependency(context) {
194
+ addDependenciesToPackageJson(context, { "@grafana/i18n": "12.2.2" }, {});
195
+ additionsDebug("Added @grafana/i18n dependency version 12.2.2");
196
+ }
197
+ function addSemverDependency(context) {
198
+ addDependenciesToPackageJson(context, { semver: "^7.6.0" }, { "@types/semver": "^7.5.0" });
199
+ additionsDebug("Added semver dependency for backward compatibility");
200
+ }
201
+ function addI18nextCli(context) {
202
+ addDependenciesToPackageJson(context, {}, { "i18next-cli": "^1.1.1" });
203
+ const packageJsonRaw = context.getFile("package.json");
204
+ if (!packageJsonRaw) {
205
+ return;
206
+ }
207
+ try {
208
+ const packageJson = JSON.parse(packageJsonRaw);
209
+ if (!packageJson.scripts) {
210
+ packageJson.scripts = {};
211
+ }
212
+ if (!packageJson.scripts["i18n-extract"]) {
213
+ packageJson.scripts["i18n-extract"] = "i18next-cli extract --sync-primary";
214
+ context.updateFile("package.json", JSON.stringify(packageJson, null, 2));
215
+ additionsDebug("Added i18n-extract script to package.json");
216
+ }
217
+ } catch (error) {
218
+ additionsDebug("Error adding i18n-extract script:", error);
219
+ }
220
+ }
221
+ function updateEslintConfig(context) {
222
+ if (!context.doesFileExist("eslint.config.mjs")) {
223
+ additionsDebug("eslint.config.mjs not found, skipping");
224
+ return;
225
+ }
226
+ const eslintConfigRaw = context.getFile("eslint.config.mjs");
227
+ if (!eslintConfigRaw) {
228
+ return;
229
+ }
230
+ if (eslintConfigRaw.includes("@grafana/eslint-plugin-plugins")) {
231
+ additionsDebug("ESLint i18n rule already configured");
232
+ return;
233
+ }
234
+ try {
235
+ const ast = recast.parse(eslintConfigRaw, {
236
+ parser: require("recast/parsers/babel-ts")
237
+ });
238
+ const imports = ast.program.body.filter((node) => node.type === "ImportDeclaration");
239
+ const lastImport = imports[imports.length - 1];
240
+ if (lastImport) {
241
+ const pluginImport = builders.importDeclaration(
242
+ [builders.importDefaultSpecifier(builders.identifier("grafanaPluginsPlugin"))],
243
+ builders.literal("@grafana/eslint-plugin-plugins")
244
+ );
245
+ const lastImportIndex = ast.program.body.indexOf(lastImport);
246
+ ast.program.body.splice(lastImportIndex + 1, 0, pluginImport);
247
+ }
248
+ recast.visit(ast, {
249
+ visitCallExpression(path) {
250
+ if (path.node.callee.name === "defineConfig" && path.node.arguments[0]?.type === "ArrayExpression") {
251
+ const configArray = path.node.arguments[0];
252
+ const pluginsConfig = builders.objectExpression([
253
+ builders.property(
254
+ "init",
255
+ builders.identifier("plugins"),
256
+ builders.objectExpression([
257
+ builders.property(
258
+ "init",
259
+ builders.literal("grafanaPlugins"),
260
+ builders.identifier("grafanaPluginsPlugin")
261
+ )
262
+ ])
263
+ ),
264
+ builders.property(
265
+ "init",
266
+ builders.identifier("rules"),
267
+ builders.objectExpression([
268
+ builders.property(
269
+ "init",
270
+ builders.literal("grafanaPlugins/no-untranslated-strings"),
271
+ builders.literal("warn")
272
+ )
273
+ ])
274
+ )
275
+ ]);
276
+ configArray.elements.push(pluginsConfig);
277
+ }
278
+ this.traverse(path);
279
+ }
280
+ });
281
+ const output = recast.print(ast, {
282
+ tabWidth: 2,
283
+ trailingComma: true,
284
+ lineTerminator: "\n"
285
+ }).code;
286
+ context.updateFile("eslint.config.mjs", output);
287
+ additionsDebug("Updated eslint.config.mjs with i18n linting rules");
288
+ } catch (error) {
289
+ additionsDebug("Error updating eslint.config.mjs:", error);
290
+ }
291
+ }
292
+ function createI18nextConfig(context) {
293
+ if (context.doesFileExist("i18next.config.ts")) {
294
+ additionsDebug("i18next.config.ts already exists, skipping");
295
+ return;
296
+ }
297
+ const pluginJsonRaw = context.getFile("src/plugin.json");
298
+ if (!pluginJsonRaw) {
299
+ additionsDebug("Cannot create i18next.config.ts without plugin.json");
300
+ return;
301
+ }
302
+ try {
303
+ const pluginJson = JSON.parse(pluginJsonRaw);
304
+ const pluginId = pluginJson.id;
305
+ if (!pluginId) {
306
+ additionsDebug("No plugin ID found in plugin.json");
307
+ return;
308
+ }
309
+ const i18nextConfig = `import { defineConfig } from 'i18next-cli';
310
+ import pluginJson from './src/plugin.json';
311
+
312
+ export default defineConfig({
313
+ locales: pluginJson.languages,
314
+ extract: {
315
+ input: ['src/**/*.{tsx,ts}'],
316
+ output: 'src/locales/{{language}}/{{namespace}}.json',
317
+ defaultNS: pluginJson.id,
318
+ functions: ['t', '*.t'],
319
+ transComponents: ['Trans'],
320
+ },
321
+ });
322
+ `;
323
+ context.addFile("i18next.config.ts", i18nextConfig);
324
+ additionsDebug("Created i18next.config.ts");
325
+ } catch (error) {
326
+ additionsDebug("Error creating i18next.config.ts:", error);
327
+ }
328
+ }
329
+ function addI18nInitialization(context, needsBackwardCompatibility) {
330
+ const moduleTsPath = context.doesFileExist("src/module.ts") ? "src/module.ts" : context.doesFileExist("src/module.tsx") ? "src/module.tsx" : null;
331
+ if (!moduleTsPath) {
332
+ additionsDebug("No module.ts or module.tsx found, skipping i18n initialization");
333
+ return;
334
+ }
335
+ const moduleContent = context.getFile(moduleTsPath);
336
+ if (!moduleContent) {
337
+ return;
338
+ }
339
+ if (moduleContent.includes("initPluginTranslations")) {
340
+ additionsDebug("i18n already initialized in module file");
341
+ return;
342
+ }
343
+ try {
344
+ const ast = recast.parse(moduleContent, {
345
+ parser: require("recast/parsers/babel-ts")
346
+ });
347
+ const imports = [];
348
+ imports.push(
349
+ builders.importDeclaration(
350
+ [builders.importSpecifier(builders.identifier("initPluginTranslations"))],
351
+ builders.literal("@grafana/i18n")
352
+ )
353
+ );
354
+ imports.push(
355
+ builders.importDeclaration(
356
+ [builders.importDefaultSpecifier(builders.identifier("pluginJson"))],
357
+ builders.literal("plugin.json")
358
+ )
359
+ );
360
+ if (needsBackwardCompatibility) {
361
+ imports.push(
362
+ builders.importDeclaration(
363
+ [builders.importSpecifier(builders.identifier("config"))],
364
+ builders.literal("@grafana/runtime")
365
+ )
366
+ );
367
+ imports.push(
368
+ builders.importDeclaration(
369
+ [builders.importDefaultSpecifier(builders.identifier("semver"))],
370
+ builders.literal("semver")
371
+ )
372
+ );
373
+ imports.push(
374
+ builders.importDeclaration(
375
+ [builders.importSpecifier(builders.identifier("loadResources"))],
376
+ builders.literal("./loadResources")
377
+ )
378
+ );
379
+ }
380
+ const firstImportIndex = ast.program.body.findIndex((node) => node.type === "ImportDeclaration");
381
+ if (firstImportIndex !== -1) {
382
+ ast.program.body.splice(firstImportIndex + 1, 0, ...imports);
383
+ } else {
384
+ ast.program.body.unshift(...imports);
385
+ }
386
+ const i18nInitCode = needsBackwardCompatibility ? `// Before Grafana version 12.1.0 the plugin is responsible for loading translation resources
387
+ // In Grafana version 12.1.0 and later Grafana is responsible for loading translation resources
388
+ const loaders = semver.lt(config?.buildInfo?.version, '12.1.0') ? [loadResources] : [];
389
+
390
+ await initPluginTranslations(pluginJson.id, loaders);` : `await initPluginTranslations(pluginJson.id);`;
391
+ const initAst = recast.parse(i18nInitCode, {
392
+ parser: require("recast/parsers/babel-ts")
393
+ });
394
+ const lastImportIndex = ast.program.body.findLastIndex((node) => node.type === "ImportDeclaration");
395
+ if (lastImportIndex !== -1) {
396
+ ast.program.body.splice(lastImportIndex + 1, 0, ...initAst.program.body);
397
+ } else {
398
+ ast.program.body.unshift(...initAst.program.body);
399
+ }
400
+ const output = recast.print(ast, {
401
+ tabWidth: 2,
402
+ trailingComma: true,
403
+ lineTerminator: "\n"
404
+ }).code;
405
+ context.updateFile(moduleTsPath, output);
406
+ additionsDebug(`Updated ${moduleTsPath} with i18n initialization`);
407
+ } catch (error) {
408
+ additionsDebug("Error updating module file:", error);
409
+ }
410
+ }
411
+ function createLoadResourcesFile(context) {
412
+ const loadResourcesPath = "src/loadResources.ts";
413
+ if (context.doesFileExist(loadResourcesPath)) {
414
+ additionsDebug("loadResources.ts already exists, skipping");
415
+ return;
416
+ }
417
+ const pluginJsonRaw = context.getFile("src/plugin.json");
418
+ if (!pluginJsonRaw) {
419
+ additionsDebug("Cannot create loadResources.ts without plugin.json");
420
+ return;
421
+ }
422
+ const loadResourcesContent = `import { LANGUAGES, ResourceLoader, Resources } from '@grafana/i18n';
423
+ import pluginJson from 'plugin.json';
424
+
425
+ const resources = LANGUAGES.reduce<Record<string, () => Promise<{ default: Resources }>>>((acc, lang) => {
426
+ acc[lang.code] = async () => await import(\`./locales/\${lang.code}/\${pluginJson.id}.json\`);
427
+ return acc;
428
+ }, {});
429
+
430
+ export const loadResources: ResourceLoader = async (resolvedLanguage: string) => {
431
+ try {
432
+ const translation = await resources[resolvedLanguage]();
433
+ return translation.default;
434
+ } catch (error) {
435
+ // This makes sure that the plugin doesn't crash when the resolved language in Grafana isn't supported by the plugin
436
+ console.error(\`The plugin '\${pluginJson.id}' doesn't support the language '\${resolvedLanguage}'\`, error);
437
+ return {};
438
+ }
439
+ };
440
+ `;
441
+ context.addFile(loadResourcesPath, loadResourcesContent);
442
+ additionsDebug("Created src/loadResources.ts for backward compatibility");
443
+ }
444
+
445
+ export { migrate as default, flags, parseFlags };
@@ -1,49 +1,17 @@
1
- import { getAvailableAdditions, getAdditionByName, runAddition } from '../additions/manager.js';
1
+ import { runAdditionByName, getAvailableAdditions, getAdditionFlags } from '../additions/manager.js';
2
2
  import { isGitDirectory, isGitDirectoryClean } from '../utils/utils.git.js';
3
3
  import { isPluginDirectory } from '../utils/utils.plugin.js';
4
4
  import { output } from '../utils/utils.console.js';
5
- import { promptI18nOptions } from './add/prompts.js';
6
5
 
7
6
  const add = async (argv) => {
8
7
  const subCommand = argv._[1];
9
8
  if (!subCommand) {
10
- const availableAdditions = getAvailableAdditions();
11
- const additionsList = Object.values(availableAdditions).map(
12
- (addition2) => `${addition2.name} - ${addition2.description}`
13
- );
14
- output.error({
15
- title: "No addition specified",
16
- body: [
17
- "Usage: npx @grafana/create-plugin add <addition-name>",
18
- "",
19
- "Available additions:",
20
- ...output.bulletList(additionsList)
21
- ]
22
- });
9
+ await showAdditionsHelp();
23
10
  process.exit(1);
24
11
  }
25
12
  await performPreAddChecks(argv);
26
- const addition = getAdditionByName(subCommand);
27
- if (!addition) {
28
- const availableAdditions = getAvailableAdditions();
29
- const additionsList = Object.values(availableAdditions).map((addition2) => addition2.name);
30
- output.error({
31
- title: `Unknown addition: ${subCommand}`,
32
- body: ["Available additions:", ...output.bulletList(additionsList)]
33
- });
34
- process.exit(1);
35
- }
36
13
  try {
37
- let options = {};
38
- switch (addition.name) {
39
- case "i18n":
40
- options = await promptI18nOptions();
41
- break;
42
- default:
43
- break;
44
- }
45
- const commitChanges = argv.commit;
46
- await runAddition(addition, options, { commitChanges });
14
+ await runAdditionByName(subCommand, argv, { commitChanges: argv.commit });
47
15
  } catch (error) {
48
16
  if (error instanceof Error) {
49
17
  output.error({
@@ -54,6 +22,32 @@ const add = async (argv) => {
54
22
  process.exit(1);
55
23
  }
56
24
  };
25
+ async function showAdditionsHelp() {
26
+ const availableAdditions = getAvailableAdditions();
27
+ const additionsList = await Promise.all(
28
+ Object.values(availableAdditions).map(async (addition) => {
29
+ let info = `${addition.name} - ${addition.description}`;
30
+ const flags = await getAdditionFlags(addition);
31
+ if (flags.length > 0) {
32
+ const flagDocs = flags.map((flag) => {
33
+ const req = flag.required ? " (required)" : " (optional)";
34
+ return ` --${flag.name}: ${flag.description}${req}`;
35
+ });
36
+ info += "\n" + flagDocs.join("\n");
37
+ }
38
+ return info;
39
+ })
40
+ );
41
+ output.error({
42
+ title: "No addition specified",
43
+ body: [
44
+ "Usage: npx @grafana/create-plugin add <addition-name> [options]",
45
+ "",
46
+ "Available additions:",
47
+ ...output.bulletList(additionsList)
48
+ ]
49
+ });
50
+ }
57
51
  async function performPreAddChecks(argv) {
58
52
  if (!await isGitDirectory() && !argv.force) {
59
53
  output.error({
package/dist/constants.js CHANGED
@@ -1,5 +1,5 @@
1
- import path from 'node:path';
2
1
  import { fileURLToPath } from 'node:url';
2
+ import path from 'node:path';
3
3
 
4
4
  const __dirname = fileURLToPath(new URL(".", import.meta.url));
5
5
  const IS_DEV = process.env.CREATE_PLUGIN_DEV !== void 0;
@@ -32,18 +32,10 @@ const EXTRA_TEMPLATE_VARIABLES = {
32
32
  const DEFAULT_FEATURE_FLAGS = {
33
33
  useReactRouterV6: true,
34
34
  bundleGrafanaUI: false,
35
- usePlaywright: true,
36
35
  useExperimentalRspack: false,
37
36
  useExperimentalUpdates: true
38
37
  };
39
- const GRAFANA_FE_PACKAGES = [
40
- "@grafana/data",
41
- "@grafana/e2e-selectors",
42
- "@grafana/e2e",
43
- "@grafana/runtime",
44
- "@grafana/schema",
45
- "@grafana/ui"
46
- ];
38
+ const GRAFANA_FE_PACKAGES = ["@grafana/data", "@grafana/runtime", "@grafana/schema", "@grafana/ui"];
47
39
  const MIGRATION_CONFIG = {
48
40
  // Files that should be overriden during a migration.
49
41
  // (paths are relative to the scaffolded projects root)