@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.
Files changed (62) hide show
  1. package/dist/bin/run.js +13 -18
  2. package/dist/commands/generate/prettify-files.js +15 -70
  3. package/dist/commands/generate/print-success-message.js +28 -31
  4. package/dist/commands/generate/prompt-user.js +23 -91
  5. package/dist/commands/generate/update-go-sdk-and-packages.js +36 -105
  6. package/dist/commands/generate.command.js +122 -240
  7. package/dist/commands/index.js +5 -21
  8. package/dist/commands/migrate.command.js +71 -134
  9. package/dist/commands/provisioning.command.js +30 -85
  10. package/dist/commands/types.js +1 -2
  11. package/dist/commands/update.command.js +44 -97
  12. package/dist/commands/version.command.js +16 -57
  13. package/dist/constants.js +37 -32
  14. package/dist/utils/tests/utils.files.test.js +21 -23
  15. package/dist/utils/tests/utils.handlebars.test.js +24 -26
  16. package/dist/utils/tests/utils.npm.test.js +103 -95
  17. package/dist/utils/tests/utils.plugin.test.js +11 -13
  18. package/dist/utils/tests/utils.templates.test.js +16 -18
  19. package/dist/utils/utils.config.js +30 -32
  20. package/dist/utils/utils.console.js +25 -31
  21. package/dist/utils/utils.files.js +38 -104
  22. package/dist/utils/utils.handlebars.js +30 -65
  23. package/dist/utils/utils.npm.js +75 -118
  24. package/dist/utils/utils.os.js +3 -7
  25. package/dist/utils/utils.packageManager.js +31 -37
  26. package/dist/utils/utils.packagejson.js +13 -22
  27. package/dist/utils/utils.path.js +7 -14
  28. package/dist/utils/utils.plugin.js +6 -13
  29. package/dist/utils/utils.templates.js +58 -80
  30. package/dist/utils/utils.version.js +9 -11
  31. package/package.json +20 -6
  32. package/src/bin/run.ts +2 -2
  33. package/src/commands/generate/prettify-files.ts +1 -1
  34. package/src/commands/generate/print-success-message.ts +4 -4
  35. package/src/commands/generate/prompt-user.ts +2 -2
  36. package/src/commands/generate/update-go-sdk-and-packages.ts +2 -2
  37. package/src/commands/generate.command.ts +15 -15
  38. package/src/commands/index.ts +5 -5
  39. package/src/commands/migrate.command.ts +6 -6
  40. package/src/commands/provisioning.command.ts +6 -6
  41. package/src/commands/types.ts +1 -1
  42. package/src/commands/update.command.ts +5 -5
  43. package/src/commands/version.command.ts +5 -2
  44. package/src/constants.ts +4 -1
  45. package/src/utils/tests/utils.files.test.ts +2 -2
  46. package/src/utils/tests/utils.handlebars.test.ts +2 -2
  47. package/src/utils/tests/utils.npm.test.ts +43 -34
  48. package/src/utils/tests/utils.plugin.test.ts +2 -2
  49. package/src/utils/tests/utils.templates.test.ts +2 -2
  50. package/src/utils/utils.config.ts +3 -3
  51. package/src/utils/utils.console.ts +16 -11
  52. package/src/utils/utils.files.ts +3 -3
  53. package/src/utils/utils.handlebars.ts +3 -3
  54. package/src/utils/utils.npm.ts +3 -3
  55. package/src/utils/utils.packageManager.ts +3 -3
  56. package/src/utils/utils.packagejson.ts +5 -5
  57. package/src/utils/utils.path.ts +3 -3
  58. package/src/utils/utils.plugin.ts +2 -3
  59. package/src/utils/utils.templates.ts +10 -10
  60. package/src/utils/utils.version.ts +5 -2
  61. package/tsconfig.json +5 -0
  62. package/vitest.config.ts +10 -0
