@grafana/create-plugin 2.6.0 → 2.7.0-canary.528.8a2e623.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
@@ -95,6 +95,14 @@ For more information see [here](https://grafana.com/developers/plugin-tools/migr
95
95
 
96
96
  ---
97
97
 
98
+ ## Package your plugin
99
+
100
+ You can use the `package` command to [package](https://grafana.com/developers/plugin-tools/publish-a-plugin/package-a-plugin) your plugin automatically.
101
+
102
+ 1. Build your plugin: e.g. `npm run build` or `yarn build` and `mage` if your plugin has a backend.
103
+ 2. [Sign your plugin](https://grafana.com/developers/plugin-tools/publish-a-plugin/sign-a-plugin).
104
+ 3. Run `npx @grafana/create-plugin@latest package` to package your plugin. A zip file with your plugin will be created.
105
+
98
106
  ## Customizing or extending the basic configs
99
107
 
100
108
  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)
package/dist/bin/run.js CHANGED
@@ -17,6 +17,7 @@ var commands = {
17
17
  migrate: commands_1.migrate,
18
18
  generate: commands_1.generate,
19
19
  update: commands_1.update,
20
+ package: commands_1.packagePlugin,
20
21
  version: commands_1.version,
21
22
  };
22
23
  var command = commands[argv._[0]] || commands.generate;
@@ -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("./package.command"), exports);
@@ -0,0 +1,130 @@
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.packagePlugin = void 0;
43
+ var fs_1 = __importDefault(require("fs"));
44
+ var utils_console_1 = require("../utils/utils.console");
45
+ var archiver_1 = __importDefault(require("archiver"));
46
+ var path_1 = __importDefault(require("path"));
47
+ var packagePlugin = function (argv) { return __awaiter(void 0, void 0, void 0, function () {
48
+ var nonInteractive, CWD, DIS_PATH, PLUGIN_JSON, MANIFEST_TXT, confirm_1, pluginJsonContent, pluginId, zipFileName, zipFilePath, confirm_2, _a, error_1;
49
+ return __generator(this, function (_b) {
50
+ switch (_b.label) {
51
+ case 0:
52
+ nonInteractive = argv['non-interactive'];
53
+ CWD = process.cwd();
54
+ DIS_PATH = path_1.default.join(CWD, 'dist');
55
+ PLUGIN_JSON = path_1.default.join(DIS_PATH, 'plugin.json');
56
+ MANIFEST_TXT = path_1.default.join(DIS_PATH, 'MANIFEST.txt');
57
+ if (!fs_1.default.existsSync(DIS_PATH) || !fs_1.default.statSync(DIS_PATH).isDirectory()) {
58
+ (0, utils_console_1.printErrorMessage)("Could not find 'dist' directory. Please build your plugin before running this command. e.g.: `yarn build` or `npm run build`");
59
+ process.exit(1);
60
+ }
61
+ if (!fs_1.default.existsSync(PLUGIN_JSON)) {
62
+ (0, utils_console_1.printErrorMessage)("Could not find 'plugin.json' inside 'dist' directory. Please build your plugin before running this command. e.g.: `yarn build` or `npm run build`");
63
+ process.exit(1);
64
+ }
65
+ if (!(!fs_1.default.existsSync(MANIFEST_TXT) && !nonInteractive)) return [3, 2];
66
+ return [4, (0, utils_console_1.confirmPrompt)("Could not find a 'MANIFEST.txt' file inside 'dist' directory. This means that the plugin is not signed. Would you like to continue generating an unsigned archive file?")];
67
+ case 1:
68
+ confirm_1 = _b.sent();
69
+ if (!confirm_1) {
70
+ process.exit(1);
71
+ }
72
+ _b.label = 2;
73
+ case 2:
74
+ pluginJsonContent = require(PLUGIN_JSON);
75
+ pluginId = pluginJsonContent.id;
76
+ zipFileName = "".concat(pluginId, ".zip");
77
+ zipFilePath = path_1.default.join(CWD, zipFileName);
78
+ if (!fs_1.default.existsSync(zipFilePath)) return [3, 5];
79
+ _a = nonInteractive;
80
+ if (_a) return [3, 4];
81
+ return [4, (0, utils_console_1.confirmPrompt)("A zip file with the name '".concat(zipFileName, "' already exists. Do you want to continue and overwrite it?"))];
82
+ case 3:
83
+ _a = (_b.sent());
84
+ _b.label = 4;
85
+ case 4:
86
+ confirm_2 = _a;
87
+ if (confirm_2) {
88
+ try {
89
+ fs_1.default.unlinkSync(zipFilePath);
90
+ }
91
+ catch (error) {
92
+ (0, utils_console_1.printErrorMessage)("Could not delete existing zip file: ".concat(error));
93
+ process.exit(1);
94
+ }
95
+ }
96
+ else {
97
+ process.exit(1);
98
+ }
99
+ _b.label = 5;
100
+ case 5:
101
+ _b.trys.push([5, 7, , 8]);
102
+ return [4, zipDistPath(DIS_PATH, zipFilePath, pluginId)];
103
+ case 6:
104
+ _b.sent();
105
+ (0, utils_console_1.printSuccessMessage)("Successfully created zip archive at ".concat(zipFileName));
106
+ return [3, 8];
107
+ case 7:
108
+ error_1 = _b.sent();
109
+ (0, utils_console_1.printErrorMessage)("Could not create zip file: ".concat(error_1));
110
+ return [3, 8];
111
+ case 8: return [2];
112
+ }
113
+ });
114
+ }); };
115
+ exports.packagePlugin = packagePlugin;
116
+ function zipDistPath(path, destination, pathName) {
117
+ return new Promise(function (resolve, reject) {
118
+ var output = fs_1.default.createWriteStream(destination);
119
+ var archive = (0, archiver_1.default)('zip', { zlib: { level: 9 } });
120
+ output.on('close', function () {
121
+ resolve(destination);
122
+ });
123
+ archive.on('error', function (err) {
124
+ reject(err);
125
+ });
126
+ archive.pipe(output);
127
+ archive.directory(path, pathName);
128
+ archive.finalize();
129
+ });
130
+ }
@@ -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.printErrorMessage = exports.printWarningMessage = 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,14 @@ function printSuccessMessage(msg) {
23
23
  console.log(displayAsMarkdown("\n\u2714 ".concat(msg)));
24
24
  }
25
25
  exports.printSuccessMessage = printSuccessMessage;
26
+ function printWarningMessage(msg) {
27
+ console.log(displayAsMarkdown("\n\u26A0 ".concat(msg)));
28
+ }
29
+ exports.printWarningMessage = printWarningMessage;
30
+ function printErrorMessage(msg) {
31
+ console.log(displayAsMarkdown("\n\u274C ".concat(msg)));
32
+ }
33
+ exports.printErrorMessage = printErrorMessage;
26
34
  function confirmPrompt(message) {
27
35
  var prompt = new Confirm({
28
36
  name: 'question',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "2.6.0",
3
+ "version": "2.7.0-canary.528.8a2e623.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "directory": "packages/create-plugin",
@@ -38,6 +38,7 @@
38
38
  "@types/mkdirp": "^1.0.2",
39
39
  "@types/semver": "^7.3.9",
40
40
  "@types/which": "^2.0.2",
41
+ "archiver": "^6.0.1",
41
42
  "enquirer": "^2.3.6",
42
43
  "find-up": "^5.0.0",
43
44
  "glob": "^7.1.7",
@@ -49,6 +50,7 @@
49
50
  "which": "^3.0.0"
50
51
  },
51
52
  "devDependencies": {
53
+ "@types/archiver": "^6.0.1",
52
54
  "@types/glob": "^7.0.0",
53
55
  "eslint-plugin-react": "^7.26.1",
54
56
  "eslint-plugin-react-hooks": "^4.2.0"
@@ -66,5 +68,5 @@
66
68
  "engines": {
67
69
  "node": ">=20"
68
70
  },
69
- "gitHead": "ffb46743a4f8a37fb1cbb4755fa2bad7feae4da5"
71
+ "gitHead": "8a2e623b848ed62103eadc61e22593acc4c5718f"
70
72
  }
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, packagePlugin } from '../commands';
5
5
  import { isUnsupportedPlatform } from '../utils/utils.os';
6
6
 
7
7
  // Exit early if operating system isn't supported.
@@ -18,6 +18,7 @@ const commands: Record<string, (argv: minimist.ParsedArgs) => void> = {
18
18
  migrate,
19
19
  generate,
20
20
  update,
21
+ package: packagePlugin,
21
22
  version,
22
23
  };
23
24
  const command = commands[argv._[0]] || commands.generate;
@@ -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 './package.command';
@@ -0,0 +1,92 @@
1
+ import minimist from 'minimist';
2
+ import fs from 'fs';
3
+ import { confirmPrompt, printErrorMessage, printSuccessMessage } from '../utils/utils.console';
4
+ import archiver from 'archiver';
5
+ import path from 'path';
6
+
7
+ export const packagePlugin = async (argv: minimist.ParsedArgs) => {
8
+ const nonInteractive = argv['non-interactive'];
9
+
10
+ const CWD = process.cwd();
11
+ const DIS_PATH = path.join(CWD, 'dist');
12
+ const PLUGIN_JSON = path.join(DIS_PATH, 'plugin.json');
13
+ const MANIFEST_TXT = path.join(DIS_PATH, 'MANIFEST.txt');
14
+
15
+ // validate DIS_PATH exists
16
+ if (!fs.existsSync(DIS_PATH) || !fs.statSync(DIS_PATH).isDirectory()) {
17
+ printErrorMessage(
18
+ "Could not find 'dist' directory. Please build your plugin before running this command. e.g.: `yarn build` or `npm run build`"
19
+ );
20
+ process.exit(1);
21
+ }
22
+
23
+ // validate PLUGIN_JSON exists
24
+ if (!fs.existsSync(PLUGIN_JSON)) {
25
+ printErrorMessage(
26
+ "Could not find 'plugin.json' inside 'dist' directory. Please build your plugin before running this command. e.g.: `yarn build` or `npm run build`"
27
+ );
28
+ process.exit(1);
29
+ }
30
+
31
+ // if no manifest file, warn user and confirm if wish to continue
32
+ if (!fs.existsSync(MANIFEST_TXT) && !nonInteractive) {
33
+ const confirm = await confirmPrompt(
34
+ `Could not find a 'MANIFEST.txt' file inside 'dist' directory. This means that the plugin is not signed. Would you like to continue generating an unsigned archive file?`
35
+ );
36
+ if (!confirm) {
37
+ process.exit(1);
38
+ }
39
+ }
40
+
41
+ const pluginJsonContent = require(PLUGIN_JSON);
42
+ const pluginId = pluginJsonContent.id;
43
+
44
+ const zipFileName = `${pluginId}.zip`;
45
+ const zipFilePath = path.join(CWD, zipFileName);
46
+
47
+ // if zip file already exists, warn user and confirm if wish to continue
48
+ if (fs.existsSync(zipFilePath)) {
49
+ const confirm =
50
+ nonInteractive ||
51
+ (await confirmPrompt(
52
+ `A zip file with the name '${zipFileName}' already exists. Do you want to continue and overwrite it?`
53
+ ));
54
+
55
+ if (confirm) {
56
+ try {
57
+ fs.unlinkSync(zipFilePath);
58
+ } catch (error) {
59
+ printErrorMessage(`Could not delete existing zip file: ${error}`);
60
+ process.exit(1);
61
+ }
62
+ } else {
63
+ process.exit(1);
64
+ }
65
+ }
66
+
67
+ try {
68
+ await zipDistPath(DIS_PATH, zipFilePath, pluginId);
69
+ printSuccessMessage(`Successfully created zip archive at ${zipFileName}`);
70
+ } catch (error) {
71
+ printErrorMessage(`Could not create zip file: ${error}`);
72
+ }
73
+ };
74
+
75
+ function zipDistPath(path: string, destination: string, pathName: string): Promise<string> {
76
+ return new Promise((resolve, reject) => {
77
+ const output = fs.createWriteStream(destination);
78
+ const archive = archiver('zip', { zlib: { level: 9 } });
79
+
80
+ output.on('close', () => {
81
+ resolve(destination);
82
+ });
83
+
84
+ archive.on('error', (err) => {
85
+ reject(err);
86
+ });
87
+
88
+ archive.pipe(output);
89
+ archive.directory(path, pathName);
90
+ archive.finalize();
91
+ });
92
+ }
@@ -22,6 +22,14 @@ export function printSuccessMessage(msg: string) {
22
22
  console.log(displayAsMarkdown(`\n✔ ${msg}`));
23
23
  }
24
24
 
25
+ export function printWarningMessage(msg: string) {
26
+ console.log(displayAsMarkdown(`\n⚠ ${msg}`));
27
+ }
28
+
29
+ export function printErrorMessage(msg: string) {
30
+ console.log(displayAsMarkdown(`\n❌ ${msg}`));
31
+ }
32
+
25
33
  export function confirmPrompt(message: string): Promise<boolean> {
26
34
  const prompt = new Confirm({
27
35
  name: 'question',