@grafana/create-plugin 2.1.2 → 2.2.0-canary.461.e4fa17a.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.
@@ -0,0 +1,75 @@
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.prettifyFiles = void 0;
43
+ var node_child_process_1 = require("node:child_process");
44
+ var node_util_1 = require("node:util");
45
+ var fs_1 = __importDefault(require("fs"));
46
+ var utils_path_1 = require("../../utils/utils.path");
47
+ var exec = (0, node_util_1.promisify)(node_child_process_1.exec);
48
+ function prettifyFiles(_a) {
49
+ var pluginName = _a.pluginName, orgName = _a.orgName, pluginType = _a.pluginType;
50
+ return __awaiter(this, void 0, void 0, function () {
51
+ var exportPath, command, error_1;
52
+ return __generator(this, function (_b) {
53
+ switch (_b.label) {
54
+ case 0:
55
+ exportPath = (0, utils_path_1.getExportPath)(pluginName, orgName, pluginType);
56
+ if (!fs_1.default.existsSync(exportPath)) {
57
+ return [2, ''];
58
+ }
59
+ _b.label = 1;
60
+ case 1:
61
+ _b.trys.push([1, 3, , 4]);
62
+ command = 'npx -y prettier@2 . --write';
63
+ return [4, exec(command, { cwd: exportPath })];
64
+ case 2:
65
+ _b.sent();
66
+ return [3, 4];
67
+ case 3:
68
+ error_1 = _b.sent();
69
+ throw new Error('There was a problem running prettier on the plugin files. Please run `npx -y prettier@2 . --write` manually in your plugin directory.');
70
+ case 4: return [2, 'Successfully ran prettier against new plugin.'];
71
+ }
72
+ });
73
+ });
74
+ }
75
+ exports.prettifyFiles = prettifyFiles;
@@ -32,10 +32,12 @@ var utils_path_1 = require("../utils/utils.path");
32
32
  var utils_packageManager_1 = require("../utils/utils.packageManager");
33
33
  var print_success_message_1 = require("./generate-actions/print-success-message");
34
34
  var update_go_sdk_and_packages_1 = require("./generate-actions/update-go-sdk-and-packages");
35
+ var prettify_files_1 = require("./generate-actions/prettify-files");
35
36
  function default_1(plop) {
36
37
  plop.setHelper('if_eq', utils_handlebars_1.ifEq);
37
38
  plop.setHelper('normalize_id', utils_handlebars_1.normalizeId);
38
39
  plop.setActionType('printSuccessMessage', print_success_message_1.printGenerateSuccessMessage);
40
+ plop.setActionType('prettifyFiles', prettify_files_1.prettifyFiles);
39
41
  plop.setActionType('updateGoSdkAndModules', update_go_sdk_and_packages_1.updateGoSdkAndModules);
40
42
  plop.setGenerator('create-plugin', {
41
43
  description: 'used to scaffold a grafana plugin',
@@ -107,7 +109,7 @@ function default_1(plop) {
107
109
  packageManagerInstallCmd: packageManagerInstallCmd,
108
110
  packageManagerVersion: packageManagerVersion,
109
111
  isAppType: isAppType,
110
- isNPM: packageManagerName === 'npm'
112
+ isNPM: packageManagerName === 'npm',
111
113
  };
112
114
  var commonActions = getActionsForTemplateFolder({
113
115
  folderPath: constants_1.TEMPLATE_PATHS.common,
@@ -150,6 +152,7 @@ function default_1(plop) {
150
152
  {
151
153
  type: 'updateGoSdkAndModules',
152
154
  },
155
+ { type: 'prettifyFiles' },
153
156
  {
154
157
  type: 'printSuccessMessage',
155
158
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "2.1.2",
3
+ "version": "2.2.0-canary.461.e4fa17a.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": ">=18"
68
68
  },
69
- "gitHead": "48891238ab03ceee986a8806a325666a64537bcf"
69
+ "gitHead": "e4fa17aa3f1decac42b75a8fe9a57bec58db530f"
70
70
  }
@@ -0,0 +1,25 @@
1
+ import { exec as nodeExec } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import fs from 'fs';
4
+ import { getExportPath } from '../../utils/utils.path';
5
+ import { CliArgs } from '../types';
6
+
7
+ const exec = promisify(nodeExec);
8
+
9
+ export async function prettifyFiles({ pluginName, orgName, pluginType }: CliArgs) {
10
+ const exportPath = getExportPath(pluginName, orgName, pluginType);
11
+
12
+ if (!fs.existsSync(exportPath)) {
13
+ return '';
14
+ }
15
+
16
+ try {
17
+ let command = 'npx -y prettier@2 . --write';
18
+ await exec(command, { cwd: exportPath });
19
+ } catch (error) {
20
+ throw new Error(
21
+ 'There was a problem running prettier on the plugin files. Please run `npx -y prettier@2 . --write` manually in your plugin directory.'
22
+ );
23
+ }
24
+ return 'Successfully ran prettier against new plugin.';
25
+ }
@@ -8,6 +8,7 @@ import { getExportPath } from '../utils/utils.path';
8
8
  import { getPackageManagerInstallCmd, getPackageManagerFromUserAgent } from '../utils/utils.packageManager';
9
9
  import { printGenerateSuccessMessage } from './generate-actions/print-success-message';
10
10
  import { updateGoSdkAndModules } from './generate-actions/update-go-sdk-and-packages';
11
+ import { prettifyFiles } from './generate-actions/prettify-files';
11
12
  import { CliArgs, TemplateData } from './types';
12
13
 
13
14
  // Plopfile API documentation: https://plopjs.com/documentation/#plopfile-api
@@ -16,6 +17,7 @@ export default function (plop: NodePlopAPI) {
16
17
  plop.setHelper('normalize_id', normalizeId);
17
18
 
18
19
  plop.setActionType('printSuccessMessage', printGenerateSuccessMessage);
20
+ plop.setActionType('prettifyFiles', prettifyFiles);
19
21
  plop.setActionType('updateGoSdkAndModules', updateGoSdkAndModules);
20
22
 
21
23
  plop.setGenerator('create-plugin', {
@@ -95,7 +97,7 @@ export default function (plop: NodePlopAPI) {
95
97
  packageManagerInstallCmd,
96
98
  packageManagerVersion,
97
99
  isAppType,
98
- isNPM: packageManagerName === 'npm'
100
+ isNPM: packageManagerName === 'npm',
99
101
  };
100
102
  // Copy over files that are shared between plugins types
101
103
  const commonActions = getActionsForTemplateFolder({
@@ -159,6 +161,7 @@ export default function (plop: NodePlopAPI) {
159
161
  {
160
162
  type: 'updateGoSdkAndModules',
161
163
  },
164
+ { type: 'prettifyFiles' },
162
165
  {
163
166
  type: 'printSuccessMessage',
164
167
  },