@grafana/create-plugin 3.2.0 → 3.3.0-canary.710.2bb43c7.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.
@@ -57,6 +57,8 @@ function getTemplateData(answers) {
57
57
  isNPM: packageManagerName === 'npm',
58
58
  version: currentVersion,
59
59
  bundleGrafanaUI: features.bundleGrafanaUI,
60
+ useReactRouterV6: features.useReactRouterV6 && pluginType === PLUGIN_TYPES.app,
61
+ reactRouterVersion: features.useReactRouterV6 && pluginType === PLUGIN_TYPES.app ? '6.22.0' : '5.2.0',
60
62
  };
61
63
  return templateData;
62
64
  }
@@ -5,6 +5,7 @@ import { confirmPrompt, selectPrompt, printMessage, printSuccessMessage, printRe
5
5
  import { updatePackageJson, hasNpmDependenciesToUpdate, getPackageJsonUpdatesAsText, updateNpmScripts, writePackageManagerInPackageJson, } from '../utils/utils.npm.js';
6
6
  import { getPackageManagerWithFallback } from '../utils/utils.packageManager.js';
7
7
  import { isGitDirectory, isGitDirectoryClean } from '../utils/utils.git.js';
8
+ import { isPluginDirectory } from '../utils/utils.plugin.js';
8
9
  export const update = async (argv) => {
9
10
  try {
10
11
  if (!(await isGitDirectory()) && !argv.force) {
@@ -25,6 +26,14 @@ In case you want to proceed as is please use the ${chalk.bold('--force')} flag.)
25
26
  });
26
27
  process.exit(1);
27
28
  }
29
+ if (!isPluginDirectory() && !argv.force) {
30
+ printRedBox({
31
+ title: 'Are you inside a plugin directory?',
32
+ subtitle: 'We couldn\'t find a "src/plugin.json" file under your current directory.',
33
+ content: `(Please make sure to run this command from the root of your plugin folder. In case you want to proceed as is please use the ${chalk.bold('--force')} flag.)`,
34
+ });
35
+ process.exit(1);
36
+ }
28
37
  printMessage(TEXT.updateCommandWarning);
