@grafana/create-plugin 4.13.0 → 4.14.0-canary.970.e321735.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,8 +3,7 @@ import { printRedBox, printBlueBox } from '../utils/utils.console.js';
3
3
  import { updatePackageJson, updateNpmScripts } from '../utils/utils.npm.js';
4
4
  import { isGitDirectory, isGitDirectoryClean } from '../utils/utils.git.js';
5
5
  import { isPluginDirectory, updateDotConfigFolder } from '../utils/utils.plugin.js';
6
- import { EXTRA_TEMPLATE_VARIABLES } from '../constants.js';
7
- import { getVersion } from '../utils/utils.version.js';
6
+ import { getVersion, getGrafanaRuntimeVersion } from '../utils/utils.version.js';
8
7
  import { getPackageManagerFromUserAgent } from '../utils/utils.packageManager.js';
9
8
  export const update = async (argv) => {
10
9
  const { packageManagerName } = getPackageManagerFromUserAgent();
@@ -43,7 +42,7 @@ In case you want to proceed as is please use the ${chalk.bold('--force')} flag.)
43
42
  });
44
43
  printBlueBox({
45
44
  title: 'Update successful ✔',
46
- content: `${chalk.bold('@grafana/* package version:')} ${EXTRA_TEMPLATE_VARIABLES.grafanaVersion}
45
+ content: `${chalk.bold('@grafana/* package version:')} ${getGrafanaRuntimeVersion()}
47
46
  ${chalk.bold('@grafana/create-plugin version:')} ${getVersion()}
48
47
 
49
48
  ${chalk.bold.underline('Next steps:')}
package/dist/constants.js CHANGED
@@ -28,7 +28,6 @@ export var PLUGIN_TYPES;
28
28
  PLUGIN_TYPES["scenes"] = "scenesapp";
29
29
  })(PLUGIN_TYPES || (PLUGIN_TYPES = {}));
30
30
  export const EXTRA_TEMPLATE_VARIABLES = {
31
- grafanaVersion: '10.3.3',
32
31
  grafanaImage: 'grafana-enterprise',
33
32
  };
