@grafana/create-plugin 6.1.1 → 6.2.0-canary.2233.18644853669.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,15 +1,3 @@
1
- # v6.1.1 (Wed Oct 15 2025)
2
-
3
- #### 🐛 Bug Fix
4
-
5
- - Fix: Use proper install command for legacy plugin migrations [#2221](https://github.com/grafana/plugin-tools/pull/2221) ([@sunker](https://github.com/sunker))
6
-
7
- #### Authors: 1
8
-
9
- - Erik Sundell ([@sunker](https://github.com/sunker))
10
-
11
- ---
12
-
13
1
  # v6.1.0 (Wed Oct 08 2025)
14
2
 
15
3
  #### 🚀 Enhancement
package/README.md CHANGED
@@ -122,6 +122,45 @@ 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
+
125
164
  ## Contributing
126
165
 
127
166
  We are always grateful for contributions! See [CONTRIBUTING.md](../../CONTRIBUTING.md) for more information.
@@ -0,0 +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
+ }
8
+ }
9
+ };
10
+
11
+ export { defaultAdditions as default };
@@ -0,0 +1,48 @@
1
+ import { additionsDebug, printChanges } from './utils.js';
2
+ import defaultAdditions from './additions.js';
3
+ import { Context } from '../migrations/context.js';
4
+ import { gitCommitNoVerify } from '../utils/utils.git.js';
5
+ import { output } from '../utils/utils.console.js';
6
+ import { formatFiles, flushChanges, installNPMDependencies } from '../migrations/utils.js';
7
+
8
+ function getAvailableAdditions(additions = defaultAdditions.additions) {
9
+ return additions;
10
+ }
11
+ function getAdditionByName(name, additions = defaultAdditions.additions) {
12
+ return additions[name];
13
+ }
14
+ async function runAddition(addition, additionOptions = {}, runOptions = {}) {
15
+ const basePath = process.cwd();
16
+ output.log({
17
+ title: `Running addition: ${addition.name}`,
18
+ body: [addition.description]
19
+ });
20
+ try {
21
+ const context = new Context(basePath);
22
+ const updatedContext = await executeAddition(addition, context, additionOptions);
23
+ const shouldCommit = runOptions.commitChanges && updatedContext.hasChanges();
24
+ additionsDebug(`context for "${addition.name} (${addition.scriptPath})":`);
25
+ additionsDebug("%O", updatedContext.listChanges());
26
+ await formatFiles(updatedContext);
27
+ flushChanges(updatedContext);
28
+ printChanges(updatedContext, addition.name, addition);
29
+ installNPMDependencies(updatedContext);
30
+ if (shouldCommit) {
31
+ await gitCommitNoVerify(`chore: add ${addition.name} support via create-plugin`);
32
+ }
33
+ output.success({
34
+ title: `Successfully added ${addition.name} to your plugin.`
35
+ });
36
+ } catch (error) {
37
+ if (error instanceof Error) {
38
+ throw new Error(`Error running addition "${addition.name} (${addition.scriptPath})": ${error.message}`);
39
+ }
40
+ throw error;
41
+ }
42
+ }
43
+ async function executeAddition(addition, context, options = {}) {
44
+ const module = await import(addition.scriptPath);
45
+ return module.default(context, options);
46
+ }
47
+
48
+ export { executeAddition, getAdditionByName, getAvailableAdditions, runAddition };
@@ -0,0 +1,433 @@
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
+ function migrate(context, options = { locales: ["en-US"] }) {
9
+ const { locales } = options;
10
+ additionsDebug("Adding i18n support with locales:", locales);
11
+ if (isI18nConfigured(context)) {
12
+ additionsDebug("i18n already configured, skipping");
13
+ return context;
14
+ }
15
+ const needsBackwardCompatibility = checkNeedsBackwardCompatibility(context);
16
+ additionsDebug("Needs backward compatibility:", needsBackwardCompatibility);
17
+ if (!needsBackwardCompatibility) {
18
+ updateDockerCompose(context);
19
+ }
20
+ updatePluginJson(context, locales, needsBackwardCompatibility);
21
+ createLocaleFiles(context, locales);
22
+ addI18nDependency(context);
23
+ if (needsBackwardCompatibility) {
24
+ addSemverDependency(context);
25
+ }
26
+ updateEslintConfig(context);
27
+ addI18nInitialization(context, needsBackwardCompatibility);
28
+ if (needsBackwardCompatibility) {
29
+ createLoadResourcesFile(context);
30
+ }
31
+ addI18nextCli(context);
32
+ createI18nextConfig(context);
33
+ return context;
34
+ }
35
+ function isI18nConfigured(context) {
36
+ if (!context.doesFileExist("src/plugin.json")) {
37
+ return false;
38
+ }
39
+ const pluginJsonRaw = context.getFile("src/plugin.json");
40
+ if (!pluginJsonRaw) {
41
+ return false;
42
+ }
43
+ try {
44
+ const pluginJson = JSON.parse(pluginJsonRaw);
45
+ if (pluginJson.languages && Array.isArray(pluginJson.languages) && pluginJson.languages.length > 0) {
46
+ additionsDebug("Found languages in plugin.json, i18n already configured");
47
+ return true;
48
+ }
49
+ } catch (error) {
50
+ additionsDebug("Error parsing plugin.json:", error);
51
+ }
52
+ return false;
53
+ }
54
+ function checkNeedsBackwardCompatibility(context) {
55
+ const pluginJsonRaw = context.getFile("src/plugin.json");
56
+ if (!pluginJsonRaw) {
57
+ return false;
58
+ }
59
+ try {
60
+ const pluginJson = JSON.parse(pluginJsonRaw);
61
+ const currentGrafanaDep = pluginJson.dependencies?.grafanaDependency || ">=11.0.0";
62
+ const minVersion = coerce("12.1.0");
63
+ const currentVersion = coerce(currentGrafanaDep.replace(/^[><=]+/, ""));
64
+ if (currentVersion && minVersion && gte(currentVersion, minVersion)) {
65
+ return false;
66
+ }
67
+ return true;
68
+ } catch (error) {
69
+ additionsDebug("Error checking backward compatibility:", error);
70
+ return true;
71
+ }
72
+ }
73
+ function updateDockerCompose(context) {
74
+ if (!context.doesFileExist("docker-compose.yaml")) {
75
+ additionsDebug("docker-compose.yaml not found, skipping");
76
+ return;
77
+ }
78
+ const composeContent = context.getFile("docker-compose.yaml");
79
+ if (!composeContent) {
80
+ return;
81
+ }
82
+ try {
83
+ const composeDoc = parseDocument(composeContent);
84
+ const currentEnv = composeDoc.getIn(["services", "grafana", "environment"]);
85
+ if (!currentEnv) {
86
+ additionsDebug("No environment section found in docker-compose.yaml, skipping");
87
+ return;
88
+ }
89
+ if (typeof currentEnv === "object") {
90
+ const envMap = currentEnv;
91
+ const toggleValue = envMap.get("GF_FEATURE_TOGGLES_ENABLE");
92
+ if (toggleValue) {
93
+ const toggleStr = toggleValue.toString();
94
+ if (toggleStr.includes("localizationForPlugins")) {
95
+ additionsDebug("localizationForPlugins already in GF_FEATURE_TOGGLES_ENABLE");
96
+ return;
97
+ }
98
+ composeDoc.setIn(
99
+ ["services", "grafana", "environment", "GF_FEATURE_TOGGLES_ENABLE"],
100
+ `${toggleStr},localizationForPlugins`
101
+ );
102
+ } else {
103
+ composeDoc.setIn(["services", "grafana", "environment", "GF_FEATURE_TOGGLES_ENABLE"], "localizationForPlugins");
104
+ }
105
+ context.updateFile("docker-compose.yaml", stringify(composeDoc));
106
+ additionsDebug("Updated docker-compose.yaml with localizationForPlugins feature toggle");
107
+ }
108
+ } catch (error) {
109
+ additionsDebug("Error updating docker-compose.yaml:", error);
110
+ }
111
+ }
112
+ function updatePluginJson(context, locales, needsBackwardCompatibility) {
113
+ if (!context.doesFileExist("src/plugin.json")) {
114
+ additionsDebug("src/plugin.json not found, skipping");
115
+ return;
116
+ }
117
+ const pluginJsonRaw = context.getFile("src/plugin.json");
118
+ if (!pluginJsonRaw) {
119
+ return;
120
+ }
121
+ try {
122
+ const pluginJson = JSON.parse(pluginJsonRaw);
123
+ pluginJson.languages = locales;
124
+ if (!pluginJson.dependencies) {
125
+ pluginJson.dependencies = {};
126
+ }
127
+ const currentGrafanaDep = pluginJson.dependencies.grafanaDependency || ">=11.0.0";
128
+ const targetVersion = needsBackwardCompatibility ? "11.0.0" : "12.1.0";
129
+ const minVersion = coerce(targetVersion);
130
+ const currentVersion = coerce(currentGrafanaDep.replace(/^[><=]+/, ""));
131
+ if (!currentVersion || !minVersion || !gte(currentVersion, minVersion)) {
132
+ pluginJson.dependencies.grafanaDependency = `>=${targetVersion}`;
133
+ additionsDebug(`Updated grafanaDependency to >=${targetVersion}`);
134
+ }
135
+ context.updateFile("src/plugin.json", JSON.stringify(pluginJson, null, 2));
136
+ additionsDebug("Updated src/plugin.json with languages:", locales);
137
+ } catch (error) {
138
+ additionsDebug("Error updating src/plugin.json:", error);
139
+ }
140
+ }
141
+ function createLocaleFiles(context, locales) {
142
+ const pluginJsonRaw = context.getFile("src/plugin.json");
143
+ if (!pluginJsonRaw) {
144
+ additionsDebug("Cannot create locale files without plugin.json");
145
+ return;
146
+ }
147
+ try {
148
+ const pluginJson = JSON.parse(pluginJsonRaw);
149
+ const pluginId = pluginJson.id;
150
+ const pluginName = pluginJson.name || pluginId;
151
+ if (!pluginId) {
152
+ additionsDebug("No plugin ID found in plugin.json");
153
+ return;
154
+ }
155
+ const exampleTranslations = {
156
+ components: {
157
+ exampleComponent: {
158
+ title: `${pluginName} component title`,
159
+ description: "Example description"
160
+ }
161
+ },
162
+ config: {
163
+ title: `${pluginName} configuration`,
164
+ apiUrl: {
165
+ label: "API URL",
166
+ placeholder: "Enter API URL"
167
+ }
168
+ }
169
+ };
170
+ for (const locale of locales) {
171
+ const localePath = `src/locales/${locale}/${pluginId}.json`;
172
+ if (!context.doesFileExist(localePath)) {
173
+ context.addFile(localePath, JSON.stringify(exampleTranslations, null, 2));
174
+ additionsDebug(`Created ${localePath} with example translations`);
175
+ }
176
+ }
177
+ } catch (error) {
178
+ additionsDebug("Error creating locale files:", error);
179
+ }
180
+ }
181
+ function addI18nDependency(context) {
182
+ addDependenciesToPackageJson(context, { "@grafana/i18n": "12.2.2" }, {});
183
+ additionsDebug("Added @grafana/i18n dependency version 12.2.2");
184
+ }
185
+ function addSemverDependency(context) {
186
+ addDependenciesToPackageJson(context, { semver: "^7.6.0" }, { "@types/semver": "^7.5.0" });
187
+ additionsDebug("Added semver dependency for backward compatibility");
188
+ }
189
+ function addI18nextCli(context) {
190
+ addDependenciesToPackageJson(context, {}, { "i18next-cli": "^1.1.1" });
191
+ const packageJsonRaw = context.getFile("package.json");
192
+ if (!packageJsonRaw) {
193
+ return;
194
+ }
195
+ try {
196
+ const packageJson = JSON.parse(packageJsonRaw);
197
+ if (!packageJson.scripts) {
198
+ packageJson.scripts = {};
199
+ }
200
+ if (!packageJson.scripts["i18n-extract"]) {
201
+ packageJson.scripts["i18n-extract"] = "i18next-cli extract --sync-primary";
202
+ context.updateFile("package.json", JSON.stringify(packageJson, null, 2));
203
+ additionsDebug("Added i18n-extract script to package.json");
204
+ }
205
+ } catch (error) {
206
+ additionsDebug("Error adding i18n-extract script:", error);
207
+ }
208
+ }
209
+ function updateEslintConfig(context) {
210
+ if (!context.doesFileExist("eslint.config.mjs")) {
211
+ additionsDebug("eslint.config.mjs not found, skipping");
212
+ return;
213
+ }
214
+ const eslintConfigRaw = context.getFile("eslint.config.mjs");
215
+ if (!eslintConfigRaw) {
216
+ return;
217
+ }
218
+ if (eslintConfigRaw.includes("@grafana/eslint-plugin-plugins")) {
219
+ additionsDebug("ESLint i18n rule already configured");
220
+ return;
221
+ }
222
+ try {
223
+ const ast = recast.parse(eslintConfigRaw, {
224
+ parser: require("recast/parsers/babel-ts")
225
+ });
226
+ const imports = ast.program.body.filter((node) => node.type === "ImportDeclaration");
227
+ const lastImport = imports[imports.length - 1];
228
+ if (lastImport) {
229
+ const pluginImport = builders.importDeclaration(
230
+ [builders.importDefaultSpecifier(builders.identifier("grafanaPluginsPlugin"))],
231
+ builders.literal("@grafana/eslint-plugin-plugins")
232
+ );
233
+ const lastImportIndex = ast.program.body.indexOf(lastImport);
234
+ ast.program.body.splice(lastImportIndex + 1, 0, pluginImport);
235
+ }
236
+ recast.visit(ast, {
237
+ visitCallExpression(path) {
238
+ if (path.node.callee.name === "defineConfig" && path.node.arguments[0]?.type === "ArrayExpression") {
239
+ const configArray = path.node.arguments[0];
240
+ const pluginsConfig = builders.objectExpression([
241
+ builders.property(
242
+ "init",
243
+ builders.identifier("plugins"),
244
+ builders.objectExpression([
245
+ builders.property(
246
+ "init",
247
+ builders.literal("grafanaPlugins"),
248
+ builders.identifier("grafanaPluginsPlugin")
249
+ )
250
+ ])
251
+ ),
252
+ builders.property(
253
+ "init",
254
+ builders.identifier("rules"),
255
+ builders.objectExpression([
256
+ builders.property(
257
+ "init",
258
+ builders.literal("grafanaPlugins/no-untranslated-strings"),
259
+ builders.literal("warn")
260
+ )
261
+ ])
262
+ )
263
+ ]);
264
+ configArray.elements.push(pluginsConfig);
265
+ }
266
+ this.traverse(path);
267
+ }
268
+ });
269
+ const output = recast.print(ast, {
270
+ tabWidth: 2,
271
+ trailingComma: true,
272
+ lineTerminator: "\n"
273
+ }).code;
274
+ context.updateFile("eslint.config.mjs", output);
275
+ additionsDebug("Updated eslint.config.mjs with i18n linting rules");
276
+ } catch (error) {
277
+ additionsDebug("Error updating eslint.config.mjs:", error);
278
+ }
279
+ }
280
+ function createI18nextConfig(context) {
281
+ if (context.doesFileExist("i18next.config.ts")) {
282
+ additionsDebug("i18next.config.ts already exists, skipping");
283
+ return;
284
+ }
285
+ const pluginJsonRaw = context.getFile("src/plugin.json");
286
+ if (!pluginJsonRaw) {
287
+ additionsDebug("Cannot create i18next.config.ts without plugin.json");
288
+ return;
289
+ }
290
+ try {
291
+ const pluginJson = JSON.parse(pluginJsonRaw);
292
+ const pluginId = pluginJson.id;
293
+ if (!pluginId) {
294
+ additionsDebug("No plugin ID found in plugin.json");
295
+ return;
296
+ }
297
+ const i18nextConfig = `import { defineConfig } from 'i18next-cli';
298
+ import pluginJson from './src/plugin.json';
299
+
300
+ export default defineConfig({
301
+ locales: pluginJson.languages,
302
+ extract: {
303
+ input: ['src/**/*.{tsx,ts}'],
304
+ output: 'src/locales/{{language}}/{{namespace}}.json',
305
+ defaultNS: pluginJson.id,
306
+ functions: ['t', '*.t'],
307
+ transComponents: ['Trans'],
308
+ },
309
+ });
310
+ `;
311
+ context.addFile("i18next.config.ts", i18nextConfig);
312
+ additionsDebug("Created i18next.config.ts");
313
+ } catch (error) {
314
+ additionsDebug("Error creating i18next.config.ts:", error);
315
+ }
316
+ }
317
+ function addI18nInitialization(context, needsBackwardCompatibility) {
318
+ const moduleTsPath = context.doesFileExist("src/module.ts") ? "src/module.ts" : context.doesFileExist("src/module.tsx") ? "src/module.tsx" : null;
319
+ if (!moduleTsPath) {
320
+ additionsDebug("No module.ts or module.tsx found, skipping i18n initialization");
321
+ return;
322
+ }
323
+ const moduleContent = context.getFile(moduleTsPath);
324
+ if (!moduleContent) {
325
+ return;
326
+ }
327
+ if (moduleContent.includes("initPluginTranslations")) {
328
+ additionsDebug("i18n already initialized in module file");
329
+ return;
330
+ }
331
+ try {
332
+ const ast = recast.parse(moduleContent, {
333
+ parser: require("recast/parsers/babel-ts")
334
+ });
335
+ const imports = [];
336
+ imports.push(
337
+ builders.importDeclaration(
338
+ [builders.importSpecifier(builders.identifier("initPluginTranslations"))],
339
+ builders.literal("@grafana/i18n")
340
+ )
341
+ );
342
+ imports.push(
343
+ builders.importDeclaration(
344
+ [builders.importDefaultSpecifier(builders.identifier("pluginJson"))],
345
+ builders.literal("plugin.json")
346
+ )
347
+ );
348
+ if (needsBackwardCompatibility) {
349
+ imports.push(
350
+ builders.importDeclaration(
351
+ [builders.importSpecifier(builders.identifier("config"))],
352
+ builders.literal("@grafana/runtime")
353
+ )
354
+ );
355
+ imports.push(
356
+ builders.importDeclaration(
357
+ [builders.importDefaultSpecifier(builders.identifier("semver"))],
358
+ builders.literal("semver")
359
+ )
360
+ );
361
+ imports.push(
362
+ builders.importDeclaration(
363
+ [builders.importSpecifier(builders.identifier("loadResources"))],
364
+ builders.literal("./loadResources")
365
+ )
366
+ );
367
+ }
368
+ const firstImportIndex = ast.program.body.findIndex((node) => node.type === "ImportDeclaration");
369
+ if (firstImportIndex !== -1) {
370
+ ast.program.body.splice(firstImportIndex + 1, 0, ...imports);
371
+ } else {
372
+ ast.program.body.unshift(...imports);
373
+ }
374
+ const i18nInitCode = needsBackwardCompatibility ? `// Before Grafana version 12.1.0 the plugin is responsible for loading translation resources
375
+ // In Grafana version 12.1.0 and later Grafana is responsible for loading translation resources
376
+ const loaders = semver.lt(config?.buildInfo?.version, '12.1.0') ? [loadResources] : [];
377
+
378
+ await initPluginTranslations(pluginJson.id, loaders);` : `await initPluginTranslations(pluginJson.id);`;
379
+ const initAst = recast.parse(i18nInitCode, {
380
+ parser: require("recast/parsers/babel-ts")
381
+ });
382
+ const lastImportIndex = ast.program.body.findLastIndex((node) => node.type === "ImportDeclaration");
383
+ if (lastImportIndex !== -1) {
384
+ ast.program.body.splice(lastImportIndex + 1, 0, ...initAst.program.body);
385
+ } else {
386
+ ast.program.body.unshift(...initAst.program.body);
387
+ }
388
+ const output = recast.print(ast, {
389
+ tabWidth: 2,
390
+ trailingComma: true,
391
+ lineTerminator: "\n"
392
+ }).code;
393
+ context.updateFile(moduleTsPath, output);
394
+ additionsDebug(`Updated ${moduleTsPath} with i18n initialization`);
395
+ } catch (error) {
396
+ additionsDebug("Error updating module file:", error);
397
+ }
398
+ }
399
+ function createLoadResourcesFile(context) {
400
+ const loadResourcesPath = "src/loadResources.ts";
401
+ if (context.doesFileExist(loadResourcesPath)) {
402
+ additionsDebug("loadResources.ts already exists, skipping");
403
+ return;
404
+ }
405
+ const pluginJsonRaw = context.getFile("src/plugin.json");
406
+ if (!pluginJsonRaw) {
407
+ additionsDebug("Cannot create loadResources.ts without plugin.json");
408
+ return;
409
+ }
410
+ const loadResourcesContent = `import { LANGUAGES, ResourceLoader, Resources } from '@grafana/i18n';
411
+ import pluginJson from 'plugin.json';
412
+
413
+ const resources = LANGUAGES.reduce<Record<string, () => Promise<{ default: Resources }>>>((acc, lang) => {
414
+ acc[lang.code] = async () => await import(\`./locales/\${lang.code}/\${pluginJson.id}.json\`);
415
+ return acc;
416
+ }, {});
417
+
418
+ export const loadResources: ResourceLoader = async (resolvedLanguage: string) => {
419
+ try {
420
+ const translation = await resources[resolvedLanguage]();
421
+ return translation.default;
422
+ } catch (error) {
423
+ // This makes sure that the plugin doesn't crash when the resolved language in Grafana isn't supported by the plugin
424
+ console.error(\`The plugin '\${pluginJson.id}' doesn't support the language '\${resolvedLanguage}'\`, error);
425
+ return {};
426
+ }
427
+ };
428
+ `;
429
+ context.addFile(loadResourcesPath, loadResourcesContent);
430
+ additionsDebug("Created src/loadResources.ts for backward compatibility");
431
+ }
432
+
433
+ export { migrate as default };
@@ -0,0 +1,28 @@
1
+ export { addDependenciesToPackageJson, flushChanges, formatFiles, installNPMDependencies } from '../migrations/utils.js';
2
+ import chalk from 'chalk';
3
+ import { debug } from '../utils/utils.cli.js';
4
+ import { output } from '../utils/utils.console.js';
5
+
6
+ const additionsDebug = debug.extend("additions");
7
+ function printChanges(context, key, addition) {
8
+ const changes = context.listChanges();
9
+ const lines = [];
10
+ for (const [filePath, { changeType }] of Object.entries(changes)) {
11
+ if (changeType === "add") {
12
+ lines.push(`${chalk.green("ADD")} ${filePath}`);
13
+ } else if (changeType === "update") {
14
+ lines.push(`${chalk.yellow("UPDATE")} ${filePath}`);
15
+ } else if (changeType === "delete") {
16
+ lines.push(`${chalk.red("DELETE")} ${filePath}`);
17
+ }
18
+ }
19
+ output.addHorizontalLine("gray");
20
+ output.logSingleLine(`${key} (${addition.description})`);
21
+ if (lines.length === 0) {
22
+ output.logSingleLine("No changes were made");
23
+ } else {
24
+ output.log({ title: "Changes:", withPrefix: false, body: output.bulletList(lines) });
25
+ }
26
+ }
27
+
28
+ export { additionsDebug, printChanges };
package/dist/bin/run.js CHANGED
@@ -4,8 +4,9 @@ import { update } from '../commands/update.command.js';
4
4
  import { migrate } from '../commands/migrate.command.js';
