@grafana/create-plugin 6.2.0-canary.2233.19097561440.0 → 6.2.0-canary.2283.19173715977.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/CONTRIBUTING.md +3 -0
  3. package/dist/bin/run.js +1 -3
  4. package/dist/commands/update.command.js +1 -1
  5. package/dist/{codemods → migrations}/context.js +2 -3
  6. package/dist/{codemods/migrations → migrations}/manager.js +7 -8
  7. package/dist/{codemods/migrations → migrations}/migrations.js +6 -3
  8. package/dist/{codemods/migrations → migrations}/scripts/003-update-eslint-deprecation-rule.js +1 -1
  9. package/dist/{codemods/migrations → migrations}/scripts/004-eslint9-flat-config.js +1 -2
  10. package/dist/migrations/scripts/005-react-18-3.js +20 -0
  11. package/dist/{codemods → migrations}/utils.js +22 -5
  12. package/dist/utils/utils.config.js +1 -16
  13. package/package.json +2 -2
  14. package/src/bin/run.ts +1 -2
  15. package/src/commands/index.ts +0 -1
  16. package/src/commands/update.command.ts +1 -1
  17. package/src/{codemods → migrations}/context.test.ts +10 -10
  18. package/src/{codemods → migrations}/context.ts +2 -4
  19. package/src/{codemods/migrations → migrations}/manager.test.ts +10 -15
  20. package/src/{codemods/migrations → migrations}/manager.ts +9 -10
  21. package/src/{codemods/migrations → migrations}/migrations.ts +8 -3
  22. package/src/{codemods/migrations → migrations}/scripts/001-update-grafana-compose-extend.test.ts +1 -1
  23. package/src/{codemods/migrations → migrations}/scripts/001-update-grafana-compose-extend.ts +1 -1
  24. package/src/{codemods/migrations → migrations}/scripts/002-update-is-compatible-workflow.test.ts +1 -1
  25. package/src/{codemods/migrations → migrations}/scripts/002-update-is-compatible-workflow.ts +1 -1
  26. package/src/{codemods/migrations → migrations}/scripts/003-update-eslint-deprecation-rule.test.ts +1 -1
  27. package/src/{codemods/migrations → migrations}/scripts/003-update-eslint-deprecation-rule.ts +2 -2
  28. package/src/{codemods/migrations → migrations}/scripts/004-eslint9-flat-config.test.ts +1 -1
  29. package/src/{codemods/migrations → migrations}/scripts/004-eslint9-flat-config.ts +2 -3
  30. package/src/migrations/scripts/005-react-18-3.test.ts +147 -0
  31. package/src/migrations/scripts/005-react-18-3.ts +19 -0
  32. package/src/{codemods/migrations → migrations}/scripts/example-migration.test.ts +1 -1
  33. package/src/{codemods/migrations → migrations}/scripts/example-migration.ts +1 -1
  34. package/src/{codemods/migrations → migrations}/utils.test.ts +4 -4
  35. package/src/{codemods → migrations}/utils.ts +33 -37
  36. package/src/utils/utils.config.ts +1 -28
  37. package/templates/common/_package.json +5 -3
  38. package/templates/github/workflows/cp-update.yml +8 -13
  39. package/dist/codemods/additions/additions.js +0 -11
  40. package/dist/codemods/additions/manager.js +0 -115
  41. package/dist/codemods/additions/scripts/add-i18n.js +0 -445
  42. package/dist/codemods/additions/utils.js +0 -10
  43. package/dist/codemods/migrations/utils.js +0 -10
  44. package/dist/commands/add.command.js +0 -86
  45. package/src/codemods/additions/additions.ts +0 -23
  46. package/src/codemods/additions/manager.ts +0 -145
  47. package/src/codemods/additions/scripts/add-i18n.test.ts +0 -347
  48. package/src/codemods/additions/scripts/add-i18n.ts +0 -584
  49. package/src/codemods/additions/utils.ts +0 -12
  50. package/src/codemods/migrations/utils.ts +0 -12
  51. package/src/codemods/types.ts +0 -21
  52. package/src/commands/add.command.ts +0 -97
  53. /package/dist/{codemods/migrations → migrations}/scripts/001-update-grafana-compose-extend.js +0 -0
  54. /package/dist/{codemods/migrations → migrations}/scripts/002-update-is-compatible-workflow.js +0 -0
  55. /package/dist/{codemods/migrations → migrations}/scripts/example-migration.js +0 -0
  56. /package/src/{codemods/migrations → migrations}/fixtures/foo/bar.ts +0 -0
  57. /package/src/{codemods/migrations → migrations}/fixtures/foo/baz.ts +0 -0
  58. /package/src/{codemods/migrations → migrations}/fixtures/migrations.ts +0 -0
  59. /package/src/{codemods/migrations → migrations}/migrations.test.ts +0 -0
  60. /package/src/{codemods → migrations}/test-utils.ts +0 -0
