@grafana/create-plugin 2.7.0 → 2.8.0-canary.529.128cfa7.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/README.md CHANGED
@@ -97,8 +97,23 @@ For more information see [here](https://grafana.com/developers/plugin-tools/migr
97
97
 
98
98
  ## Customizing or extending the basic configs
99
99
 
100
- You can read more about customizing or extending the basic configuration [here](https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations)
100
+ You can read more about customizing or extending the basic configuration in our [documentation](https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations).
101
+
102
+ ## Add provisioning to your existing plugin
103
+
104
+ You can streamline the plugin review process by incorporating provisioning into your existing plugin, enabling reviewers to test your plugin more efficiently.
105
+
106
+ ```bash
107
+ # Run this command from the root of your plugin
108
+ cd ./my-plugin
109
+
110
+ npx @grafana/create-plugin@latest provisioning
111
+ ```
112
+
113
+ For more information see our [documentation](https://grafana.com/developers/plugin-tools/publish-a-plugin/develop-a-plugin/provide-provisioning).
114
+
115
+ ---
101
116
 
102
117
  ## Contributing
103
118
 
104
- We are always grateful for contributions! See the [CONTRIBUTING.md](../CONTRIBUTING.md) for more information.
119
+ We are always grateful for contributions! See [CONTRIBUTING.md](../CONTRIBUTING.md) for more information.
package/dist/bin/run.js CHANGED
@@ -18,6 +18,7 @@ var commands = {
18
18
  generate: commands_1.generate,
19
19
  update: commands_1.update,
20
20
  version: commands_1.version,
21
+ provisioning: commands_1.provisioning,
21
22
  };
22
23
  var command = commands[argv._[0]] || commands.generate;
23
24
  command(argv);
@@ -18,3 +18,4 @@ __exportStar(require("./generate.command"), exports);
18
18
  __exportStar(require("./update.command"), exports);
19
19
  __exportStar(require("./migrate.command"), exports);
20
20
  __exportStar(require("./version.command"), exports);
21
+ __exportStar(require("./provisioning.command"), exports);
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.provisioning = void 0;
43
+ var glob_1 = __importDefault(require("glob"));
44
+ var path_1 = __importDefault(require("path"));
45
+ var fs_1 = __importDefault(require("fs"));
46
+ var constants_1 = require("../constants");
47
+ var utils_plugin_1 = require("../utils/utils.plugin");
48
+ var utils_templates_1 = require("../utils/utils.templates");
49
+ var utils_console_1 = require("../utils/utils.console");
50
+ var provisioning = function () { return __awaiter(void 0, void 0, void 0, function () {
51
+ var type, provisioningFolder, provisioningSpecificFiles, error_1;
52
+ return __generator(this, function (_a) {
53
+ switch (_a.label) {
54
+ case 0:
55
+ type = (0, utils_plugin_1.getPluginJson)().type;
56
+ provisioningFolder = path_1.default.join(process.cwd(), 'provisioning');
57
+ _a.label = 1;
58
+ case 1:
59
+ _a.trys.push([1, 3, , 4]);
60
+ return [4, (0, utils_console_1.confirmPrompt)(constants_1.TEXT.addProvisioning)];
61
+ case 2:
62
+ if (_a.sent()) {
63
+ if (!fs_1.default.existsSync(provisioningFolder)) {
64
+ provisioningSpecificFiles = glob_1.default.sync("".concat(constants_1.TEMPLATE_PATHS[type], "/provisioning/**"), { dot: true });
65
+ provisioningSpecificFiles.forEach(function (file) {
66
+ (0, utils_templates_1.compileProvisioningTemplateFile)(type, file, (0, utils_templates_1.getTemplateData)());
67
+ });
68
+ (0, utils_console_1.printSuccessMessage)(constants_1.TEXT.addProvisioningSuccess);
69
+ }
70
+ else {
71
+ (0, utils_console_1.printMessage)("You plugin already has provisioning files located under ".concat(provisioningFolder, ", aborting."));
72
+ process.exit(0);
73
+ }
74
+ }
75
+ else {
76
+ (0, utils_console_1.printMessage)(constants_1.TEXT.addProvisioningAborted);
77
+ process.exit(1);
78
+ }
79
+ return [3, 4];
80
+ case 3:
81
+ error_1 = _a.sent();
82
+ (0, utils_console_1.printError)(error_1);
83
+ return [3, 4];
84
+ case 4: return [2];
85
+ }
86
+ });
87
+ }); };
88
+ exports.provisioning = provisioning;
package/dist/constants.js CHANGED
@@ -75,7 +75,10 @@ exports.TEXT = {
75
75
  updateNpmDependenciesPrompt: '**Would you like to update the following dependencies in the `package.json?`**',
76
76
  updateNpmDependenciesSuccess: 'Successfully updated the NPM dependencies.',
77
77
  updateNpmDependenciesAborted: 'No NPM dependencies have been updated.',
78
- removeNpmDependenciesPrompt: '**Would you like to remove the following possibly unnecessary NPM dependencies?**',
78
+ addProvisioning: '**Do you want to add provisioning files?**',
79
+ addProvisioningSuccess: 'Successfully added provisioning.',
80
+ addProvisioningAborted: 'No provisioning has been added.',
81
+ removeNpmDependenciesPrompt: '**Do you want to remove the following possibly unnecessary NPM dependencies?**',
79
82
  removeNpmDependenciesSuccess: 'Unnecessary NPM dependencies removed successfully.',
80
83
  removeNpmDependenciesAborted: 'No NPM dependencies have been removed.',
81
84
  updateConfigPrompt: "**Would you like to update the project's configuration?**",
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.selectPrompt = exports.confirmPrompt = exports.printSuccessMessage = exports.printMessage = exports.displayArrayAsList = exports.displayAsMarkdown = void 0;
3
+ exports.selectPrompt = exports.confirmPrompt = exports.printError = exports.printSuccessMessage = exports.printMessage = exports.displayArrayAsList = exports.displayAsMarkdown = void 0;
4
4
  var marked = require('marked').marked;
5
5
  var TerminalRenderer = require('marked-terminal');
6
6
  var _a = require('enquirer'), Confirm = _a.Confirm, Select = _a.Select;
@@ -23,6 +23,10 @@ function printSuccessMessage(msg) {
23
23
  console.log(displayAsMarkdown("\n\u2714 ".concat(msg)));
24
24
  }
25
25
  exports.printSuccessMessage = printSuccessMessage;
26
+ function printError(error) {
27
+ console.error(displayAsMarkdown("\n\u274C ".concat(error)));
28
+ }
29
+ exports.printError = printError;
26
30
  function confirmPrompt(message) {
27
31
  var prompt = new Confirm({
28
32
  name: 'question',
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.getTemplateData = exports.renderTemplateFromFile = exports.compileSingleTemplateFile = exports.compileTemplateFiles = exports.getProjectRelativeTemplatePath = exports.getTemplateFiles = void 0;
26
+ exports.getTemplateData = exports.renderTemplateFromFile = exports.compileProvisioningTemplateFile = exports.compileSingleTemplateFile = exports.compileTemplateFiles = exports.getProjectRelativeTemplatePath = exports.getTemplateFiles = void 0;
27
27
  var glob_1 = __importDefault(require("glob"));
28
28
  var path_1 = __importDefault(require("path"));
29
29
  var fs_1 = __importDefault(require("fs"));
@@ -69,6 +69,17 @@ function compileSingleTemplateFile(pluginType, templateFile, data) {
69
69
  fs_1.default.writeFileSync(exportPath, rendered);
70
70
  }
71
71
  exports.compileSingleTemplateFile = compileSingleTemplateFile;
72
+ function compileProvisioningTemplateFile(pluginType, templateFile, data) {
73
+ if (!(0, utils_files_1.isFile)(templateFile)) {
74
+ return;
75
+ }
76
+ var rendered = renderTemplateFromFile(templateFile, data);
77
+ var relativeExportPath = templateFile.replace(constants_1.TEMPLATE_PATHS[pluginType], '.');
78
+ var exportPath = path_1.default.join(constants_1.EXPORT_PATH_PREFIX, path_1.default.dirname(relativeExportPath), (0, utils_files_2.getExportFileName)(templateFile));
79
+ mkdirp_1.default.sync(path_1.default.dirname(exportPath));
80
+ fs_1.default.writeFileSync(exportPath, rendered);
81
+ }
82
+ exports.compileProvisioningTemplateFile = compileProvisioningTemplateFile;
72
83
  function renderTemplateFromFile(templateFile, data) {
73
84
  return (0, utils_handlebars_1.renderHandlebarsTemplate)(fs_1.default.readFileSync(templateFile).toString(), data);
74
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "2.7.0",
3
+ "version": "2.8.0-canary.529.128cfa7.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "directory": "packages/create-plugin",
@@ -66,5 +66,5 @@
66
66
  "engines": {
67
67
  "node": ">=20"
68
68
  },
69
- "gitHead": "a3755f78d7c2565d39543be73c1814e2e69011da"
69
+ "gitHead": "128cfa7f4672ca7d23bef627d1488ecdac14c906"
70
70
  }
package/src/bin/run.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import minimist from 'minimist';
4
- import { generate, update, migrate, version } from '../commands';
4
+ import { generate, update, migrate, version, provisioning } from '../commands';
5
5
  import { isUnsupportedPlatform } from '../utils/utils.os';
6
6
 
7
7
  // Exit early if operating system isn't supported.
@@ -19,6 +19,7 @@ const commands: Record<string, (argv: minimist.ParsedArgs) => void> = {
19
19
  generate,
20
20
  update,
21
21
  version,
22
+ provisioning,
22
23
  };
23
24
  const command = commands[argv._[0]] || commands.generate;
24
25
 
@@ -2,3 +2,4 @@ export * from './generate.command';
2
2
  export * from './update.command';
3
3
  export * from './migrate.command';
4
4
  export * from './version.command';
5
+ export * from './provisioning.command';
@@ -0,0 +1,32 @@
1
+ import glob from 'glob';
2
+ import path from 'path';
3
+ import fs from 'fs';
4
+ import { TEMPLATE_PATHS, TEXT } from '../constants';
5
+ import { getPluginJson } from '../utils/utils.plugin';
6
+ import { compileProvisioningTemplateFile, getTemplateData } from '../utils/utils.templates';
7
+ import { confirmPrompt, printMessage, printSuccessMessage, printError } from '../utils/utils.console';
8
+
9
+ export const provisioning = async () => {
10
+ const { type } = getPluginJson();
11
+ const provisioningFolder = path.join(process.cwd(), 'provisioning');
12
+ try {
13
+ if (await confirmPrompt(TEXT.addProvisioning)) {
14
+ if (!fs.existsSync(provisioningFolder)) {
15
+ const provisioningSpecificFiles = glob.sync(`${TEMPLATE_PATHS[type]}/provisioning/**`, { dot: true });
16
+
17
+ provisioningSpecificFiles.forEach((file) => {
18
+ compileProvisioningTemplateFile(type, file, getTemplateData());
19
+ });
20
+ printSuccessMessage(TEXT.addProvisioningSuccess);
21
+ } else {
22
+ printMessage(`You plugin already has provisioning files located under ${provisioningFolder}, aborting.`);
23
+ process.exit(0);
24
+ }
25
+ } else {
26
+ printMessage(TEXT.addProvisioningAborted);
27
+ process.exit(1);
28
+ }
29
+ } catch (error) {
30
+ printError(error);
31
+ }
32
+ };
package/src/constants.ts CHANGED
@@ -99,7 +99,11 @@ export const TEXT = {
99
99
  updateNpmDependenciesSuccess: 'Successfully updated the NPM dependencies.',
100
100
  updateNpmDependenciesAborted: 'No NPM dependencies have been updated.',
101
101
 
102
- removeNpmDependenciesPrompt: '**Would you like to remove the following possibly unnecessary NPM dependencies?**',
102
+ addProvisioning: '**Do you want to add provisioning files?**',
103
+ addProvisioningSuccess: 'Successfully added provisioning.',
104
+ addProvisioningAborted: 'No provisioning has been added.',
105
+
106
+ removeNpmDependenciesPrompt: '**Do you want to remove the following possibly unnecessary NPM dependencies?**',
103
107
  removeNpmDependenciesSuccess: 'Unnecessary NPM dependencies removed successfully.',
104
108
  removeNpmDependenciesAborted: 'No NPM dependencies have been removed.',
105
109
 
@@ -22,6 +22,10 @@ export function printSuccessMessage(msg: string) {
22
22
  console.log(displayAsMarkdown(`\n✔ ${msg}`));
23
23
  }
24
24
 
25
+ export function printError(error: string) {
26
+ console.error(displayAsMarkdown(`\n❌ ${error}`));
27
+ }
28
+
25
29
  export function confirmPrompt(message: string): Promise<boolean> {
26
30
  const prompt = new Confirm({
27
31
  name: 'question',
@@ -61,6 +61,19 @@ export function compileSingleTemplateFile(pluginType: string, templateFile: stri
61
61
  fs.writeFileSync(exportPath, rendered);
62
62
  }
63
63
 
64
+ export function compileProvisioningTemplateFile(pluginType: string, templateFile: string, data?: any) {
65
+ if (!isFile(templateFile)) {
66
+ return;
67
+ }
68
+
69
+ const rendered = renderTemplateFromFile(templateFile, data);
70
+ const relativeExportPath = templateFile.replace(TEMPLATE_PATHS[pluginType], '.');
71
+ const exportPath = path.join(EXPORT_PATH_PREFIX, path.dirname(relativeExportPath), getExportFileName(templateFile));
72
+
73
+ mkdirp.sync(path.dirname(exportPath));
74
+ fs.writeFileSync(exportPath, rendered);
75
+ }
76
+
64
77
  export function renderTemplateFromFile(templateFile: string, data?: any) {
65
78
  return renderHandlebarsTemplate(fs.readFileSync(templateFile).toString(), data);
66
79
  }
@@ -0,0 +1,4 @@
1
+ For more information see our documentation:
2
+
3
+ - [Provision Grafana](https://grafana.com/docs/grafana/latest/administration/provisioning/)
4
+ - [Provision a plugin](https://grafana.com/developers/plugin-tools/publish-a-plugin/provide-provisioning)
@@ -2,4 +2,10 @@ apiVersion: 1
2
2
 
3
3
  apps:
4
4
  - type: '{{ normalize_id pluginName orgName 'app' }}'
5
+ org_id: 1
6
+ org_name: '{{ orgName }}'
5
7
  disabled: false
8
+ jsonData:
9
+ apiUrl: http://default-url.com
10
+ secureJsonData:
11
+ apiKey: secret-key
@@ -0,0 +1 @@
1
+ For more information see [Provision dashboards and data sources](https://grafana.com/tutorials/provision-dashboards-and-data-sources/)
@@ -0,0 +1,10 @@
1
+ apiVersion: 1
2
+
3
+ datasources:
4
+ - name: '{{ pluginName }}'
5
+ type: '{{ normalize_id pluginName orgName 'datasource' }}'
6
+ access: proxy
7
+ isDefault: false
8
+ orgId: 1
9
+ version: 1
10
+ editable: true
@@ -0,0 +1 @@
1
+ For more information see [Provision dashboards and data sources](https://grafana.com/tutorials/provision-dashboards-and-data-sources/)
@@ -0,0 +1,71 @@
1
+ {
2
+ "annotations": {
3
+ "list": [
4
+ {
5
+ "builtIn": 1,
6
+ "datasource": {
7
+ "type": "grafana",
8
+ "uid": "-- Grafana --"
9
+ },
10
+ "enable": true,
11
+ "hide": true,
12
+ "iconColor": "rgba(0, 211, 255, 1)",
13
+ "name": "Annotations & Alerts",
14
+ "type": "dashboard"
15
+ }
16
+ ]
17
+ },
18
+ "editable": true,
19
+ "fiscalYearStartMonth": 0,
20
+ "graphTooltip": 0,
21
+ "links": [],
22
+ "liveNow": false,
23
+ "panels": [
24
+ {
25
+ "datasource": {
26
+ "type": "grafana",
27
+ "uid": "grafana"
28
+ },
29
+ "gridPos": {
30
+ "h": 8,
31
+ "w": 12,
32
+ "x": 0,
33
+ "y": 0
34
+ },
35
+ "id": 1,
36
+ "options": {
37
+ "seriesCountSize": "sm",
38
+ "showSeriesCount": false,
39
+ "text": "Default value of text input option"
40
+ },
41
+ "targets": [
42
+ {
43
+ "datasource": {
44
+ "type": "datasource",
45
+ "uid": "grafana"
46
+ },
47
+ "queryType": "randomWalk",
48
+ "refId": "A"
49
+ }
50
+ ],
51
+ "title": "Panel Title",
52
+ "type": "{{ pluginId }}"
53
+ }
54
+ ],
55
+ "refresh": "",
56
+ "schemaVersion": 38,
57
+ "style": "dark",
58
+ "tags": [],
59
+ "templating": {
60
+ "list": []
61
+ },
62
+ "time": {
63
+ "from": "now-6h",
64
+ "to": "now"
65
+ },
66
+ "timepicker": {},
67
+ "timezone": "",
68
+ "title": "Provisioned {{ pluginName }} dashboard",
69
+ "version": 0,
70
+ "weekStart": ""
71
+ }
@@ -0,0 +1,7 @@
1
+ apiVersion: 1
2
+
3
+ providers:
4
+ - name: '{{ pluginName }}'
5
+ type: file
6
+ options:
7
+ path: /etc/grafana/provisioning/dashboards
@@ -0,0 +1,4 @@
1
+ For more information see our documentation:
2
+
3
+ - [Provision Grafana](https://grafana.com/docs/grafana/latest/administration/provisioning/)
4
+ - [Provision a plugin](https://grafana.com/developers/plugin-tools/publish-a-plugin/provide-provisioning)
@@ -0,0 +1,5 @@
1
+ app_mode = development
2
+
3
+ [feature_toggles]
4
+
5
+
@@ -2,5 +2,5 @@ apiVersion: 1
2
2
 
3
3
  datasources:
4
4
  - name: gdev-testdata
5
- isDefault: true
5
+ isDefault: false
6
6
  type: testdata
@@ -0,0 +1,12 @@
1
+ apiVersion: 1
2
+
3
+ apps:
4
+ - type: '{{ normalize_id pluginName orgName 'app' }}'
5
+ org_id: 1
6
+ org_name: '{{ orgName }}'
7
+ disabled: false
8
+ jsonData:
9
+ apiUrl: http://default-url.com
10
+ isApiKeySet: true
11
+ secureJsonData:
12
+ apiKey: secret-key
@@ -1,5 +0,0 @@
1
- apiVersion: 1
2
-
3
- apps:
4
- - type: '{{ normalize_id pluginName orgName 'app' }}'
5
- disabled: false