@grafana/create-plugin 5.17.0 → 5.18.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 +18 -0
- package/CONTRIBUTING.md +117 -1
- package/dist/commands/update.command.js +28 -68
- package/dist/commands/update.migrate.command.js +27 -0
- package/dist/commands/update.standard.command.js +51 -0
- package/dist/migrations/context.js +118 -0
- package/dist/migrations/context.test.js +122 -0
- package/dist/migrations/fixtures/foo/bar.js +2 -0
- package/dist/migrations/fixtures/foo/baz.js +1 -0
- package/dist/migrations/fixtures/migrations.js +19 -0
- package/dist/migrations/manager.js +50 -0
- package/dist/migrations/manager.test.js +177 -0
- package/dist/migrations/migrations.js +3 -0
- package/dist/migrations/migrations.test.js +10 -0
- package/dist/migrations/scripts/example-migration.js +23 -0
- package/dist/migrations/scripts/example-migration.test.js +24 -0
- package/dist/migrations/test-utils.js +9 -0
- package/dist/migrations/utils.js +46 -0
- package/dist/migrations/utils.test.js +65 -0
- package/dist/utils/utils.cli.js +3 -0
- package/dist/utils/utils.config.js +9 -1
- package/dist/utils/utils.console.js +6 -0
- package/dist/utils/utils.git.js +13 -0
- package/dist/utils/utils.goSdk.js +6 -6
- package/dist/utils/utils.templates.js +3 -3
- package/package.json +6 -4
- package/src/commands/update.command.ts +33 -75
- package/src/commands/update.migrate.command.ts +31 -0
- package/src/commands/update.standard.command.ts +55 -0
- package/src/migrations/context.test.ts +148 -0
- package/src/migrations/context.ts +155 -0
- package/src/migrations/fixtures/foo/bar.ts +1 -0
- package/src/migrations/fixtures/foo/baz.ts +0 -0
- package/src/migrations/fixtures/migrations.ts +19 -0
- package/src/migrations/manager.test.ts +217 -0
- package/src/migrations/manager.ts +70 -0
- package/src/migrations/migrations.test.ts +12 -0
- package/src/migrations/migrations.ts +20 -0
- package/src/migrations/scripts/example-migration.test.ts +40 -0
- package/src/migrations/scripts/example-migration.ts +34 -0
- package/src/migrations/test-utils.ts +12 -0
- package/src/migrations/utils.test.ts +81 -0
- package/src/migrations/utils.ts +50 -0
- package/src/utils/utils.cli.ts +5 -0
- package/src/utils/utils.config.ts +12 -1
- package/src/utils/utils.console.ts +7 -0
- package/src/utils/utils.git.ts +14 -0
- package/src/utils/utils.goSdk.ts +6 -6
- package/src/utils/utils.templates.ts +3 -3
- package/templates/common/.config/docker-compose-base.yaml +1 -1
- package/templates/common/_package.json +4 -4
- package/tsconfig.json +1 -1
- package/vitest.config.ts +1 -0
- package/vitest.d.ts +11 -0
- package/vitest.setup.ts +53 -0
|
@@ -2,10 +2,10 @@ import { lt as semverLt } from 'semver';
|
|
|
2
2
|
import { glob } from 'glob';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import fs from 'node:fs';
|
|
5
|
-
import createDebug from 'debug';
|
|
6
5
|
import { filterOutCommonFiles, isFile, isFileStartingWith } from './utils.files.js';
|
|
7
6
|
import { normalizeId, renderHandlebarsTemplate } from './utils.handlebars.js';
|
|
8
7
|
import { getPluginJson } from './utils.plugin.js';
|
|
8
|
+
import { debug } from './utils.cli.js';
|
|
9
9
|
import {
|
|
10
10
|
TEMPLATE_PATHS,
|
|
11
11
|
EXPORT_PATH_PREFIX,
|
|
@@ -23,7 +23,7 @@ import { getExportFileName } from '../utils/utils.files.js';
|
|
|
23
23
|
import { getGrafanaRuntimeVersion, getVersion } from './utils.version.js';
|
|
24
24
|
import { getConfig } from './utils.config.js';
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const templatesDebugger = debug.extend('templates');
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
*
|
|
@@ -161,7 +161,7 @@ export function getTemplateData(cliArgs?: GenerateCliArgs): TemplateData {
|
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
|
|
164
|
+
templatesDebugger('\nTemplate data:\n' + JSON.stringify(templateData, null, 2));
|
|
165
165
|
|
|
166
166
|
return templateData;
|
|
167
167
|
}
|
|
@@ -7,7 +7,7 @@ services:
|
|
|
7
7
|
context: .
|
|
8
8
|
args:
|
|
9
9
|
grafana_image: ${GRAFANA_IMAGE:-{{~grafanaImage~}} }
|
|
10
|
-
grafana_version: ${GRAFANA_VERSION:-11.5.
|
|
10
|
+
grafana_version: ${GRAFANA_VERSION:-11.5.2}
|
|
11
11
|
development: ${DEVELOPMENT:-false}
|
|
12
12
|
anonymous_auth_enabled: ${ANONYMOUS_AUTH_ENABLED:-true}
|
|
13
13
|
ports:
|
|
@@ -72,10 +72,10 @@
|
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
74
|
"@emotion/css": "11.10.6",
|
|
75
|
-
"@grafana/data": "^11.5.
|
|
76
|
-
"@grafana/runtime": "^11.5.
|
|
77
|
-
"@grafana/ui": "^11.5.
|
|
78
|
-
"@grafana/schema": "^11.5.
|
|
75
|
+
"@grafana/data": "^11.5.2",
|
|
76
|
+
"@grafana/runtime": "^11.5.2",
|
|
77
|
+
"@grafana/ui": "^11.5.2",
|
|
78
|
+
"@grafana/schema": "^11.5.2",{{#if_eq pluginType "scenesapp"}}
|
|
79
79
|
"@grafana/scenes": "^5.41.3",{{/if_eq}}
|
|
80
80
|
"react": "18.2.0",
|
|
81
81
|
"react-dom": "18.2.0"{{#if isAppType}},
|
package/tsconfig.json
CHANGED
package/vitest.config.ts
CHANGED
package/vitest.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import 'vitest';
|
|
2
|
+
import { Context } from './src/migrations/context';
|
|
3
|
+
|
|
4
|
+
interface CustomMatchers<R = unknown> {
|
|
5
|
+
toBeIdempotent(context: Context): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare module 'vitest' {
|
|
9
|
+
interface Assertion<T = any> extends CustomMatchers<T> {}
|
|
10
|
+
interface AsymmetricMatchersContaining extends CustomMatchers {}
|
|
11
|
+
}
|
package/vitest.setup.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { expect } from 'vitest';
|
|
2
|
+
import type { Context } from './src/migrations/context';
|
|
3
|
+
import { inspect } from 'node:util';
|
|
4
|
+
|
|
5
|
+
type ClonedContext = {
|
|
6
|
+
files: Record<string, { content: string; changeType: 'add' | 'update' | 'delete' }>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
async function compareContexts(firstRun: ClonedContext, secondRun: ClonedContext) {
|
|
10
|
+
for (const file of Object.keys(firstRun.files)) {
|
|
11
|
+
const firstRunContent = firstRun.files[file].content;
|
|
12
|
+
const secondRunContent = secondRun.files[file].content;
|
|
13
|
+
if (firstRunContent !== secondRunContent) {
|
|
14
|
+
return {
|
|
15
|
+
pass: false,
|
|
16
|
+
file,
|
|
17
|
+
firstRunContent,
|
|
18
|
+
secondRunContent,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return { pass: true };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const parseContent = (content?: string) => (content ? JSON.parse(content) : '');
|
|
27
|
+
|
|
28
|
+
expect.extend({
|
|
29
|
+
async toBeIdempotent(migrate: (context: Context) => Promise<Context>, context: Context) {
|
|
30
|
+
const firstRun = await migrate(context);
|
|
31
|
+
const firstRunDeepCopy = structuredClone(firstRun) as unknown as ClonedContext;
|
|
32
|
+
|
|
33
|
+
const secondRun = await migrate(firstRun);
|
|
34
|
+
const secondRunDeepCopy = structuredClone(secondRun) as unknown as ClonedContext;
|
|
35
|
+
|
|
36
|
+
const result = await compareContexts(firstRunDeepCopy, secondRunDeepCopy);
|
|
37
|
+
|
|
38
|
+
if (result.pass) {
|
|
39
|
+
return {
|
|
40
|
+
pass: true,
|
|
41
|
+
message: () => 'Expected migration not to be idempotent',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
pass: false,
|
|
47
|
+
message: () =>
|
|
48
|
+
`Migration is not idempotent. File ${result.file} changed on second run.\n` +
|
|
49
|
+
`First run content: ${inspect(parseContent(result.firstRunContent), { colors: true })}\n` +
|
|
50
|
+
`Second run content: ${inspect(parseContent(result.secondRunContent), { colors: true })}`,
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
});
|