@grafana/create-plugin 2.10.0 → 2.11.0-canary.602.81e7a0e.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 +19 -0
- package/dist/commands/{generate-actions → generate}/prettify-files.js +8 -11
- package/dist/commands/{generate-actions → generate}/print-success-message.js +2 -2
- package/dist/commands/generate/prompt-user.js +145 -0
- package/dist/commands/{generate-actions → generate}/update-go-sdk-and-packages.js +10 -13
- package/dist/commands/generate.command.js +225 -9
- package/dist/utils/utils.console.js +5 -2
- package/dist/utils/utils.files.js +58 -1
- package/dist/utils/utils.handlebars.js +14 -3
- package/package.json +22 -15
- package/src/commands/{generate-actions → generate}/prettify-files.ts +1 -5
- package/src/commands/{generate-actions → generate}/print-success-message.ts +2 -3
- package/src/commands/generate/prompt-user.ts +102 -0
- package/src/commands/{generate-actions → generate}/update-go-sdk-and-packages.ts +1 -6
- package/src/commands/generate.command.ts +194 -11
- package/src/utils/utils.console.ts +5 -2
- package/src/utils/utils.files.ts +10 -0
- package/src/utils/utils.handlebars.ts +17 -4
- package/templates/app/README.md +6 -6
- package/templates/common/.config/webpack/webpack.config.ts +1 -0
- package/templates/datasource/README.md +3 -3
- package/templates/panel/README.md +2 -2
- package/templates/scenes-app/README.md +2 -2
- package/dist/commands/generate.plopfile.js +0 -214
- package/scripts/generate-app-backend.js +0 -29
- package/scripts/generate-app.js +0 -29
- package/scripts/generate-datasource-with-backend.js +0 -29
- package/scripts/generate-datasource-without-backend.js +0 -29
- package/scripts/generate-panel.js +0 -28
- package/scripts/generate-scenes-app.js +0 -29
- package/src/commands/generate.plopfile.ts +0 -272
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
# v2.10.1 (Thu Dec 14 2023)
|
|
2
|
+
|
|
3
|
+
:tada: This release contains work from a new contributor! :tada:
|
|
4
|
+
|
|
5
|
+
Thank you, Carson ([@mure](https://github.com/mure)), for all your work!
|
|
6
|
+
|
|
7
|
+
#### 🐛 Bug Fix
|
|
8
|
+
|
|
9
|
+
- Copy over `query_help.md` when building plugins [#374](https://github.com/grafana/plugin-tools/pull/374) ([@mure](https://github.com/mure) [@jackw](https://github.com/jackw))
|
|
10
|
+
- Minor edits to style of README.md [#583](https://github.com/grafana/plugin-tools/pull/583) ([@josmperez](https://github.com/josmperez))
|
|
11
|
+
|
|
12
|
+
#### Authors: 3
|
|
13
|
+
|
|
14
|
+
- Carson ([@mure](https://github.com/mure))
|
|
15
|
+
- Jack Westbrook ([@jackw](https://github.com/jackw))
|
|
16
|
+
- Joseph Perez ([@josmperez](https://github.com/josmperez))
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
1
20
|
# v2.10.0 (Tue Dec 12 2023)
|
|
2
21
|
|
|
3
22
|
#### 🚀 Enhancement
|
|
@@ -43,29 +43,26 @@ exports.prettifyFiles = void 0;
|
|
|
43
43
|
var node_child_process_1 = require("node:child_process");
|
|
44
44
|
var node_util_1 = require("node:util");
|
|
45
45
|
var fs_1 = __importDefault(require("fs"));
|
|
46
|
-
var utils_path_1 = require("../../utils/utils.path");
|
|
47
46
|
var exec = (0, node_util_1.promisify)(node_child_process_1.exec);
|
|
48
|
-
function prettifyFiles(
|
|
49
|
-
var pluginName = _a.pluginName, orgName = _a.orgName, pluginType = _a.pluginType;
|
|
47
|
+
function prettifyFiles(exportPath) {
|
|
50
48
|
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
-
var
|
|
52
|
-
return __generator(this, function (
|
|
53
|
-
switch (
|
|
49
|
+
var command, error_1;
|
|
50
|
+
return __generator(this, function (_a) {
|
|
51
|
+
switch (_a.label) {
|
|
54
52
|
case 0:
|
|
55
|
-
exportPath = (0, utils_path_1.getExportPath)(pluginName, orgName, pluginType);
|
|
56
53
|
if (!fs_1.default.existsSync(exportPath)) {
|
|
57
54
|
return [2, ''];
|
|
58
55
|
}
|
|
59
|
-
|
|
56
|
+
_a.label = 1;
|
|
60
57
|
case 1:
|
|
61
|
-
|
|
58
|
+
_a.trys.push([1, 3, , 4]);
|
|
62
59
|
command = 'npx -y prettier@2 . --write';
|
|
63
60
|
return [4, exec(command, { cwd: exportPath })];
|
|
64
61
|
case 2:
|
|
65
|
-
|
|
62
|
+
_a.sent();
|
|
66
63
|
return [3, 4];
|
|
67
64
|
case 3:
|
|
68
|
-
error_1 =
|
|
65
|
+
error_1 = _a.sent();
|
|
69
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.');
|
|
70
67
|
case 4: return [2, 'Successfully ran prettier against new plugin.'];
|
|
71
68
|
}
|
|
@@ -28,7 +28,7 @@ function printGenerateSuccessMessage(answers) {
|
|
|
28
28
|
'- `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
29
|
'- Open http://localhost:3000 in your browser to create a dashboard to begin developing your plugin.',
|
|
30
30
|
], false);
|
|
31
|
-
var msg = "\
|
|
32
|
-
|
|
31
|
+
var msg = "\n# Congratulations 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- Learn more about Grafana Plugin Development at https://grafana.com/developers/plugin-tools\n");
|
|
32
|
+
console.log((0, utils_console_1.displayAsMarkdown)(msg));
|
|
33
33
|
}
|
|
34
34
|
exports.printGenerateSuccessMessage = printGenerateSuccessMessage;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
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;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
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];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
exports.promptUser = promptUser;
|
|
91
|
+
var prompts = [
|
|
92
|
+
{
|
|
93
|
+
name: 'pluginName',
|
|
94
|
+
type: 'input',
|
|
95
|
+
message: 'What is going to be the name of your plugin?',
|
|
96
|
+
validate: function (value) {
|
|
97
|
+
if (/.+/.test(value)) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
return 'Plugin name is required';
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: 'orgName',
|
|
105
|
+
type: 'input',
|
|
106
|
+
message: 'What is the organization name of your plugin?',
|
|
107
|
+
validate: function (value) {
|
|
108
|
+
if (/.+/.test(value)) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
return 'Organization name is required';
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'pluginDescription',
|
|
116
|
+
type: 'input',
|
|
117
|
+
message: 'How would you describe your plugin?',
|
|
118
|
+
initial: '',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: 'pluginType',
|
|
122
|
+
type: 'select',
|
|
123
|
+
choices: [constants_1.PLUGIN_TYPES.app, constants_1.PLUGIN_TYPES.datasource, constants_1.PLUGIN_TYPES.panel, constants_1.PLUGIN_TYPES.scenes],
|
|
124
|
+
message: 'What type of plugin would you like?',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: 'hasBackend',
|
|
128
|
+
type: 'confirm',
|
|
129
|
+
message: 'Do you want a backend part of your plugin?',
|
|
130
|
+
initial: false,
|
|
131
|
+
shouldPrompt: function (answers) { return answers.pluginType !== constants_1.PLUGIN_TYPES.panel; },
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
name: 'hasGithubWorkflows',
|
|
135
|
+
type: 'confirm',
|
|
136
|
+
message: 'Do you want to add Github CI and Release workflows?',
|
|
137
|
+
initial: false,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
name: 'hasGithubLevitateWorkflow',
|
|
141
|
+
type: 'confirm',
|
|
142
|
+
message: 'Do you want to add a Github workflow for automatically checking "Grafana API compatibility" on PRs?',
|
|
143
|
+
initial: false,
|
|
144
|
+
},
|
|
145
|
+
];
|
|
@@ -40,41 +40,38 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
40
40
|
};
|
|
41
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
42
|
exports.updateGoSdkAndModules = void 0;
|
|
43
|
-
var utils_path_1 = require("../../utils/utils.path");
|
|
44
43
|
var which_1 = __importDefault(require("which"));
|
|
45
44
|
var fs_1 = __importDefault(require("fs"));
|
|
46
45
|
var child_process_1 = require("child_process");
|
|
47
46
|
var SDK_GO_MODULE = 'github.com/grafana/grafana-plugin-sdk-go';
|
|
48
|
-
function updateGoSdkAndModules(
|
|
49
|
-
var pluginName = _a.pluginName, orgName = _a.orgName, pluginType = _a.pluginType;
|
|
47
|
+
function updateGoSdkAndModules(exportPath) {
|
|
50
48
|
return __awaiter(this, void 0, void 0, function () {
|
|
51
|
-
var
|
|
52
|
-
return __generator(this, function (
|
|
53
|
-
switch (
|
|
49
|
+
var goModPath, goBinaryPath, _a;
|
|
50
|
+
return __generator(this, function (_b) {
|
|
51
|
+
switch (_b.label) {
|
|
54
52
|
case 0:
|
|
55
|
-
exportPath = (0, utils_path_1.getExportPath)(pluginName, orgName, pluginType);
|
|
56
53
|
goModPath = "".concat(exportPath, "/go.mod");
|
|
57
54
|
if (!fs_1.default.existsSync(goModPath)) {
|
|
58
55
|
return [2, ''];
|
|
59
56
|
}
|
|
60
57
|
return [4, (0, which_1.default)('go', { nothrow: true })];
|
|
61
58
|
case 1:
|
|
62
|
-
goBinaryPath =
|
|
59
|
+
goBinaryPath = _b.sent();
|
|
63
60
|
if (!goBinaryPath) {
|
|
64
61
|
return [2, ''];
|
|
65
62
|
}
|
|
66
|
-
|
|
63
|
+
_b.label = 2;
|
|
67
64
|
case 2:
|
|
68
|
-
|
|
65
|
+
_b.trys.push([2, 5, , 6]);
|
|
69
66
|
return [4, updateSdk(exportPath)];
|
|
70
67
|
case 3:
|
|
71
|
-
|
|
68
|
+
_b.sent();
|
|
72
69
|
return [4, updateGoMod(exportPath)];
|
|
73
70
|
case 4:
|
|
74
|
-
|
|
71
|
+
_b.sent();
|
|
75
72
|
return [3, 6];
|
|
76
73
|
case 5:
|
|
77
|
-
|
|
74
|
+
_a = _b.sent();
|
|
78
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.');
|
|
79
76
|
case 6: return [2, 'Grafana go sdk updated successfully.'];
|
|
80
77
|
}
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -35,22 +46,227 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
46
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
47
|
}
|
|
37
48
|
};
|
|
49
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
50
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
51
|
+
if (ar || !(i in from)) {
|
|
52
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
53
|
+
ar[i] = from[i];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
57
|
+
};
|
|
38
58
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
59
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
60
|
};
|
|
41
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
62
|
exports.generate = void 0;
|
|
63
|
+
var glob_1 = __importDefault(require("glob"));
|
|
64
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
65
|
+
var promises_1 = require("node:fs/promises");
|
|
43
66
|
var path_1 = __importDefault(require("path"));
|
|
44
|
-
var
|
|
67
|
+
var constants_1 = require("../constants");
|
|
68
|
+
var utils_config_1 = require("../utils/utils.config");
|
|
69
|
+
var utils_console_1 = require("../utils/utils.console");
|
|
70
|
+
var utils_files_1 = require("../utils/utils.files");
|
|
71
|
+
var utils_handlebars_1 = require("../utils/utils.handlebars");
|
|
72
|
+
var utils_packageManager_1 = require("../utils/utils.packageManager");
|
|
73
|
+
var utils_path_1 = require("../utils/utils.path");
|
|
74
|
+
var utils_templates_1 = require("../utils/utils.templates");
|
|
75
|
+
var utils_version_1 = require("../utils/utils.version");
|
|
76
|
+
var prettify_files_1 = require("./generate/prettify-files");
|
|
77
|
+
var print_success_message_1 = require("./generate/print-success-message");
|
|
78
|
+
var prompt_user_1 = require("./generate/prompt-user");
|
|
79
|
+
var update_go_sdk_and_packages_1 = require("./generate/update-go-sdk-and-packages");
|
|
45
80
|
var generate = function (argv) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
81
|
+
var answers, templateData, exportPath, exportPathExists, exportPathIsPopulated, _a, actions, _b, changes, failures;
|
|
82
|
+
return __generator(this, function (_c) {
|
|
83
|
+
switch (_c.label) {
|
|
84
|
+
case 0: return [4, (0, prompt_user_1.promptUser)(argv)];
|
|
85
|
+
case 1:
|
|
86
|
+
answers = _c.sent();
|
|
87
|
+
templateData = getTemplateData(answers);
|
|
88
|
+
exportPath = (0, utils_path_1.getExportPath)(answers.pluginName, answers.orgName, answers.pluginType);
|
|
89
|
+
return [4, (0, utils_files_1.directoryExists)(exportPath)];
|
|
90
|
+
case 2:
|
|
91
|
+
exportPathExists = _c.sent();
|
|
92
|
+
if (!exportPathExists) return [3, 4];
|
|
93
|
+
return [4, (0, promises_1.readdir)(exportPath)];
|
|
94
|
+
case 3:
|
|
95
|
+
_a = (_c.sent()).length > 0;
|
|
96
|
+
return [3, 5];
|
|
97
|
+
case 4:
|
|
98
|
+
_a = false;
|
|
99
|
+
_c.label = 5;
|
|
100
|
+
case 5:
|
|
101
|
+
exportPathIsPopulated = _a;
|
|
102
|
+
if (exportPathIsPopulated && !constants_1.IS_DEV) {
|
|
103
|
+
(0, utils_console_1.printError)("**Aborting plugin scaffold. '".concat(exportPath, "' exists and contains files.**"));
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
actions = getTemplateActions({ templateData: templateData, exportPath: exportPath });
|
|
107
|
+
return [4, generateFiles({ actions: actions })];
|
|
108
|
+
case 6:
|
|
109
|
+
_b = _c.sent(), changes = _b.changes, failures = _b.failures;
|
|
110
|
+
changes.forEach(function (change) {
|
|
111
|
+
console.log("".concat(chalk_1.default.green('✔︎ ++'), " ").concat(change.path));
|
|
112
|
+
});
|
|
113
|
+
failures.forEach(function (failure) {
|
|
114
|
+
(0, utils_console_1.printError)("".concat(failure.error));
|
|
115
|
+
});
|
|
116
|
+
if (!answers.hasBackend) return [3, 8];
|
|
117
|
+
return [4, execPostScaffoldFunction(update_go_sdk_and_packages_1.updateGoSdkAndModules, exportPath)];
|
|
118
|
+
case 7:
|
|
119
|
+
_c.sent();
|
|
120
|
+
_c.label = 8;
|
|
121
|
+
case 8: return [4, execPostScaffoldFunction(prettify_files_1.prettifyFiles, exportPath)];
|
|
122
|
+
case 9:
|
|
123
|
+
_c.sent();
|
|
124
|
+
(0, print_success_message_1.printGenerateSuccessMessage)(answers);
|
|
125
|
+
return [2];
|
|
126
|
+
}
|
|
54
127
|
});
|
|
55
128
|
}); };
|
|
56
129
|
exports.generate = generate;
|
|
130
|
+
function getTemplateData(answers) {
|
|
131
|
+
var pluginName = answers.pluginName, orgName = answers.orgName, pluginType = answers.pluginType;
|
|
132
|
+
var features = (0, utils_config_1.getConfig)().features;
|
|
133
|
+
var currentVersion = (0, utils_version_1.getVersion)();
|
|
134
|
+
var pluginId = (0, utils_handlebars_1.normalizeId)(pluginName, orgName, pluginType);
|
|
135
|
+
var _a = (0, utils_packageManager_1.getPackageManagerFromUserAgent)(), packageManagerName = _a.packageManagerName, packageManagerVersion = _a.packageManagerVersion;
|
|
136
|
+
var packageManagerInstallCmd = (0, utils_packageManager_1.getPackageManagerInstallCmd)(packageManagerName);
|
|
137
|
+
var isAppType = pluginType === constants_1.PLUGIN_TYPES.app || pluginType === constants_1.PLUGIN_TYPES.scenes;
|
|
138
|
+
var templateData = __assign(__assign({}, answers), { pluginId: pluginId, packageManagerName: packageManagerName, packageManagerInstallCmd: packageManagerInstallCmd, packageManagerVersion: packageManagerVersion, isAppType: isAppType, isNPM: packageManagerName === 'npm', version: currentVersion, bundleGrafanaUI: features.bundleGrafanaUI });
|
|
139
|
+
return templateData;
|
|
140
|
+
}
|
|
141
|
+
function getTemplateActions(_a) {
|
|
142
|
+
var exportPath = _a.exportPath, templateData = _a.templateData;
|
|
143
|
+
var commonActions = getActionsForTemplateFolder({
|
|
144
|
+
folderPath: constants_1.TEMPLATE_PATHS.common,
|
|
145
|
+
exportPath: exportPath,
|
|
146
|
+
templateData: templateData,
|
|
147
|
+
});
|
|
148
|
+
var pluginTypeSpecificActions = getActionsForTemplateFolder({
|
|
149
|
+
folderPath: constants_1.TEMPLATE_PATHS[templateData.pluginType],
|
|
150
|
+
exportPath: exportPath,
|
|
151
|
+
templateData: templateData,
|
|
152
|
+
});
|
|
153
|
+
var backendFolderPath = templateData.isAppType ? constants_1.TEMPLATE_PATHS.backendApp : constants_1.TEMPLATE_PATHS.backend;
|
|
154
|
+
var backendActions = templateData.hasBackend
|
|
155
|
+
? getActionsForTemplateFolder({ folderPath: backendFolderPath, exportPath: exportPath, templateData: templateData })
|
|
156
|
+
: [];
|
|
157
|
+
var pluginActions = __spreadArray(__spreadArray(__spreadArray([], backendActions, true), pluginTypeSpecificActions, true), commonActions, true).reduce(function (acc, file) {
|
|
158
|
+
var actionExists = acc.find(function (f) { return f.path === file.path; });
|
|
159
|
+
if (actionExists) {
|
|
160
|
+
return acc;
|
|
161
|
+
}
|
|
162
|
+
acc.push(file);
|
|
163
|
+
return acc;
|
|
164
|
+
}, []);
|
|
165
|
+
var ciWorkflowActions = templateData.hasGithubWorkflows
|
|
166
|
+
? getActionsForTemplateFolder({
|
|
167
|
+
folderPath: constants_1.TEMPLATE_PATHS.ciWorkflows,
|
|
168
|
+
exportPath: exportPath,
|
|
169
|
+
templateData: templateData,
|
|
170
|
+
})
|
|
171
|
+
: [];
|
|
172
|
+
var isCompatibleWorkflowActions = templateData.hasGithubLevitateWorkflow
|
|
173
|
+
? getActionsForTemplateFolder({
|
|
174
|
+
folderPath: constants_1.TEMPLATE_PATHS.isCompatibleWorkflow,
|
|
175
|
+
exportPath: exportPath,
|
|
176
|
+
templateData: templateData,
|
|
177
|
+
})
|
|
178
|
+
: [];
|
|
179
|
+
return __spreadArray(__spreadArray(__spreadArray([], pluginActions, true), ciWorkflowActions, true), isCompatibleWorkflowActions, true);
|
|
180
|
+
}
|
|
181
|
+
function getActionsForTemplateFolder(_a) {
|
|
182
|
+
var folderPath = _a.folderPath, exportPath = _a.exportPath, templateData = _a.templateData;
|
|
183
|
+
var files = glob_1.default.sync("".concat(folderPath, "/**"), { dot: true });
|
|
184
|
+
if (templateData.packageManagerName !== 'pnpm') {
|
|
185
|
+
files = files.filter(function (file) { return path_1.default.basename(file) !== 'npmrc'; });
|
|
186
|
+
}
|
|
187
|
+
function getFileExportPath(f) {
|
|
188
|
+
return path_1.default.relative(folderPath, path_1.default.dirname(f));
|
|
189
|
+
}
|
|
190
|
+
return files.filter(utils_files_1.isFile).map(function (f) { return ({
|
|
191
|
+
templateFile: f,
|
|
192
|
+
path: path_1.default.join(exportPath, getFileExportPath(f), (0, utils_files_1.getExportFileName)(f)),
|
|
193
|
+
data: __assign(__assign({}, constants_1.EXTRA_TEMPLATE_VARIABLES), templateData),
|
|
194
|
+
}); });
|
|
195
|
+
}
|
|
196
|
+
function generateFiles(_a) {
|
|
197
|
+
var actions = _a.actions;
|
|
198
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
199
|
+
var failures, changes, _i, actions_1, action, rootDir, pathExists, rendered, error_1;
|
|
200
|
+
return __generator(this, function (_b) {
|
|
201
|
+
switch (_b.label) {
|
|
202
|
+
case 0:
|
|
203
|
+
failures = [];
|
|
204
|
+
changes = [];
|
|
205
|
+
_i = 0, actions_1 = actions;
|
|
206
|
+
_b.label = 1;
|
|
207
|
+
case 1:
|
|
208
|
+
if (!(_i < actions_1.length)) return [3, 9];
|
|
209
|
+
action = actions_1[_i];
|
|
210
|
+
_b.label = 2;
|
|
211
|
+
case 2:
|
|
212
|
+
_b.trys.push([2, 7, , 8]);
|
|
213
|
+
rootDir = path_1.default.dirname(action.path);
|
|
214
|
+
return [4, (0, utils_files_1.directoryExists)(rootDir)];
|
|
215
|
+
case 3:
|
|
216
|
+
pathExists = _b.sent();
|
|
217
|
+
if (!!pathExists) return [3, 5];
|
|
218
|
+
return [4, (0, promises_1.mkdir)(rootDir, { recursive: true })];
|
|
219
|
+
case 4:
|
|
220
|
+
_b.sent();
|
|
221
|
+
_b.label = 5;
|
|
222
|
+
case 5:
|
|
223
|
+
rendered = (0, utils_templates_1.renderTemplateFromFile)(action.templateFile, action.data);
|
|
224
|
+
return [4, (0, promises_1.writeFile)(action.path, rendered)];
|
|
225
|
+
case 6:
|
|
226
|
+
_b.sent();
|
|
227
|
+
changes.push({
|
|
228
|
+
path: action.path,
|
|
229
|
+
});
|
|
230
|
+
return [3, 8];
|
|
231
|
+
case 7:
|
|
232
|
+
error_1 = _b.sent();
|
|
233
|
+
failures.push({
|
|
234
|
+
path: action.path,
|
|
235
|
+
error: error_1.message || error_1.toString(),
|
|
236
|
+
});
|
|
237
|
+
return [3, 8];
|
|
238
|
+
case 8:
|
|
239
|
+
_i++;
|
|
240
|
+
return [3, 1];
|
|
241
|
+
case 9: return [2, { failures: failures, changes: changes }];
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
function execPostScaffoldFunction(fn) {
|
|
247
|
+
var args = [];
|
|
248
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
249
|
+
args[_i - 1] = arguments[_i];
|
|
250
|
+
}
|
|
251
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
252
|
+
var resultMsg, error_2;
|
|
253
|
+
return __generator(this, function (_a) {
|
|
254
|
+
switch (_a.label) {
|
|
255
|
+
case 0:
|
|
256
|
+
_a.trys.push([0, 2, , 3]);
|
|
257
|
+
return [4, fn.apply(undefined, args)];
|
|
258
|
+
case 1:
|
|
259
|
+
resultMsg = _a.sent();
|
|
260
|
+
if (resultMsg) {
|
|
261
|
+
console.log("".concat(chalk_1.default.green('✔︎'), " ").concat(resultMsg));
|
|
262
|
+
}
|
|
263
|
+
return [3, 3];
|
|
264
|
+
case 2:
|
|
265
|
+
error_2 = _a.sent();
|
|
266
|
+
(0, utils_console_1.printError)("".concat(error_2));
|
|
267
|
+
return [3, 3];
|
|
268
|
+
case 3: return [2];
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
});
|
|
272
|
+
}
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.selectPrompt = exports.confirmPrompt = exports.printError = exports.printSuccessMessage = exports.printMessage = exports.displayArrayAsList = exports.displayAsMarkdown = void 0;
|
|
4
4
|
var marked = require('marked').marked;
|
|
5
|
+
var chalk = require('chalk');
|
|
5
6
|
var TerminalRenderer = require('marked-terminal');
|
|
6
7
|
var _a = require('enquirer'), Confirm = _a.Confirm, Select = _a.Select;
|
|
7
8
|
marked.setOptions({
|
|
8
|
-
renderer: new TerminalRenderer(
|
|
9
|
+
renderer: new TerminalRenderer({
|
|
10
|
+
firstHeading: chalk.hex('#ff9900').underline.bold,
|
|
11
|
+
}),
|
|
9
12
|
});
|
|
10
13
|
function displayAsMarkdown(msg) {
|
|
11
14
|
return marked(msg);
|
|
@@ -20,7 +23,7 @@ function printMessage(msg) {
|
|
|
20
23
|
}
|
|
21
24
|
exports.printMessage = printMessage;
|
|
22
25
|
function printSuccessMessage(msg) {
|
|
23
|
-
console.log(displayAsMarkdown("\n\u2714 ".concat(msg)));
|
|
26
|
+
console.log(displayAsMarkdown("\n\u2714 ".concat(msg)).trim());
|
|
24
27
|
}
|
|
25
28
|
exports.printSuccessMessage = printSuccessMessage;
|
|
26
29
|
function printError(error) {
|
|
@@ -1,12 +1,49 @@
|
|
|
1
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
|
+
};
|
|
2
38
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
39
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
40
|
};
|
|
5
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isFileStartingWith = exports.getExportFileName = exports.removeFilesInCwd = exports.getOnlyNotExistingInCwd = exports.getOnlyExistingInCwd = exports.readJsonFile = exports.isFile = exports.filterOutCommonFiles = void 0;
|
|
42
|
+
exports.isFileStartingWith = exports.getExportFileName = exports.removeFilesInCwd = exports.getOnlyNotExistingInCwd = exports.getOnlyExistingInCwd = exports.directoryExists = exports.readJsonFile = exports.isFile = exports.filterOutCommonFiles = void 0;
|
|
7
43
|
var path_1 = __importDefault(require("path"));
|
|
8
44
|
var fs_1 = __importDefault(require("fs"));
|
|
9
45
|
var constants_1 = require("../constants");
|
|
46
|
+
var promises_1 = require("fs/promises");
|
|
10
47
|
function filterOutCommonFiles(files, pluginType) {
|
|
11
48
|
var isFileCommonAndOverriden = function (file) {
|
|
12
49
|
return file.includes(constants_1.TEMPLATE_PATHS.common) &&
|
|
@@ -37,6 +74,26 @@ function readJsonFile(filename) {
|
|
|
37
74
|
}
|
|
38
75
|
}
|
|
39
76
|
exports.readJsonFile = readJsonFile;
|
|
77
|
+
function directoryExists(path) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
+
var e_1;
|
|
80
|
+
return __generator(this, function (_a) {
|
|
81
|
+
switch (_a.label) {
|
|
82
|
+
case 0:
|
|
83
|
+
_a.trys.push([0, 2, , 3]);
|
|
84
|
+
return [4, (0, promises_1.access)(path, promises_1.constants.F_OK)];
|
|
85
|
+
case 1:
|
|
86
|
+
_a.sent();
|
|
87
|
+
return [2, true];
|
|
88
|
+
case 2:
|
|
89
|
+
e_1 = _a.sent();
|
|
90
|
+
return [2, false];
|
|
91
|
+
case 3: return [2];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
exports.directoryExists = directoryExists;
|
|
40
97
|
function getOnlyExistingInCwd(files) {
|
|
41
98
|
return files.filter(function (file) { return fs_1.default.existsSync(path_1.default.join(process.cwd(), file)); });
|
|
42
99
|
}
|