29
38
  if (await confirmPrompt(TEXT.updateConfigPrompt)) {
30
39
  compileTemplateFiles(UDPATE_CONFIG.filesToOverride, getTemplateData());
@@ -51,6 +51,7 @@ function readRCFileSync(path) {
51
51
  }
52
52
  function createFeatureFlags(flags) {
53
53
  return {
54
+ useReactRouterV6: true,
54
55
  bundleGrafanaUI: false,
55
56
  ...flags,
56
57
  };
@@ -5,3 +5,12 @@ export function getPluginJson(srcDir) {
5
5
  const pluginJsonPath = path.join(srcPath, 'plugin.json');
6
6
  return readJsonFile(pluginJsonPath);
7
7
  }
8
+ export function isPluginDirectory() {
9
+ try {
10
+ getPluginJson();
11
+ return true;
12
+ }
13
+ catch (e) {
14
+ return false;
15
+ }
16
+ }
@@ -5,7 +5,7 @@ import mkdirp from 'mkdirp';
5
5
  import { filterOutCommonFiles, isFile, isFileStartingWith } from './utils.files.js';
6
6
  import { renderHandlebarsTemplate } from './utils.handlebars.js';
7
7
  import { getPluginJson } from './utils.plugin.js';
8
- import { TEMPLATE_PATHS, EXPORT_PATH_PREFIX, EXTRA_TEMPLATE_VARIABLES } from '../constants.js';
8
+ import { TEMPLATE_PATHS, EXPORT_PATH_PREFIX, EXTRA_TEMPLATE_VARIABLES, PLUGIN_TYPES } from '../constants.js';
9
9
  import { getPackageManagerWithFallback } from './utils.packageManager.js';
10
10
  import { getExportFileName } from '../utils/utils.files.js';
11
11
  import { getVersion } from './utils.version.js';
@@ -69,5 +69,7 @@ export function getTemplateData() {
69
69
  packageManagerVersion,
70
70
  version: currentVersion,
71
71
  bundleGrafanaUI: features.bundleGrafanaUI,
72
+ useReactRouterV6: features.useReactRouterV6 && pluginJson.type === PLUGIN_TYPES.app,
73
+ reactRouterVersion: features.useReactRouterV6 ? '6.22.0' : '5.2.0',
72
74
  };
73
75
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "3.2.0",
3
+ "version": "3.3.0-canary.710.2bb43c7.0",
4
4
  "repository": {
5
5
  "directory": "packages/create-plugin",
6
6
  "url": "https://github.com/grafana/plugin-tools"
@@ -86,5 +86,5 @@
86
86
  "engines": {
87
87
  "node": ">=20"
88
88
  },
89
- "gitHead": "96e111bfcc9615a97c3085f16646d1bb76f5ddb4"
89
+ "gitHead": "2bb43c7ea455eec1f96590c21280ca41ff1586a9"
90
90
  }
@@ -69,6 +69,8 @@ function getTemplateData(answers: CliArgs) {
69
69
  isNPM: packageManagerName === 'npm',
70
70
  version: currentVersion,
71
71
  bundleGrafanaUI: features.bundleGrafanaUI,
72
+ useReactRouterV6: features.useReactRouterV6 && pluginType === PLUGIN_TYPES.app,
73
+ reactRouterVersion: features.useReactRouterV6 && pluginType === PLUGIN_TYPES.app ? '6.22.0' : '5.2.0',
72
74
  };
73
75
 
74
76
  return templateData;
@@ -19,4 +19,6 @@ export type TemplateData = {
19
19
  isNPM: boolean;
20
20
  version: string;
21
21
  bundleGrafanaUI: boolean;
22
+ useReactRouterV6: boolean;
23
+ reactRouterVersion: string;
22
24
  };
@@ -12,6 +12,7 @@ import {
12
12
  } from '../utils/utils.npm.js';
13
13
  import { getPackageManagerWithFallback } from '../utils/utils.packageManager.js';
14
14
  import { isGitDirectory, isGitDirectoryClean } from '../utils/utils.git.js';
15
+ import { isPluginDirectory } from '../utils/utils.plugin.js';
15
16
 
16
17
  export const update = async (argv: minimist.ParsedArgs) => {
17
18
  try {
@@ -37,6 +38,18 @@ In case you want to proceed as is please use the ${chalk.bold('--force')} flag.)
37
38
  process.exit(1);
38
39
  }
39
40
 
41
+ if (!isPluginDirectory() && !argv.force) {
42
+ printRedBox({
43
+ title: 'Are you inside a plugin directory?',
44
+ subtitle: 'We couldn\'t find a "src/plugin.json" file under your current directory.',
45
+ content: `(Please make sure to run this command from the root of your plugin folder. In case you want to proceed as is please use the ${chalk.bold(
46
+ '--force'
47
+ )} flag.)`,
48
+ });
49
+
50
+ process.exit(1);
51
+ }
52
+
40
53
  // 0. Warning
41
54
  // ----------
42
55
  printMessage(TEXT.updateCommandWarning);
@@ -4,6 +4,10 @@ import { getVersion } from './utils.version.js';
4
4
 
5
5
  type FeatureFlags = {
6
6
  bundleGrafanaUI: boolean;
7
+
8
+ // If set to true, the plugin will be scaffolded with React Router v6. Defaults to true.
9
+ // (Attention! We always scaffold new projects with React Router v6, so if you are changing this to `false` manually you will need to make changes to the React code as well.)
10
+ useReactRouterV6: boolean;
7
11
  };
8
12
 
9
13
  type CreatePluginConfig = UserConfig & {
@@ -66,6 +70,7 @@ function readRCFileSync(path: string): CreatePluginConfig | undefined {
66
70
 
67
71
  function createFeatureFlags(flags?: FeatureFlags): FeatureFlags {
68
72
  return {
73
+ useReactRouterV6: true,
69
74
  bundleGrafanaUI: false,
70
75
  ...flags,
71
76
  };
@@ -6,3 +6,13 @@ export function getPluginJson(srcDir?: string) {
6
6
  const pluginJsonPath = path.join(srcPath, 'plugin.json');
7
7
  return readJsonFile(pluginJsonPath);
8
8
  }
9
+
10
+ // Checks if CWD is a valid root directory of a plugin
11
+ export function isPluginDirectory() {
12
+ try {
13
+ getPluginJson();
14
+ return true;
15
+ } catch (e) {
16
+ return false;
17
+ }
18
+ }
@@ -5,7 +5,7 @@ import mkdirp from 'mkdirp';
5
5
  import { filterOutCommonFiles, isFile, isFileStartingWith } from './utils.files.js';
6
6
  import { renderHandlebarsTemplate } from './utils.handlebars.js';
7
7
  import { getPluginJson } from './utils.plugin.js';
8
- import { TEMPLATE_PATHS, EXPORT_PATH_PREFIX, EXTRA_TEMPLATE_VARIABLES } from '../constants.js';
8
+ import { TEMPLATE_PATHS, EXPORT_PATH_PREFIX, EXTRA_TEMPLATE_VARIABLES, PLUGIN_TYPES } from '../constants.js';
9
9
  import { getPackageManagerWithFallback } from './utils.packageManager.js';
10
10
  import { getExportFileName } from '../utils/utils.files.js';
11
11
  import { getVersion } from './utils.version.js';
@@ -97,5 +97,7 @@ export function getTemplateData() {
97
97
  packageManagerVersion,
98
98
  version: currentVersion,
99
99
  bundleGrafanaUI: features.bundleGrafanaUI,
100
+ useReactRouterV6: features.useReactRouterV6 && pluginJson.type === PLUGIN_TYPES.app,
101
+ reactRouterVersion: features.useReactRouterV6 ? '6.22.0' : '5.2.0',
100
102
  };
101
103
  }
@@ -1,21 +1,20 @@
1
1
  import React from 'react';
2
- import { Route, Switch } from 'react-router-dom';
2
+ import { Route, Routes } from 'react-router-dom';
3
3
  import { AppRootProps } from '@grafana/data';
4
4
  import { ROUTES } from '../../constants';
5
5
  import { PageFour, PageOne, PageThree, PageTwo } from '../../pages';
6
- import { prefixRoute } from '../../utils/utils.routing';
7
6
 
8
7
  export function App(props: AppRootProps) {
9
8
  return (
10
- <Switch>
11
- <Route exact path={prefixRoute(ROUTES.Two)} component={PageTwo} />
12
- <Route exact path={prefixRoute(`${ROUTES.Three}/:id?`)} component={PageThree} />
9
+ <Routes>
10
+ <Route path={ROUTES.Two} element={<PageTwo />} />
11
+ <Route path={`${ROUTES.Three}/:id?`} element={<PageThree />} />
13
12
 
14
13
  {/* Full-width page (this page will have no side navigation) */}
15
- <Route exact path={prefixRoute(ROUTES.Four)} component={PageFour} />
14
+ <Route path={ROUTES.Four} element={<PageFour />} />
16
15
 
17
16
  {/* Default page */}
18
- <Route component={PageOne} />
19
- </Switch>
17
+ <Route path="*" element={<PageOne />} />
18
+ </Routes>
20
19
  );
21
20
  }
@@ -49,8 +49,8 @@ const config = async (env): Promise<Configuration> => {
49
49
  'react-redux',
50
50
  'redux',
51
51
  'rxjs',
52
- 'react-router',
53
- 'react-router-dom',
52
+ 'react-router',{{#unless useReactRouterV6}}
53
+ 'react-router-dom',{{/unless}}
54
54
  'd3',
55
55
  'angular',{{#unless bundleGrafanaUI}}
56
56
  '@grafana/ui',{{/unless}}
@@ -2,5 +2,7 @@
2
2
  "features": {
3
3
  {{#if bundleGrafanaUI}}
4
4
  "bundleGrafanaUI": true{{/if}}
5
+ {{#if useReactRouterV6}}
6
+ "useReactRouterV6": true{{/if}}
5
7
  }
6
8
  }
@@ -30,8 +30,8 @@
30
30
  "@testing-library/react": "14.0.0",
31
31
  "@types/jest": "^29.5.0",
32
32
  "@types/lodash": "^4.14.194",
33
- "@types/node": "^20.8.7",{{#if isAppType}}
34
- "@types/react-router-dom": "^5.3.3",{{/if}}
33
+ "@types/node": "^20.8.7",{{#unless useReactRouterV6}}
34
+ "@types/react-router-dom": "^{{ reactRouterVersion }}",{{/unless}}
35
35
  "@types/testing-library__jest-dom": "5.14.8",
36
36
  "copy-webpack-plugin": "^11.0.0",
37
37
  "css-loader": "^6.7.3",
@@ -67,7 +67,7 @@
67
67
  "@grafana/scenes": "^1.28.0",{{/if_eq}}
68
68
  "react": "18.2.0",
69
69
  "react-dom": "18.2.0",{{#if isAppType}}
70
- "react-router-dom": "5.3.3",
70
+ "react-router-dom": "^{{ reactRouterVersion }}",
71
71
  "rxjs": "7.8.0",{{/if}}
72
72
  "tslib": "2.5.3"
73
73
  },