@@ -1,445 +0,0 @@
1
- import * as recast from 'recast';
2
- import { coerce, gte } from 'semver';
3
- import { parseDocument, stringify } from 'yaml';
4
- import { addDependenciesToPackageJson } from '../../utils.js';
5
- import { additionsDebug } from '../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,10 +0,0 @@
1
- import { debug } from '../../utils/utils.cli.js';
2
- import { printChanges as printChanges$1 } from '../utils.js';
3
-
4
- const additionsDebug = debug.extend("additions");
5
- function printChanges(context, key, addition) {
6
- additionsDebug("printChanges for addition: %s", key);
7
- printChanges$1(context, key, addition);
8
- }
9
-
10
- export { additionsDebug, printChanges };
@@ -1,10 +0,0 @@
1
- import { debug } from '../../utils/utils.cli.js';
2
- import { printChanges as printChanges$1 } from '../utils.js';
3
-
4
- const migrationsDebug = debug.extend("migrations");
5
- function printChanges(context, key, migration) {
6
- migrationsDebug("printChanges for migration: %s", key);
7
- printChanges$1(context, key, migration);
8
- }
9
-
10
- export { migrationsDebug, printChanges };
@@ -1,86 +0,0 @@
1
- import { runAdditionByName, getAvailableAdditions, getAdditionFlags } from '../codemods/additions/manager.js';
2
- import { isGitDirectory, isGitDirectoryClean } from '../utils/utils.git.js';
3
- import { isPluginDirectory } from '../utils/utils.plugin.js';
4
- import { output } from '../utils/utils.console.js';
5
-
6
- const add = async (argv) => {
7
- const subCommand = argv._[1];
8
- if (!subCommand) {
9
- await showAdditionsHelp();
10
- process.exit(1);
11
- }
12
- await performPreAddChecks(argv);
13
- try {
14
- await runAdditionByName(subCommand, argv);
15
- } catch (error) {
16
- if (error instanceof Error) {
17
- output.error({
18
- title: "Addition failed",
19
- body: [error.message]
20
- });
21
- }
22
- process.exit(1);
23
- }
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
- }
51
- async function performPreAddChecks(argv) {
52
- if (!await isGitDirectory() && !argv.force) {
53
- output.error({
54
- title: "You are not inside a git directory",
55
- body: [
56
- `In order to proceed please run ${output.formatCode("git init")} in the root of your project and commit your changes.`,
57
- `(This check is necessary to make sure that the changes are easy to revert and don't interfere with any changes you currently have.`,
58
- `In case you want to proceed as is please use the ${output.formatCode("--force")} flag.)`
59
- ]
60
- });
61
- process.exit(1);
62
- }
63
- if (!await isGitDirectoryClean() && !argv.force) {
64
- output.error({
65
- title: "Please clean your repository working tree before adding features.",
66
- body: [
67
- "Commit your changes or stash them.",
68
- `(This check is necessary to make sure that the changes are easy to revert and don't mess with any changes you currently have.`,
69
- `In case you want to proceed as is please use the ${output.formatCode("--force")} flag.)`
70
- ]
71
- });
72
- process.exit(1);
73
- }
74
- if (!isPluginDirectory() && !argv.force) {
75
- output.error({
76
- title: "Are you inside a plugin directory?",
77
- body: [
78
- `We couldn't find a "src/plugin.json" file under your current directory.`,
79
- `(Please make sure to run this command from the root of your plugin folder. In case you want to proceed as is please use the ${output.formatCode("--force")} flag.)`
80
- ]
81
- });
82
- process.exit(1);
83
- }
84
- }
85
-
86
- export { add };
@@ -1,23 +0,0 @@
1
- export type AdditionMeta<TFeatureName extends string = string> = {
2
- name: string;
3
- description: string;
4
- scriptPath: string;
5
- featureName: TFeatureName;
6
- };
7
-
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
- },
15
- };
16
-
17
- export default { additions };
18
-
19
- // extract feature names for type-safe FeatureFlags in utils.config.ts
20
- type AdditionValues = (typeof additions)[keyof typeof additions];
21
- export type AdditionFeatureName = AdditionValues['featureName'];
22
-
23
- export type TypedAdditionMeta = AdditionMeta<AdditionFeatureName>;