@grafana/create-plugin 1.0.1 β†’ 1.1.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 CHANGED
@@ -1,3 +1,26 @@
1
+ # v1.1.0 (Mon Mar 06 2023)
2
+
3
+ :tada: This release contains work from a new contributor! :tada:
4
+
5
+ Thank you, Romain Gaillard ([@romain-gaillard](https://github.com/romain-gaillard)), for all your work!
6
+
7
+ #### πŸš€ Enhancement
8
+
9
+ - Auto update grafana go sdk after generation [#214](https://github.com/grafana/plugin-tools/pull/214) ([@academo](https://github.com/academo))
10
+
11
+ #### πŸ› Bug Fix
12
+
13
+ - Bumped mage action to v2 to avoid the warning "Node.js 12 actions are… [#213](https://github.com/grafana/plugin-tools/pull/213) ([@romain-gaillard](https://github.com/romain-gaillard))
14
+ - Fix datasource without backend template and update test CI [#206](https://github.com/grafana/plugin-tools/pull/206) ([@academo](https://github.com/academo))
15
+ - Minor typo fixed and improved comment consistency in frontend-getting-started.md [#211](https://github.com/grafana/plugin-tools/pull/211) ([@romain-gaillard](https://github.com/romain-gaillard))
16
+
17
+ #### Authors: 2
18
+
19
+ - Esteban Beltran ([@academo](https://github.com/academo))
20
+ - Romain Gaillard ([@romain-gaillard](https://github.com/romain-gaillard))
21
+
22
+ ---
23
+
1
24
  # v1.0.1 (Fri Mar 03 2023)
2
25
 
3
26
  :tada: This release contains work from a new contributor! :tada:
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
10
+ };
11
+ exports.__esModule = true;
12
+ exports.printGenerateSuccessMessage = void 0;
13
+ var utils_console_1 = require("../../utils/utils.console");
14
+ var utils_handlebars_1 = require("../../utils/utils.handlebars");
15
+ function printGenerateSuccessMessage(answers) {
16
+ var directory = (0, utils_handlebars_1.normalizeId)(answers.pluginName, answers.orgName, answers.pluginType);
17
+ var commands = __spreadArray(__spreadArray([
18
+ "- `cd ./".concat(directory, "`"),
19
+ '- `yarn install` to install frontend dependencies.',
20
+ '- `yarn dev` to build (and watch) the plugin frontend code.'
21
+ ], (answers.hasBackend
22
+ ? [
23
+ '- `mage -v build:linux` to build the plugin backend code. Rerun this command every time you edit your backend files.',
24
+ ]
25
+ : []), true), [
26
+ '- `docker-compose up` to start a grafana development server. Restart this command after each time you run mage to run your new backend code.',
27
+ '- Open http://localhost:3000 in your browser to create a dashboard to begin developing your plugin.',
28
+ ], false);
29
+ var msg = "\nCongratulations on scaffolding a Grafana ".concat(answers.pluginType, " plugin! \uD83D\uDE80\n\n## What's next?\n\nRun the following commands to get started:\n").concat(commands.map(function (command) { return command; }).join('\n'), "\n\n_Note: We strongly recommend creating a new Git repository by running `git init` in ./").concat(directory, " before continuing._\n\n- View create-plugin documentation at https://grafana.github.io/plugin-tools/\n- Learn more about Grafana Plugins at https://grafana.com/docs/grafana/latest/plugins/developing/development/\n");
30
+ return (0, utils_console_1.displayAsMarkdown)(msg);
31
+ }
32
+ exports.printGenerateSuccessMessage = printGenerateSuccessMessage;
@@ -0,0 +1,79 @@
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 (_) 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
+ exports.__esModule = true;
42
+ exports.updateGoSdkAndModules = void 0;
43
+ var utils_path_1 = require("../../utils/utils.path");
44
+ var which_1 = __importDefault(require("which"));
45
+ var fs_1 = __importDefault(require("fs"));
46
+ var child_process_1 = require("child_process");
47
+ var SDK_GO_MODULE = 'github.com/grafana/grafana-plugin-sdk-go';
48
+ function updateGoSdkAndModules(_a) {
49
+ var _this = this;
50
+ var pluginName = _a.pluginName, orgName = _a.orgName, pluginType = _a.pluginType;
51
+ return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
52
+ var exportPath, goModPath, goBinaryPath, command;
53
+ return __generator(this, function (_a) {
54
+ switch (_a.label) {
55
+ case 0:
56
+ exportPath = (0, utils_path_1.getExportPath)(pluginName, orgName, pluginType);
57
+ goModPath = "".concat(exportPath, "/go.mod");
58
+ if (!fs_1["default"].existsSync(goModPath)) {
59
+ resolve('');
60
+ }
61
+ return [4, (0, which_1["default"])('go', { nothrow: true })];
62
+ case 1:
63
+ goBinaryPath = _a.sent();
64
+ if (!goBinaryPath) {
65
+ resolve('');
66
+ }
67
+ command = "go get ".concat(SDK_GO_MODULE);
68
+ (0, child_process_1.exec)(command, { cwd: exportPath }, function (error) {
69
+ if (error) {
70
+ reject('There was an error trying to update the grafana go sdk. Please run `go get github.com/grafana/grafana-plugin-sdk-go` manually in your plugin directory.');
71
+ }
72
+ resolve('Grafana go sdk updated successfully.');
73
+ });
74
+ return [2];
75
+ }
76
+ });
77
+ }); });
78
+ }
79
+ exports.updateGoSdkAndModules = updateGoSdkAndModules;
@@ -27,12 +27,15 @@ var glob_1 = __importDefault(require("glob"));
27
27
  var path_1 = __importDefault(require("path"));
28
28
  var fs_1 = __importDefault(require("fs"));
29
29
  var utils_handlebars_1 = require("../utils/utils.handlebars");
30
- var utils_console_1 = require("../utils/utils.console");
31
30
  var constants_1 = require("../constants");
31
+ var print_success_message_1 = require("./generate-actions/print-success-message");
32
+ var update_go_sdk_and_packages_1 = require("./generate-actions/update-go-sdk-and-packages");
33
+ var utils_path_1 = require("../utils/utils.path");
32
34
  function default_1(plop) {
33
35
  plop.setHelper('if_eq', utils_handlebars_1.ifEq);
34
36
  plop.setHelper('normalize_id', utils_handlebars_1.normalizeId);
35
- plop.setActionType('printSuccessMessage', printSuccessMessage);
37
+ plop.setActionType('printSuccessMessage', print_success_message_1.printGenerateSuccessMessage);
38
+ plop.setActionType('updateGoSdkAndModules', update_go_sdk_and_packages_1.updateGoSdkAndModules);
36
39
  plop.setGenerator('create-plugin', {
37
40
  description: 'used to scaffold a grafana plugin',
38
41
  prompts: [
@@ -92,7 +95,7 @@ function default_1(plop) {
92
95
  ],
93
96
  actions: function (_a) {
94
97
  var pluginName = _a.pluginName, orgName = _a.orgName, pluginType = _a.pluginType, hasBackend = _a.hasBackend, hasGithubWorkflows = _a.hasGithubWorkflows, hasGithubLevitateWorkflow = _a.hasGithubLevitateWorkflow;
95
- var exportPath = getExportPath(pluginName, orgName, pluginType);
98
+ var exportPath = (0, utils_path_1.getExportPath)(pluginName, orgName, pluginType);
96
99
  var pluginId = (0, utils_handlebars_1.normalizeId)(pluginName, orgName, pluginType);
97
100
  var commonActions = getActionsForTemplateFolder({
98
101
  folderPath: constants_1.TEMPLATE_PATHS.common,
@@ -123,6 +126,9 @@ function default_1(plop) {
123
126
  : [];
124
127
  var readmeActions = getActionsForReadme({ exportPath: exportPath });
125
128
  return __spreadArray(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], pluginActions, true), ciWorkflowActions, true), readmeActions, true), isCompatibleWorkflowActions, true), [
129
+ {
130
+ type: 'updateGoSdkAndModules'
131
+ },
126
132
  {
127
133
  type: 'printSuccessMessage'
128
134
  },
@@ -178,28 +184,3 @@ function isFile(path) {
178
184
  return false;
179
185
  }
180
186
  }
181
- function getExportPath(pluginName, orgName, pluginType) {
182
- if (constants_1.IS_DEV) {
183
- return constants_1.DEV_EXPORT_DIR;
184
- }
185
- else {
186
- return path_1["default"].join(process.cwd(), (0, utils_handlebars_1.normalizeId)(pluginName, orgName, pluginType));
187
- }
188
- }
189
- function printSuccessMessage(answers) {
190
- var directory = (0, utils_handlebars_1.normalizeId)(answers.pluginName, answers.orgName, answers.pluginType);
191
- var commands = __spreadArray(__spreadArray([
192
- "- `cd ./".concat(directory, "`"),
193
- '- `yarn install` to install frontend dependencies.',
194
- '- `yarn dev` to build (and watch) the plugin frontend code.'
195
- ], (answers.hasBackend
196
- ? [
197
- '- `mage -v build:linux` to build the plugin backend code. Rerun this command every time you edit your backend files.',
198
- ]
199
- : []), true), [
200
- '- `docker-compose up` to start a grafana development server. Restart this command after each time you run mage to run your new backend code.',
201
- '- Open http://localhost:3000 in your browser to create a dashboard to begin developing your plugin.',
202
- ], false);
203
- var msg = "\nCongratulations on scaffolding a Grafana ".concat(answers.pluginType, " plugin! \uD83D\uDE80\n\n## What's next?\n\nRun the following commands to get started:\n").concat(commands.map(function (command) { return command; }).join('\n'), "\n\n_Note: We strongly recommend creating a new Git repository by running `git init` in ./").concat(directory, " before continuing._\n\n- View create-plugin documentation at https://grafana.github.io/plugin-tools/\n- Learn more about Grafana Plugins at https://grafana.com/docs/grafana/latest/plugins/developing/development/\n");
204
- return (0, utils_console_1.displayAsMarkdown)(msg);
205
- }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ exports.__esModule = true;
package/dist/constants.js CHANGED
@@ -30,7 +30,7 @@ var PLUGIN_TYPES;
30
30
  PLUGIN_TYPES["secretsmanager"] = "secretsmanager";
31
31
  })(PLUGIN_TYPES = exports.PLUGIN_TYPES || (exports.PLUGIN_TYPES = {}));
32
32
  exports.EXTRA_TEMPLATE_VARIABLES = {
33
- grafanaVersion: '9.2.5'
33
+ grafanaVersion: '9.3.8'
34
34
  };
35
35
  exports.GRAFANA_FE_PACKAGES = [
36
36
  '@grafana/data',
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ exports.__esModule = true;
6
+ exports.getExportPath = void 0;
7
+ var path_1 = __importDefault(require("path"));
8
+ var constants_1 = require("../constants");
9
+ var utils_handlebars_1 = require("./utils.handlebars");
10
+ function getExportPath(pluginName, orgName, pluginType) {
11
+ if (constants_1.IS_DEV) {
12
+ return constants_1.DEV_EXPORT_DIR;
13
+ }
14
+ else {
15
+ return path_1["default"].join(process.cwd(), (0, utils_handlebars_1.normalizeId)(pluginName, orgName, pluginType));
16
+ }
17
+ }
18
+ exports.getExportPath = getExportPath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "directory": "packages/create-plugin",
@@ -24,7 +24,8 @@
24
24
  "generate-app": "tsc && yarn clean-generated && CREATE_PLUGIN_DEV=true node ./scripts/generate-app.js",
25
25
  "generate-app-backend": "tsc && yarn clean-generated && CREATE_PLUGIN_DEV=true node ./scripts/generate-app-backend.js",
26
26
  "generate-panel": "tsc && yarn clean-generated && CREATE_PLUGIN_DEV=true node ./scripts/generate-panel.js",
27
- "generate-datasource": "tsc && yarn clean-generated && CREATE_PLUGIN_DEV=true node ./scripts/generate-datasource.js",
27
+ "generate-datasource": "tsc && yarn clean-generated && CREATE_PLUGIN_DEV=true node ./scripts/generate-datasource-without-backend.js",
28
+ "generate-datasource-backend": "tsc && yarn clean-generated && CREATE_PLUGIN_DEV=true node ./scripts/generate-datasource-with-backend.js",
28
29
  "lint": "eslint --cache --ext .js,.jsx,.ts,.tsx ./src",
29
30
  "lint:fix": "yarn lint --fix",
30
31
  "test": "jest",
@@ -34,13 +35,15 @@
34
35
  "@types/minimist": "^1.2.2",
35
36
  "@types/mkdirp": "^1.0.2",
36
37
  "@types/semver": "^7.3.9",
38
+ "@types/which": "^2.0.2",
37
39
  "enquirer": "^2.3.6",
38
40
  "glob": "^7.1.7",
39
41
  "marked": "^4.0.12",
40
42
  "marked-terminal": "^5.1.1",
41
43
  "mkdirp": "^1.0.4",
42
44
  "plop": "^2.7.4",
43
- "semver": "^7.3.5"
45
+ "semver": "^7.3.5",
46
+ "which": "^3.0.0"
44
47
  },
45
48
  "devDependencies": {
46
49
  "@types/glob": "^7.0.0",
@@ -60,5 +63,5 @@
60
63
  "engines": {
61
64
  "node": ">=16"
62
65
  },
63
- "gitHead": "df4b2df88e1f540db9d6f3122115e1ac5bbdf2cf"
66
+ "gitHead": "411764c1c19aec00fb109d91c71c4aef109b05e2"
64
67
  }
@@ -2,7 +2,7 @@ const nodePlop = require('node-plop');
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
4
 
5
- async function generateApp() {
5
+ async function generate() {
6
6
  const plopFile = path.join(__dirname, '../dist/commands/generate.plopfile.js');
7
7
  if (!fs.existsSync(plopFile)) {
8
8
  console.error('Run build first');
@@ -21,4 +21,4 @@ async function generateApp() {
21
21
  });
22
22
  }
23
23
 
24
- generateApp();
24
+ generate();
@@ -2,7 +2,7 @@ const nodePlop = require('node-plop');
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
4
 
5
- async function generatePanel() {
5
+ async function generate() {
6
6
  const plopFile = path.join(__dirname, '../dist/commands/generate.plopfile.js');
7
7
  if (!fs.existsSync(plopFile)) {
8
8
  console.error('Run build first');
@@ -21,4 +21,4 @@ async function generatePanel() {
21
21
  });
22
22
  }
23
23
 
24
- generatePanel();
24
+ generate();
@@ -2,7 +2,7 @@ const nodePlop = require('node-plop');
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
4
 
5
- async function generatePanel() {
5
+ async function generate() {
6
6
  const plopFile = path.join(__dirname, '../dist/commands/generate.plopfile.js');
7
7
  if (!fs.existsSync(plopFile)) {
8
8
  console.error('Run build first');
@@ -21,4 +21,4 @@ async function generatePanel() {
21
21
  });
22
22
  }
23
23
 
24
- generatePanel();
24
+ generate();
@@ -0,0 +1,24 @@
1
+ const nodePlop = require('node-plop');
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+
5
+ async function generate() {
6
+ const plopFile = path.join(__dirname, '../dist/commands/generate.plopfile.js');
7
+ if (!fs.existsSync(plopFile)) {
8
+ console.error('Run build first');
9
+ process.exit(1);
10
+ }
11
+ const plop = await nodePlop(plopFile);
12
+ const generator = plop.getGenerator('create-plugin');
13
+ await generator.runActions({
14
+ pluginName: 'my-plugin',
15
+ orgName: 'my-org',
16
+ pluginDescription: 'Auto-generated datasource',
17
+ pluginType: 'datasource',
18
+ hasBackend: false,
19
+ hasGithubWorkflows: true,
20
+ hasGithubLevitateWorkflow: true,
21
+ });
22
+ }
23
+
24
+ generate();
@@ -2,7 +2,7 @@ const nodePlop = require('node-plop');
2
2
  const path = require('path');
3
3
  const fs = require('fs');
4
4
 
5
- async function generatePanel() {
5
+ async function generate() {
6
6
  const plopFile = path.join(__dirname, '../dist/commands/generate.plopfile.js');
7
7
  if (!fs.existsSync(plopFile)) {
8
8
  console.error('Run build first');
@@ -20,4 +20,4 @@ async function generatePanel() {
20
20
  });
21
21
  }
22
22
 
23
- generatePanel();
23
+ generate();
@@ -0,0 +1,36 @@
1
+ import { displayAsMarkdown } from '../../utils/utils.console';
2
+ import { normalizeId } from '../../utils/utils.handlebars';
3
+ import { CliArgs } from '../types';
4
+
5
+ export function printGenerateSuccessMessage(answers: CliArgs) {
6
+ const directory = normalizeId(answers.pluginName, answers.orgName, answers.pluginType);
7
+
8
+ const commands = [
9
+ `- \`cd ./${directory}\``,
10
+ '- `yarn install` to install frontend dependencies.',
11
+ '- `yarn dev` to build (and watch) the plugin frontend code.',
12
+ ...(answers.hasBackend
13
+ ? [
14
+ '- `mage -v build:linux` to build the plugin backend code. Rerun this command every time you edit your backend files.',
15
+ ]
16
+ : []),
17
+ '- `docker-compose up` to start a grafana development server. Restart this command after each time you run mage to run your new backend code.',
18
+ '- Open http://localhost:3000 in your browser to create a dashboard to begin developing your plugin.',
19
+ ];
20
+
21
+ const msg = `
22
+ Congratulations on scaffolding a Grafana ${answers.pluginType} plugin! πŸš€
23
+
24
+ ## What's next?
25
+
26
+ Run the following commands to get started:
27
+ ${commands.map((command) => command).join('\n')}
28
+
29
+ _Note: We strongly recommend creating a new Git repository by running \`git init\` in ./${directory} before continuing._
30
+
31
+ - View create-plugin documentation at https://grafana.github.io/plugin-tools/
32
+ - Learn more about Grafana Plugins at https://grafana.com/docs/grafana/latest/plugins/developing/development/
33
+ `;
34
+
35
+ return displayAsMarkdown(msg);
36
+ }
@@ -0,0 +1,39 @@
1
+ import { getExportPath } from '../../utils/utils.path';
2
+ import { CliArgs } from '../types';
3
+ import which from 'which';
4
+ import fs from 'fs';
5
+ import { exec } from 'child_process';
6
+
7
+ const SDK_GO_MODULE = 'github.com/grafana/grafana-plugin-sdk-go';
8
+
9
+ export function updateGoSdkAndModules({ pluginName, orgName, pluginType }: CliArgs): Promise<string> {
10
+ return new Promise(async (resolve, reject) => {
11
+ // plugin directory
12
+ const exportPath = getExportPath(pluginName, orgName, pluginType);
13
+
14
+ // check if there is a go.mod file in exportPath
15
+ const goModPath = `${exportPath}/go.mod`;
16
+ if (!fs.existsSync(goModPath)) {
17
+ // skip if there is no go.mod file
18
+ resolve('');
19
+ }
20
+
21
+ const goBinaryPath = await which('go', { nothrow: true });
22
+
23
+ // if no go binary is found, skip
24
+ if (!goBinaryPath) {
25
+ resolve('');
26
+ }
27
+
28
+ // run go get SDK_GO_MODULE to update the go.mod file
29
+ const command = `go get ${SDK_GO_MODULE}`;
30
+ exec(command, { cwd: exportPath }, (error) => {
31
+ if (error) {
32
+ reject(
33
+ 'There was an error trying to update the grafana go sdk. Please run `go get github.com/grafana/grafana-plugin-sdk-go` manually in your plugin directory.'
34
+ );
35
+ }
36
+ resolve('Grafana go sdk updated successfully.');
37
+ });
38
+ });
39
+ }
@@ -3,32 +3,19 @@ import glob from 'glob';
3
3
  import path from 'path';
4
4
  import fs from 'fs';
5
5
  import { ifEq, normalizeId } from '../utils/utils.handlebars';
6
- import { displayAsMarkdown } from '../utils/utils.console';
7
- import {
8
- IS_DEV,
9
- TEMPLATE_PATHS,
10
- PARTIALS_DIR,
11
- PLUGIN_TYPES,
12
- EXTRA_TEMPLATE_VARIABLES,
13
- DEV_EXPORT_DIR,
14
- } from '../constants';
15
-
16
- type CliArgs = {
17
- pluginName: string;
18
- pluginDescription: string;
19
- orgName: string;
20
- pluginType: PLUGIN_TYPES;
21
- hasBackend: boolean;
22
- hasGithubWorkflows: boolean;
23
- hasGithubLevitateWorkflow: boolean;
24
- };
6
+ import { IS_DEV, TEMPLATE_PATHS, PARTIALS_DIR, PLUGIN_TYPES, EXTRA_TEMPLATE_VARIABLES } from '../constants';
7
+ import { printGenerateSuccessMessage } from './generate-actions/print-success-message';
8
+ import { updateGoSdkAndModules } from './generate-actions/update-go-sdk-and-packages';
9
+ import { CliArgs } from './types';
10
+ import { getExportPath } from '../utils/utils.path';
25
11
 
26
12
  // Plopfile API documentation: https://plopjs.com/documentation/#plopfile-api
27
13
  export default function (plop: NodePlopAPI) {
28
14
  plop.setHelper('if_eq', ifEq);
29
15
  plop.setHelper('normalize_id', normalizeId);
30
16
 
31
- plop.setActionType('printSuccessMessage', printSuccessMessage);
17
+ plop.setActionType('printSuccessMessage', printGenerateSuccessMessage);
18
+ plop.setActionType('updateGoSdkAndModules', updateGoSdkAndModules);
32
19
 
33
20
  plop.setGenerator('create-plugin', {
34
21
  description: 'used to scaffold a grafana plugin',
@@ -147,6 +134,9 @@ export default function (plop: NodePlopAPI) {
147
134
  ...ciWorkflowActions,
148
135
  ...readmeActions,
149
136
  ...isCompatibleWorkflowActions,
137
+ {
138
+ type: 'updateGoSdkAndModules',
139
+ },
150
140
  {
151
141
  type: 'printSuccessMessage',
152
142
  },
@@ -237,44 +227,3 @@ function isFile(path: string) {
237
227
  return false;
238
228
  }
239
229
  }
240
-
241
- function getExportPath(pluginName: string, orgName: string, pluginType: PLUGIN_TYPES) {
242
- if (IS_DEV) {
243
- return DEV_EXPORT_DIR;
244
- } else {
245
- return path.join(process.cwd(), normalizeId(pluginName, orgName, pluginType));
246
- }
247
- }
248
-
249
- function printSuccessMessage(answers: CliArgs) {
250
- const directory = normalizeId(answers.pluginName, answers.orgName, answers.pluginType);
251
-
252
- const commands = [
253
- `- \`cd ./${directory}\``,
254
- '- `yarn install` to install frontend dependencies.',
255
- '- `yarn dev` to build (and watch) the plugin frontend code.',
256
- ...(answers.hasBackend
257
- ? [
258
- '- `mage -v build:linux` to build the plugin backend code. Rerun this command every time you edit your backend files.',
259
- ]
260
- : []),
261
- '- `docker-compose up` to start a grafana development server. Restart this command after each time you run mage to run your new backend code.',
262
- '- Open http://localhost:3000 in your browser to create a dashboard to begin developing your plugin.',
263
- ];
264
-
265
- const msg = `
266
- Congratulations on scaffolding a Grafana ${answers.pluginType} plugin! πŸš€
267
-
268
- ## What's next?
269
-
270
- Run the following commands to get started:
271
- ${commands.map((command) => command).join('\n')}
272
-
273
- _Note: We strongly recommend creating a new Git repository by running \`git init\` in ./${directory} before continuing._
274
-
275
- - View create-plugin documentation at https://grafana.github.io/plugin-tools/
276
- - Learn more about Grafana Plugins at https://grafana.com/docs/grafana/latest/plugins/developing/development/
277
- `;
278
-
279
- return displayAsMarkdown(msg);
280
- }
@@ -0,0 +1,11 @@
1
+ import { PLUGIN_TYPES } from '../constants';
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
+ };
package/src/constants.ts CHANGED
@@ -38,7 +38,7 @@ export enum PLUGIN_TYPES {
38
38
  // and will be available to use in the templates.
39
39
  // Example: "@grafana/ui": "{{ grafanaVersion }}"
40
40
  export const EXTRA_TEMPLATE_VARIABLES = {
41
- grafanaVersion: '9.2.5',
41
+ grafanaVersion: '9.3.8',
42
42
  };
43
43
 
44
44
  export const GRAFANA_FE_PACKAGES = [
@@ -0,0 +1,11 @@
1
+ import path from 'path';
2
+ import { PLUGIN_TYPES, IS_DEV, DEV_EXPORT_DIR } from '../constants';
3
+ import { normalizeId } from './utils.handlebars';
4
+
5
+ export function getExportPath(pluginName: string, orgName: string, pluginType: PLUGIN_TYPES): string {
6
+ if (IS_DEV) {
7
+ return DEV_EXPORT_DIR;
8
+ } else {
9
+ return path.join(process.cwd(), normalizeId(pluginName, orgName, pluginType));
10
+ }
11
+ }
@@ -24,7 +24,7 @@
24
24
  # Runs the tests and watches for changes, requires git init first
25
25
  yarn test
26
26
 
27
- # Exists after running all the tests
27
+ # Exits after running all the tests
28
28
  yarn test:ci
29
29
  ```
30
30
 
@@ -37,10 +37,10 @@
37
37
  6. Run the E2E tests (using Cypress)
38
38
 
39
39
  ```bash
40
- # Spin up a Grafana instance first that we tests against
40
+ # Spins up a Grafana instance first that we tests against
41
41
  yarn server
42
42
 
43
- # Start the tests
43
+ # Starts the tests
44
44
  yarn e2e
45
45
  ```
46
46
 
@@ -7,7 +7,7 @@ import {
7
7
  FieldType,
8
8
  } from '@grafana/data';
9
9
 
10
- import { MyQuery, MyDataSourceOptions, DEFAULT_QUERY } from './types';
10
+ import { MyQuery, MyDataSourceOptions } from './types';
11
11
 
12
12
  export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
13
13
  constructor(instanceSettings: DataSourceInstanceSettings<MyDataSourceOptions>) {
@@ -59,14 +59,14 @@ jobs:
59
59
 
60
60
  - name: Test backend
61
61
  if: steps.check-for-backend.outputs.has-backend == 'true'
62
- uses: magefile/mage-action@v1
62
+ uses: magefile/mage-action@v2
63
63
  with:
64
64
  version: latest
65
65
  args: coverage
66
66
 
67
67
  - name: Build backend
68
68
  if: steps.check-for-backend.outputs.has-backend == 'true'
69
- uses: magefile/mage-action@v1
69
+ uses: magefile/mage-action@v2
70
70
  with:
71
71
  version: latest
72
72
  args: buildAll
@@ -41,14 +41,14 @@ jobs:
41
41
 
42
42
  - name: Test backend
43
43
  if: steps.check-for-backend.outputs.has-backend == 'true'
44
- uses: magefile/mage-action@v1
44
+ uses: magefile/mage-action@v2
45
45
  with:
46
46
  version: latest
47
47
  args: coverage
48
48
 
49
49
  - name: Build backend
50
50
  if: steps.check-for-backend.outputs.has-backend == 'true'
51
- uses: magefile/mage-action@v1
51
+ uses: magefile/mage-action@v2
52
52
  with:
53
53
  version: latest
54
54
  args: buildAll