34
33
  export const DEFAULT_FEATURE_FLAGS = {
@@ -10,7 +10,7 @@ import { getPluginJson } from './utils.plugin.js';
10
10
  import { TEMPLATE_PATHS, EXPORT_PATH_PREFIX, EXTRA_TEMPLATE_VARIABLES, PLUGIN_TYPES, DEFAULT_FEATURE_FLAGS, } from '../constants.js';
11
11
  import { getPackageManagerInstallCmd, getPackageManagerWithFallback, getPackageManagerFromUserAgent, } from './utils.packageManager.js';
12
12
  import { getExportFileName } from '../utils/utils.files.js';
13
- import { getVersion } from './utils.version.js';
13
+ import { getGrafanaRuntimeVersion, getVersion } from './utils.version.js';
14
14
  import { getConfig } from './utils.config.js';
15
15
  const debug = createDebug('templates');
16
16
  export function getTemplateFiles(pluginType, filter) {
@@ -58,7 +58,7 @@ export function renderTemplateFromFile(templateFile, data) {
58
58
  export function getTemplateData(cliArgs) {
59
59
  const { features } = getConfig();
60
60
  const currentVersion = getVersion();
61
- const grafanaVersion = EXTRA_TEMPLATE_VARIABLES.grafanaVersion;
61
+ const grafanaVersion = getGrafanaRuntimeVersion();
62
62
  const usePlaywright = features.usePlaywright === true || isFile(path.join(process.cwd(), 'playwright.config.ts'));
63
63
  const useCypress = !usePlaywright && semverLt(grafanaVersion, '11.0.0') && fs.existsSync(path.join(process.cwd(), 'cypress'));
64
64
  const bundleGrafanaUI = features.bundleGrafanaUI ?? DEFAULT_FEATURE_FLAGS.bundleGrafanaUI;
@@ -1,6 +1,7 @@
1
1
  import { readFileSync } from 'node:fs';
2
- import { resolve } from 'node:path';
2
+ import path, { resolve } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
+ import { TEMPLATE_PATHS } from '../constants.js';
4
5
  const __dirname = fileURLToPath(new URL('.', import.meta.url));
5
6
  export function getVersion() {
6
7
  const packageJsonPath = resolve(__dirname, '..', '..', 'package.json');
@@ -11,3 +12,9 @@ export function getVersion() {
11
12
  }
12
13
  return version;
13
14
  }
15
+ export function getGrafanaRuntimeVersion() {
16
+ const packageJsonPath = path.join(TEMPLATE_PATHS.common, '_package.json');
17
+ const pkg = readFileSync(packageJsonPath, 'utf8');
18
+ const { version } = /\"(@grafana\/runtime)\":\s\"\^(?<version>.*)\"/.exec(pkg)?.groups ?? {};
19
+ return version;
20
+ }
@@ -29,7 +29,7 @@
29
29
  }
30
30
  ],
31
31
  "dependencies": {
32
- "grafanaDependency": ">={{ grafanaVersion }}",
32
+ "grafanaDependency": ">=10.3.2",
33
33
  "plugins": []
34
34
  }
35
35
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "4.13.0",
3
+ "version": "4.14.0-canary.970.e321735.0",
4
4
  "repository": {
5
5
  "directory": "packages/create-plugin",
6
6
  "url": "https://github.com/grafana/plugin-tools"
@@ -87,5 +87,5 @@
87
87
  "engines": {
88
88
  "node": ">=20"
89
89
  },
90
- "gitHead": "0d126394b9c16cdbd47e3749cb25f258a233ac1a"
90
+ "gitHead": "e321735191a4937a1dae824ec38d8e505c5eddbb"
91
91
  }
@@ -4,8 +4,7 @@ import { printRedBox, printBlueBox } from '../utils/utils.console.js';
4
4
  import { updatePackageJson, updateNpmScripts } from '../utils/utils.npm.js';
5
5
  import { isGitDirectory, isGitDirectoryClean } from '../utils/utils.git.js';
6
6
  import { isPluginDirectory, updateDotConfigFolder } from '../utils/utils.plugin.js';
7
- import { EXTRA_TEMPLATE_VARIABLES } from '../constants.js';
8
- import { getVersion } from '../utils/utils.version.js';
7
+ import { getVersion, getGrafanaRuntimeVersion } from '../utils/utils.version.js';
9
8
  import { getPackageManagerFromUserAgent } from '../utils/utils.packageManager.js';
10
9
 
11
10
  export const update = async (argv: minimist.ParsedArgs) => {
@@ -57,7 +56,7 @@ In case you want to proceed as is please use the ${chalk.bold('--force')} flag.)
57
56
 
58
57
  printBlueBox({
59
58
  title: 'Update successful ✔',
60
- content: `${chalk.bold('@grafana/* package version:')} ${EXTRA_TEMPLATE_VARIABLES.grafanaVersion}
59
+ content: `${chalk.bold('@grafana/* package version:')} ${getGrafanaRuntimeVersion()}
61
60
  ${chalk.bold('@grafana/create-plugin version:')} ${getVersion()}
62
61
 
63
62
  ${chalk.bold.underline('Next steps:')}
package/src/constants.ts CHANGED
@@ -41,9 +41,7 @@ export enum PLUGIN_TYPES {
41
41
 
42
42
  // This gets merged into variables coming from user prompts (when scaffolding) or any other dynamic variables,
43
43
  // and will be available to use in the templates.
44
- // Example: "@grafana/ui": "{{ grafanaVersion }}"
45
44
  export const EXTRA_TEMPLATE_VARIABLES = {
46
- grafanaVersion: '10.3.3',
47
45
  grafanaImage: 'grafana-enterprise',
48
46
  };
49
47
 
@@ -21,7 +21,7 @@ import {
21
21
  getPackageManagerFromUserAgent,
22
22
  } from './utils.packageManager.js';
23
23
  import { getExportFileName } from '../utils/utils.files.js';
24
- import { getVersion } from './utils.version.js';
24
+ import { getGrafanaRuntimeVersion, getVersion } from './utils.version.js';
25
25
  import { getConfig } from './utils.config.js';
26
26
 
27
27
  const debug = createDebug('templates');
@@ -96,7 +96,7 @@ export function renderTemplateFromFile(templateFile: string, data?: any) {
96
96
  export function getTemplateData(cliArgs?: GenerateCliArgs): TemplateData {
97
97
  const { features } = getConfig();
98
98
  const currentVersion = getVersion();
99
- const grafanaVersion = EXTRA_TEMPLATE_VARIABLES.grafanaVersion;
99
+ const grafanaVersion = getGrafanaRuntimeVersion();
100
100
  const usePlaywright = features.usePlaywright === true || isFile(path.join(process.cwd(), 'playwright.config.ts'));
101
101
  //@grafana/e2e was deprecated in Grafana 11
102
102
  const useCypress =
@@ -1,6 +1,7 @@
1
1
  import { readFileSync } from 'node:fs';
2
- import { resolve } from 'node:path';
2
+ import path, { resolve } from 'node:path';
3
3
  import { fileURLToPath } from 'node:url';
4
+ import { TEMPLATE_PATHS } from '../constants.js';
4
5
 
5
6
  const __dirname = fileURLToPath(new URL('.', import.meta.url));
6
7
 
@@ -13,3 +14,10 @@ export function getVersion(): string {
13
14
  }
14
15
  return version;
15
16
  }
17
+
18
+ export function getGrafanaRuntimeVersion() {
19
+ const packageJsonPath = path.join(TEMPLATE_PATHS.common, '_package.json');
20
+ const pkg = readFileSync(packageJsonPath, 'utf8');
21
+ const { version } = /\"(@grafana\/runtime)\":\s\"\^(?<version>.*)\"/.exec(pkg)?.groups ?? {};
22
+ return version;
23
+ }
@@ -62,7 +62,7 @@
62
62
  }
63
63
  ],
64
64
  "dependencies": {
65
- "grafanaDependency": ">={{ grafanaVersion }}",
65
+ "grafanaDependency": ">=10.4.0",
66
66
  "plugins": []
67
67
  }
68
68
  }
@@ -12,7 +12,7 @@ export class DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOptio
12
12
  return DEFAULT_QUERY;
13
13
  }
14
14
 
15
- applyTemplateVariables(query: MyQuery, scopedVars: ScopedVars): Record<string, any> {
15
+ applyTemplateVariables(query: MyQuery, scopedVars: ScopedVars) {
16
16
  return {
17
17
  ...query,
18
18
  queryText: getTemplateSrv().replace(query.queryText, scopedVars),
@@ -29,6 +29,11 @@ export function getPluginJson() {
29
29
  return require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
30
30
  }
31
31
 
32
+ export function getCPConfigVersion() {
33
+ const cprcJson = path.resolve(__dirname, '../', '.cprc.json');
34
+ return fs.existsSync(cprcJson) ? require(cprcJson).version : { version: 'unknown' };
35
+ }
36
+
32
37
  export function hasReadme() {
33
38
  return fs.existsSync(path.resolve(process.cwd(), SOURCE_DIR, 'README.md'));
34
39
  }
@@ -11,12 +11,14 @@ import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
11
11
  import LiveReloadPlugin from 'webpack-livereload-plugin';
12
12
  import path from 'path';
13
13
  import ReplaceInFileWebpackPlugin from 'replace-in-file-webpack-plugin';
14
- import { Configuration } from 'webpack';
14
+ import TerserPlugin from 'terser-webpack-plugin';
15
+ import { type Configuration, BannerPlugin } from 'webpack';
15
16
 
16
- import { getPackageJson, getPluginJson, hasReadme, getEntries, isWSL } from './utils';
17
+ import { getPackageJson, getPluginJson, hasReadme, getEntries, isWSL, getCPConfigVersion } from './utils';
17
18
  import { SOURCE_DIR, DIST_DIR } from './constants';
18
19
 
19
20
  const pluginJson = getPluginJson();
21
+ const cpVersion = getCPConfigVersion();
20
22
 
21
23
  const config = async (env): Promise<Configuration> => {
22
24
  const baseConfig: Configuration = {
@@ -133,6 +135,19 @@ const config = async (env): Promise<Configuration> => {
133
135
  ],
134
136
  },
135
137
 
138
+ optimization: {
139
+ minimize: Boolean(env.production),
140
+ minimizer: [
141
+ new TerserPlugin({
142
+ terserOptions: {
143
+ format: {
144
+ comments: (_, { type, value }) => type === 'comment2' && value.trim().startsWith('[create-plugin]'),
145
+ },
146
+ },
147
+ }),
148
+ ],
149
+ },
150
+
136
151
  output: {
137
152
  clean: {
138
153
  keep: new RegExp(`(.*?_(amd64|arm(64)?)(.exe)?|go_plugin_build_manifest)`),
@@ -147,6 +162,12 @@ const config = async (env): Promise<Configuration> => {
147
162
  },
148
163
 
149
164
  plugins: [
165
+ // Insert create plugin version information into the bundle
166
+ new BannerPlugin({
167
+ banner: "/* [create-plugin] version: " + cpVersion + " */",
168
+ raw: true,
169
+ entryOnly: true,
170
+ }),
150
171
  new CopyWebpackPlugin({
151
172
  patterns: [
152
173
  // If src/README.md exists use it; otherwise the root README
@@ -20,10 +20,10 @@
20
20
  "license": "Apache-2.0",
21
21
  "devDependencies": {
22
22
  "@babel/core": "^7.21.4",{{#if useCypress}}
23
- "@grafana/e2e": "{{ grafanaVersion }}",
24
- "@grafana/e2e-selectors": "{{ grafanaVersion }}",{{/if}}
23
+ "@grafana/e2e": "^10.4.0",
24
+ "@grafana/e2e-selectors": "^10.4.0",{{/if}}
25
25
  "@grafana/eslint-config": "^7.0.0",{{#if usePlaywright}}
26
- "@grafana/plugin-e2e": "1.2.0",{{/if}}
26
+ "@grafana/plugin-e2e": "^1.2.0",{{/if}}
27
27
  "@grafana/tsconfig": "^1.2.0-rc1",{{#if usePlaywright}}
28
28
  "@playwright/test": "^1.41.2",{{/if}}
29
29
  "@swc/core": "^1.3.90",
@@ -63,10 +63,10 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "@emotion/css": "11.10.6",
66
- "@grafana/data": "{{ grafanaVersion }}",
67
- "@grafana/runtime": "{{ grafanaVersion }}",
68
- "@grafana/ui": "{{ grafanaVersion }}",
69
- "@grafana/schema": "{{ grafanaVersion }}",{{#if_eq pluginType "scenesapp"}}
66
+ "@grafana/data": "^10.4.0",
67
+ "@grafana/runtime": "^10.4.0",
68
+ "@grafana/ui": "^10.4.0",
69
+ "@grafana/schema": "^10.4.0",{{#if_eq pluginType "scenesapp"}}
70
70
  "@grafana/scenes": "^3.6.0",{{/if_eq}}
71
71
  "react": "18.2.0",
72
72
  "react-dom": "18.2.0",{{#if isAppType}}
@@ -8,7 +8,7 @@ services:
8
8
  context: ./.config
9
9
  args:
10
10
  grafana_image: ${GRAFANA_IMAGE:-{{~grafanaImage~}} }
11
- grafana_version: ${GRAFANA_VERSION:-{{~grafanaVersion~}} }
11
+ grafana_version: ${GRAFANA_VERSION:-10.4.0}
12
12
  development: ${DEVELOPMENT:-false}
13
13
  ports:
14
14
  - 3000:3000/tcp
@@ -9,6 +9,7 @@ public-hoist-pattern[]="*prettier*"
9
9
 
10
10
  # Hoist all types packages to the root for better TS support
11
11
  public-hoist-pattern[]="@types/*"
12
+ public-hoist-pattern[]="*terser-webpack-plugin*"
12
13
  {{#unless usePlaywright}}
13
14
  # @grafana/e2e expects cypress to exist in the root of the node_modules directory
14
15
  public-hoist-pattern[]="*cypress*"{{/unless}}
@@ -22,7 +22,7 @@
22
22
  "updated": "%TODAY%"
23
23
  },
24
24
  "dependencies": {
25
- "grafanaDependency": ">={{ grafanaVersion }}",
25
+ "grafanaDependency": ">=10.4.0",
26
26
  "plugins": []
27
27
  }
28
28
  }
@@ -19,7 +19,7 @@
19
19
  "updated": "%TODAY%"
20
20
  },
21
21
  "dependencies": {
22
- "grafanaDependency": ">={{ grafanaVersion }}",
22
+ "grafanaDependency": ">=10.4.0",
23
23
  "plugins": []
24
24
  }
25
25
  }
@@ -56,7 +56,7 @@
56
56
  }
57
57
  ],
58
58
  "dependencies": {
59
- "grafanaDependency": ">={{ grafanaVersion }}",
59
+ "grafanaDependency": ">=10.4.0",
60
60
  "plugins": []
61
61
  }
62
62
  }