@grafana/create-plugin 2.11.2 → 2.12.0-canary.658.dabaee1.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 +13 -18
- package/dist/commands/generate/prettify-files.js +15 -70
- package/dist/commands/generate/print-success-message.js +28 -31
- package/dist/commands/generate/prompt-user.js +23 -91
- package/dist/commands/generate/update-go-sdk-and-packages.js +36 -105
- package/dist/commands/generate.command.js +122 -240
- package/dist/commands/index.js +5 -21
- package/dist/commands/migrate.command.js +71 -134
- package/dist/commands/provisioning.command.js +30 -85
- package/dist/commands/types.js +1 -2
- package/dist/commands/update.command.js +44 -97
- package/dist/commands/version.command.js +16 -57
- package/dist/constants.js +37 -32
- package/dist/utils/tests/utils.files.test.js +21 -23
- package/dist/utils/tests/utils.handlebars.test.js +24 -26
- package/dist/utils/tests/utils.npm.test.js +103 -95
- package/dist/utils/tests/utils.plugin.test.js +11 -13
- package/dist/utils/tests/utils.templates.test.js +16 -18
- package/dist/utils/utils.config.js +30 -32
- package/dist/utils/utils.console.js +25 -31
- package/dist/utils/utils.files.js +38 -104
- package/dist/utils/utils.handlebars.js +30 -65
- package/dist/utils/utils.npm.js +75 -118
- package/dist/utils/utils.os.js +3 -7
- package/dist/utils/utils.packageManager.js +31 -37
- package/dist/utils/utils.packagejson.js +13 -22
- package/dist/utils/utils.path.js +7 -14
- package/dist/utils/utils.plugin.js +6 -13
- package/dist/utils/utils.templates.js +58 -80
- package/dist/utils/utils.version.js +9 -11
- package/package.json +20 -6
- package/src/bin/run.ts +2 -2
- package/src/commands/generate/prettify-files.ts +1 -1
- package/src/commands/generate/print-success-message.ts +4 -4
- package/src/commands/generate/prompt-user.ts +2 -2
- package/src/commands/generate/update-go-sdk-and-packages.ts +2 -2
- package/src/commands/generate.command.ts +15 -15
- package/src/commands/index.ts +5 -5
- package/src/commands/migrate.command.ts +6 -6
- package/src/commands/provisioning.command.ts +6 -6
- package/src/commands/types.ts +1 -1
- package/src/commands/update.command.ts +5 -5
- package/src/commands/version.command.ts +5 -2
- package/src/constants.ts +4 -1
- package/src/utils/tests/utils.files.test.ts +2 -2
- package/src/utils/tests/utils.handlebars.test.ts +2 -2
- package/src/utils/tests/utils.npm.test.ts +43 -34
- package/src/utils/tests/utils.plugin.test.ts +2 -2
- package/src/utils/tests/utils.templates.test.ts +2 -2
- package/src/utils/utils.config.ts +3 -3
- package/src/utils/utils.console.ts +16 -11
- package/src/utils/utils.files.ts +3 -3
- package/src/utils/utils.handlebars.ts +3 -3
- package/src/utils/utils.npm.ts +3 -3
- package/src/utils/utils.packageManager.ts +3 -3
- package/src/utils/utils.packagejson.ts +5 -5
- package/src/utils/utils.path.ts +3 -3
- package/src/utils/utils.plugin.ts +2 -3
- package/src/utils/utils.templates.ts +10 -10
- package/src/utils/utils.version.ts +5 -2
- package/tsconfig.json +5 -0
- package/vitest.config.ts +10 -0
package/dist/bin/run.js
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
var minimist_1 = __importDefault(require("minimist"));
|
|
8
|
-
var commands_1 = require("../commands");
|
|
9
|
-
var utils_os_1 = require("../utils/utils.os");
|
|
10
|
-
if ((0, utils_os_1.isUnsupportedPlatform)()) {
|
|
2
|
+
import minimist from 'minimist';
|
|
3
|
+
import { generate, update, migrate, version, provisioning } from '../commands/index.js';
|
|
4
|
+
import { isUnsupportedPlatform } from '../utils/utils.os.js';
|
|
5
|
+
if (isUnsupportedPlatform()) {
|
|
11
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");
|
|
12
7
|
process.exit(1);
|
|
13
8
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
migrate
|
|
18
|
-
generate
|
|
19
|
-
update
|
|
20
|
-
version
|
|
21
|
-
provisioning
|
|
9
|
+
const args = process.argv.slice(2);
|
|
10
|
+
const argv = minimist(args);
|
|
11
|
+
const commands = {
|
|
12
|
+
migrate,
|
|
13
|
+
generate,
|
|
14
|
+
update,
|
|
15
|
+
version,
|
|
16
|
+
provisioning,
|
|
22
17
|
};
|
|
23
|
-
|
|
18
|
+
const command = commands[argv._[0]] || commands.generate;
|
|
24
19
|
command(argv);
|
|
@@ -1,72 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 };
|
|
1
|
+
import { exec as nodeExec } from 'node:child_process';
|
|
2
|
+
import { promisify } from 'node:util';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
const exec = promisify(nodeExec);
|
|
5
|
+
export async function prettifyFiles(exportPath) {
|
|
6
|
+
if (!fs.existsSync(exportPath)) {
|
|
7
|
+
return '';
|
|
36
8
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var fs_1 = __importDefault(require("fs"));
|
|
46
|
-
var exec = (0, node_util_1.promisify)(node_child_process_1.exec);
|
|
47
|
-
function prettifyFiles(exportPath) {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
49
|
-
var command, error_1;
|
|
50
|
-
return __generator(this, function (_a) {
|
|
51
|
-
switch (_a.label) {
|
|
52
|
-
case 0:
|
|
53
|
-
if (!fs_1.default.existsSync(exportPath)) {
|
|
54
|
-
return [2, ''];
|
|
55
|
-
}
|
|
56
|
-
_a.label = 1;
|
|
57
|
-
case 1:
|
|
58
|
-
_a.trys.push([1, 3, , 4]);
|
|
59
|
-
command = 'npx -y prettier@2 . --write';
|
|
60
|
-
return [4, exec(command, { cwd: exportPath })];
|
|
61
|
-
case 2:
|
|
62
|
-
_a.sent();
|
|
63
|
-
return [3, 4];
|
|
64
|
-
case 3:
|
|
65
|
-
error_1 = _a.sent();
|
|
66
|
-
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.');
|
|
67
|
-
case 4: return [2, 'Successfully ran prettier against new plugin.'];
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
});
|
|
9
|
+
try {
|
|
10
|
+
let command = 'npx -y prettier@2 . --write';
|
|
11
|
+
await exec(command, { cwd: exportPath });
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
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.');
|
|
15
|
+
}
|
|
16
|
+
return 'Successfully ran prettier against new plugin.';
|
|
71
17
|
}
|
|
72
|
-
exports.prettifyFiles = prettifyFiles;
|
|
@@ -1,34 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
function printGenerateSuccessMessage(answers) {
|
|
17
|
-
var directory = (0, utils_handlebars_1.normalizeId)(answers.pluginName, answers.orgName, answers.pluginType);
|
|
18
|
-
var packageManagerName = (0, utils_packageManager_1.getPackageManagerFromUserAgent)().packageManagerName;
|
|
19
|
-
var commands = __spreadArray(__spreadArray([
|
|
20
|
-
"- `cd ./".concat(directory, "`"),
|
|
21
|
-
"- `".concat(packageManagerName, " install` to install frontend dependencies."),
|
|
22
|
-
"- `".concat(packageManagerName, " run dev` to build (and watch) the plugin frontend code.")
|
|
23
|
-
], (answers.hasBackend
|
|
24
|
-
? [
|
|
25
|
-
'- `mage -v build:linux` to build the plugin backend code. Rerun this command every time you edit your backend files.',
|
|
26
|
-
]
|
|
27
|
-
: []), true), [
|
|
1
|
+
import { displayAsMarkdown } from '../../utils/utils.console.js';
|
|
2
|
+
import { normalizeId } from '../../utils/utils.handlebars.js';
|
|
3
|
+
import { getPackageManagerFromUserAgent } from '../../utils/utils.packageManager.js';
|
|
4
|
+
export function printGenerateSuccessMessage(answers) {
|
|
5
|
+
const directory = normalizeId(answers.pluginName, answers.orgName, answers.pluginType);
|
|
6
|
+
const { packageManagerName } = getPackageManagerFromUserAgent();
|
|
7
|
+
const commands = [
|
|
8
|
+
`- \`cd ./${directory}\``,
|
|
9
|
+
`- \`${packageManagerName} install\` to install frontend dependencies.`,
|
|
10
|
+
`- \`${packageManagerName} run dev\` to build (and watch) the plugin frontend code.`,
|
|
11
|
+
...(answers.hasBackend
|
|
12
|
+
? [
|
|
13
|
+
'- `mage -v build:linux` to build the plugin backend code. Rerun this command every time you edit your backend files.',
|
|
14
|
+
]
|
|
15
|
+
: []),
|
|
28
16
|
'- `docker-compose up` to start a grafana development server. Restart this command after each time you run mage to run your new backend code.',
|
|
29
17
|
'- Open http://localhost:3000 in your browser to create a dashboard to begin developing your plugin.',
|
|
30
|
-
]
|
|
31
|
-
|
|
32
|
-
|
|
18
|
+
];
|
|
19
|
+
const msg = `\n# Congratulations on scaffolding a Grafana ${answers.pluginType} plugin! 🚀
|
|
20
|
+
|
|
21
|
+
## What's next?
|
|
22
|
+
|
|
23
|
+
Run the following commands to get started:
|
|
24
|
+
${commands.map((command) => command).join('\n')}
|
|
25
|
+
|
|
26
|
+
_Note: We strongly recommend creating a new Git repository by running \`git init\` in ./${directory} before continuing._
|
|
27
|
+
|
|
28
|
+
- Learn more about Grafana Plugin Development at https://grafana.com/developers/plugin-tools
|
|
29
|
+
`;
|
|
30
|
+
console.log(displayAsMarkdown(msg));
|
|
33
31
|
}
|
|
34
|
-
exports.printGenerateSuccessMessage = printGenerateSuccessMessage;
|
|
@@ -1,99 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import Enquirer from 'enquirer';
|
|
2
|
+
import { PLUGIN_TYPES } from '../../constants.js';
|
|
3
|
+
export async function promptUser(argv) {
|
|
4
|
+
let answers = {};
|
|
5
|
+
const enquirer = new Enquirer();
|
|
6
|
+
for (const prompt of prompts) {
|
|
7
|
+
const { name, shouldPrompt } = prompt;
|
|
8
|
+
if (argv.hasOwnProperty(name)) {
|
|
9
|
+
answers = { ...answers, [name]: argv[name] };
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
11
|
+
else {
|
|
12
|
+
if (typeof shouldPrompt === 'function' && !shouldPrompt(answers)) {
|
|
13
|
+
continue;
|
|
43
14
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
50
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
51
|
-
};
|
|
52
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
53
|
-
exports.promptUser = void 0;
|
|
54
|
-
var enquirer_1 = __importDefault(require("enquirer"));
|
|
55
|
-
var constants_1 = require("../../constants");
|
|
56
|
-
function promptUser(argv) {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
58
|
-
var answers, enquirer, _i, prompts_1, prompt_1, name_1, shouldPrompt, result;
|
|
59
|
-
var _a;
|
|
60
|
-
return __generator(this, function (_b) {
|
|
61
|
-
switch (_b.label) {
|
|
62
|
-
case 0:
|
|
63
|
-
answers = {};
|
|
64
|
-
enquirer = new enquirer_1.default();
|
|
65
|
-
_i = 0, prompts_1 = prompts;
|
|
66
|
-
_b.label = 1;
|
|
67
|
-
case 1:
|
|
68
|
-
if (!(_i < prompts_1.length)) return [3, 6];
|
|
69
|
-
prompt_1 = prompts_1[_i];
|
|
70
|
-
name_1 = prompt_1.name, shouldPrompt = prompt_1.shouldPrompt;
|
|
71
|
-
if (!argv.hasOwnProperty(name_1)) return [3, 2];
|
|
72
|
-
answers = __assign(__assign({}, answers), (_a = {}, _a[name_1] = argv[name_1], _a));
|
|
73
|
-
return [3, 5];
|
|
74
|
-
case 2:
|
|
75
|
-
if (!(typeof shouldPrompt === 'function' && !shouldPrompt(answers))) return [3, 3];
|
|
76
|
-
return [3, 5];
|
|
77
|
-
case 3: return [4, enquirer.prompt(prompt_1)];
|
|
78
|
-
case 4:
|
|
79
|
-
result = _b.sent();
|
|
80
|
-
answers = __assign(__assign({}, answers), result);
|
|
81
|
-
_b.label = 5;
|
|
82
|
-
case 5:
|
|
83
|
-
_i++;
|
|
84
|
-
return [3, 1];
|
|
85
|
-
case 6: return [2, answers];
|
|
15
|
+
else {
|
|
16
|
+
const result = await enquirer.prompt(prompt);
|
|
17
|
+
answers = { ...answers, ...result };
|
|
86
18
|
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return answers;
|
|
89
22
|
}
|
|
90
|
-
|
|
91
|
-
var prompts = [
|
|
23
|
+
const prompts = [
|
|
92
24
|
{
|
|
93
25
|
name: 'pluginName',
|
|
94
26
|
type: 'input',
|
|
95
27
|
message: 'What is going to be the name of your plugin?',
|
|
96
|
-
validate:
|
|
28
|
+
validate: (value) => {
|
|
97
29
|
if (/.+/.test(value)) {
|
|
98
30
|
return true;
|
|
99
31
|
}
|
|
@@ -104,7 +36,7 @@ var prompts = [
|
|
|
104
36
|
name: 'orgName',
|
|
105
37
|
type: 'input',
|
|
106
38
|
message: 'What is the organization name of your plugin?',
|
|
107
|
-
validate:
|
|
39
|
+
validate: (value) => {
|
|
108
40
|
if (/.+/.test(value)) {
|
|
109
41
|
return true;
|
|
110
42
|
}
|
|
@@ -120,7 +52,7 @@ var prompts = [
|
|
|
120
52
|
{
|
|
121
53
|
name: 'pluginType',
|
|
122
54
|
type: 'select',
|
|
123
|
-
choices: [
|
|
55
|
+
choices: [PLUGIN_TYPES.app, PLUGIN_TYPES.datasource, PLUGIN_TYPES.panel, PLUGIN_TYPES.scenes],
|
|
124
56
|
message: 'What type of plugin would you like?',
|
|
125
57
|
},
|
|
126
58
|
{
|
|
@@ -128,7 +60,7 @@ var prompts = [
|
|
|
128
60
|
type: 'confirm',
|
|
129
61
|
message: 'Do you want a backend part of your plugin?',
|
|
130
62
|
initial: false,
|
|
131
|
-
shouldPrompt:
|
|
63
|
+
shouldPrompt: (answers) => answers.pluginType !== PLUGIN_TYPES.panel,
|
|
132
64
|
},
|
|
133
65
|
{
|
|
134
66
|
name: 'hasGithubWorkflows',
|
|
@@ -1,113 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 };
|
|
1
|
+
import which from 'which';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { exec } from 'node:child_process';
|
|
4
|
+
const SDK_GO_MODULE = 'github.com/grafana/grafana-plugin-sdk-go';
|
|
5
|
+
export async function updateGoSdkAndModules(exportPath) {
|
|
6
|
+
const goModPath = `${exportPath}/go.mod`;
|
|
7
|
+
if (!fs.existsSync(goModPath)) {
|
|
8
|
+
return '';
|
|
36
9
|
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return
|
|
49
|
-
var goModPath, goBinaryPath, _a;
|
|
50
|
-
return __generator(this, function (_b) {
|
|
51
|
-
switch (_b.label) {
|
|
52
|
-
case 0:
|
|
53
|
-
goModPath = "".concat(exportPath, "/go.mod");
|
|
54
|
-
if (!fs_1.default.existsSync(goModPath)) {
|
|
55
|
-
return [2, ''];
|
|
56
|
-
}
|
|
57
|
-
return [4, (0, which_1.default)('go', { nothrow: true })];
|
|
58
|
-
case 1:
|
|
59
|
-
goBinaryPath = _b.sent();
|
|
60
|
-
if (!goBinaryPath) {
|
|
61
|
-
return [2, ''];
|
|
62
|
-
}
|
|
63
|
-
_b.label = 2;
|
|
64
|
-
case 2:
|
|
65
|
-
_b.trys.push([2, 5, , 6]);
|
|
66
|
-
return [4, updateSdk(exportPath)];
|
|
67
|
-
case 3:
|
|
68
|
-
_b.sent();
|
|
69
|
-
return [4, updateGoMod(exportPath)];
|
|
70
|
-
case 4:
|
|
71
|
-
_b.sent();
|
|
72
|
-
return [3, 6];
|
|
73
|
-
case 5:
|
|
74
|
-
_a = _b.sent();
|
|
75
|
-
throw new Error('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.');
|
|
76
|
-
case 6: return [2, 'Grafana go sdk updated successfully.'];
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
});
|
|
10
|
+
const goBinaryPath = await which('go', { nothrow: true });
|
|
11
|
+
if (!goBinaryPath) {
|
|
12
|
+
return '';
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
await updateSdk(exportPath);
|
|
16
|
+
await updateGoMod(exportPath);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
throw new Error('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.');
|
|
20
|
+
}
|
|
21
|
+
return 'Grafana go sdk updated successfully.';
|
|
80
22
|
}
|
|
81
|
-
exports.updateGoSdkAndModules = updateGoSdkAndModules;
|
|
82
23
|
function updateSdk(exportPath) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
reject();
|
|
91
|
-
}
|
|
92
|
-
resolve();
|
|
93
|
-
});
|
|
94
|
-
return [2];
|
|
24
|
+
return new Promise(async (resolve, reject) => {
|
|
25
|
+
const command = `go get ${SDK_GO_MODULE}`;
|
|
26
|
+
exec(command, { cwd: exportPath }, (error) => {
|
|
27
|
+
if (error) {
|
|
28
|
+
reject();
|
|
29
|
+
}
|
|
30
|
+
resolve();
|
|
95
31
|
});
|
|
96
|
-
});
|
|
32
|
+
});
|
|
97
33
|
}
|
|
98
34
|
function updateGoMod(exportPath) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
reject();
|
|
107
|
-
}
|
|
108
|
-
resolve();
|
|
109
|
-
});
|
|
110
|
-
return [2];
|
|
35
|
+
return new Promise(async (resolve, reject) => {
|
|
36
|
+
const command = `go mod tidy`;
|
|
37
|
+
exec(command, { cwd: exportPath }, (error) => {
|
|
38
|
+
if (error) {
|
|
39
|
+
reject();
|
|
40
|
+
}
|
|
41
|
+
resolve();
|
|
111
42
|
});
|
|
112
|
-
});
|
|
43
|
+
});
|
|
113
44
|
}
|