@grafana/create-plugin 7.12.3 → 7.14.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 (93) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/dist/codemods/additions/additions.js +20 -7
  3. package/dist/codemods/additions/prompts/docs-content.md +119 -0
  4. package/dist/codemods/additions/prompts/example-prompt.md +56 -0
  5. package/dist/codemods/additions/scripts/docs-content.js +30 -0
  6. package/dist/codemods/additions/scripts/docs.js +250 -0
  7. package/dist/codemods/additions/scripts/experimental-app-sdk.js +39 -33
  8. package/dist/codemods/agentic/definitions.js +31 -0
  9. package/dist/codemods/agentic/detect.js +57 -0
  10. package/dist/codemods/agentic/handoff.js +35 -0
  11. package/dist/codemods/agentic/index.js +143 -0
  12. package/dist/codemods/agentic/prompts.js +115 -0
  13. package/dist/codemods/agentic/resolve.js +120 -0
  14. package/dist/codemods/agentic/runner.js +79 -0
  15. package/dist/codemods/agentic/verify.js +55 -0
  16. package/dist/codemods/migrations/migrations.js +12 -0
  17. package/dist/codemods/migrations/scripts/017-jest-30.js +32 -0
  18. package/dist/codemods/migrations/scripts/018-replace-eslint-webpack-plugin.js +115 -0
  19. package/dist/codemods/utils.agents.js +64 -0
  20. package/dist/codemods/utils.js +51 -8
  21. package/dist/codemods/utils.workflows.js +94 -0
  22. package/dist/commands/add.command.js +74 -12
  23. package/dist/utils/utils.cli.js +7 -2
  24. package/dist/utils/utils.console.js +10 -1
  25. package/dist/utils/utils.git.js +10 -1
  26. package/dist/utils/utils.handlebars.js +9 -2
  27. package/dist/utils/utils.packageManager.js +2 -2
  28. package/dist/utils/utils.templates.js +38 -24
  29. package/package.json +1 -1
  30. package/src/codemods/AGENTS.md +25 -0
  31. package/src/codemods/additions/additions.test.ts +69 -4
  32. package/src/codemods/additions/additions.ts +50 -8
  33. package/src/codemods/additions/prompts/docs-content.md +119 -0
  34. package/src/codemods/additions/prompts/example-prompt.md +56 -0
  35. package/src/codemods/additions/scripts/docs-content.test.ts +94 -0
  36. package/src/codemods/additions/scripts/docs-content.ts +32 -0
  37. package/src/codemods/additions/scripts/docs.test.ts +1037 -0
  38. package/src/codemods/additions/scripts/docs.ts +353 -0
  39. package/src/codemods/additions/scripts/experimental-app-sdk.test.ts +40 -80
  40. package/src/codemods/additions/scripts/experimental-app-sdk.ts +42 -34
  41. package/src/codemods/agentic/definitions.test.ts +67 -0
  42. package/src/codemods/agentic/definitions.ts +33 -0
  43. package/src/codemods/agentic/detect.test.ts +136 -0
  44. package/src/codemods/agentic/detect.ts +75 -0
  45. package/src/codemods/agentic/handoff.test.ts +102 -0
  46. package/src/codemods/agentic/handoff.ts +45 -0
  47. package/src/codemods/agentic/index.test.ts +342 -0
  48. package/src/codemods/agentic/index.ts +221 -0
  49. package/src/codemods/agentic/prompts.test.ts +233 -0
  50. package/src/codemods/agentic/prompts.ts +166 -0
  51. package/src/codemods/agentic/resolve.test.ts +220 -0
  52. package/src/codemods/agentic/resolve.ts +165 -0
  53. package/src/codemods/agentic/runner.test.ts +146 -0
  54. package/src/codemods/agentic/runner.ts +103 -0
  55. package/src/codemods/agentic/types.ts +50 -0
  56. package/src/codemods/agentic/verify.test.ts +106 -0
  57. package/src/codemods/agentic/verify.ts +93 -0
  58. package/src/codemods/migrations/migrations.ts +14 -0
  59. package/src/codemods/migrations/scripts/004-eslint9-flat-config.ts +1 -3
  60. package/src/codemods/migrations/scripts/017-jest-30.test.ts +72 -0
  61. package/src/codemods/migrations/scripts/017-jest-30.ts +39 -0
  62. package/src/codemods/migrations/scripts/018-replace-eslint-webpack-plugin.test.ts +174 -0
  63. package/src/codemods/migrations/scripts/018-replace-eslint-webpack-plugin.ts +141 -0
  64. package/src/codemods/utils.agents.test.ts +140 -0
  65. package/src/codemods/utils.agents.ts +81 -0
  66. package/src/codemods/utils.test.ts +131 -1
  67. package/src/codemods/utils.ts +79 -8
  68. package/src/codemods/utils.workflows.test.ts +153 -0
  69. package/src/codemods/utils.workflows.ts +140 -0
  70. package/src/commands/add.command.ts +92 -9
  71. package/src/utils/utils.cli.ts +5 -0
  72. package/src/utils/utils.git.test.ts +57 -0
  73. package/src/utils/utils.git.ts +25 -0
  74. package/src/utils/utils.handlebars.ts +9 -0
  75. package/src/utils/utils.packageManager.test.ts +23 -0
  76. package/src/utils/utils.packageManager.ts +3 -2
  77. package/src/utils/utils.templates.ts +50 -25
  78. package/templates/app-sdk/.config/app-sdk/generate-kinds.mjs +1 -1
  79. package/templates/common/.config/webpack/webpack.config.ts +4 -5
  80. package/templates/common/_package.json +9 -8
  81. package/templates/docs/common/workflows/validate-docs.yml +52 -0
  82. package/templates/docs/panel/docs/AGENTS.md +107 -0
  83. package/templates/docs/panel/docs/CLAUDE.md +1 -0
  84. package/templates/docs/panel/docs/README.md +20 -0
  85. package/templates/docs/panel/docs/data-formats.md +27 -0
  86. package/templates/docs/panel/docs/examples.md +35 -0
  87. package/templates/docs/panel/docs/index.md +26 -0
  88. package/templates/docs/panel/docs/options.md +53 -0
  89. package/templates/docs/panel/docs/troubleshooting.md +35 -0
  90. package/templates/github/workflows/bundle-stats.yml +1 -1
  91. package/templates/github/workflows/ci.yml +7 -7
  92. package/templates/github/workflows/is-compatible.yml +3 -3
  93. package/templates/github/workflows/release.yml +1 -1