@@ -1,88 +1,33 @@
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;
1
+ import glob from 'glob';
2
+ import path from 'node:path';
3
+ import fs from 'node:fs';
4
+ import { TEMPLATE_PATHS, TEXT } from '../constants.js';
5
+ import { getPluginJson } from '../utils/utils.plugin.js';
6
+ import { compileProvisioningTemplateFile, getTemplateData } from '../utils/utils.templates.js';
7
+ import { confirmPrompt, printMessage, printSuccessMessage, printError } from '../utils/utils.console.js';
8
+ export const provisioning = async () => {
9
+ const { type } = getPluginJson();
10
+ const provisioningFolder = path.join(process.cwd(), 'provisioning');
11
+ try {
12
+ if (await confirmPrompt(TEXT.addProvisioning)) {
13
+ if (!fs.existsSync(provisioningFolder)) {
14
+ const provisioningSpecificFiles = glob.sync(`${TEMPLATE_PATHS[type]}/provisioning/**`, { dot: true });
15
+ provisioningSpecificFiles.forEach((file) => {
16
+ compileProvisioningTemplateFile(type, file, getTemplateData());
17
+ });
18
+ printSuccessMessage(TEXT.addProvisioningSuccess);
19
+ }
20
+ else {
21
+ printMessage(`You plugin already has provisioning files located under ${provisioningFolder}, aborting.`);
22
+ process.exit(0);
32
23
  }
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 };
24
+ }
25
+ else {
26
+ printMessage(TEXT.addProvisioningAborted);
27
+ process.exit(1);
28
+ }
29
+ }
30
+ catch (error) {
31
+ printError(error);
36
32
  }
