@grafana/create-plugin 4.0.0 → 4.0.1-canary.746.8a86e72.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/dist/bin/run.js +2 -4
- package/dist/types.js +1 -0
- package/dist/utils/utils.cli.js +4 -0
- package/dist/utils/utils.config.js +39 -10
- package/dist/utils/utils.templates.js +13 -4
- package/package.json +3 -2
- package/src/bin/run.ts +2 -3
- package/src/commands/generate.command.ts +2 -2
- package/src/types.ts +24 -0
- package/src/utils/utils.cli.ts +7 -0
- package/src/utils/utils.config.ts +55 -10
- package/src/utils/utils.templates.ts +18 -6
package/dist/bin/run.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import minimist from 'minimist';
|
|
3
2
|
import { generate, update, migrate, version, provisioning } from '../commands/index.js';
|
|
4
3
|
import { isUnsupportedPlatform } from '../utils/utils.os.js';
|
|
4
|
+
import { argv, commandName } from '../utils/utils.cli.js';
|
|
5
5
|
if (isUnsupportedPlatform()) {
|
|
6
6
|
console.error("Unsupported operating system 'Windows' detected. Please use WSL with create-plugin. For more info visit: https://grafana.com/developers/plugin-tools/troubleshooting#i-am-getting-unsupported-operating-system-windows-detected-please-use-wsl-with-create-plugin");
|
|
7
7
|
process.exit(1);
|
|
8
8
|
}
|
|
9
|
-
const args = process.argv.slice(2);
|
|
10
|
-
const argv = minimist(args, { alias: { f: 'force' } });
|
|
11
9
|
const commands = {
|
|
12
10
|
migrate,
|
|
13
11
|
generate,
|
|
@@ -15,5 +13,5 @@ const commands = {
|
|
|
15
13
|
version,
|
|
16
14
|
provisioning,
|
|
17
15
|
};
|
|
18
|
-
const command = commands[
|
|
16
|
+
const command = commands[commandName] || 'generate';
|
|
19
17
|
command(argv);
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,25 +1,43 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { getVersion } from './utils.version.js';
|
|
4
|
+
import { commandName } from './utils.cli.js';
|
|
4
5
|
export function getConfig() {
|
|
6
|
+
const rootConfig = getRootConfig();
|
|
7
|
+
const userConfig = getUserConfig();
|
|
8
|
+
return {
|
|
9
|
+
...rootConfig,
|
|
10
|
+
...userConfig,
|
|
11
|
+
version: rootConfig.version,
|
|
12
|
+
features: createFeatureFlags({
|
|
13
|
+
...rootConfig.features,
|
|
14
|
+
...userConfig.features,
|
|
15
|
+
}),
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function getRootConfig() {
|
|
19
|
+
const defaultConfig = {
|
|
20
|
+
version: getVersion(),
|
|
21
|
+
features: createFeatureFlags(),
|
|
22
|
+
};
|
|
5
23
|
try {
|
|
6
24
|
const rootPath = path.resolve(process.cwd(), '.config/.cprc.json');
|
|
7
25
|
const rootConfig = readRCFileSync(rootPath);
|
|
8
|
-
const userConfig = getUserConfig();
|
|
9
26
|
return {
|
|
10
|
-
...
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
features: createFeatureFlags({
|
|
27
|
+
...defaultConfig,
|
|
28
|
+
features: {
|
|
29
|
+
...defaultConfig.features,
|
|
14
30
|
...rootConfig.features,
|
|
15
|
-
|
|
16
|
-
}),
|
|
31
|
+
},
|
|
17
32
|
};
|
|
18
33
|
}
|
|
19
34
|
catch (error) {
|
|
35
|
+
if (commandName === 'generate') {
|
|
36
|
+
return defaultConfig;
|
|
37
|
+
}
|
|
20
38
|
return {
|
|
21
|
-
|
|
22
|
-
features:
|
|
39
|
+
...defaultConfig,
|
|
40
|
+
features: createDisabledFeatureFlags(),
|
|
23
41
|
};
|
|
24
42
|
}
|
|
25
43
|
}
|
|
@@ -35,8 +53,13 @@ function getUserConfig() {
|
|
|
35
53
|
};
|
|
36
54
|
}
|
|
37
55
|
catch (error) {
|
|
56
|
+
if (commandName === 'generate') {
|
|
57
|
+
return {
|
|
58
|
+
features: createFeatureFlags(),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
38
61
|
return {
|
|
39
|
-
features:
|
|
62
|
+
features: createDisabledFeatureFlags(),
|
|
40
63
|
};
|
|
41
64
|
}
|
|
42
65
|
}
|
|
@@ -56,3 +79,9 @@ function createFeatureFlags(flags) {
|
|
|
56
79
|
...flags,
|
|
57
80
|
};
|
|
58
81
|
}
|
|
82
|
+
function createDisabledFeatureFlags() {
|
|
83
|
+
return {
|
|
84
|
+
useReactRouterV6: false,
|
|
85
|
+
bundleGrafanaUI: false,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -2,14 +2,16 @@ import glob from 'glob';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import mkdirp from 'mkdirp';
|
|
5
|
+
import createDebug from 'debug';
|
|
5
6
|
import { filterOutCommonFiles, isFile, isFileStartingWith } from './utils.files.js';
|
|
6
7
|
import { renderHandlebarsTemplate } from './utils.handlebars.js';
|
|
7
8
|
import { getPluginJson } from './utils.plugin.js';
|
|
8
9
|
import { TEMPLATE_PATHS, EXPORT_PATH_PREFIX, EXTRA_TEMPLATE_VARIABLES, PLUGIN_TYPES } from '../constants.js';
|
|
9
|
-
import { getPackageManagerWithFallback } from './utils.packageManager.js';
|
|
10
|
+
import { getPackageManagerInstallCmd, getPackageManagerWithFallback } from './utils.packageManager.js';
|
|
10
11
|
import { getExportFileName } from '../utils/utils.files.js';
|
|
11
12
|
import { getVersion } from './utils.version.js';
|
|
12
13
|
import { getConfig } from './utils.config.js';
|
|
14
|
+
const debug = createDebug('templates');
|
|
13
15
|
export function getTemplateFiles(pluginType, filter) {
|
|
14
16
|
const commonFiles = glob.sync(`${TEMPLATE_PATHS.common}/**`, { dot: true });
|
|
15
17
|
const pluginTypeSpecificFiles = glob.sync(`${TEMPLATE_PATHS[pluginType]}/**`, { dot: true });
|
|
@@ -56,8 +58,10 @@ export function getTemplateData() {
|
|
|
56
58
|
const pluginJson = getPluginJson();
|
|
57
59
|
const { features } = getConfig();
|
|
58
60
|
const currentVersion = getVersion();
|
|
61
|
+
const useReactRouterV6 = features.useReactRouterV6 && pluginJson.type === PLUGIN_TYPES.app;
|
|
59
62
|
const { packageManagerName, packageManagerVersion } = getPackageManagerWithFallback();
|
|
60
|
-
|
|
63
|
+
const packageManagerInstallCmd = getPackageManagerInstallCmd(packageManagerName);
|
|
64
|
+
const templateData = {
|
|
61
65
|
...EXTRA_TEMPLATE_VARIABLES,
|
|
62
66
|
pluginId: pluginJson.id,
|
|
63
67
|
pluginName: pluginJson.name,
|
|
@@ -65,11 +69,16 @@ export function getTemplateData() {
|
|
|
65
69
|
hasBackend: Boolean(pluginJson.backend),
|
|
66
70
|
orgName: pluginJson.info?.author?.name,
|
|
67
71
|
pluginType: pluginJson.type,
|
|
72
|
+
isAppType: pluginJson.type === PLUGIN_TYPES.app || pluginJson.type === PLUGIN_TYPES.scenes,
|
|
73
|
+
isNPM: packageManagerName === 'npm',
|
|
68
74
|
packageManagerName,
|
|
69
75
|
packageManagerVersion,
|
|
76
|
+
packageManagerInstallCmd,
|
|
70
77
|
version: currentVersion,
|
|
71
78
|
bundleGrafanaUI: features.bundleGrafanaUI,
|
|
72
|
-
useReactRouterV6:
|
|
73
|
-
reactRouterVersion:
|
|
79
|
+
useReactRouterV6: useReactRouterV6,
|
|
80
|
+
reactRouterVersion: useReactRouterV6 ? '6.22.0' : '5.2.0',
|
|
74
81
|
};
|
|
82
|
+
debug('\nTemplate data:\n' + JSON.stringify(templateData, null, 2));
|
|
83
|
+
return templateData;
|
|
75
84
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/create-plugin",
|
|
3
|
-
"version": "4.0.0",
|
|
3
|
+
"version": "4.0.1-canary.746.8a86e72.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"directory": "packages/create-plugin",
|
|
6
6
|
"url": "https://github.com/grafana/plugin-tools"
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"boxen": "^7.1.1",
|
|
49
49
|
"chalk": "^5.3.0",
|
|
50
50
|
"change-case": "^5.4.0",
|
|
51
|
+
"debug": "^4.3.4",
|
|
51
52
|
"enquirer": "^2.4.1",
|
|
52
53
|
"find-up": "^5.0.0",
|
|
53
54
|
"glob": "^7.1.7",
|
|
@@ -86,5 +87,5 @@
|
|
|
86
87
|
"engines": {
|
|
87
88
|
"node": ">=20"
|
|
88
89
|
},
|
|
89
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "8a86e720cdec53c50202da391f38e9bf10737e61"
|
|
90
91
|
}
|
package/src/bin/run.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import minimist from 'minimist';
|
|
4
4
|
import { generate, update, migrate, version, provisioning } from '../commands/index.js';
|
|
5
5
|
import { isUnsupportedPlatform } from '../utils/utils.os.js';
|
|
6
|
+
import { argv, commandName } from '../utils/utils.cli.js';
|
|
6
7
|
|
|
7
8
|
// Exit early if operating system isn't supported.
|
|
8
9
|
if (isUnsupportedPlatform()) {
|
|
@@ -12,8 +13,6 @@ if (isUnsupportedPlatform()) {
|
|
|
12
13
|
process.exit(1);
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
const args = process.argv.slice(2);
|
|
16
|
-
const argv = minimist(args, { alias: { f: 'force' } });
|
|
17
16
|
const commands: Record<string, (argv: minimist.ParsedArgs) => void> = {
|
|
18
17
|
migrate,
|
|
19
18
|
generate,
|
|
@@ -21,6 +20,6 @@ const commands: Record<string, (argv: minimist.ParsedArgs) => void> = {
|
|
|
21
20
|
version,
|
|
22
21
|
provisioning,
|
|
23
22
|
};
|
|
24
|
-
const command = commands[
|
|
23
|
+
const command = commands[commandName] || 'generate';
|
|
25
24
|
|
|
26
25
|
command(argv);
|
|
@@ -16,7 +16,7 @@ import { prettifyFiles } from '../utils/utils.prettifyFiles.js';
|
|
|
16
16
|
import { printGenerateSuccessMessage } from './generate/print-success-message.js';
|
|
17
17
|
import { promptUser } from './generate/prompt-user.js';
|
|
18
18
|
import { updateGoSdkAndModules } from './generate/update-go-sdk-and-packages.js';
|
|
19
|
-
import { CliArgs, TemplateData } from '
|
|
19
|
+
import { CliArgs, TemplateData } from '../types.js';
|
|
20
20
|
|
|
21
21
|
export const generate = async (argv: minimist.ParsedArgs) => {
|
|
22
22
|
const answers = await promptUser(argv);
|
|
@@ -59,7 +59,7 @@ function getTemplateData(answers: CliArgs) {
|
|
|
59
59
|
const { packageManagerName, packageManagerVersion } = getPackageManagerFromUserAgent();
|
|
60
60
|
const packageManagerInstallCmd = getPackageManagerInstallCmd(packageManagerName);
|
|
61
61
|
const isAppType = pluginType === PLUGIN_TYPES.app || pluginType === PLUGIN_TYPES.scenes;
|
|
62
|
-
const useReactRouterV6 = features.useReactRouterV6 && pluginType === PLUGIN_TYPES.app;
|
|
62
|
+
const useReactRouterV6 = features.useReactRouterV6 && pluginType === PLUGIN_TYPES.app; // We don't enable this by default yet for new scenes plugins.
|
|
63
63
|
const templateData: TemplateData = {
|
|
64
64
|
...answers,
|
|
65
65
|
pluginId,
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PLUGIN_TYPES } from './constants.js';
|
|
2
|
+
|
|
3
|
+
export type CliArgs = {
|
|
4
|
+
pluginName: string;
|
|
5
|
+
pluginDescription: string;
|
|
6
|
+
orgName: string;
|
|
7
|
+
pluginType: PLUGIN_TYPES;
|
|
8
|
+
hasBackend: boolean;
|
|
9
|
+
hasGithubWorkflows: boolean;
|
|
10
|
+
hasGithubLevitateWorkflow: boolean;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type TemplateData = {
|
|
14
|
+
pluginId: string;
|
|
15
|
+
packageManagerName: string;
|
|
16
|
+
packageManagerInstallCmd: string;
|
|
17
|
+
packageManagerVersion: string;
|
|
18
|
+
isAppType: boolean;
|
|
19
|
+
isNPM: boolean;
|
|
20
|
+
version: string;
|
|
21
|
+
bundleGrafanaUI: boolean;
|
|
22
|
+
useReactRouterV6: boolean;
|
|
23
|
+
reactRouterVersion: string;
|
|
24
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { getVersion } from './utils.version.js';
|
|
4
|
+
import { commandName } from './utils.cli.js';
|
|
5
|
+
import { features } from 'node:process';
|
|
4
6
|
|
|
5
7
|
type FeatureFlags = {
|
|
6
8
|
bundleGrafanaUI: boolean;
|
|
@@ -19,24 +21,49 @@ type UserConfig = {
|
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
export function getConfig(): CreatePluginConfig {
|
|
24
|
+
const rootConfig = getRootConfig();
|
|
25
|
+
const userConfig = getUserConfig();
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
...rootConfig,
|
|
29
|
+
...userConfig,
|
|
30
|
+
version: rootConfig!.version,
|
|
31
|
+
features: createFeatureFlags({
|
|
32
|
+
...rootConfig!.features,
|
|
33
|
+
...userConfig!.features,
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function getRootConfig(): CreatePluginConfig {
|
|
39
|
+
const defaultConfig = {
|
|
40
|
+
version: getVersion(),
|
|
41
|
+
features: createFeatureFlags(),
|
|
42
|
+
};
|
|
43
|
+
|
|
22
44
|
try {
|
|
23
45
|
const rootPath = path.resolve(process.cwd(), '.config/.cprc.json');
|
|
24
46
|
const rootConfig = readRCFileSync(rootPath);
|
|
25
|
-
const userConfig = getUserConfig();
|
|
26
47
|
|
|
27
48
|
return {
|
|
28
|
-
...
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
features: createFeatureFlags({
|
|
49
|
+
...defaultConfig,
|
|
50
|
+
features: {
|
|
51
|
+
...defaultConfig.features,
|
|
32
52
|
...rootConfig!.features,
|
|
33
|
-
|
|
34
|
-
}),
|
|
53
|
+
},
|
|
35
54
|
};
|
|
55
|
+
// Most likely this happens because of no ".config/.cprc.json" (root configuration) file.
|
|
56
|
+
// (This can both happen for new scaffolds and for existing plugins that have not been updated yet.)
|
|
36
57
|
} catch (error) {
|
|
58
|
+
// Scaffolding a new plugin
|
|
59
|
+
if (commandName === 'generate') {
|
|
60
|
+
return defaultConfig;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Most probably updating an existing plugin
|
|
37
64
|
return {
|
|
38
|
-
|
|
39
|
-
features:
|
|
65
|
+
...defaultConfig,
|
|
66
|
+
features: createDisabledFeatureFlags(),
|
|
40
67
|
};
|
|
41
68
|
}
|
|
42
69
|
}
|
|
@@ -52,9 +79,19 @@ function getUserConfig(): UserConfig | undefined {
|
|
|
52
79
|
...userConfig!.features,
|
|
53
80
|
}),
|
|
54
81
|
};
|
|
82
|
+
// Most likely this happens because of no ".cprc.json" (user configuration) file.
|
|
83
|
+
// (This can both happen for new scaffolds and for existing plugins that have not been updated yet.)
|
|
55
84
|
} catch (error) {
|
|
85
|
+
// Scaffolding a new plugin
|
|
86
|
+
if (commandName === 'generate') {
|
|
87
|
+
return {
|
|
88
|
+
features: createFeatureFlags(),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Most probably updating an existing plugin
|
|
56
93
|
return {
|
|
57
|
-
features:
|
|
94
|
+
features: createDisabledFeatureFlags(),
|
|
58
95
|
};
|
|
59
96
|
}
|
|
60
97
|
}
|
|
@@ -69,9 +106,17 @@ function readRCFileSync(path: string): CreatePluginConfig | undefined {
|
|
|
69
106
|
}
|
|
70
107
|
|
|
71
108
|
function createFeatureFlags(flags?: FeatureFlags): FeatureFlags {
|
|
109
|
+
// Default values for new scaffoldings
|
|
72
110
|
return {
|
|
73
111
|
useReactRouterV6: true,
|
|
74
112
|
bundleGrafanaUI: false,
|
|
75
113
|
...flags,
|
|
76
114
|
};
|
|
77
115
|
}
|
|
116
|
+
|
|
117
|
+
function createDisabledFeatureFlags(): FeatureFlags {
|
|
118
|
+
return {
|
|
119
|
+
useReactRouterV6: false,
|
|
120
|
+
bundleGrafanaUI: false,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
@@ -2,15 +2,19 @@ import glob from 'glob';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import mkdirp from 'mkdirp';
|
|
5
|
+
import createDebug from 'debug';
|
|
5
6
|
import { filterOutCommonFiles, isFile, isFileStartingWith } from './utils.files.js';
|
|
6
7
|
import { renderHandlebarsTemplate } from './utils.handlebars.js';
|
|
7
8
|
import { getPluginJson } from './utils.plugin.js';
|
|
8
9
|
import { TEMPLATE_PATHS, EXPORT_PATH_PREFIX, EXTRA_TEMPLATE_VARIABLES, PLUGIN_TYPES } from '../constants.js';
|
|
9
|
-
import {
|
|
10
|
+
import { TemplateData } from '../types.js';
|
|
11
|
+
import { getPackageManagerInstallCmd, getPackageManagerWithFallback } from './utils.packageManager.js';
|
|
10
12
|
import { getExportFileName } from '../utils/utils.files.js';
|
|
11
13
|
import { getVersion } from './utils.version.js';
|
|
12
14
|
import { getConfig } from './utils.config.js';
|
|
13
15
|
|
|
16
|
+
const debug = createDebug('templates');
|
|
17
|
+
|
|
14
18
|
/**
|
|
15
19
|
*
|
|
16
20
|
* @param pluginType - The type of the plugin to get template files for (plugin-specific templates override the common ones)
|
|
@@ -78,14 +82,15 @@ export function renderTemplateFromFile(templateFile: string, data?: any) {
|
|
|
78
82
|
return renderHandlebarsTemplate(fs.readFileSync(templateFile).toString(), data);
|
|
79
83
|
}
|
|
80
84
|
|
|
81
|
-
export function getTemplateData() {
|
|
85
|
+
export function getTemplateData(): TemplateData {
|
|
82
86
|
const pluginJson = getPluginJson();
|
|
83
87
|
const { features } = getConfig();
|
|
84
88
|
const currentVersion = getVersion();
|
|
85
|
-
|
|
89
|
+
const useReactRouterV6 = features.useReactRouterV6 && pluginJson.type === PLUGIN_TYPES.app;
|
|
86
90
|
const { packageManagerName, packageManagerVersion } = getPackageManagerWithFallback();
|
|
91
|
+
const packageManagerInstallCmd = getPackageManagerInstallCmd(packageManagerName);
|
|
87
92
|
|
|
88
|
-
|
|
93
|
+
const templateData = {
|
|
89
94
|
...EXTRA_TEMPLATE_VARIABLES,
|
|
90
95
|
pluginId: pluginJson.id,
|
|
91
96
|
pluginName: pluginJson.name,
|
|
@@ -93,11 +98,18 @@ export function getTemplateData() {
|
|
|
93
98
|
hasBackend: Boolean(pluginJson.backend),
|
|
94
99
|
orgName: pluginJson.info?.author?.name,
|
|
95
100
|
pluginType: pluginJson.type,
|
|
101
|
+
isAppType: pluginJson.type === PLUGIN_TYPES.app || pluginJson.type === PLUGIN_TYPES.scenes,
|
|
102
|
+
isNPM: packageManagerName === 'npm',
|
|
96
103
|
packageManagerName,
|
|
97
104
|
packageManagerVersion,
|
|
105
|
+
packageManagerInstallCmd,
|
|
98
106
|
version: currentVersion,
|
|
99
107
|
bundleGrafanaUI: features.bundleGrafanaUI,
|
|
100
|
-
useReactRouterV6:
|
|
101
|
-
reactRouterVersion:
|
|
108
|
+
useReactRouterV6: useReactRouterV6,
|
|
109
|
+
reactRouterVersion: useReactRouterV6 ? '6.22.0' : '5.2.0',
|
|
102
110
|
};
|
|
111
|
+
|
|
112
|
+
debug('\nTemplate data:\n' + JSON.stringify(templateData, null, 2));
|
|
113
|
+
|
|
114
|
+
return templateData;
|
|
103
115
|
}
|