@grafana/create-plugin 6.4.4 → 6.5.0-canary.2320.20231018478.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.
@@ -3,6 +3,11 @@ var defaultAdditions = [
3
3
  name: "example-addition",
4
4
  description: "Adds an example addition to the plugin",
5
5
  scriptPath: import.meta.resolve("./scripts/example-addition.js")
6
+ },
7
+ {
8
+ name: "i18n",
9
+ description: "Adds internationalization (i18n) support to the plugin",
10
+ scriptPath: import.meta.resolve("./scripts/i18n/index.js")
6
11
  }
7
12
  ];
8
13
 
@@ -0,0 +1,122 @@
1
+ import * as recast from 'recast';
2
+ import * as babelParser from 'recast/parsers/babel-ts.js';
3
+ import { additionsDebug } from '../../../utils.js';
4
+
5
+ const { builders } = recast.types;
6
+ function addI18nInitialization(context, needsBackwardCompatibility) {
7
+ const moduleTsPath = context.doesFileExist("src/module.ts") ? "src/module.ts" : context.doesFileExist("src/module.tsx") ? "src/module.tsx" : null;
8
+ if (!moduleTsPath) {
9
+ additionsDebug("No module.ts or module.tsx found, skipping i18n initialization");
10
+ return;
11
+ }
12
+ const moduleContent = context.getFile(moduleTsPath);
13
+ if (!moduleContent) {
14
+ return;
15
+ }
16
+ if (moduleContent.includes("initPluginTranslations")) {
17
+ additionsDebug("i18n already initialized in module file");
18
+ return;
19
+ }
20
+ try {
21
+ const ast = recast.parse(moduleContent, {
22
+ parser: babelParser
23
+ });
24
+ const imports = [];
25
+ imports.push(
26
+ builders.importDeclaration(
27
+ [builders.importSpecifier(builders.identifier("initPluginTranslations"))],
28
+ builders.literal("@grafana/i18n")
29
+ )
30
+ );
31
+ imports.push(
32
+ builders.importDeclaration(
33
+ [builders.importDefaultSpecifier(builders.identifier("pluginJson"))],
34
+ builders.literal("plugin.json")
35
+ )
36
+ );
37
+ if (needsBackwardCompatibility) {
38
+ imports.push(
39
+ builders.importDeclaration(
40
+ [builders.importSpecifier(builders.identifier("config"))],
41
+ builders.literal("@grafana/runtime")
42
+ )
43
+ );
44
+ imports.push(
45
+ builders.importDeclaration(
46
+ [builders.importDefaultSpecifier(builders.identifier("semver"))],
47
+ builders.literal("semver")
48
+ )
49
+ );
50
+ imports.push(
51
+ builders.importDeclaration(
52
+ [builders.importSpecifier(builders.identifier("loadResources"))],
53
+ builders.literal("./loadResources")
54
+ )
55
+ );
56
+ }
57
+ const firstImportIndex = ast.program.body.findIndex((node) => node.type === "ImportDeclaration");
58
+ if (firstImportIndex !== -1) {
59
+ ast.program.body.splice(firstImportIndex + 1, 0, ...imports);
60
+ } else {
61
+ ast.program.body.unshift(...imports);
62
+ }
63
+ const i18nInitCode = needsBackwardCompatibility ? `// Before Grafana version 12.1.0 the plugin is responsible for loading translation resources
64
+ // In Grafana version 12.1.0 and later Grafana is responsible for loading translation resources
65
+ const loaders = semver.lt(config?.buildInfo?.version, '12.1.0') ? [loadResources] : [];
66
+
67
+ await initPluginTranslations(pluginJson.id, loaders);` : `await initPluginTranslations(pluginJson.id);`;
68
+ const initAst = recast.parse(i18nInitCode, {
69
+ parser: babelParser
70
+ });
71
+ const lastImportIndex = ast.program.body.findLastIndex((node) => node.type === "ImportDeclaration");
72
+ if (lastImportIndex !== -1) {
73
+ ast.program.body.splice(lastImportIndex + 1, 0, ...initAst.program.body);
74
+ } else {
75
+ ast.program.body.unshift(...initAst.program.body);
76
+ }
77
+ const output = recast.print(ast, {
78
+ tabWidth: 2,
79
+ trailingComma: true,
80
+ lineTerminator: "\n"
81
+ }).code;
82
+ context.updateFile(moduleTsPath, output);
83
+ additionsDebug(`Updated ${moduleTsPath} with i18n initialization`);
84
+ } catch (error) {
85
+ additionsDebug("Error updating module file:", error);
86
+ }
87
+ }
88
+ function createLoadResourcesFile(context) {
89
+ const loadResourcesPath = "src/loadResources.ts";
90
+ if (context.doesFileExist(loadResourcesPath)) {
91
+ additionsDebug("loadResources.ts already exists, skipping");
92
+ return;
93
+ }
94
+ const pluginJsonRaw = context.getFile("src/plugin.json");
95
+ if (!pluginJsonRaw) {
96
+ additionsDebug("Cannot create loadResources.ts without plugin.json");
97
+ return;
98
+ }
99
+ const loadResourcesContent = `import { LANGUAGES, ResourceLoader, Resources } from '@grafana/i18n';
100
+ import pluginJson from 'plugin.json';
101
+
102
+ const resources = LANGUAGES.reduce<Record<string, () => Promise<{ default: Resources }>>>((acc, lang) => {
103
+ acc[lang.code] = async () => await import(\`./locales/\${lang.code}/\${pluginJson.id}.json\`);
104
+ return acc;
105
+ }, {});
106
+
107
+ export const loadResources: ResourceLoader = async (resolvedLanguage: string) => {
108
+ try {
109
+ const translation = await resources[resolvedLanguage]();
110
+ return translation.default;
111
+ } catch (error) {
112
+ // This makes sure that the plugin doesn't crash when the resolved language in Grafana isn't supported by the plugin
113
+ console.error(\`The plugin '\${pluginJson.id}' doesn't support the language '\${resolvedLanguage}'\`, error);
114
+ return {};
115
+ }
116
+ };
117
+ `;
118
+ context.addFile(loadResourcesPath, loadResourcesContent);
119
+ additionsDebug("Created src/loadResources.ts for backward compatibility");
120
+ }
121
+
122
+ export { addI18nInitialization, createLoadResourcesFile };
@@ -0,0 +1,270 @@
1
+ import { coerce, gte } from 'semver';
2
+ import { parseDocument, stringify } from 'yaml';
3
+ import * as recast from 'recast';
4
+ import * as typeScriptParser from 'recast/parsers/typescript.js';
5
+ import { additionsDebug } from '../../../utils.js';
6
+
7
+ const { builders } = recast.types;
8
+ function updateDockerCompose(context) {
9
+ if (!context.doesFileExist("docker-compose.yaml")) {
10
+ additionsDebug("docker-compose.yaml not found, skipping");
11
+ return;
12
+ }
13
+ const composeContent = context.getFile("docker-compose.yaml");
14
+ if (!composeContent) {
15
+ return;
16
+ }
17
+ try {
18
+ const composeDoc = parseDocument(composeContent);
19
+ const currentEnv = composeDoc.getIn(["services", "grafana", "environment"]);
20
+ if (!currentEnv) {
21
+ additionsDebug("No environment section found in docker-compose.yaml, skipping");
22
+ return;
23
+ }
24
+ if (typeof currentEnv === "object") {
25
+ const envMap = currentEnv;
26
+ const toggleValue = envMap.get("GF_FEATURE_TOGGLES_ENABLE");
27
+ if (toggleValue) {
28
+ const toggleStr = toggleValue.toString();
29
+ if (toggleStr.includes("localizationForPlugins")) {
30
+ additionsDebug("localizationForPlugins already in GF_FEATURE_TOGGLES_ENABLE");
31
+ return;
32
+ }
33
+ composeDoc.setIn(
34
+ ["services", "grafana", "environment", "GF_FEATURE_TOGGLES_ENABLE"],
35
+ `${toggleStr},localizationForPlugins`
36
+ );
37
+ } else {
38
+ composeDoc.setIn(["services", "grafana", "environment", "GF_FEATURE_TOGGLES_ENABLE"], "localizationForPlugins");
39
+ }
40
+ context.updateFile("docker-compose.yaml", stringify(composeDoc));
41
+ additionsDebug("Updated docker-compose.yaml with localizationForPlugins feature toggle");
42
+ }
43
+ } catch (error) {
44
+ additionsDebug("Error updating docker-compose.yaml:", error);
45
+ }
46
+ }
47
+ function updatePluginJson(context, locales, needsBackwardCompatibility) {
48
+ if (!context.doesFileExist("src/plugin.json")) {
49
+ additionsDebug("src/plugin.json not found, skipping");
50
+ return;
51
+ }
52
+ const pluginJsonRaw = context.getFile("src/plugin.json");
53
+ if (!pluginJsonRaw) {
54
+ return;
55
+ }
56
+ try {
57
+ const pluginJson = JSON.parse(pluginJsonRaw);
58
+ const existingLanguages = Array.isArray(pluginJson.languages) ? pluginJson.languages : [];
59
+ const mergedLanguages = [.../* @__PURE__ */ new Set([...existingLanguages, ...locales])];
60
+ pluginJson.languages = mergedLanguages;
61
+ if (!pluginJson.dependencies) {
62
+ pluginJson.dependencies = {};
63
+ }
64
+ const currentGrafanaDep = pluginJson.dependencies.grafanaDependency || ">=11.0.0";
65
+ const targetVersion = needsBackwardCompatibility ? "11.0.0" : "12.1.0";
66
+ const minVersion = coerce(targetVersion);
67
+ const currentVersion = coerce(currentGrafanaDep.replace(/^[><=]+/, ""));
68
+ if (!currentVersion || !minVersion || !gte(currentVersion, minVersion)) {
69
+ pluginJson.dependencies.grafanaDependency = `>=${targetVersion}`;
70
+ additionsDebug(`Updated grafanaDependency to >=${targetVersion}`);
71
+ }
72
+ context.updateFile("src/plugin.json", JSON.stringify(pluginJson, null, 2));
73
+ additionsDebug("Updated src/plugin.json with languages:", locales);
74
+ } catch (error) {
75
+ additionsDebug("Error updating src/plugin.json:", error);
76
+ }
77
+ }
78
+ function createI18nextConfig(context) {
79
+ if (context.doesFileExist("i18next.config.ts")) {
80
+ additionsDebug("i18next.config.ts already exists, skipping");
81
+ return;
82
+ }
83
+ const pluginJsonRaw = context.getFile("src/plugin.json");
84
+ if (!pluginJsonRaw) {
85
+ additionsDebug("Cannot create i18next.config.ts without plugin.json");
86
+ return;
87
+ }
88
+ try {
89
+ const pluginJson = JSON.parse(pluginJsonRaw);
90
+ const pluginId = pluginJson.id;
91
+ if (!pluginId) {
92
+ additionsDebug("No plugin ID found in plugin.json");
93
+ return;
94
+ }
95
+ const i18nextConfig = `import { defineConfig } from 'i18next-cli';
96
+ import pluginJson from './src/plugin.json';
97
+
98
+ export default defineConfig({
99
+ locales: pluginJson.languages,
100
+ extract: {
101
+ input: ['src/**/*.{tsx,ts}'],
102
+ output: 'src/locales/{{language}}/{{namespace}}.json',
103
+ defaultNS: pluginJson.id,
104
+ functions: ['t', '*.t'],
105
+ transComponents: ['Trans'],
106
+ },
107
+ });
108
+ `;
109
+ context.addFile("i18next.config.ts", i18nextConfig);
110
+ additionsDebug("Created i18next.config.ts");
111
+ } catch (error) {
112
+ additionsDebug("Error creating i18next.config.ts:", error);
113
+ }
114
+ }
115
+ function addI18nextToExternalsArray(externalsArray) {
116
+ const hasI18next = externalsArray.elements.some((element) => {
117
+ if (element && (element.type === "Literal" || element.type === "StringLiteral") && typeof element.value === "string") {
118
+ return element.value === "i18next";
119
+ }
120
+ return false;
121
+ });
122
+ if (hasI18next) {
123
+ additionsDebug("'i18next' already in externals array");
124
+ return false;
125
+ }
126
+ let insertIndex = -1;
127
+ for (let i = 0; i < externalsArray.elements.length; i++) {
128
+ const element = externalsArray.elements[i];
129
+ if (element && (element.type === "Literal" || element.type === "StringLiteral") && element.value === "rxjs") {
130
+ insertIndex = i + 1;
131
+ break;
132
+ }
133
+ }
134
+ if (insertIndex === -1) {
135
+ for (let i = externalsArray.elements.length - 1; i >= 0; i--) {
136
+ const element = externalsArray.elements[i];
137
+ if (element && element.type !== "FunctionExpression" && element.type !== "ArrowFunctionExpression") {
138
+ insertIndex = i + 1;
139
+ break;
140
+ }
141
+ }
142
+ if (insertIndex === -1) {
143
+ insertIndex = externalsArray.elements.length;
144
+ }
145
+ }
146
+ externalsArray.elements.splice(insertIndex, 0, builders.literal("i18next"));
147
+ additionsDebug(`Added 'i18next' to externals array at position ${insertIndex}`);
148
+ return true;
149
+ }
150
+ function ensureI18nextExternal(context) {
151
+ try {
152
+ additionsDebug("Checking for externals configuration...");
153
+ const externalsPath = ".config/bundler/externals.ts";
154
+ if (context.doesFileExist(externalsPath)) {
155
+ additionsDebug(`Found ${externalsPath}, checking for i18next...`);
156
+ const externalsContent = context.getFile(externalsPath);
157
+ if (externalsContent) {
158
+ try {
159
+ const ast = recast.parse(externalsContent, {
160
+ parser: typeScriptParser
161
+ });
162
+ let hasChanges = false;
163
+ recast.visit(ast, {
164
+ visitVariableDeclarator(path) {
165
+ const { node } = path;
166
+ if (node.id.type === "Identifier" && node.id.name === "externals" && node.init && node.init.type === "ArrayExpression") {
167
+ additionsDebug("Found externals array in externals.ts");
168
+ if (addI18nextToExternalsArray(node.init)) {
169
+ hasChanges = true;
170
+ }
171
+ }
172
+ return this.traverse(path);
173
+ }
174
+ });
175
+ if (hasChanges) {
176
+ const output = recast.print(ast, {
177
+ tabWidth: 2,
178
+ trailingComma: true,
179
+ lineTerminator: "\n"
180
+ });
181
+ context.updateFile(externalsPath, output.code);
182
+ additionsDebug(`Updated ${externalsPath} with i18next external`);
183
+ }
184
+ return;
185
+ } catch (error) {
186
+ additionsDebug(`Error updating ${externalsPath}:`, error);
187
+ }
188
+ }
189
+ }
190
+ const webpackConfigPath = ".config/webpack/webpack.config.ts";
191
+ additionsDebug(`Checking for ${webpackConfigPath}...`);
192
+ if (context.doesFileExist(webpackConfigPath)) {
193
+ additionsDebug(`Found ${webpackConfigPath}, checking for inline externals...`);
194
+ const webpackContent = context.getFile(webpackConfigPath);
195
+ if (webpackContent) {
196
+ try {
197
+ const ast = recast.parse(webpackContent, {
198
+ parser: typeScriptParser
199
+ });
200
+ let hasChanges = false;
201
+ let foundExternals = false;
202
+ recast.visit(ast, {
203
+ visitObjectExpression(path) {
204
+ const { node } = path;
205
+ const properties = node.properties;
206
+ if (properties) {
207
+ for (const prop of properties) {
208
+ if (prop && (prop.type === "Property" || prop.type === "ObjectProperty")) {
209
+ const key = "key" in prop ? prop.key : null;
210
+ const value = "value" in prop ? prop.value : null;
211
+ if (key && key.type === "Identifier" && key.name === "externals" && value && value.type === "ArrayExpression") {
212
+ foundExternals = true;
213
+ additionsDebug("Found externals property in webpack.config.ts");
214
+ if (addI18nextToExternalsArray(value)) {
215
+ hasChanges = true;
216
+ }
217
+ }
218
+ }
219
+ }
220
+ }
221
+ return this.traverse(path);
222
+ },
223
+ visitProperty(path) {
224
+ const { node } = path;
225
+ if (node.key && node.key.type === "Identifier" && node.key.name === "externals" && node.value && node.value.type === "ArrayExpression") {
226
+ if (!foundExternals) {
227
+ foundExternals = true;
228
+ additionsDebug("Found externals property in webpack.config.ts (via visitProperty)");
229
+ }
230
+ if (addI18nextToExternalsArray(node.value)) {
231
+ hasChanges = true;
232
+ }
233
+ }
234
+ return this.traverse(path);
235
+ }
236
+ });
237
+ if (!foundExternals) {
238
+ additionsDebug("No externals property found in webpack.config.ts");
239
+ }
240
+ if (hasChanges) {
241
+ const output = recast.print(ast, {
242
+ tabWidth: 2,
243
+ trailingComma: true,
244
+ lineTerminator: "\n"
245
+ });
246
+ context.updateFile(webpackConfigPath, output.code);
247
+ additionsDebug(`Updated ${webpackConfigPath} with i18next external`);
248
+ } else if (foundExternals) {
249
+ additionsDebug("i18next already present in externals, no changes needed");
250
+ }
251
+ return;
252
+ } catch (error) {
253
+ additionsDebug(`Error updating ${webpackConfigPath}:`, error);
254
+ additionsDebug(`Error details: ${error instanceof Error ? error.message : String(error)}`);
255
+ }
256
+ } else {
257
+ additionsDebug(`File ${webpackConfigPath} exists but content is empty`);
258
+ }
259
+ } else {
260
+ additionsDebug(`File ${webpackConfigPath} does not exist`);
261
+ }
262
+ additionsDebug("No externals configuration found, skipping i18next external check");
263
+ } catch (error) {
264
+ additionsDebug(
265
+ `Unexpected error in ensureI18nextExternal: ${error instanceof Error ? error.message : String(error)}`
266
+ );
267
+ }
268
+ }
269
+
270
+ export { createI18nextConfig, ensureI18nextExternal, updateDockerCompose, updatePluginJson };
@@ -0,0 +1,54 @@
1
+ import * as v from 'valibot';
2
+ import { additionsDebug } from '../../../utils.js';
3
+ import { updateDockerCompose, updatePluginJson, createI18nextConfig, ensureI18nextExternal } from './config-updates.js';
4
+ import { addI18nInitialization, createLoadResourcesFile } from './code-generation.js';
5
+ import { addI18nDependency, addSemverDependency, updateEslintConfig, addI18nextCli } from './tooling.js';
6
+ import { checkNeedsBackwardCompatibility, createLocaleFiles } from './utils.js';
7
+
8
+ const schema = v.object(
9
+ {
10
+ locales: v.pipe(
11
+ v.union([v.string(), v.array(v.string())]),
12
+ v.transform((input) => {
13
+ return typeof input === "string" ? input.split(",").map((s) => s.trim()) : input;
14
+ }),
15
+ v.array(
16
+ v.pipe(
17
+ v.string(),
18
+ v.regex(/^[a-z]{2}-[A-Z]{2}$/, "Locale must be in format xx-XX (e.g., en-US, es-ES, sv-SE)")
19
+ ),
20
+ 'Please provide a comma-separated list of all supported locales, e.g., "en-US,es-ES,sv-SE"'
21
+ ),
22
+ v.minLength(1, 'Please provide a comma-separated list of all supported locales, e.g., "en-US,es-ES,sv-SE"')
23
+ )
24
+ },
25
+ 'Please provide a comma-separated list of all supported locales, e.g., "en-US,es-ES,sv-SE"'
26
+ );
27
+ function i18nAddition(context, options) {
28
+ const { locales } = options;
29
+ additionsDebug("Adding i18n support with locales:", locales);
30
+ const needsBackwardCompatibility = checkNeedsBackwardCompatibility(context);
31
+ additionsDebug("Needs backward compatibility:", needsBackwardCompatibility);
32
+ updateDockerCompose(context);
33
+ updatePluginJson(context, locales, needsBackwardCompatibility);
34
+ createLocaleFiles(context, locales);
35
+ addI18nDependency(context);
36
+ if (needsBackwardCompatibility) {
37
+ addSemverDependency(context);
38
+ }
39
+ updateEslintConfig(context);
40
+ addI18nInitialization(context, needsBackwardCompatibility);
41
+ if (needsBackwardCompatibility) {
42
+ createLoadResourcesFile(context);
43
+ }
44
+ addI18nextCli(context);
45
+ createI18nextConfig(context);
46
+ try {
47
+ ensureI18nextExternal(context);
48
+ } catch (error) {
49
+ additionsDebug(`Error ensuring i18next external: ${error instanceof Error ? error.message : String(error)}`);
50
+ }
51
+ return context;
52
+ }
53
+
54
+ export { i18nAddition as default, schema };
@@ -0,0 +1,119 @@
1
+ import * as recast from 'recast';
2
+ import * as babelParser from 'recast/parsers/babel-ts.js';
3
+ import { addDependenciesToPackageJson, additionsDebug } from '../../../utils.js';
4
+
5
+ const { builders } = recast.types;
6
+ function addI18nDependency(context) {
7
+ addDependenciesToPackageJson(context, { "@grafana/i18n": "^12.2.2" }, {});
8
+ additionsDebug("Added @grafana/i18n dependency version ^12.2.2");
9
+ }
10
+ function addSemverDependency(context) {
11
+ addDependenciesToPackageJson(context, { semver: "^7.6.0" }, { "@types/semver": "^7.5.0" });
12
+ additionsDebug("Added semver dependency");
13
+ }
14
+ function addI18nextCli(context) {
15
+ addDependenciesToPackageJson(context, {}, { "i18next-cli": "^1.1.1" });
16
+ const packageJsonRaw = context.getFile("package.json");
17
+ if (!packageJsonRaw) {
18
+ return;
19
+ }
20
+ try {
21
+ const packageJson = JSON.parse(packageJsonRaw);
22
+ if (!packageJson.scripts) {
23
+ packageJson.scripts = {};
24
+ }
25
+ if (!packageJson.scripts["i18n-extract"]) {
26
+ packageJson.scripts["i18n-extract"] = "i18next-cli extract --sync-primary";
27
+ context.updateFile("package.json", JSON.stringify(packageJson, null, 2));
28
+ additionsDebug("Added i18n-extract script to package.json");
29
+ } else {
30
+ additionsDebug("i18n-extract script already exists, skipping");
31
+ }
32
+ } catch (error) {
33
+ additionsDebug("Error adding i18n-extract script:", error);
34
+ }
35
+ }
36
+ function updateEslintConfig(context) {
37
+ if (!context.doesFileExist("eslint.config.mjs")) {
38
+ additionsDebug("eslint.config.mjs not found, skipping");
39
+ return;
40
+ }
41
+ const eslintConfigRaw = context.getFile("eslint.config.mjs");
42
+ if (!eslintConfigRaw) {
43
+ return;
44
+ }
45
+ if (eslintConfigRaw.includes("@grafana/i18n/eslint-plugin")) {
46
+ additionsDebug("ESLint i18n rule already configured");
47
+ return;
48
+ }
49
+ try {
50
+ const ast = recast.parse(eslintConfigRaw, {
51
+ parser: babelParser
52
+ });
53
+ const imports = ast.program.body.filter((node) => node.type === "ImportDeclaration");
54
+ const lastImport = imports[imports.length - 1];
55
+ if (lastImport) {
56
+ const pluginImport = builders.importDeclaration(
57
+ [builders.importDefaultSpecifier(builders.identifier("grafanaI18nPlugin"))],
58
+ builders.literal("@grafana/i18n/eslint-plugin")
59
+ );
60
+ const lastImportIndex = ast.program.body.indexOf(lastImport);
61
+ ast.program.body.splice(lastImportIndex + 1, 0, pluginImport);
62
+ }
63
+ recast.visit(ast, {
64
+ visitCallExpression(path) {
65
+ if (path.node.callee.name === "defineConfig" && path.node.arguments[0]?.type === "ArrayExpression") {
66
+ const configArray = path.node.arguments[0];
67
+ const i18nConfig = builders.objectExpression([
68
+ builders.property("init", builders.identifier("name"), builders.literal("grafana/i18n-rules")),
69
+ builders.property(
70
+ "init",
71
+ builders.identifier("plugins"),
72
+ builders.objectExpression([
73
+ builders.property("init", builders.literal("@grafana/i18n"), builders.identifier("grafanaI18nPlugin"))
74
+ ])
75
+ ),
76
+ builders.property(
77
+ "init",
78
+ builders.identifier("rules"),
79
+ builders.objectExpression([
80
+ builders.property(
81
+ "init",
82
+ builders.literal("@grafana/i18n/no-untranslated-strings"),
83
+ builders.arrayExpression([
84
+ builders.literal("error"),
85
+ builders.objectExpression([
86
+ builders.property(
87
+ "init",
88
+ builders.identifier("calleesToIgnore"),
89
+ builders.arrayExpression([builders.literal("^css$"), builders.literal("use[A-Z].*")])
90
+ )
91
+ ])
92
+ ])
93
+ ),
94
+ builders.property(
95
+ "init",
96
+ builders.literal("@grafana/i18n/no-translation-top-level"),
97
+ builders.literal("error")
98
+ )
99
+ ])
100
+ )
101
+ ]);
102
+ configArray.elements.push(i18nConfig);
103
+ }
104
+ this.traverse(path);
105
+ }
106
+ });
107
+ const output = recast.print(ast, {
108
+ tabWidth: 2,
109
+ trailingComma: true,
110
+ lineTerminator: "\n"
111
+ }).code;
112
+ context.updateFile("eslint.config.mjs", output);
113
+ additionsDebug("Updated eslint.config.mjs with i18n linting rules");
114
+ } catch (error) {
115
+ additionsDebug("Error updating eslint.config.mjs:", error);
116
+ }
117
+ }
118
+
119
+ export { addI18nDependency, addI18nextCli, addSemverDependency, updateEslintConfig };
@@ -0,0 +1,50 @@
1
+ import { coerce, gte } from 'semver';
2
+ import { additionsDebug } from '../../../utils.js';
3
+
4
+ function checkNeedsBackwardCompatibility(context) {
5
+ const pluginJsonRaw = context.getFile("src/plugin.json");
6
+ if (!pluginJsonRaw) {
7
+ return false;
8
+ }
9
+ try {
10
+ const pluginJson = JSON.parse(pluginJsonRaw);
11
+ const currentGrafanaDep = pluginJson.dependencies?.grafanaDependency || ">=11.0.0";
12
+ const minVersion = coerce("12.1.0");
13
+ const currentVersion = coerce(currentGrafanaDep.replace(/^[><=]+/, ""));
14
+ if (currentVersion && minVersion && gte(currentVersion, minVersion)) {
15
+ return false;
16
+ }
17
+ return true;
18
+ } catch (error) {
19
+ additionsDebug("Error checking backward compatibility:", error);
20
+ return true;
21
+ }
22
+ }
23
+ function createLocaleFiles(context, locales) {
24
+ const pluginJsonRaw = context.getFile("src/plugin.json");
25
+ if (!pluginJsonRaw) {
26
+ additionsDebug("Cannot create locale files without plugin.json");
27
+ return;
28
+ }
29
+ try {
30
+ const pluginJson = JSON.parse(pluginJsonRaw);
31
+ const pluginId = pluginJson.id;
32
+ if (!pluginId) {
33
+ additionsDebug("No plugin ID found in plugin.json");
34
+ return;
35
+ }
36
+ for (const locale of locales) {
37
+ const localePath = `src/locales/${locale}/${pluginId}.json`;
38
+ if (!context.doesFileExist(localePath)) {
39
+ context.addFile(localePath, JSON.stringify({}, null, 2));
40
+ additionsDebug(`Created ${localePath}`);
41
+ } else {
42
+ additionsDebug(`${localePath} already exists, skipping`);
43
+ }
44
+ }
45
+ } catch (error) {
46
+ additionsDebug("Error creating locale files:", error);
47
+ }
48
+ }
49
+
50
+ export { checkNeedsBackwardCompatibility, createLocaleFiles };
@@ -205,6 +205,6 @@ function sortObjectByKeys(obj) {
205
205
  return Object.keys(obj).sort().reduce((acc, key) => ({ ...acc, [key]: obj[key] }), {});
206
206
  }
207
207
  const migrationsDebug = debug.extend("migrations");
208
- debug.extend("additions");
208
+ const additionsDebug = debug.extend("additions");
209
209
 
210
- export { addDependenciesToPackageJson, flushChanges, formatFiles, installNPMDependencies, isVersionGreater, migrationsDebug, printChanges, readJsonFile, removeDependenciesFromPackageJson };
210
+ export { addDependenciesToPackageJson, additionsDebug, flushChanges, formatFiles, installNPMDependencies, isVersionGreater, migrationsDebug, printChanges, readJsonFile, removeDependenciesFromPackageJson };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "6.4.4",
3
+ "version": "6.5.0-canary.2320.20231018478.0",
4
4
  "repository": {
5
5
  "directory": "packages/create-plugin",
6
6
  "url": "https://github.com/grafana/plugin-tools"
@@ -56,5 +56,5 @@
56
56
  "engines": {
57
57
  "node": ">=20"
58
58
  },
59
- "gitHead": "23f984f85e43420e1418a4cefc4d77b5392c9e28"
59
+ "gitHead": "2c9b13a41672a1b9e24a92b61a39533bcee266a6"
60
60
  }