@@ -0,0 +1,94 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { Context } from '../../context.js';
3
+ import docsContent from './docs-content.js';
4
+
5
+ function makeContext(pluginJson: Record<string, unknown>, files: Record<string, string> = {}): Context {
6
+ const context = new Context('/virtual');
7
+ context.addFile('src/plugin.json', JSON.stringify(pluginJson));
8
+ for (const [path, content] of Object.entries(files)) {
9
+ context.addFile(path, content);
10
+ }
11
+ return context;
12
+ }
13
+
14
+ const wiredPanel = { type: 'panel', name: 'Clock', docsPath: 'catalog-docs' };
15
+
16
+ describe('docs-content', () => {
17
+ it('should change nothing when catalog docs are set up', () => {
18
+ const context = makeContext(wiredPanel, {
19
+ 'catalog-docs/index.md': '# Clock\n',
20
+ 'catalog-docs/AGENTS.md': '# Agents\n',
21
+ });
22
+ const changesBefore = context.listChanges();
23
+
24
+ const result = docsContent(context);
25
+
26
+ expect(result.listChanges()).toEqual(changesBefore);
27
+ });
28
+
29
+ it('should be idempotent', async () => {
30
+ const context = makeContext(wiredPanel, {
31
+ 'catalog-docs/index.md': '# Clock\n',
32
+ 'catalog-docs/AGENTS.md': '# Agents\n',
33
+ });
34
+
35
+ await expect(docsContent).toBeIdempotent(context);
36
+ });
37
+
38
+ it('should stop when plugin.json has no docsPath', () => {
39
+ const context = makeContext({ type: 'panel', name: 'Clock' });
40
+
41
+ expect(() => docsContent(context)).toThrow(/no docsPath.*create-plugin add docs$/s);
42
+ });
43
+
44
+ it.each([
45
+ ['is missing', {}],
46
+ [
47
+ 'holds only files that are not pages',
48
+ { 'catalog-docs/README.md': '# Notes\n', 'catalog-docs/AGENTS.md': '# A\n' },
49
+ ],
50
+ ['holds only images', { 'catalog-docs/img/clock.png': 'png' }],
51
+ ])('should stop when the docs folder %s', (_label, files) => {
52
+ const context = makeContext(wiredPanel, files);
53
+
54
+ expect(() => docsContent(context)).toThrow(
55
+ /'catalog-docs', but that folder has no docs pages.*create-plugin add docs --docsPath catalog-docs$/s
56
+ );
57
+ });
58
+
59
+ it('should accept a docs folder whose pages all live in subfolders', () => {
60
+ const context = makeContext(wiredPanel, {
61
+ 'catalog-docs/README.md': '# Notes\n',
62
+ 'catalog-docs/AGENTS.md': '# Agents\n',
63
+ 'catalog-docs/options/index.md': '# Options\n',
64
+ 'catalog-docs/guide/setup.md': '# Setup\n',
65
+ });
66
+
67
+ expect(() => docsContent(context)).not.toThrow();
68
+ });
69
+
70
+ it.each<unknown>(['../shared-docs', './docs', null, 5])('should stop when docsPath is %s', (docsPath) => {
71
+ const context = makeContext(
72
+ { ...wiredPanel, docsPath },
73
+ { 'catalog-docs/index.md': '# Clock\n', 'catalog-docs/AGENTS.md': '# Agents\n' }
74
+ );
75
+
76
+ expect(() => docsContent(context)).toThrow(
77
+ `src/plugin.json has docsPath set to '${docsPath}', which create-plugin add docs-content can't use.`
78
+ );
79
+ });
80
+
81
+ it('should stop when the docs folder has pages but no AGENTS.md', () => {
82
+ const context = makeContext(wiredPanel, { 'catalog-docs/index.md': '# Clock\n' });
83
+
84
+ expect(() => docsContent(context)).toThrow(
85
+ /catalog-docs\/AGENTS.md is missing.*create-plugin add docs --docsPath catalog-docs$/s
86
+ );
87
+ });
88
+
89
+ it('should name docs-content when the plugin type is not supported', () => {
90
+ const context = makeContext({ ...wiredPanel, type: 'app' }, { 'catalog-docs/index.md': '# App\n' });
91
+
92
+ expect(() => docsContent(context)).toThrow("create-plugin add docs-content does not support 'app' plugins yet");
93
+ });
94
+ });
@@ -0,0 +1,32 @@
1
+ import type { Context } from '../../context.js';
2
+ import { readJsonFile } from '../../utils.js';
3
+ import { assertSupportedPluginType, assertValidDocsPath, hasDocsPages } from './docs.js';
4
+
5
+ // the agent step does the writing. this only stops it from starting on a plugin with no docs pages to fill
6
+ export default function docsContent(context: Context): Context {
7
+ assertSupportedPluginType(context, 'docs-content');
8
+
9
+ const { docsPath } = readJsonFile<{ docsPath?: unknown }>(context, 'src/plugin.json');
10
+ if (docsPath === undefined) {
11
+ throw new Error(
12
+ 'src/plugin.json has no docsPath, so there are no docs pages to write yet.\n Scaffold them first, commit the result, then run this again:\n create-plugin add docs'
13
+ );
14
+ }
15
+
16
+ assertValidDocsPath(docsPath, 'add docs-content', 'run create-plugin add docs to scaffold the pages there');
17
+
18
+ if (!hasDocsPages(context, docsPath)) {
19
+ throw new Error(
20
+ `src/plugin.json sets docsPath to '${docsPath}', but that folder has no docs pages.\n Scaffold the pages first, commit the result, then run this again:\n create-plugin add docs --docsPath ${docsPath}`
21
+ );
22
+ }
23
+
24
+ // the prompt relies on its page-to-source table, and re-running add docs adds it without touching pages
25
+ if (!context.doesFileExist(`${docsPath}/AGENTS.md`)) {
26
+ throw new Error(
27
+ `${docsPath}/AGENTS.md is missing, and the agent needs it to know which source each page documents.\n Add it, commit the result, then run this again:\n create-plugin add docs --docsPath ${docsPath}`
28
+ );
29
+ }
30
+
31
+ return context;
32
+ }