5
5
  import { version } from '../commands/version.command.js';
6
6
  import { provisioning } from '../commands/provisioning.command.js';
7
- import { isUnsupportedPlatform } from '../utils/utils.os.js';
7
+ import { add } from '../commands/add.command.js';
8
8
  import { argv, commandName } from '../utils/utils.cli.js';
9
+ import { isUnsupportedPlatform } from '../utils/utils.os.js';
9
10
  import { output } from '../utils/utils.console.js';
10
11
 
11
12
  if (isUnsupportedPlatform()) {
@@ -21,7 +22,8 @@ const commands = {
21
22
  generate,
22
23
  update,
23
24
  version,
24
- provisioning
25
+ provisioning,
26
+ add
25
27
  };
26
28
  const command = commands[commandName] || "generate";
27
29
  command(argv);
@@ -0,0 +1,72 @@
1
+ import Enquirer from 'enquirer';
2
+ import { output } from '../../utils/utils.console.js';
3
+
4
+ const COMMON_LOCALES = [
5
+ { name: "en-US", message: "English (US)" },
6
+ { name: "es-ES", message: "Spanish (Spain)" },
7
+ { name: "fr-FR", message: "French (France)" },
8
+ { name: "de-DE", message: "German (Germany)" },
9
+ { name: "zh-Hans", message: "Chinese (Simplified)" },
10
+ { name: "pt-BR", message: "Portuguese (Brazil)" },
11
+ { name: "sv-SE", message: "Swedish (Sweden)" },
12
+ { name: "nl-NL", message: "Dutch (Netherlands)" },
13
+ { name: "ja-JP", message: "Japanese (Japan)" },
14
+ { name: "it-IT", message: "Italian (Italy)" }
15
+ ];
16
+ async function promptI18nOptions() {
17
+ const enquirer = new Enquirer();
18
+ output.log({
19
+ title: "Configure internationalization (i18n) for your plugin",
20
+ body: [
21
+ "Select the locales you want to support. At least one locale must be selected.",
22
+ "Use space to select, enter to continue."
23
+ ]
24
+ });
25
+ const localeChoices = COMMON_LOCALES.map((locale) => ({
26
+ name: locale.name,
27
+ message: locale.message,
28
+ value: locale.name
29
+ }));
30
+ let selectedLocales = [];
31
+ try {
32
+ const result = await enquirer.prompt({
33
+ type: "multiselect",
34
+ name: "locales",
35
+ message: "Select locales to support:",
36
+ choices: localeChoices,
37
+ initial: [0],
38
+ // Pre-select en-US by default
39
+ validate(value) {
40
+ if (value.length === 0) {
41
+ return "At least one locale must be selected";
42
+ }
43
+ return true;
44
+ }
45
+ });
46
+ selectedLocales = result.locales;
47
+ } catch (error) {
48
+ output.warning({ title: "Addition cancelled by user." });
49
+ process.exit(0);
50
+ }
51
+ try {
52
+ const addMoreResult = await enquirer.prompt({
53
+ type: "input",
54
+ name: "additionalLocales",
55
+ message: 'Enter additional locale codes (comma-separated, e.g., "ko-KR,ru-RU") or press enter to skip:'
56
+ });
57
+ const additionalLocalesInput = addMoreResult.additionalLocales;
58
+ if (additionalLocalesInput && additionalLocalesInput.trim()) {
59
+ const additionalLocales = additionalLocalesInput.split(",").map((locale) => locale.trim()).filter((locale) => locale.length > 0 && !selectedLocales.includes(locale));
60
+ selectedLocales.push(...additionalLocales);
61
+ }
62
+ } catch (error) {
63
+ }
64
+ output.log({
65
+ title: `Selected locales: ${selectedLocales.join(", ")}`
66
+ });
67
+ return {
68
+ locales: selectedLocales
69
+ };
70
+ }
71
+
72
+ export { promptI18nOptions };