latest-protoc-binary 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Kada Zoltán
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # latest-protoc-binary.git
2
+ Dovnload latest Protocol Compiler (protoc) pre-built binary from https://github.com/protocolbuffers/protobuf/releases.
3
+
4
+ ## Usage
5
+ ```
6
+ npm i latest-protoc-binary
7
+ npx protoc --version
8
+ ```
package/bin/protoc ADDED
File without changes
package/index.mjs ADDED
@@ -0,0 +1,96 @@
1
+ import fetch from 'node-fetch';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import unzipper from 'unzipper';
5
+ const getPlatform = (() => {
6
+ const arch = process.arch;
7
+ switch (process.platform) {
8
+ case 'win32':
9
+ return arch === 'x64' ? 'win64' : arch === 'ia32' ? 'win32' : 'unknown';
10
+ case 'darwin':
11
+ return arch === 'arm64' ? 'osx-aarch_64' : arch === 'x64' ? 'osx-x86_64' : 'osx-universal_binary';
12
+ case 'linux':
13
+ if (arch === 'x64') return 'linux-x86_64';
14
+ if (arch === 'ia32') return 'linux-x86_32';
15
+ if (arch === 'arm64') return 'linux-aarch_64';
16
+ if (arch === 'ppc64') return 'linux-ppcle_64';
17
+ if (arch === 's390x') return 'linux-s390_64';
18
+ return 'unknown';
19
+ default:
20
+ return 'unknown';
21
+ }
22
+ });
23
+ const downloadProtoc = async () => {
24
+ const releasesUrl = 'https://api.github.com/repos/protocolbuffers/protobuf/releases/latest';
25
+
26
+ try {
27
+ const response = await fetch(releasesUrl);
28
+ if (!response.ok) {
29
+ throw new Error(`Failed to fetch releases: ${response.statusText}`);
30
+ }
31
+ const data = await response.json();
32
+ const assets = data.assets;
33
+ const platform=getPlatform();
34
+ console.log(`Detected platform: ${platform}`);
35
+ console.log('Available assets:', assets.map(asset => asset.name));
36
+
37
+ const searchPattern = `protoc-${data.tag_name.replace(/^v/, '')}-${platform}`;
38
+ console.log(`Search pattern: ${searchPattern}`);
39
+
40
+ const asset = assets.find(asset => asset.name.includes(searchPattern));
41
+ if (!asset) {
42
+ console.error('No suitable asset found for your platform.');
43
+ return;
44
+ }
45
+
46
+ const downloadUrl = asset.browser_download_url;
47
+ console.log(`Download URL: ${downloadUrl}`);
48
+ console.log(`Asset name: ${asset.name}`);
49
+
50
+ const outputPath = path.join(process.cwd(), asset.name);
51
+
52
+ const downloadResponse = await fetch(downloadUrl);
53
+ if (!downloadResponse.ok) {
54
+ throw new Error(`Failed to download asset: ${downloadResponse.statusText}`);
55
+ }
56
+ const fileStream = fs.createWriteStream(outputPath);
57
+ downloadResponse.body.pipe(fileStream);
58
+
59
+ fileStream.on('finish', async () => {
60
+ console.log(`Downloaded ${asset.name} to ${outputPath}`);
61
+
62
+ // Extract the ZIP file to the desired directory
63
+ const binPath = path.join(process.cwd());
64
+ console.log(`Extracting to ${binPath}...`);
65
+ fs.mkdirSync(binPath, { recursive: true });
66
+
67
+ fs.createReadStream(outputPath)
68
+ .pipe(unzipper.Extract({ path: binPath }))
69
+ .on('close', () => {
70
+ console.log("move include to /bin/include");
71
+ fs.rename("include", "bin/include",(err)=>{
72
+ if (!err) {
73
+ console.log(`remove ${outputPath}`)
74
+ fs.unlink(outputPath,(err)=>{
75
+ if(!err){
76
+
77
+ }else{
78
+ console.error(`${outputPath} file unlink error #7XUVX1`, err.message);
79
+ }
80
+ });
81
+ } else {
82
+ console.error(`Error in move dirctory: ${err.message} #enaKL4`);
83
+ }
84
+ });
85
+ console.log(`Extracted files to ${binPath}`);
86
+ })
87
+ .on('error', (err) => {
88
+ console.error(`Failed to extract files: ${err.message}`);
89
+ });
90
+ });
91
+ } catch (error) {
92
+ console.error(`Error: ${error.message}`);
93
+ }
94
+ }
95
+
96
+ downloadProtoc();
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "latest-protoc-binary",
3
+ "version": "0.0.1",
4
+ "description": "Dovnload latest Protocol Compiler (protoc) pre-built binary from https://github.com/protocolbuffers/protobuf/releases.",
5
+ "main": "index.mjs",
6
+ "bin": {
7
+ "protoc": "bin/protoc"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "postinstall": "node ./index.mjs"
12
+ },
13
+ "keywords": [
14
+ "Protocol Compiler",
15
+ "protoc",
16
+ "protobuf"
17
+ ],
18
+ "author": "Zoltan Istvan KADA",
19
+ "license": "MIT",
20
+ "dependencies": {
21
+ "node-fetch": "^3.3.2",
22
+ "unzipper": "^0.12.3"
23
+ }
24
+ }
package/readme.txt ADDED
@@ -0,0 +1,12 @@
1
+ Protocol Buffers - Google's data interchange format
2
+ Copyright 2008 Google Inc.
3
+ https://developers.google.com/protocol-buffers/
4
+ This package contains a precompiled binary version of the protocol buffer
5
+ compiler (protoc). This binary is intended for users who want to use Protocol
6
+ Buffers in languages other than C++ but do not want to compile protoc
7
+ themselves. To install, simply place this binary somewhere in your PATH.
8
+ If you intend to use the included well known types then don't forget to
9
+ copy the contents of the 'include' directory somewhere as well, for example
10
+ into '/usr/local/include/'.
11
+ Please refer to our official github site for more installation instructions:
12
+ https://github.com/protocolbuffers/protobuf