37
33
  };
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;
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,110 +1,57 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.update = void 0;
40
- var constants_1 = require("../constants");
41
- var utils_templates_1 = require("../utils/utils.templates");
42
- var utils_console_1 = require("../utils/utils.console");
43
- var utils_npm_1 = require("../utils/utils.npm");
44
- var utils_packageManager_1 = require("../utils/utils.packageManager");
45
- var update = function () { return __awaiter(void 0, void 0, void 0, function () {
46
- var updatableText, PROMPT_CHOICES, shouldUpdateDeps, packageManager, error_1;
47
- return __generator(this, function (_a) {
48
- switch (_a.label) {
49
- case 0:
50
- _a.trys.push([0, 5, , 6]);
51
- (0, utils_console_1.printMessage)(constants_1.TEXT.updateCommandWarning);
52
- return [4, (0, utils_console_1.confirmPrompt)(constants_1.TEXT.updateConfigPrompt)];
53
- case 1:
54
- if (_a.sent()) {
55
- (0, utils_templates_1.compileTemplateFiles)(constants_1.UDPATE_CONFIG.filesToOverride, (0, utils_templates_1.getTemplateData)());
56
- (0, utils_console_1.printSuccessMessage)(constants_1.TEXT.overrideFilesSuccess);
57
- }
58
- else {
59
- (0, utils_console_1.printMessage)(constants_1.TEXT.overrideFilesAborted);
60
- process.exit(0);
61
- }
62
- if (!(0, utils_npm_1.hasNpmDependenciesToUpdate)({ devOnly: true })) return [3, 3];
63
- updatableText = (0, utils_npm_1.getPackageJsonUpdatesAsText)({ ignoreGrafanaDependencies: true, devOnly: true });
64
- if (!(updatableText.length > 0)) return [3, 3];
65
- PROMPT_CHOICES = {
1
+ import { TEXT, UDPATE_CONFIG } from '../constants.js';
2
+ import { compileTemplateFiles, getTemplateData } from '../utils/utils.templates.js';
3
+ import { confirmPrompt, selectPrompt, printMessage, printSuccessMessage } from '../utils/utils.console.js';
4
+ import { updatePackageJson, hasNpmDependenciesToUpdate, getPackageJsonUpdatesAsText, updateNpmScripts, writePackageManagerInPackageJson, } from '../utils/utils.npm.js';
5
+ import { getPackageManagerWithFallback } from '../utils/utils.packageManager.js';
6
+ export const update = async () => {
7
+ try {
8
+ printMessage(TEXT.updateCommandWarning);
9
+ if (await confirmPrompt(TEXT.updateConfigPrompt)) {
10
+ compileTemplateFiles(UDPATE_CONFIG.filesToOverride, getTemplateData());
11
+ printSuccessMessage(TEXT.overrideFilesSuccess);
12
+ }
13
+ else {
14
+ printMessage(TEXT.overrideFilesAborted);
15
+ process.exit(0);
16
+ }
17
+ if (hasNpmDependenciesToUpdate({ devOnly: true })) {
18
+ const updatableText = getPackageJsonUpdatesAsText({ ignoreGrafanaDependencies: true, devOnly: true });
19
+ if (updatableText.length > 0) {
20
+ const PROMPT_CHOICES = {
66
21
  ALL: 'Yes, all of them',
67
22
  ONLY_OUTDATED: 'Yes, but only the outdated ones',
68
23
  NONE: 'No',
69
24
  };
70
- return [4, (0, utils_console_1.selectPrompt)(constants_1.TEXT.updateNpmDependenciesPrompt + updatableText, [
71
- PROMPT_CHOICES.ALL,
72
- PROMPT_CHOICES.ONLY_OUTDATED,
73
- PROMPT_CHOICES.NONE,
74
- ])];
75
- case 2:
76
- shouldUpdateDeps = _a.sent();
25
+ const shouldUpdateDeps = await selectPrompt(TEXT.updateNpmDependenciesPrompt + updatableText, [
26
+ PROMPT_CHOICES.ALL,
27
+ PROMPT_CHOICES.ONLY_OUTDATED,
28
+ PROMPT_CHOICES.NONE,
29
+ ]);
77
30
  if (shouldUpdateDeps && shouldUpdateDeps !== PROMPT_CHOICES.NONE) {
78
- (0, utils_npm_1.updatePackageJson)({
31
+ updatePackageJson({
79
32
  onlyOutdated: shouldUpdateDeps === PROMPT_CHOICES.ONLY_OUTDATED,
80
33
  ignoreGrafanaDependencies: true,
81
34
  devOnly: true,
82
35
  });
83
- (0, utils_console_1.printSuccessMessage)(constants_1.TEXT.updateNpmDependenciesSuccess);
36
+ printSuccessMessage(TEXT.updateNpmDependenciesSuccess);
84
37
  }
85
38
  else {
86
- (0, utils_console_1.printMessage)(constants_1.TEXT.updateNpmDependenciesAborted);
39
+ printMessage(TEXT.updateNpmDependenciesAborted);
87
40
  }
88
- _a.label = 3;
89
- case 3: return [4, (0, utils_console_1.confirmPrompt)(constants_1.TEXT.updateNpmScriptsPrompt)];
90
- case 4:
91
- if (_a.sent()) {
92
- (0, utils_npm_1.updateNpmScripts)();
93
- (0, utils_console_1.printSuccessMessage)(constants_1.TEXT.updateNpmScriptsSuccess);
94
- }
95
- else {
96
- (0, utils_console_1.printMessage)(constants_1.TEXT.updateNpmScriptsAborted);
97
- }
98
- packageManager = (0, utils_packageManager_1.getPackageManagerWithFallback)();
99
- (0, utils_npm_1.writePackageManagerInPackageJson)(packageManager);
100
- (0, utils_console_1.printSuccessMessage)(constants_1.TEXT.updateCommandSuccess);
101
- return [3, 6];
102
- case 5:
103
- error_1 = _a.sent();
104
- console.error(error_1);
105
- return [3, 6];
106
- case 6: return [2];
41
+ }
42
+ }
43
+ if (await confirmPrompt(TEXT.updateNpmScriptsPrompt)) {
44
+ updateNpmScripts();
45
+ printSuccessMessage(TEXT.updateNpmScriptsSuccess);
107
46
  }
108
- });
109
- }); };
110
- exports.update = update;
47
+ else {
48
+ printMessage(TEXT.updateNpmScriptsAborted);
49
+ }
50
+ const packageManager = getPackageManagerWithFallback();
51
+ writePackageManagerInPackageJson(packageManager);
52
+ printSuccessMessage(TEXT.updateCommandSuccess);
53
+ }
54
+ catch (error) {
55
+ console.error(error);
56
+ }
57
+ };
@@ -1,63 +1,22 @@
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 };
1
+ import { resolve } from 'node:path';
2
+ import { readFileSync } from 'node:fs';
3
+ import { fileURLToPath } from 'node:url';
4
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
5
+ export const version = async () => {
6
+ try {
7
+ console.log(getVersion());
8
+ }
9
+ catch (error) {
10
+ console.error(error);
11
+ process.exit(1);
36
12
  }
37
13
  };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.version = void 0;
40
- var path_1 = require("path");
41
- var fs_1 = require("fs");
42
- var version = function () { return __awaiter(void 0, void 0, void 0, function () {
43
- return __generator(this, function (_a) {
44
- try {
45
- console.log(getVersion());
46
- }
47
- catch (error) {
48
- console.error(error);
49
- process.exit(1);
50
- }
51
- return [2];
52
- });
53
- }); };
54
- exports.version = version;
55
- var getVersion = function () {
56
- var packageJsonPath = (0, path_1.resolve)(__dirname, '..', '..', 'package.json');
57
- var pkg = (0, fs_1.readFileSync)(packageJsonPath, 'utf8');
58
- var version = JSON.parse(pkg).version;
14
+ const getVersion = () => {
15
+ const packageJsonPath = resolve(__dirname, '..', '..', 'package.json');
16
+ const pkg = readFileSync(packageJsonPath, 'utf8');
17
+ const { version } = JSON.parse(pkg);
59
18
  if (!version) {
60
- throw "Could not find the version of sign-plugin";
19
+ throw `Could not find the version of sign-plugin`;
61
20
  }
62
21
  return version;
63
22
  };
package/dist/constants.js CHANGED
@@ -1,41 +1,37 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
4
+ export const IS_DEV = process.env.CREATE_PLUGIN_DEV !== undefined;
5
+ export const DEV_EXPORT_DIR = path.join(__dirname, '..', 'generated');
6
+ export const EXPORT_PATH_PREFIX = IS_DEV ? DEV_EXPORT_DIR : process.cwd();
7
+ export const DIST_DIR = path.join(__dirname, 'dist');
8
+ export const TEMPLATES_DIR = path.join(__dirname, '..', 'templates');
9
+ export const PARTIALS_DIR = path.join(TEMPLATES_DIR, '_partials');
10
+ export const FIXTURES_PATH = path.join(__dirname, '..', 'fixtures');
11
+ export const TEMPLATE_PATHS = {
12
+ app: path.join(TEMPLATES_DIR, 'app'),
13
+ scenesapp: path.join(TEMPLATES_DIR, 'scenes-app'),
14
+ backend: path.join(TEMPLATES_DIR, 'backend'),
15
+ backendApp: path.join(TEMPLATES_DIR, 'backend-app'),
16
+ common: path.join(TEMPLATES_DIR, 'common'),
17
+ datasource: path.join(TEMPLATES_DIR, 'datasource'),
18
+ panel: path.join(TEMPLATES_DIR, 'panel'),
19
+ ciWorkflows: path.join(TEMPLATES_DIR, 'github', 'ci'),
20
+ isCompatibleWorkflow: path.join(TEMPLATES_DIR, 'github', 'is-compatible'),
4
21
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.TEXT = exports.UDPATE_CONFIG = exports.MIGRATION_CONFIG = exports.GRAFANA_FE_PACKAGES = exports.EXTRA_TEMPLATE_VARIABLES = exports.PLUGIN_TYPES = exports.TEMPLATE_PATHS = exports.FIXTURES_PATH = exports.PARTIALS_DIR = exports.TEMPLATES_DIR = exports.DIST_DIR = exports.EXPORT_PATH_PREFIX = exports.DEV_EXPORT_DIR = exports.IS_DEV = void 0;
7
- var path_1 = __importDefault(require("path"));
8
- exports.IS_DEV = process.env.CREATE_PLUGIN_DEV !== undefined;
9
- exports.DEV_EXPORT_DIR = path_1.default.join(__dirname, '..', 'generated');
10
- exports.EXPORT_PATH_PREFIX = exports.IS_DEV ? exports.DEV_EXPORT_DIR : process.cwd();
11
- exports.DIST_DIR = path_1.default.join(__dirname, 'dist');
12
- exports.TEMPLATES_DIR = path_1.default.join(__dirname, '..', 'templates');
13
- exports.PARTIALS_DIR = path_1.default.join(exports.TEMPLATES_DIR, '_partials');
14
- exports.FIXTURES_PATH = path_1.default.join(__dirname, '..', 'fixtures');
15
- exports.TEMPLATE_PATHS = {
16
- app: path_1.default.join(exports.TEMPLATES_DIR, 'app'),
17
- scenesapp: path_1.default.join(exports.TEMPLATES_DIR, 'scenes-app'),
18
- backend: path_1.default.join(exports.TEMPLATES_DIR, 'backend'),
19
- backendApp: path_1.default.join(exports.TEMPLATES_DIR, 'backend-app'),
20
- common: path_1.default.join(exports.TEMPLATES_DIR, 'common'),
21
- datasource: path_1.default.join(exports.TEMPLATES_DIR, 'datasource'),
22
- panel: path_1.default.join(exports.TEMPLATES_DIR, 'panel'),
23
- ciWorkflows: path_1.default.join(exports.TEMPLATES_DIR, 'github', 'ci'),
24
- isCompatibleWorkflow: path_1.default.join(exports.TEMPLATES_DIR, 'github', 'is-compatible'),
25
- };
26
- var PLUGIN_TYPES;
22
+ export var PLUGIN_TYPES;
27
23
  (function (PLUGIN_TYPES) {
28
24
  PLUGIN_TYPES["app"] = "app";
29
25
  PLUGIN_TYPES["panel"] = "panel";
30
26
  PLUGIN_TYPES["datasource"] = "datasource";
31
27
  PLUGIN_TYPES["secretsmanager"] = "secretsmanager";
32
28
  PLUGIN_TYPES["scenes"] = "scenesapp";
33
- })(PLUGIN_TYPES || (exports.PLUGIN_TYPES = PLUGIN_TYPES = {}));
34
- exports.EXTRA_TEMPLATE_VARIABLES = {
29
+ })(PLUGIN_TYPES || (PLUGIN_TYPES = {}));
30
+ export const EXTRA_TEMPLATE_VARIABLES = {
35
31
  grafanaVersion: '10.0.3',
36
32
  grafanaImage: 'grafana-enterprise',
37
33
  };
38
- exports.GRAFANA_FE_PACKAGES = [
34
+ export const GRAFANA_FE_PACKAGES = [
39
35
  '@grafana/data',
40
36
  '@grafana/e2e-selectors',
41
37
  '@grafana/e2e',
@@ -43,7 +39,7 @@ exports.GRAFANA_FE_PACKAGES = [
43
39
  '@grafana/schema',
44
40
  '@grafana/ui',
45
41
  ];
46
- exports.MIGRATION_CONFIG = {
42
+ export const MIGRATION_CONFIG = {
47
43
  filesToOverride: [
48
44
  '.config/',
49
45
  '.eslintrc',
@@ -59,10 +55,10 @@ exports.MIGRATION_CONFIG = {
59
55
  npmDependenciesToRemove: ['ts-loader', 'babel-loader', '@grafana/toolkit'],
60
56
  devNpmDependenciesToRemove: ['@grafana/toolkit', '@grafana/runtime', '@grafana/data', '@grafana/ui'],
61
57
  };
62
- exports.UDPATE_CONFIG = {
58
+ export const UDPATE_CONFIG = {
63
59
  filesToOverride: ['.config/'],
64
60
  };
65
- exports.TEXT = {
61
+ export const TEXT = {
66
62
  overrideFilesPrompt: '**The following files will be overriden, would you like to continue?**',
67
63
  overrideFilesSuccess: 'Configuration files updated successfully.',
68
64
  overrideFilesAborted: 'Migration aborted.',
@@ -86,7 +82,16 @@ exports.TEXT = {
86
82
  updateNpmScriptsSuccess: 'NPM scripts updated successfully.',
87
83
  updateNpmScriptsAborted: 'No NPM scripts have been added or updated.',
88
84
  migrationCommandWarning: '**⚠️ Warning!**\nThis is going to change files in your current project to make it up-to-date with the latest plugin configuration.\nPlease make sure that you have backed up your changes.',
89
- migrationCommandSuccess: "\n## What's next?\n * Run `yarn install` to install the latest dependencies.\n * Check your tsconfig.json. You might need to update if you had a custom configuration.\n * If you have a custom webpack configuration you might need to update it too.\n * Run `yarn build` and observe the output for any errors.\n * Test your plugin in grafana and make sure everything works as expected.\n\nSee instructions on how to customize your configuration here https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations\n ",
85
+ migrationCommandSuccess: `
86
+ ## What's next?
87
+ * Run \`yarn install\` to install the latest dependencies.
88
+ * Check your tsconfig.json. You might need to update if you had a custom configuration.
89
+ * If you have a custom webpack configuration you might need to update it too.
90
+ * Run \`yarn build\` and observe the output for any errors.
91
+ * Test your plugin in grafana and make sure everything works as expected.
92
+
93
+ See instructions on how to customize your configuration here https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations
94
+ `,
90
95
  updateCommandWarning: '**⚠️ Warning!**\nThis is going to update files under the `.config/` folder.\nMake sure to commit your changes before running this script.',
91
96
  updateCommandSuccess: '**Done.**\nIf you have any questions please open an issue/discussion in https://github.com/grafana/plugin-tools.',
92
97
  };
@@ -1,30 +1,28 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var constants_1 = require("../../constants");
4
- var utils_files_1 = require("../utils.files");
5
- describe('Utils/Files', function () {
6
- describe('filterOutCommonFiles()', function () {
7
- test('should remove common template files from the list that have a plugin-specific override', function () {
8
- expect((0, utils_files_1.filterOutCommonFiles)([
9
- "".concat(constants_1.TEMPLATE_PATHS.common, "/.config/.eslintrc"),
10
- "".concat(constants_1.TEMPLATE_PATHS.common, "/.config/.gitignore"),
11
- "".concat(constants_1.TEMPLATE_PATHS.common, "/.config/package.json"),
12
- "".concat(constants_1.TEMPLATE_PATHS.app, "/.config/package.json"),
13
- "".concat(constants_1.TEMPLATE_PATHS.app, "/.config/README.md"),
14
- ], constants_1.PLUGIN_TYPES.app)).toEqual([
15
- "".concat(constants_1.TEMPLATE_PATHS.common, "/.config/.eslintrc"),
16
- "".concat(constants_1.TEMPLATE_PATHS.common, "/.config/.gitignore"),
17
- "".concat(constants_1.TEMPLATE_PATHS.app, "/.config/package.json"),
18
- "".concat(constants_1.TEMPLATE_PATHS.app, "/.config/README.md"),
1
+ import { PLUGIN_TYPES, TEMPLATE_PATHS } from '../../constants.js';
2
+ import { filterOutCommonFiles, isFile } from '../utils.files.js';
3
+ describe('Utils/Files', () => {
4
+ describe('filterOutCommonFiles()', () => {
5
+ test('should remove common template files from the list that have a plugin-specific override', () => {
6
+ expect(filterOutCommonFiles([
7
+ `${TEMPLATE_PATHS.common}/.config/.eslintrc`,
8
+ `${TEMPLATE_PATHS.common}/.config/.gitignore`,
9
+ `${TEMPLATE_PATHS.common}/.config/package.json`,
10
+ `${TEMPLATE_PATHS.app}/.config/package.json`,
11
+ `${TEMPLATE_PATHS.app}/.config/README.md`,
12
+ ], PLUGIN_TYPES.app)).toEqual([
13
+ `${TEMPLATE_PATHS.common}/.config/.eslintrc`,
14
+ `${TEMPLATE_PATHS.common}/.config/.gitignore`,
15
+ `${TEMPLATE_PATHS.app}/.config/package.json`,
16
+ `${TEMPLATE_PATHS.app}/.config/README.md`,
19
17
  ]);
20
18
  });
21
19
  });
22
- describe('isFile()', function () {
23
- test('should return TRUE if the path is pointing to a file', function () {
24
- expect((0, utils_files_1.isFile)("".concat(constants_1.TEMPLATE_PATHS.common, "/LICENSE"))).toBe(true);
20
+ describe('isFile()', () => {
21
+ test('should return TRUE if the path is pointing to a file', () => {
22
+ expect(isFile(`${TEMPLATE_PATHS.common}/LICENSE`)).toBe(true);
25
23
  });
26
- test('should return FALSE if the path is pointing to a directory', function () {
27
- expect((0, utils_files_1.isFile)(constants_1.TEMPLATE_PATHS.common)).toBe(false);
24
+ test('should return FALSE if the path is pointing to a directory', () => {
25
+ expect(isFile(TEMPLATE_PATHS.common)).toBe(false);
28
26
  });
29
27
  });
30
28
  });
@@ -1,32 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var constants_1 = require("../../constants");
4
- var utils_handlebars_1 = require("../utils.handlebars");
5
- describe('Handlebars helpers', function () {
6
- describe('normalize id', function () {
7
- test.each([constants_1.PLUGIN_TYPES.app, constants_1.PLUGIN_TYPES.datasource, constants_1.PLUGIN_TYPES.panel])('should return the id with the type appended', function (type) {
8
- var pluginName = 'my-plugin';
9
- var orgName = 'my-org';
10
- var actual = (0, utils_handlebars_1.normalizeId)(pluginName, orgName, type);
11
- expect(actual).toEqual("myorg-myplugin-".concat(type));
1
+ import { PLUGIN_TYPES } from '../../constants.js';
2
+ import { normalizeId } from '../utils.handlebars.js';
3
+ describe('Handlebars helpers', () => {
4
+ describe('normalize id', () => {
5
+ test.each([PLUGIN_TYPES.app, PLUGIN_TYPES.datasource, PLUGIN_TYPES.panel])('should return the id with the type appended', (type) => {
6
+ const pluginName = 'my-plugin';
7
+ const orgName = 'my-org';
8
+ const actual = normalizeId(pluginName, orgName, type);
9
+ expect(actual).toEqual(`myorg-myplugin-${type}`);
12
10
  });
13
- test.each([constants_1.PLUGIN_TYPES.app, constants_1.PLUGIN_TYPES.datasource, constants_1.PLUGIN_TYPES.panel])('should not duplicate the type if it is already present', function (type) {
14
- var pluginName = "my-plugin-".concat(type);
15
- var orgName = 'my-org';
16
- var actual = (0, utils_handlebars_1.normalizeId)(pluginName, orgName, type);
17
- expect(actual).toEqual("myorg-myplugin-".concat(type));
11
+ test.each([PLUGIN_TYPES.app, PLUGIN_TYPES.datasource, PLUGIN_TYPES.panel])('should not duplicate the type if it is already present', (type) => {
12
+ const pluginName = `my-plugin-${type}`;
13
+ const orgName = 'my-org';
14
+ const actual = normalizeId(pluginName, orgName, type);
15
+ expect(actual).toEqual(`myorg-myplugin-${type}`);
18
16
  });
19
- test.each([constants_1.PLUGIN_TYPES.app, constants_1.PLUGIN_TYPES.datasource, constants_1.PLUGIN_TYPES.panel])('should not duplicate the type if it is already present (no dash before type)', function (type) {
20
- var pluginName = "my-plugin".concat(type);
21
- var orgName = 'my-org';
22
- var actual = (0, utils_handlebars_1.normalizeId)(pluginName, orgName, type);
23
- expect(actual).toEqual("myorg-myplugin-".concat(type));
17
+ test.each([PLUGIN_TYPES.app, PLUGIN_TYPES.datasource, PLUGIN_TYPES.panel])('should not duplicate the type if it is already present (no dash before type)', (type) => {
18
+ const pluginName = `my-plugin${type}`;
19
+ const orgName = 'my-org';
20
+ const actual = normalizeId(pluginName, orgName, type);
21
+ expect(actual).toEqual(`myorg-myplugin-${type}`);
24
22
  });
25
- test.each([constants_1.PLUGIN_TYPES.app, constants_1.PLUGIN_TYPES.datasource, constants_1.PLUGIN_TYPES.panel])('should handle uppercase characters', function (type) {
26
- var pluginName = "MyPlugin";
27
- var orgName = 'MyOrg';
28
- var actual = (0, utils_handlebars_1.normalizeId)(pluginName, orgName, type);
29
- expect(actual).toEqual("myorg-myplugin-".concat(type));
23
+ test.each([PLUGIN_TYPES.app, PLUGIN_TYPES.datasource, PLUGIN_TYPES.panel])('should handle uppercase characters', (type) => {
24
+ const pluginName = `MyPlugin`;
25
+ const orgName = 'MyOrg';
26
+ const actual = normalizeId(pluginName, orgName, type);
27
+ expect(actual).toEqual(`myorg-myplugin-${type}`);
30
28
  });
31
29
  });
32
30
  });