@grafana/plugin-validator 0.17.3 → 0.19.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/bin/index.js ADDED
@@ -0,0 +1,150 @@
1
+ #!/usr/bin/env node
2
+ const fs = require("fs");
3
+ const path = require("path");
4
+ const zlib = require("zlib");
5
+ const https = require("https");
6
+ const tar = require("tar");
7
+ const { spawn } = require("child_process");
8
+
9
+ const packageJson = require("../package.json");
10
+ const version = packageJson.version;
11
+ const urlTemplate = packageJson.binWrapper.urlTemplate;
12
+ const binaryName =
13
+ process.platform === "win32"
14
+ ? packageJson.binWrapper.name + ".exe"
15
+ : packageJson.binWrapper.name;
16
+
17
+ const downloadPath = path.join(__dirname, ".bin");
18
+ const binaryPath = path.join(downloadPath, binaryName);
19
+
20
+ const ARCH_MAPPING = {
21
+ ia32: "386",
22
+ x64: "amd64",
23
+ arm: "arm",
24
+ arm64: "arm64",
25
+ };
26
+
27
+ function getPlatformSpecificDownloadUrl(platform, arch) {
28
+ let finalArch = ARCH_MAPPING[arch] || arch;
29
+
30
+ return urlTemplate
31
+ .replaceAll("{{version}}", version)
32
+ .replaceAll("{{platform}}", platform)
33
+ .replaceAll("{{arch}}", finalArch);
34
+ }
35
+
36
+ function downloadFile(fileUrl, outputFolder) {
37
+ const fileName = path.basename(new URL(fileUrl).pathname);
38
+ const outputPath = path.join(outputFolder, fileName);
39
+
40
+ // Check if the file already exists
41
+ if (fs.existsSync(outputPath)) {
42
+ return Promise.resolve(outputPath);
43
+ }
44
+
45
+ return new Promise((resolve, reject) => {
46
+ const download = (urlToDownload) => {
47
+ https
48
+ .get(urlToDownload, (response) => {
49
+ if (
50
+ response.statusCode >= 300 &&
51
+ response.statusCode < 400 &&
52
+ response.headers.location
53
+ ) {
54
+ // Handle redirection
55
+ const redirectedUrl = new URL(
56
+ response.headers.location,
57
+ urlToDownload,
58
+ ).toString();
59
+ download(redirectedUrl);
60
+ } else if (response.statusCode === 200) {
61
+ const fileStream = fs.createWriteStream(outputPath);
62
+ response.pipe(fileStream);
63
+
64
+ fileStream.on("finish", () => {
65
+ fileStream.close(() => {
66
+ resolve(outputPath);
67
+ });
68
+ });
69
+ } else {
70
+ reject(
71
+ new Error(
72
+ `Failed to download '${fileUrl}' (${response.statusCode})`,
73
+ ),
74
+ );
75
+ }
76
+ })
77
+ .on("error", reject);
78
+ };
79
+
80
+ download(fileUrl);
81
+ });
82
+ }
83
+
84
+ function extractTarGz(filePath, outputDir) {
85
+ return new Promise((resolve, reject) => {
86
+ fs.createReadStream(filePath)
87
+ .pipe(zlib.createGunzip())
88
+ .pipe(tar.extract({ cwd: outputDir }))
89
+ .on("error", reject)
90
+ .on("finish", resolve);
91
+ });
92
+ }
93
+
94
+ async function ensureBinary() {
95
+ if (fs.existsSync(binaryPath)) {
96
+ return;
97
+ }
98
+
99
+ const platformSpecificDownloadUrl = getPlatformSpecificDownloadUrl(
100
+ process.platform,
101
+ process.arch,
102
+ );
103
+
104
+ if (!fs.existsSync(downloadPath)) {
105
+ fs.mkdirSync(downloadPath, { recursive: true });
106
+ }
107
+
108
+ let tarGzPath;
109
+ try {
110
+ tarGzPath = await downloadFile(platformSpecificDownloadUrl, downloadPath);
111
+ } catch (e) {
112
+ console.error(e);
113
+ throw new Error(`Failed to download ${platformSpecificDownloadUrl}`);
114
+ }
115
+ try {
116
+ await extractTarGz(tarGzPath, downloadPath);
117
+ } catch (e) {
118
+ console.error(e);
119
+ throw new Error(`Failed to extract ${tarGzPath} to ${downloadPath}`);
120
+ }
121
+
122
+ // Check if the binary exists
123
+ if (!fs.existsSync(path.join(downloadPath, binaryName))) {
124
+ throw new Error(
125
+ `Binary not found at ${downloadPath}. There might be a problem with the release files.`,
126
+ );
127
+ }
128
+
129
+ // make the binary executable
130
+ fs.chmodSync(path.join(downloadPath, binaryName), 0o755);
131
+ }
132
+
133
+ async function main() {
134
+ try {
135
+ await ensureBinary();
136
+ // run the binary
137
+ const args = process.argv.slice(2);
138
+ const child = spawn(binaryPath, args, {
139
+ stdio: "inherit",
140
+ });
141
+ child.on("exit", (code) => {
142
+ process.exit(code);
143
+ });
144
+ } catch (e) {
145
+ console.error(e);
146
+ process.exit(1);
147
+ }
148
+ }
149
+
150
+ main();
package/package.json CHANGED
@@ -1,14 +1,8 @@
1
1
  {
2
2
  "name": "@grafana/plugin-validator",
3
- "version": "0.17.3",
3
+ "version": "0.19.0",
4
4
  "description": "Grafana Plugin Validator",
5
5
  "main": "index.js",
6
- "scripts": {
7
- "install": "binwrap-install",
8
- "prepare": "binwrap-prepare",
9
- "test": "binwrap-test",
10
- "prepublish": "npm test"
11
- },
12
6
  "repository": {
13
7
  "type": "git",
14
8
  "url": "git+https://github.com/grafana/plugin-validator.git"
@@ -24,14 +18,15 @@
24
18
  "url": "https://github.com/grafana/plugin-validator/issues"
25
19
  },
26
20
  "homepage": "https://github.com/grafana/plugin-validator#readme",
27
- "dependencies": {
28
- "binwrap": "^0.2.3"
29
- },
30
21
  "files": [
31
- "index.js",
32
- "bin"
22
+ "bin/index.js"
33
23
  ],
34
- "bin": {
35
- "plugincheck2": "bin/plugincheck2"
24
+ "bin": "./bin/index.js",
25
+ "binWrapper": {
26
+ "name": "plugincheck2",
27
+ "urlTemplate": "https://github.com/grafana/plugin-validator/releases/download/v{{version}}/plugin-validator_{{version}}_{{platform}}_{{arch}}.tar.gz"
28
+ },
29
+ "dependencies": {
30
+ "tar": "^7.4.3"
36
31
  }
37
32
  }
package/bin/plugincheck2 DELETED
@@ -1,45 +0,0 @@
1
- #!/usr/bin/env node
2
- var path = require("path");
3
- var spawn = require("child_process").spawn;
4
- var fs = require("fs");
5
-
6
- var os = process.env.BINWRAP_PLATFORM || process.platform;
7
- var arch = process.env.BINWRAP_ARCH || process.arch;
8
-
9
- var requested = os + "-" + arch;
10
- var current = process.platform + "-" + process.arch;
11
- if (requested !== current ) {
12
- console.error("WARNING: Using binaries for the requested platform (" + requested + ") instead of for the actual platform (" + current + ").")
13
- }
14
-
15
- var binExt = "";
16
- if (os == "win32") {
17
- binExt = ".exe";
18
- }
19
-
20
- var unpackedBinPath = path.join(__dirname, "..", "unpacked_bin");
21
- var binPath = path.join(unpackedBinPath, "plugincheck2" + binExt);
22
-
23
- function execBin() {
24
- spawn(
25
- binPath,
26
- process.argv.slice(2),
27
- {stdio: 'inherit'}
28
- ).on('exit', process.exit);
29
- }
30
-
31
- if (fs.existsSync(binPath)) {
32
- execBin();
33
- } else {
34
- console.error("INFO: Running " + path.basename(__filename) + " for the first time; downloading the actual binary");
35
-
36
- var packageInfo = require(path.join(__dirname, "..", "package.json"));
37
- var package = require(path.join(__dirname, "..", packageInfo.main));
38
-
39
- package.install(unpackedBinPath, os, arch).then(function(result) {
40
- execBin();
41
- }, function(err) {
42
- console.log("ERR", err);
43
- process.exit(1);
44
- });
45
- }
package/index.js DELETED
@@ -1,23 +0,0 @@
1
- var binwrap = require("binwrap");
2
- var path = require("path");
3
-
4
- var packageInfo = require(path.join(__dirname, "package.json"));
5
- var version = packageInfo.version;
6
- var root = `https://github.com/grafana/plugin-validator/releases/download/v${version}`;
7
-
8
- module.exports = binwrap({
9
- dirname: __dirname,
10
- binaries: ["plugincheck2"],
11
- urls: {
12
- "darwin-x64":
13
- root + "/plugin-validator_" + version + "_darwin_amd64.tar.gz",
14
- "darwin-arm64":
15
- root + "/plugin-validator_" + version + "_darwin_arm64.tar.gz",
16
- "linux-x64": root + "/plugin-validator_" + version + "_linux_amd64.tar.gz",
17
- "linux-arm64":
18
- root + "/plugin-validator_" + version + "_linux_arm64.tar.gz",
19
- "win32-x64": root + "/plugin-validator_" + version + "_windows_amd64.zip",
20
- "win32-ia32": root + "/plugin-validator_" + version + "_windows_386.zip",
21
- "win32-arm64": root + "/plugin-validator_" + version + "_windows_arm64.zip",
22
- },
23
- });