From 2ac2d5514ba7f14e82490574a50ea1f35364eb14 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:08:15 +0100 Subject: [PATCH 01/49] Update README.md --- README.md | 35 +---------------------------------- 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/README.md b/README.md index 45a5f5d..5ca269b 100644 --- a/README.md +++ b/README.md @@ -1,34 +1 @@ -# Protocol Buffers for Node -A wrapper in Node for the compiled protoc from https://github.com/protocolbuffers/protobuf. - -## Version -It's currently using Protocol Buffers `v3.20.3`. - -## Platforms -Google only provides binary files for Windows, Linux and OSX in x86_64 and x86_32. - -## Examples -There's currently no documentation. Hopefully this example will help. - -```JavaScript -var protoc = require("protoc"); - -protoc.library(["path/to/file.proto", "path/to/file2.proto"], function(err, files) { - if (err) { - console.error(err); - return; - } - - // Handle the JavaScript Vinyl files. - // These files can be used in Google Closure Compiler, - // but they require the files in - // https://github.com/google/protobuf/tree/master/js - - // ... -}); -``` - -It's also possible to directly call the protoc binary file: -``` -npx protoc --help -``` +Forked from *node-protoc* to add additional languages From 69e6fc0a4258d41b3a08c7a6231d5ccde1348d53 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Mon, 11 Mar 2024 15:09:18 +0100 Subject: [PATCH 02/49] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ca269b..92dc766 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -Forked from *node-protoc* to add additional languages +Forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages From 939608844ae97799f408c9f1228824487f42d587 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Mon, 11 Mar 2024 18:36:42 +0100 Subject: [PATCH 03/49] added other languages --- index.js | 226 ++++++++++++++++++--------------------- package.json | 7 +- scripts/helloworld.proto | 41 +++++++ scripts/test.js | 13 ++- 4 files changed, 155 insertions(+), 132 deletions(-) create mode 100644 scripts/helloworld.proto diff --git a/index.js b/index.js index 1daed70..2030985 100644 --- a/index.js +++ b/index.js @@ -1,130 +1,112 @@ -const path = require("path"); -const cp = require("child_process"); -const fs = require("fs"); -const protoc = require("./protoc.js"); -const Vinyl = require("vinyl"); -const uuid = require("uuid"); -const mkdirp = require("mkdirp"); -const glob = require("glob"); - -exports.protoc = function(args, options, callback) { - cp.execFile(protoc, args, options, callback); -}; - -exports.closure = function(files, options, callback) { - if (!callback) { - callback = options; - options = null; - } - - options.imports = options.imports || []; - options.outputPath = options.outputPath || "./"; - const cwd = process.cwd(); - const absoluteOutputPath = path.resolve(cwd, options.outputPath); - const relative = path.relative(absoluteOutputPath, cwd); - - const args = [ - "--js_out=one_output_file_per_input_file,binary:." - ]; - - for (var i = 0; i < options.imports.length; i++) { - args.push("-I", path.join(relative, options.imports[i])); - } +const fs = require("fs"); +const { exec } = require('child_process'); +const path = require('path'); +const cp = require("child_process"); +// In einer Datei, z.B. currentDir.js - for (var i = 0; i < files.length; i++) { - args.push(path.join(relative, files[i])); +function mycallback(null1,in1,err){ + console.log(err) } - - mkdirp(options.outputPath, function(err) { - if (err) { - callback(err); - return; +class ProtobuffGenerator { + /** + * Constructor for the ProtobufGenerator class. + * Initializes necessary variables and configurations. + */ + constructor() { + // Initialization of necessary variables and configurations + // This could include setting up paths, loading configurations, etc. } - - exports.protoc(args, { - "cwd": options.outputPath - }, callback); - }); -}; - -/** - * Converts .proto files to .js files that can be used in Google Closure - * Compiler. - * The generated .js files require the files in - * https://github.com/protocolbuffers/protobuf/tree/v3.20.3/js. - * @param {?Array} files the proto files. - * @param {?function(?Error, ?Array)} callback the callback method. - */ -exports.library = function(files, callback) { - var dirpath = "tmp"; - var filename = uuid.v4(); - var jsFile = path.join(dirpath, filename); - mkdirp("tmp", function(err) { - if (err) { - callback(err); - return; - } - - exports.protoc(["--js_out=library=" + jsFile + ",binary:."].concat(files), function(err, stdout, stderr) { - if (err) { - callback(err); - return; - } - - if (fs.existsSync(jsFile + ".js")) { - fs.readFile(jsFile + ".js", function(err, contents) { - if (err) { - callback(err); + + /** + * Generates a Protobuf file for a specified programming language. + * @param {string} language - The programming language for which the Protobuf file should be generated. + * @param {string} proto_path - The path to the Proto file that should be used as the source. + * @param {string} outputPath - The path where the generated Protobuf file should be saved. + * @returns {Promise} A promise that resolves with the output of the command execution or rejects with an error. + * @throws {Error} If the specified language is not supported. + */ + generateProtobuf(language, proto_path,proto_file, outputPath) { + let command; + switch (language) { + case 'go': + // Example for Go --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative + command = `npx protoc --go_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'java': + // Example for Java + command = `npx protoc --java_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'python': + // Example for Python + command = `npx protoc --python_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'csharp': + // Example for C# + command = `npx protoc --objc_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'ruby': + // Example for Ruby + command = `npx protoc --ruby_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'objc': + // Example for Objective-C + command = `npx protoc --objc_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'php': + // Example for PHP + command = `npx protoc --php_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'dart': + // Example for Dart + command = `npx protoc --dart_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'rust': + // Example for Rust + command = `npx protoc --rust_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'swift': + // Example for Swift + command = `npx protoc --swift_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'kotlin': + // Example for Kotlin + command = `npx protoc --kotlin_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'scala': + // Example for Scala + command = `npx protoc --scala_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'js': + // Example for JavaScript/TypeScript + const protocGenTsPath = `${process.cwd()}/frontend/node_modules/ts-protoc-gen/bin/protoc-gen-ts`; // todo + const outDir = `${process.cwd()}/frontend/src`; + const protoPath = `${process.cwd()}/protos/`; + command = ` + npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-node,mode=grpc-js:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} + npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-web:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} + `; + break; + default: + throw new Error(`Unsupported language: ${language}`); + } + console.log(command) + // fs.mkdirSync(outputPath, { recursive: true }); + exec(command, function(err, stdout, stderr) { + console.log(stdout); + if (err) { + mycallback(err); + console.error(err); return; - } - - fs.unlink(jsFile + ".js", function(err) { - if (err) { - callback(err); - return; - } + } + console.log(stderr); + mycallback(null, stdout, stderr); + }) + - fs.rmdir(dirpath, function() { - callback(null, [new Vinyl({ - "cwd": "/", - "base": "/", - "path": filename + ".js", - "contents": contents - })]); - }); - }); - }); - } else { - glob("**/*.js", { - "cwd": jsFile - }, function(err, matches) { - if (err) { - callback(err, null); - return; - } - - var files = matches.map(function(match) { - return new Vinyl({ - "cwd": "/", - "base": "/", - "path": match, - "contents": fs.readFileSync(path.join(jsFile, match)) - }); - }); + + } + } - rimraf(jsFile, function(err) { - if (err) { - callback(err); - return; - } - fs.rmdir(dirpath, function() { - callback(null, files); - }); - }); - }); - } - }); - }); -}; +module.exports ={ProtobuffGenerator} \ No newline at end of file diff --git a/package.json b/package.json index e726168..9dfec0a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "protoc", "version": "1.1.3", - "description": "A tool for converting proto buffers (.proto) files into javascript files usable in Closure Compiler with Closure Library.", + "description": "A tool for converting proto buffers (.proto) files into javascript files and any other available languages. It was forked from git+https://github.com/YePpHa/node-protoc.git. i added the multi language support", "main": "index.js", "scripts": { "postinstall": "node scripts/postinstall.js", @@ -10,16 +10,17 @@ "bin": { "protoc": "./bin/protoc" }, - "author": "Jeppe Rune Mortensen ", + "author": "ji and Jeppe Rune Mortensen ", "license": "MIT", "repository": { "type": "git", - "url": "git+https://github.com/YePpHa/node-protoc.git" + "url": "git+https://github.com/ji-podhead/protoc-helper" }, "dependencies": { "glob": "^7.2.3", "mkdirp": "^0.5.6", "node-fetch": "^3.2.10", + "protoc-gen-ts": "^0.8.7", "rimraf": "^3.0.2", "unzipper": "^0.10.11", "uuid": "^9.0.0", diff --git a/scripts/helloworld.proto b/scripts/helloworld.proto new file mode 100644 index 0000000..9136951 --- /dev/null +++ b/scripts/helloworld.proto @@ -0,0 +1,41 @@ +// Copyright 2015 gRPC authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "./"; +option java_outer_classname = "HelloWorldProto"; +option objc_class_prefix = "HLW"; +option go_package = "./"; + +package helloworld; + +// The greeting service definition. +service Greeter { + // Sends a greeting + rpc SayHello (HelloRequest) returns (HelloReply) {} + + rpc SayHelloStreamReply (HelloRequest) returns (stream HelloReply) {} +} + +// The request message containing the user's name. +message HelloRequest { + string name = 1; +} + +// The response message containing the greetings +message HelloReply { + string message = 1; +} \ No newline at end of file diff --git a/scripts/test.js b/scripts/test.js index 930d513..896a7fe 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -1,7 +1,6 @@ -const protoc = require("../index.js"); -protoc.library(["protoc/include/google/protobuf/timestamp.proto"], function(err, files) { - if (err) { - console.error(err); - return; - } -}); +const { ProtobuffGenerator } = require('../index'); + +console.log(__dirname) +const dir = String(__dirname)+"/" +const generator = new ProtobuffGenerator() +generator.generateProtobuf("go",dir,"helloworld.proto",dir) From e4ac4fd0741c5caf696e3c128f41b95d73e8722b Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Mon, 11 Mar 2024 18:46:54 +0100 Subject: [PATCH 04/49] other languages --- index.js | 226 +++++++++++++++++++++++++--------------------- otherlanguages.js | 112 +++++++++++++++++++++++ package.json | 7 +- 3 files changed, 237 insertions(+), 108 deletions(-) create mode 100644 otherlanguages.js diff --git a/index.js b/index.js index 2030985..1daed70 100644 --- a/index.js +++ b/index.js @@ -1,112 +1,130 @@ - -const fs = require("fs"); -const { exec } = require('child_process'); -const path = require('path'); +const path = require("path"); const cp = require("child_process"); -// In einer Datei, z.B. currentDir.js +const fs = require("fs"); +const protoc = require("./protoc.js"); +const Vinyl = require("vinyl"); +const uuid = require("uuid"); +const mkdirp = require("mkdirp"); +const glob = require("glob"); + +exports.protoc = function(args, options, callback) { + cp.execFile(protoc, args, options, callback); +}; + +exports.closure = function(files, options, callback) { + if (!callback) { + callback = options; + options = null; + } + + options.imports = options.imports || []; + options.outputPath = options.outputPath || "./"; + + const cwd = process.cwd(); + const absoluteOutputPath = path.resolve(cwd, options.outputPath); + const relative = path.relative(absoluteOutputPath, cwd); + + const args = [ + "--js_out=one_output_file_per_input_file,binary:." + ]; + + for (var i = 0; i < options.imports.length; i++) { + args.push("-I", path.join(relative, options.imports[i])); + } -function mycallback(null1,in1,err){ - console.log(err) + for (var i = 0; i < files.length; i++) { + args.push(path.join(relative, files[i])); } -class ProtobuffGenerator { - /** - * Constructor for the ProtobufGenerator class. - * Initializes necessary variables and configurations. - */ - constructor() { - // Initialization of necessary variables and configurations - // This could include setting up paths, loading configurations, etc. + + mkdirp(options.outputPath, function(err) { + if (err) { + callback(err); + return; } - - /** - * Generates a Protobuf file for a specified programming language. - * @param {string} language - The programming language for which the Protobuf file should be generated. - * @param {string} proto_path - The path to the Proto file that should be used as the source. - * @param {string} outputPath - The path where the generated Protobuf file should be saved. - * @returns {Promise} A promise that resolves with the output of the command execution or rejects with an error. - * @throws {Error} If the specified language is not supported. - */ - generateProtobuf(language, proto_path,proto_file, outputPath) { - let command; - switch (language) { - case 'go': - // Example for Go --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative - command = `npx protoc --go_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'java': - // Example for Java - command = `npx protoc --java_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'python': - // Example for Python - command = `npx protoc --python_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'csharp': - // Example for C# - command = `npx protoc --objc_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'ruby': - // Example for Ruby - command = `npx protoc --ruby_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'objc': - // Example for Objective-C - command = `npx protoc --objc_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'php': - // Example for PHP - command = `npx protoc --php_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'dart': - // Example for Dart - command = `npx protoc --dart_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'rust': - // Example for Rust - command = `npx protoc --rust_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'swift': - // Example for Swift - command = `npx protoc --swift_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'kotlin': - // Example for Kotlin - command = `npx protoc --kotlin_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'scala': - // Example for Scala - command = `npx protoc --scala_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'js': - // Example for JavaScript/TypeScript - const protocGenTsPath = `${process.cwd()}/frontend/node_modules/ts-protoc-gen/bin/protoc-gen-ts`; // todo - const outDir = `${process.cwd()}/frontend/src`; - const protoPath = `${process.cwd()}/protos/`; - command = ` - npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-node,mode=grpc-js:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} - npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-web:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} - `; - break; - default: - throw new Error(`Unsupported language: ${language}`); - } - console.log(command) - // fs.mkdirSync(outputPath, { recursive: true }); - exec(command, function(err, stdout, stderr) { - console.log(stdout); - if (err) { - mycallback(err); - console.error(err); - return; - } - console.log(stderr); - mycallback(null, stdout, stderr); - }) - - + exports.protoc(args, { + "cwd": options.outputPath + }, callback); + }); +}; + +/** + * Converts .proto files to .js files that can be used in Google Closure + * Compiler. + * The generated .js files require the files in + * https://github.com/protocolbuffers/protobuf/tree/v3.20.3/js. + * @param {?Array} files the proto files. + * @param {?function(?Error, ?Array)} callback the callback method. + */ +exports.library = function(files, callback) { + var dirpath = "tmp"; + var filename = uuid.v4(); + var jsFile = path.join(dirpath, filename); + mkdirp("tmp", function(err) { + if (err) { + callback(err); + return; } - } + exports.protoc(["--js_out=library=" + jsFile + ",binary:."].concat(files), function(err, stdout, stderr) { + if (err) { + callback(err); + return; + } + + if (fs.existsSync(jsFile + ".js")) { + fs.readFile(jsFile + ".js", function(err, contents) { + if (err) { + callback(err); + return; + } + + fs.unlink(jsFile + ".js", function(err) { + if (err) { + callback(err); + return; + } + + fs.rmdir(dirpath, function() { + callback(null, [new Vinyl({ + "cwd": "/", + "base": "/", + "path": filename + ".js", + "contents": contents + })]); + }); + }); + }); + } else { + glob("**/*.js", { + "cwd": jsFile + }, function(err, matches) { + if (err) { + callback(err, null); + return; + } + + var files = matches.map(function(match) { + return new Vinyl({ + "cwd": "/", + "base": "/", + "path": match, + "contents": fs.readFileSync(path.join(jsFile, match)) + }); + }); + + rimraf(jsFile, function(err) { + if (err) { + callback(err); + return; + } -module.exports ={ProtobuffGenerator} \ No newline at end of file + fs.rmdir(dirpath, function() { + callback(null, files); + }); + }); + }); + } + }); + }); +}; diff --git a/otherlanguages.js b/otherlanguages.js new file mode 100644 index 0000000..2030985 --- /dev/null +++ b/otherlanguages.js @@ -0,0 +1,112 @@ + +const fs = require("fs"); +const { exec } = require('child_process'); +const path = require('path'); +const cp = require("child_process"); +// In einer Datei, z.B. currentDir.js + +function mycallback(null1,in1,err){ + console.log(err) + } +class ProtobuffGenerator { + /** + * Constructor for the ProtobufGenerator class. + * Initializes necessary variables and configurations. + */ + constructor() { + // Initialization of necessary variables and configurations + // This could include setting up paths, loading configurations, etc. + } + + /** + * Generates a Protobuf file for a specified programming language. + * @param {string} language - The programming language for which the Protobuf file should be generated. + * @param {string} proto_path - The path to the Proto file that should be used as the source. + * @param {string} outputPath - The path where the generated Protobuf file should be saved. + * @returns {Promise} A promise that resolves with the output of the command execution or rejects with an error. + * @throws {Error} If the specified language is not supported. + */ + generateProtobuf(language, proto_path,proto_file, outputPath) { + let command; + switch (language) { + case 'go': + // Example for Go --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative + command = `npx protoc --go_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'java': + // Example for Java + command = `npx protoc --java_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'python': + // Example for Python + command = `npx protoc --python_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'csharp': + // Example for C# + command = `npx protoc --objc_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'ruby': + // Example for Ruby + command = `npx protoc --ruby_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'objc': + // Example for Objective-C + command = `npx protoc --objc_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'php': + // Example for PHP + command = `npx protoc --php_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'dart': + // Example for Dart + command = `npx protoc --dart_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'rust': + // Example for Rust + command = `npx protoc --rust_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'swift': + // Example for Swift + command = `npx protoc --swift_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'kotlin': + // Example for Kotlin + command = `npx protoc --kotlin_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'scala': + // Example for Scala + command = `npx protoc --scala_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'js': + // Example for JavaScript/TypeScript + const protocGenTsPath = `${process.cwd()}/frontend/node_modules/ts-protoc-gen/bin/protoc-gen-ts`; // todo + const outDir = `${process.cwd()}/frontend/src`; + const protoPath = `${process.cwd()}/protos/`; + command = ` + npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-node,mode=grpc-js:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} + npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-web:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} + `; + break; + default: + throw new Error(`Unsupported language: ${language}`); + } + console.log(command) + // fs.mkdirSync(outputPath, { recursive: true }); + exec(command, function(err, stdout, stderr) { + console.log(stdout); + if (err) { + mycallback(err); + console.error(err); + return; + } + console.log(stderr); + mycallback(null, stdout, stderr); + }) + + + + } + } + + +module.exports ={ProtobuffGenerator} \ No newline at end of file diff --git a/package.json b/package.json index 9dfec0a..e726168 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "protoc", "version": "1.1.3", - "description": "A tool for converting proto buffers (.proto) files into javascript files and any other available languages. It was forked from git+https://github.com/YePpHa/node-protoc.git. i added the multi language support", + "description": "A tool for converting proto buffers (.proto) files into javascript files usable in Closure Compiler with Closure Library.", "main": "index.js", "scripts": { "postinstall": "node scripts/postinstall.js", @@ -10,17 +10,16 @@ "bin": { "protoc": "./bin/protoc" }, - "author": "ji and Jeppe Rune Mortensen ", + "author": "Jeppe Rune Mortensen ", "license": "MIT", "repository": { "type": "git", - "url": "git+https://github.com/ji-podhead/protoc-helper" + "url": "git+https://github.com/YePpHa/node-protoc.git" }, "dependencies": { "glob": "^7.2.3", "mkdirp": "^0.5.6", "node-fetch": "^3.2.10", - "protoc-gen-ts": "^0.8.7", "rimraf": "^3.0.2", "unzipper": "^0.10.11", "uuid": "^9.0.0", From 4349d43fb7f35bf2c6d17f45df472cdcc3da3f6b Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Mon, 11 Mar 2024 18:50:53 +0100 Subject: [PATCH 05/49] my changes --- otherlanguages.js | 4 ++-- scripts/helloworld.proto | 4 ++-- scripts/test.js | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/otherlanguages.js b/otherlanguages.js index 2030985..d1f1568 100644 --- a/otherlanguages.js +++ b/otherlanguages.js @@ -1,4 +1,4 @@ - +//other languages const fs = require("fs"); const { exec } = require('child_process'); const path = require('path'); @@ -109,4 +109,4 @@ class ProtobuffGenerator { } -module.exports ={ProtobuffGenerator} \ No newline at end of file +module.exports ={ProtobuffGenerator} diff --git a/scripts/helloworld.proto b/scripts/helloworld.proto index 9136951..c92cec6 100644 --- a/scripts/helloworld.proto +++ b/scripts/helloworld.proto @@ -11,7 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. - +//demoproto syntax = "proto3"; option java_multiple_files = true; @@ -38,4 +38,4 @@ message HelloRequest { // The response message containing the greetings message HelloReply { string message = 1; -} \ No newline at end of file +} diff --git a/scripts/test.js b/scripts/test.js index 896a7fe..350e1c0 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -1,3 +1,4 @@ +//newtest const { ProtobuffGenerator } = require('../index'); console.log(__dirname) From 07b214b22b2266fadd69be18e12cf8f30a66ed57 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Mon, 11 Mar 2024 19:29:37 +0100 Subject: [PATCH 06/49] made my package out of it --- index.js | 226 +++++++++++++++++++++------------------------- otherlanguages.js | 112 ----------------------- package.json | 9 +- 3 files changed, 109 insertions(+), 238 deletions(-) delete mode 100644 otherlanguages.js diff --git a/index.js b/index.js index 1daed70..d1f1568 100644 --- a/index.js +++ b/index.js @@ -1,130 +1,112 @@ -const path = require("path"); -const cp = require("child_process"); +//other languages const fs = require("fs"); -const protoc = require("./protoc.js"); -const Vinyl = require("vinyl"); -const uuid = require("uuid"); -const mkdirp = require("mkdirp"); -const glob = require("glob"); - -exports.protoc = function(args, options, callback) { - cp.execFile(protoc, args, options, callback); -}; - -exports.closure = function(files, options, callback) { - if (!callback) { - callback = options; - options = null; - } - - options.imports = options.imports || []; - options.outputPath = options.outputPath || "./"; - - const cwd = process.cwd(); - const absoluteOutputPath = path.resolve(cwd, options.outputPath); - const relative = path.relative(absoluteOutputPath, cwd); - - const args = [ - "--js_out=one_output_file_per_input_file,binary:." - ]; - - for (var i = 0; i < options.imports.length; i++) { - args.push("-I", path.join(relative, options.imports[i])); - } +const { exec } = require('child_process'); +const path = require('path'); +const cp = require("child_process"); +// In einer Datei, z.B. currentDir.js - for (var i = 0; i < files.length; i++) { - args.push(path.join(relative, files[i])); +function mycallback(null1,in1,err){ + console.log(err) } - - mkdirp(options.outputPath, function(err) { - if (err) { - callback(err); - return; +class ProtobuffGenerator { + /** + * Constructor for the ProtobufGenerator class. + * Initializes necessary variables and configurations. + */ + constructor() { + // Initialization of necessary variables and configurations + // This could include setting up paths, loading configurations, etc. } - - exports.protoc(args, { - "cwd": options.outputPath - }, callback); - }); -}; - -/** - * Converts .proto files to .js files that can be used in Google Closure - * Compiler. - * The generated .js files require the files in - * https://github.com/protocolbuffers/protobuf/tree/v3.20.3/js. - * @param {?Array} files the proto files. - * @param {?function(?Error, ?Array)} callback the callback method. - */ -exports.library = function(files, callback) { - var dirpath = "tmp"; - var filename = uuid.v4(); - var jsFile = path.join(dirpath, filename); - mkdirp("tmp", function(err) { - if (err) { - callback(err); - return; - } - - exports.protoc(["--js_out=library=" + jsFile + ",binary:."].concat(files), function(err, stdout, stderr) { - if (err) { - callback(err); - return; - } - - if (fs.existsSync(jsFile + ".js")) { - fs.readFile(jsFile + ".js", function(err, contents) { - if (err) { - callback(err); + + /** + * Generates a Protobuf file for a specified programming language. + * @param {string} language - The programming language for which the Protobuf file should be generated. + * @param {string} proto_path - The path to the Proto file that should be used as the source. + * @param {string} outputPath - The path where the generated Protobuf file should be saved. + * @returns {Promise} A promise that resolves with the output of the command execution or rejects with an error. + * @throws {Error} If the specified language is not supported. + */ + generateProtobuf(language, proto_path,proto_file, outputPath) { + let command; + switch (language) { + case 'go': + // Example for Go --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative + command = `npx protoc --go_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'java': + // Example for Java + command = `npx protoc --java_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'python': + // Example for Python + command = `npx protoc --python_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'csharp': + // Example for C# + command = `npx protoc --objc_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'ruby': + // Example for Ruby + command = `npx protoc --ruby_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'objc': + // Example for Objective-C + command = `npx protoc --objc_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'php': + // Example for PHP + command = `npx protoc --php_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'dart': + // Example for Dart + command = `npx protoc --dart_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'rust': + // Example for Rust + command = `npx protoc --rust_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'swift': + // Example for Swift + command = `npx protoc --swift_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'kotlin': + // Example for Kotlin + command = `npx protoc --kotlin_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'scala': + // Example for Scala + command = `npx protoc --scala_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'js': + // Example for JavaScript/TypeScript + const protocGenTsPath = `${process.cwd()}/frontend/node_modules/ts-protoc-gen/bin/protoc-gen-ts`; // todo + const outDir = `${process.cwd()}/frontend/src`; + const protoPath = `${process.cwd()}/protos/`; + command = ` + npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-node,mode=grpc-js:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} + npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-web:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} + `; + break; + default: + throw new Error(`Unsupported language: ${language}`); + } + console.log(command) + // fs.mkdirSync(outputPath, { recursive: true }); + exec(command, function(err, stdout, stderr) { + console.log(stdout); + if (err) { + mycallback(err); + console.error(err); return; - } - - fs.unlink(jsFile + ".js", function(err) { - if (err) { - callback(err); - return; - } + } + console.log(stderr); + mycallback(null, stdout, stderr); + }) + - fs.rmdir(dirpath, function() { - callback(null, [new Vinyl({ - "cwd": "/", - "base": "/", - "path": filename + ".js", - "contents": contents - })]); - }); - }); - }); - } else { - glob("**/*.js", { - "cwd": jsFile - }, function(err, matches) { - if (err) { - callback(err, null); - return; - } - - var files = matches.map(function(match) { - return new Vinyl({ - "cwd": "/", - "base": "/", - "path": match, - "contents": fs.readFileSync(path.join(jsFile, match)) - }); - }); + + } + } - rimraf(jsFile, function(err) { - if (err) { - callback(err); - return; - } - fs.rmdir(dirpath, function() { - callback(null, files); - }); - }); - }); - } - }); - }); -}; +module.exports ={ProtobuffGenerator} diff --git a/otherlanguages.js b/otherlanguages.js deleted file mode 100644 index d1f1568..0000000 --- a/otherlanguages.js +++ /dev/null @@ -1,112 +0,0 @@ -//other languages -const fs = require("fs"); -const { exec } = require('child_process'); -const path = require('path'); -const cp = require("child_process"); -// In einer Datei, z.B. currentDir.js - -function mycallback(null1,in1,err){ - console.log(err) - } -class ProtobuffGenerator { - /** - * Constructor for the ProtobufGenerator class. - * Initializes necessary variables and configurations. - */ - constructor() { - // Initialization of necessary variables and configurations - // This could include setting up paths, loading configurations, etc. - } - - /** - * Generates a Protobuf file for a specified programming language. - * @param {string} language - The programming language for which the Protobuf file should be generated. - * @param {string} proto_path - The path to the Proto file that should be used as the source. - * @param {string} outputPath - The path where the generated Protobuf file should be saved. - * @returns {Promise} A promise that resolves with the output of the command execution or rejects with an error. - * @throws {Error} If the specified language is not supported. - */ - generateProtobuf(language, proto_path,proto_file, outputPath) { - let command; - switch (language) { - case 'go': - // Example for Go --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative - command = `npx protoc --go_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'java': - // Example for Java - command = `npx protoc --java_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'python': - // Example for Python - command = `npx protoc --python_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'csharp': - // Example for C# - command = `npx protoc --objc_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'ruby': - // Example for Ruby - command = `npx protoc --ruby_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'objc': - // Example for Objective-C - command = `npx protoc --objc_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'php': - // Example for PHP - command = `npx protoc --php_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'dart': - // Example for Dart - command = `npx protoc --dart_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'rust': - // Example for Rust - command = `npx protoc --rust_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'swift': - // Example for Swift - command = `npx protoc --swift_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'kotlin': - // Example for Kotlin - command = `npx protoc --kotlin_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'scala': - // Example for Scala - command = `npx protoc --scala_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'js': - // Example for JavaScript/TypeScript - const protocGenTsPath = `${process.cwd()}/frontend/node_modules/ts-protoc-gen/bin/protoc-gen-ts`; // todo - const outDir = `${process.cwd()}/frontend/src`; - const protoPath = `${process.cwd()}/protos/`; - command = ` - npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-node,mode=grpc-js:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} - npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-web:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} - `; - break; - default: - throw new Error(`Unsupported language: ${language}`); - } - console.log(command) - // fs.mkdirSync(outputPath, { recursive: true }); - exec(command, function(err, stdout, stderr) { - console.log(stdout); - if (err) { - mycallback(err); - console.error(err); - return; - } - console.log(stderr); - mycallback(null, stdout, stderr); - }) - - - - } - } - - -module.exports ={ProtobuffGenerator} diff --git a/package.json b/package.json index e726168..ac8691b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "protoc", + "name": "protoc-helper", "version": "1.1.3", - "description": "A tool for converting proto buffers (.proto) files into javascript files usable in Closure Compiler with Closure Library.", + "description": "multilanguage grpc protobuff generator for node. forked from node-protoc.git. ", "main": "index.js", "scripts": { "postinstall": "node scripts/postinstall.js", @@ -10,16 +10,17 @@ "bin": { "protoc": "./bin/protoc" }, - "author": "Jeppe Rune Mortensen ", + "author": "ji & Jeppe Rune Mortensen ", "license": "MIT", "repository": { "type": "git", - "url": "git+https://github.com/YePpHa/node-protoc.git" + "url": "git+https://github.com/ji-podhead/protoc-helper" }, "dependencies": { "glob": "^7.2.3", "mkdirp": "^0.5.6", "node-fetch": "^3.2.10", + "protoc-gen-ts": "^0.8.7", "rimraf": "^3.0.2", "unzipper": "^0.10.11", "uuid": "^9.0.0", From 4847577a6b6265e574350207d70fc49ca1c1fa0f Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Mon, 11 Mar 2024 19:31:42 +0100 Subject: [PATCH 07/49] Update index.js --- index.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index d1f1568..cc54e47 100644 --- a/index.js +++ b/index.js @@ -82,10 +82,12 @@ class ProtobuffGenerator { const protocGenTsPath = `${process.cwd()}/frontend/node_modules/ts-protoc-gen/bin/protoc-gen-ts`; // todo const outDir = `${process.cwd()}/frontend/src`; const protoPath = `${process.cwd()}/protos/`; - command = ` - npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-node,mode=grpc-js:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} - npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-web:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} - `; + // command = ` + // npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-node,mode=grpc-js:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} + // npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-web:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} + // `; + command = `npx protoc --js_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; default: throw new Error(`Unsupported language: ${language}`); From b169c671e5a649d58e82478135a9af38c5da1349 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Mon, 11 Mar 2024 19:36:17 +0100 Subject: [PATCH 08/49] Update README.md --- README.md | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 92dc766..57a9f53 100644 --- a/README.md +++ b/README.md @@ -1 +1,30 @@ -Forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages +# protoc-helper +multilanguage grpc protobuff generator for node. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. +uses the protoc binary and supports multiple platforms and processors. + +you can find a demo in the scripts folder: + +``` +//test +const { ProtobuffGenerator } = require('../index'); + +console.log(__dirname) +const dir = String(__dirname)+"/" +const generator = new ProtobuffGenerator() +generator.generateProtobuf("go",dir,"helloworld.proto",dir) +``` +# NPX and additional args + +you can use `npx protoc` or add your own arguments in the index.js: +``` + switch (language) { + case 'go': + // Example for Go --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative + command = `npx protoc --go_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'java': + // Example for Java + command = `npx protoc --java_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'python': +``` From 722a8eecf9a6b2d4ba6fc2c93e8e6f3e94c032bc Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Mon, 11 Mar 2024 19:40:17 +0100 Subject: [PATCH 09/49] Create npm-publish.yml --- .github/workflows/npm-publish.yml | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/npm-publish.yml diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..6cdebaf --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,33 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages + +name: Node.js Package + +on: + release: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - run: npm ci + - run: npm test + + publish-npm: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + registry-url: https://registry.npmjs.org/ + - run: npm ci + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.npm_token}} From e8204c08e49697639bb147d55024492aa412d97c Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Mon, 11 Mar 2024 19:47:23 +0100 Subject: [PATCH 10/49] Create npm-publish-github-packages.yml --- .../workflows/npm-publish-github-packages.yml | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/npm-publish-github-packages.yml diff --git a/.github/workflows/npm-publish-github-packages.yml b/.github/workflows/npm-publish-github-packages.yml new file mode 100644 index 0000000..47a37f9 --- /dev/null +++ b/.github/workflows/npm-publish-github-packages.yml @@ -0,0 +1,36 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages + +name: Node.js Package + +on: + release: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - run: npm ci + - run: npm test + + publish-gpr: + needs: build + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + registry-url: https://npm.pkg.github.com/ + - run: npm ci + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} From df05025c5f991d2bfbaed8bb9eee4d4db6cb0f0d Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Mon, 11 Mar 2024 20:35:55 +0100 Subject: [PATCH 11/49] Update package.json --- package.json | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index ac8691b..1d88d33 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,9 @@ "type": "git", "url": "git+https://github.com/ji-podhead/protoc-helper" }, + "publishConfig": { + "registry": "https://npm.pkg.github.com/@ji-podhead" + }, "dependencies": { "glob": "^7.2.3", "mkdirp": "^0.5.6", @@ -25,5 +28,10 @@ "unzipper": "^0.10.11", "uuid": "^9.0.0", "vinyl": "^2.2.1" - } + }, + "publishConfig": { + "registry": "https://registry.npmjs.org/", + "access": "restricted", + "token": "{{NPM_TOKEN}}" + } } From 04ac3755b9da9a667ab1d1e4b43e86adcaab4f53 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Mon, 11 Mar 2024 20:50:51 +0100 Subject: [PATCH 12/49] changed package --- README.md | 1 + package.json | 11 ++++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 57a9f53..8994a56 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # protoc-helper multilanguage grpc protobuff generator for node. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. uses the protoc binary and supports multiple platforms and processors. +npm: `npm i protoc-helper` you can find a demo in the scripts folder: diff --git a/package.json b/package.json index 1d88d33..65d70c5 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,9 @@ "main": "index.js", "scripts": { "postinstall": "node scripts/postinstall.js", - "test": "node scripts/test.js" + "test": "node scripts/test.js", + "build": "npm run build", + "deploy": "npm publish" }, "bin": { "protoc": "./bin/protoc" @@ -28,10 +30,5 @@ "unzipper": "^0.10.11", "uuid": "^9.0.0", "vinyl": "^2.2.1" - }, - "publishConfig": { - "registry": "https://registry.npmjs.org/", - "access": "restricted", - "token": "{{NPM_TOKEN}}" - } + } } From bba6813e6855e9ff9c454f585f6c403e0fd77a19 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Mon, 11 Mar 2024 21:08:26 +0100 Subject: [PATCH 13/49] Update package.json --- package.json | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 65d70c5..41f3cc1 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "protoc-helper", + "name": "@ji-podhead/protoc-helper", "version": "1.1.3", "description": "multilanguage grpc protobuff generator for node. forked from node-protoc.git. ", "main": "index.js", @@ -16,11 +16,15 @@ "license": "MIT", "repository": { "type": "git", - "url": "git+https://github.com/ji-podhead/protoc-helper" + "url": "https://github.com/ji-podhead/protoc-helper" }, + "publishConfig": { - "registry": "https://npm.pkg.github.com/@ji-podhead" + "registry": "https://npm.pkg.github.com/@ji-podhead", + "access": "restricted", + "token": "{{NPM_TOKEN}}" }, + "dependencies": { "glob": "^7.2.3", "mkdirp": "^0.5.6", From 2e3181cfd08b7ce2956ce3aa13768c7f369d2030 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Mon, 11 Mar 2024 22:19:17 +0100 Subject: [PATCH 14/49] a --- .npmrc | 1 + package.json | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 .npmrc diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..31f5976 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +//npm.pkg.github.com/:_authToken=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 diff --git a/package.json b/package.json index 41f3cc1..60bc8fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ji-podhead/protoc-helper", - "version": "1.1.3", + "version": "1.1.4", "description": "multilanguage grpc protobuff generator for node. forked from node-protoc.git. ", "main": "index.js", "scripts": { @@ -20,8 +20,8 @@ }, "publishConfig": { - "registry": "https://npm.pkg.github.com/@ji-podhead", - "access": "restricted", + "registry": "https://npm.pkg.github.com/ji-podhead", + "access": "public", "token": "{{NPM_TOKEN}}" }, From d0eca1c6f148a0ad18f6c529e27ef07be14f43de Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Tue, 12 Mar 2024 00:18:57 +0100 Subject: [PATCH 15/49] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8994a56..09b6342 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # protoc-helper multilanguage grpc protobuff generator for node. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. uses the protoc binary and supports multiple platforms and processors. -npm: `npm i protoc-helper` +##Install +`npm i @ji-podhead/protoc-helper` you can find a demo in the scripts folder: @@ -14,7 +15,7 @@ const dir = String(__dirname)+"/" const generator = new ProtobuffGenerator() generator.generateProtobuf("go",dir,"helloworld.proto",dir) ``` -# NPX and additional args +## NPX and additional args you can use `npx protoc` or add your own arguments in the index.js: ``` From 7e50b9a19e3388a1a4b17892da99c53656a8995e Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Tue, 12 Mar 2024 00:19:15 +0100 Subject: [PATCH 16/49] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 09b6342..7a7af37 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # protoc-helper multilanguage grpc protobuff generator for node. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. uses the protoc binary and supports multiple platforms and processors. -##Install + +## Install `npm i @ji-podhead/protoc-helper` you can find a demo in the scripts folder: From bc8ba0ec09aa5790d2c35f6c5d3829889ae2e153 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Tue, 12 Mar 2024 00:22:14 +0100 Subject: [PATCH 17/49] added second publish option --- .github/workflows/npm-publish.yml | 33 +++++++++------------------ .npmrc | 3 ++- .npmrc copy | 3 +++ package copy.json | 37 +++++++++++++++++++++++++++++++ package.json | 12 +++++----- 5 files changed, 57 insertions(+), 31 deletions(-) create mode 100644 .npmrc copy create mode 100644 package copy.json diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 6cdebaf..8bec15a 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -1,33 +1,20 @@ -# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created -# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages - -name: Node.js Package +name: Publish to npm on: - release: - types: [created] + push: + branches: + - main # Ersetzen Sie 'main' durch den Namen Ihrer Hauptbranch, falls anders jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 16 - - run: npm ci - - run: npm test - - publish-npm: - needs: build + publish: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 with: - node-version: 16 - registry-url: https://registry.npmjs.org/ + node-version: '14' # Ersetzen Sie '14' durch die gewünschte Node.js-Version + registry-url: 'https://registry.npmjs.org' - run: npm ci - run: npm publish env: - NODE_AUTH_TOKEN: ${{secrets.npm_token}} + NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} \ No newline at end of file diff --git a/.npmrc b/.npmrc index 31f5976..a9ab829 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ -//npm.pkg.github.com/:_authToken=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 +registry=https://registry.npmjs.org/ +´ \ No newline at end of file diff --git a/.npmrc copy b/.npmrc copy new file mode 100644 index 0000000..4c60baa --- /dev/null +++ b/.npmrc copy @@ -0,0 +1,3 @@ +registry=https://registry.npmjs.org/ +@ji-podhead:registry=https://npm.pkg.github.com/ +//npm.pkg.github.com/:_authToken=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 diff --git a/package copy.json b/package copy.json new file mode 100644 index 0000000..1afb33b --- /dev/null +++ b/package copy.json @@ -0,0 +1,37 @@ +{ + "name": "@ji-podhead/protoc-helper", + "version": "1.0.5", + "description": "multilanguage grpc protobuff generator for node. forked from node-protoc.git. ", + "main": "index.js", + "scripts": { + "postinstall": "node scripts/postinstall.js", + "test": "node scripts/test.js", + "build": "npm run build", + "deploy": "npm publish" + }, + "bin": { + "protoc": "./bin/protoc" + }, + "author": "ji & Jeppe Rune Mortensen ", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/ji-podhead/protoc-helper" + }, + "publishConfig": { + "registry": "https://npm.pkg.github.com", + "access": "public", + "token": "{{NPM_TOKEN}}" + }, + "dependencies": { + "@ji-podhead/protoc-helper": "^1.0.3", + "glob": "^7.2.3", + "mkdirp": "^0.5.6", + "node-fetch": "^3.2.10", + "protoc-gen-ts": "^0.8.7", + "rimraf": "^3.0.2", + "unzipper": "^0.10.11", + "uuid": "^9.0.0", + "vinyl": "^2.2.1" + } +} diff --git a/package.json b/package.json index 60bc8fd..fd32659 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ji-podhead/protoc-helper", - "version": "1.1.4", + "version": "1.0.6", "description": "multilanguage grpc protobuff generator for node. forked from node-protoc.git. ", "main": "index.js", "scripts": { @@ -18,18 +18,16 @@ "type": "git", "url": "https://github.com/ji-podhead/protoc-helper" }, - "publishConfig": { - "registry": "https://npm.pkg.github.com/ji-podhead", - "access": "public", - "token": "{{NPM_TOKEN}}" + "registry": "https://registry.npmjs.org/", + "access": "public" }, - "dependencies": { + "@ji-podhead/protoc-helper": "^1.0.3", "glob": "^7.2.3", "mkdirp": "^0.5.6", "node-fetch": "^3.2.10", - "protoc-gen-ts": "^0.8.7", + "protoc-gen-ts": "^0.8.7", "rimraf": "^3.0.2", "unzipper": "^0.10.11", "uuid": "^9.0.0", From 3f6ce7de9248e99b1e3060e8b6cb84186a87e52d Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Tue, 12 Mar 2024 01:26:03 +0100 Subject: [PATCH 18/49] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7a7af37..43be154 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![npm version](https://badge.fury.io/js/@ji-podhead%2Fprotoc-helper.svg)](https://badge.fury.io/js/@ji-podhead%2Fprotoc-helper) # protoc-helper multilanguage grpc protobuff generator for node. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. uses the protoc binary and supports multiple platforms and processors. From 3e3bf2316e93261fb97fac3fdb642a7240f3e515 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Tue, 12 Mar 2024 01:28:05 +0100 Subject: [PATCH 19/49] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 43be154..da082ec 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ uses the protoc binary and supports multiple platforms and processors. you can find a demo in the scripts folder: -``` +```JavaScript //test const { ProtobuffGenerator } = require('../index'); @@ -20,7 +20,7 @@ generator.generateProtobuf("go",dir,"helloworld.proto",dir) ## NPX and additional args you can use `npx protoc` or add your own arguments in the index.js: -``` +```JavaScript switch (language) { case 'go': // Example for Go --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative From 9703c460df8e0b22b38f4831e92d2949be2d90b3 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Tue, 12 Mar 2024 02:31:00 +0100 Subject: [PATCH 20/49] Update README.md --- README.md | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index da082ec..5baf496 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,24 @@ uses the protoc binary and supports multiple platforms and processors. ## Install `npm i @ji-podhead/protoc-helper` -you can find a demo in the scripts folder: - +## How to use +- import via npm install ```JavaScript -//test -const { ProtobuffGenerator } = require('../index'); + const {ProtobuffGenerator} = require("@ji-podhead/protoc-helper") + ``` -console.log(__dirname) +- import via git clone +```JavaScript + const { ProtobuffGenerator } = require('../index'); + ``` +- generate the protobuffs +```JavaScript const dir = String(__dirname)+"/" const generator = new ProtobuffGenerator() generator.generateProtobuf("go",dir,"helloworld.proto",dir) ``` +- here were are using the helloworld protofile from the current directory. +- you can find a demoscript and the proto file in the scripts folder. ## NPX and additional args you can use `npx protoc` or add your own arguments in the index.js: From 659fa821f3f85411bef5936553610dac5fd4301e Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:58:16 +0100 Subject: [PATCH 21/49] Update .npmrc copy --- .npmrc copy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.npmrc copy b/.npmrc copy index 4c60baa..183dc89 100644 --- a/.npmrc copy +++ b/.npmrc copy @@ -1,3 +1,3 @@ registry=https://registry.npmjs.org/ @ji-podhead:registry=https://npm.pkg.github.com/ -//npm.pkg.github.com/:_authToken=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 +//npm.pkg.github.com/:_authToken=key From 3bacb164d58c9458c16598316244eb1846ac1b3f Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Thu, 14 Mar 2024 19:58:51 +0100 Subject: [PATCH 22/49] Update README.md --- README.md | 127 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 117 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5baf496..005a7f5 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,136 @@ [![npm version](https://badge.fury.io/js/@ji-podhead%2Fprotoc-helper.svg)](https://badge.fury.io/js/@ji-podhead%2Fprotoc-helper) # protoc-helper multilanguage grpc protobuff generator for node. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. -uses the protoc binary and supports multiple platforms and processors. +uses the protoc binary and supports multiple platforms and processors. Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/edit/master/README.md#protobuf-plugin-installation) to install the required plugins for your target language. ## Install -`npm i @ji-podhead/protoc-helper` - +- **local:** `npm i @ji-podhead/protoc-helper` +- **cli-tool:** `npx install protoch` ## How to use -- import via npm install +### CLI (via npx global install) ```JavaScript - const {ProtobuffGenerator} = require("@ji-podhead/protoc-helper") - ``` +npx install protoch +npx protoch +``` +--- -- import via git clone +### LOCAL +- **Import** ```JavaScript - const { ProtobuffGenerator } = require('../index'); + const {ProtobuffGenerator,createProtobuff} = require("@ji-podhead/protoc-helper") ``` -- generate the protobuffs + +- **create a path** ```JavaScript const dir = String(__dirname)+"/" +``` + +### generate the protobuffs + +- **`without instance` (array is supported)** + +```JavaScript +createProtobuff("js",dir,path.join(dir,"helloworld.proto")) +``` + +- **`using class instance`** + +```JavaScript const generator = new ProtobuffGenerator() -generator.generateProtobuf("go",dir,"helloworld.proto",dir) +generator.generateProtobuf("js",dir,"helloworld.proto",dir) +``` +- **`usings array` for multiple files** + +```JavaScript +generator.generateProtobuf([["go",dir,"helloworld.proto",dir],["python",dir,"helloworld.proto",dir]]) ``` +--- - here were are using the helloworld protofile from the current directory. - you can find a demoscript and the proto file in the scripts folder. +--- + +## Protobuf Plugin Installation + +### Go +- **Repository**: [https://github.com/golang/protobuf](https://github.com/golang/protobuf) +- **Installation**: +bash go get -u github.com/golang/protobuf/protoc-gen-go + + +### Java +- **Repository**: [https://github.com/google/protobuf-gradle-plugin](https://github.com/google/protobuf-gradle-plugin) +- **Installation**: +gradle plugins { id 'com.google.protobuf' version '0.8.17' } + + +### Python +- **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) +- **Installation**: +bash pip install protobuf + + +### C# +- **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) +- **Installation**: +powershell Install-Package Google.Protobuf.Tools + + +### Ruby +- **Repository**: [https://github.com/localshred/protobuf](https://github.com/localshred/protobuf) +- **Installation**: +bash gem install protobuf + + +### Objective-C +- **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) +- **Installation**: +ruby pod '!ProtoCompiler-gRPCPlugin' + + +### PHP +- **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) +- **Installation**: +bash composer require google/protobuf + + +### Dart +- **Repository**: [https://github.com/dart-lang/protobuf](https://github.com/dart-lang/protobuf) +- **Installation**: +bash dart pub global activate protoc_plugin + + +### Rust +- **Repository**: (https://github.com/neoeinstein/protoc-gen-prost](https://github.com/neoeinstein/protoc-gen-prost) +- **Installation**: +*see repo + + +### Swift +- **Repository**: [https://github.com/apple/swift-protobuf](https://github.com/apple/swift-protobuf) +- **Installation**: +swift // Add SwiftProtobuf as a dependency to your Xcode project + + +### Kotlin +- **Repository**: [https://github.com/grpc/grpc-kotlin/tree/master/compiler](https://github.com/grpc/grpc-kotlin/tree/master/compiler) +- **Installation**: +bash + +Clone and build the plugin +git clone https://github.com/grpc/grpc-kotlin.git cd grpc-kotlin/compiler ./gradlew installDist + + +### Scala +- **Repository**: [https://github.com/scalapb/ScalaPB](https://github.com/scalapb/ScalaPB) +- **Installation**: +scala // Add ScalaPB as a dependency to your sbt project libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.1" + + +### JavaScript/TypeScript +- **Repository**: [https://github.com/improbable-eng/ts-protoc-gen](https://github.com/improbable-eng/ts-protoc-gen) +- **Installation**: +bash npm install ts-protoc-gen + ## NPX and additional args you can use `npx protoc` or add your own arguments in the index.js: From d135413967771d8d13b9d87274600bbf30810931 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:02:22 +0100 Subject: [PATCH 23/49] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 005a7f5..d198f47 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,6 @@ npx protoch ```JavaScript const dir = String(__dirname)+"/" ``` - ### generate the protobuffs - **`without instance` (array is supported)** @@ -48,7 +47,9 @@ generator.generateProtobuf([["go",dir,"helloworld.proto",dir],["python",dir,"hel - here were are using the helloworld protofile from the current directory. - you can find a demoscript and the proto file in the scripts folder. --- +if you like this package, pls consider giving Jeppe’s and my repo a Star on github +--- ## Protobuf Plugin Installation ### Go From 94cdcf913b03e4995578866cc63d507845ee7904 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:06:39 +0100 Subject: [PATCH 24/49] added Typescript --- .npmrc | 2 - .npmrc copy | 3 - index.js | 189 +++++++++++++++++++++++++++--------------------- package.json | 25 ++++++- scripts/test.js | 150 +++++++++++++++++++++++++++++++++++++- 5 files changed, 275 insertions(+), 94 deletions(-) delete mode 100644 .npmrc delete mode 100644 .npmrc copy diff --git a/.npmrc b/.npmrc deleted file mode 100644 index a9ab829..0000000 --- a/.npmrc +++ /dev/null @@ -1,2 +0,0 @@ -registry=https://registry.npmjs.org/ -´ \ No newline at end of file diff --git a/.npmrc copy b/.npmrc copy deleted file mode 100644 index 183dc89..0000000 --- a/.npmrc copy +++ /dev/null @@ -1,3 +0,0 @@ -registry=https://registry.npmjs.org/ -@ji-podhead:registry=https://npm.pkg.github.com/ -//npm.pkg.github.com/:_authToken=key diff --git a/index.js b/index.js index cc54e47..ed9a469 100644 --- a/index.js +++ b/index.js @@ -3,10 +3,27 @@ const fs = require("fs"); const { exec } = require('child_process'); const path = require('path'); const cp = require("child_process"); -// In einer Datei, z.B. currentDir.js +const { type } = require("os"); -function mycallback(null1,in1,err){ - console.log(err) + + +function createProtobuff(language,outputPath,proto_file,proto_path){ + let directoryPath,fileName + if(proto_path==undefined) { + directoryPath = path.dirname(proto_file); + fileName = path.basename(proto_file); + console.log(`Directory: ${directoryPath}`); + console.log(`File Name: ${fileName}`); + } + else{ + directoryPath=proto_path + fileName=proto_file + } + new ProtobuffGenerator().generateProtobuf(language,directoryPath,fileName,outputPath) +} + +function mycallback(){ + //console.log("created ") } class ProtobuffGenerator { /** @@ -26,89 +43,97 @@ class ProtobuffGenerator { * @returns {Promise} A promise that resolves with the output of the command execution or rejects with an error. * @throws {Error} If the specified language is not supported. */ - generateProtobuf(language, proto_path,proto_file, outputPath) { - let command; - switch (language) { - case 'go': - // Example for Go --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative - command = `npx protoc --go_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'java': - // Example for Java - command = `npx protoc --java_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'python': - // Example for Python - command = `npx protoc --python_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'csharp': - // Example for C# - command = `npx protoc --objc_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'ruby': - // Example for Ruby - command = `npx protoc --ruby_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'objc': - // Example for Objective-C - command = `npx protoc --objc_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'php': - // Example for PHP - command = `npx protoc --php_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'dart': - // Example for Dart - command = `npx protoc --dart_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'rust': - // Example for Rust - command = `npx protoc --rust_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'swift': - // Example for Swift - command = `npx protoc --swift_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'kotlin': - // Example for Kotlin - command = `npx protoc --kotlin_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'scala': - // Example for Scala - command = `npx protoc --scala_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'js': - // Example for JavaScript/TypeScript - const protocGenTsPath = `${process.cwd()}/frontend/node_modules/ts-protoc-gen/bin/protoc-gen-ts`; // todo - const outDir = `${process.cwd()}/frontend/src`; - const protoPath = `${process.cwd()}/protos/`; - // command = ` - // npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-node,mode=grpc-js:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} - // npx protoc --plugin="protoc-gen-ts=${protocGenTsPath}" --ts_out="service=grpc-web:${outDir}" --js_out="import_style=commonjs,binary:${outDir}" --proto_path="${protoPath}" ${proto_path} - // `; - command = `npx protoc --js_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + + + generateProtobuf(language, proto_path,proto_file, outputPath, additionalCommands) { + let command; + let arr + switch (language) { + case 'go': + // Example for Go --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative + command = `npx protoc --go_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + break; + case 'java': + // Example for Java + command = `npx protoc --java_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + break; + case 'python': + // Example for Python + command = `npx protoc --python_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + break; + case 'csharp': + // Example for C# + command = `npx protoc --objc_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + break; + case 'ruby': + // Example for Ruby + command = `npx protoc --ruby_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + break; + case 'objc': + // Example for Objective-C + command = `npx protoc --objc_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + break; + case 'php': + // Example for PHP + command = `npx protoc --php_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + break; + case 'dart': + // Example for Dart + command = `npx protoc --dart_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + break; + case 'rust': + // Example for Rust + command = `npx protoc --rust_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + break; + case 'swift': + // Example for Swift + command = `npx protoc --swift_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + break; + case 'kotlin': + // Example for Kotlin + command = `npx protoc --kotlin_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + break; + case 'scala': + // Example for Scala + command = `npx protoc --scala_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + break; + case 'js': + command = `npx protoc --js_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'ts': + // Example for JavaScript/TypeScript + command= `npx protoc --ts_out=${outputPath} --proto_path=${proto_path} ${proto_file}` + break; + default: + + if(Array.isArray(language)){ + arr = true; + for (let arg of language){ + this.generateProtobuf(...arg); + } + } else if(typeof(language) == 'object'){ + arr = true; + for (let arg in language){ + this.generateProtobuf(...arg); - break; - default: - throw new Error(`Unsupported language: ${language}`); - } - console.log(command) - // fs.mkdirSync(outputPath, { recursive: true }); - exec(command, function(err, stdout, stderr) { - console.log(stdout); + } + } else { + throw new Error(`Unsupported language: ${language}`); + } + } + if(arr!=true){ + } +if(arr!=true) + { exec(command, function(err, stdout, stderr) { if (err) { - mycallback(err); console.error(err); return; } - console.log(stderr); - mycallback(null, stdout, stderr); - }) - - - + console.log("__________\n"+"finished command: " + JSON.stringify([language, proto_path,proto_file, outputPath, additionalCommands])) +// mycallback(null, stdout, stderr); + } + ) + } } } - - -module.exports ={ProtobuffGenerator} +module.exports ={createProtobuff,ProtobuffGenerator,cli} diff --git a/package.json b/package.json index fd32659..f215dd3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ji-podhead/protoc-helper", - "version": "1.0.6", + "version": "1.0.7", "description": "multilanguage grpc protobuff generator for node. forked from node-protoc.git. ", "main": "index.js", "scripts": { @@ -23,7 +23,6 @@ "access": "public" }, "dependencies": { - "@ji-podhead/protoc-helper": "^1.0.3", "glob": "^7.2.3", "mkdirp": "^0.5.6", "node-fetch": "^3.2.10", @@ -32,5 +31,25 @@ "unzipper": "^0.10.11", "uuid": "^9.0.0", "vinyl": "^2.2.1" - } + }, + "keywords": [ + "protobuff_gen for node", + "grpc", + "protoc", + "protoc-gen", + "ts", + "go", +"java", +"python", +"csharp", +"ruby", +"objc", +"php", +"dart", +"rust", +"swift", +"kotlin", +"scala", +"js" + ] } diff --git a/scripts/test.js b/scripts/test.js index 350e1c0..30bd672 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -1,7 +1,149 @@ //newtest -const { ProtobuffGenerator } = require('../index'); - +const { ProtobuffGenerator, createProtobuff } = require('../index'); +const path = require('path'); console.log(__dirname) -const dir = String(__dirname)+"/" +const dir = String(__dirname) + +console.log("_______ WITHOUT CLASS _________") +createProtobuff("js",dir,path.join(dir,"helloworld.proto")) + +console.log("_______ CLASS _________") +const generator = new ProtobuffGenerator() +generator.generateProtobuf("js",dir,"helloworld.proto",dir) + +console.log("_______ CLASS + ARRAY ARGUMENTS_________") +generator.generateProtobuf([["go",dir,"helloworld.proto",dir],["python",dir,"helloworld.proto",dir]]) + +[![npm version](https://badge.fury.io/js/@ji-podhead%2Fprotoc-helper.svg)](https://badge.fury.io/js/@ji-podhead%2Fprotoc-helper) +# protoc-helper +multilanguage grpc protobuff generator for node. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. +uses the protoc binary and supports multiple platforms and processors. Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/edit/master/README.md#protobuf-plugin-installation) to install the required plugins for your target language. + +## Install +`npm i @ji-podhead/protoc-helper` + +## How to use +- import via npm install +```JavaScript + const {ProtobuffGenerator} = require("@ji-podhead/protoc-helper") + ``` + +

import via git clone

+```JavaScript + const { ProtobuffGenerator } = require('../index'); + ``` +

generate the protobuffs `WITHOUT CLASS` (array is supported)

+ +```JavaScript +createProtobuff("js",dir,path.join(dir,"helloworld.proto")) +``` +

+generate the protobuffs `WITH CLASS`

+```JavaScript const generator = new ProtobuffGenerator() -generator.generateProtobuf("go",dir,"helloworld.proto",dir) +generator.generateProtobuf("js",dir,"helloworld.proto",dir) +``` +

generate the protobuffs `CLASS + ARRAY ARGUMENTS`

+```JavaScript +generator.generateProtobuf([["go",dir,"helloworld.proto",dir],["python",dir,"helloworld.proto",dir]]) +``` +- here were are using the helloworld protofile from the current directory. +- you can find a demoscript and the proto file in the scripts folder. + +## Protobuf Plugin Installation + +### Go +- **Repository**: [https://github.com/golang/protobuf](https://github.com/golang/protobuf) +- **Installation**: +bash go get -u github.com/golang/protobuf/protoc-gen-go + + +### Java +- **Repository**: [https://github.com/google/protobuf-gradle-plugin](https://github.com/google/protobuf-gradle-plugin) +- **Installation**: +gradle plugins { id 'com.google.protobuf' version '0.8.17' } + + +### Python +- **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) +- **Installation**: +bash pip install protobuf + + +### C# +- **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) +- **Installation**: +powershell Install-Package Google.Protobuf.Tools + + +### Ruby +- **Repository**: [https://github.com/localshred/protobuf](https://github.com/localshred/protobuf) +- **Installation**: +bash gem install protobuf + + +### Objective-C +- **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) +- **Installation**: +ruby pod '!ProtoCompiler-gRPCPlugin' + + +### PHP +- **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) +- **Installation**: +bash composer require google/protobuf + + +### Dart +- **Repository**: [https://github.com/dart-lang/protobuf](https://github.com/dart-lang/protobuf) +- **Installation**: +bash dart pub global activate protoc_plugin + + +### Rust +- **Repository**: (https://github.com/neoeinstein/protoc-gen-prost](https://github.com/neoeinstein/protoc-gen-prost) +- **Installation**: +*see repo + + +### Swift +- **Repository**: [https://github.com/apple/swift-protobuf](https://github.com/apple/swift-protobuf) +- **Installation**: +swift // Add SwiftProtobuf as a dependency to your Xcode project + + +### Kotlin +- **Repository**: [https://github.com/grpc/grpc-kotlin/tree/master/compiler](https://github.com/grpc/grpc-kotlin/tree/master/compiler) +- **Installation**: +bash + +Clone and build the plugin +git clone https://github.com/grpc/grpc-kotlin.git cd grpc-kotlin/compiler ./gradlew installDist + + +### Scala +- **Repository**: [https://github.com/scalapb/ScalaPB](https://github.com/scalapb/ScalaPB) +- **Installation**: +scala // Add ScalaPB as a dependency to your sbt project libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.1" + + +### JavaScript/TypeScript +- **Repository**: [https://github.com/improbable-eng/ts-protoc-gen](https://github.com/improbable-eng/ts-protoc-gen) +- **Installation**: +bash npm install ts-protoc-gen + +## NPX and additional args + +you can use `npx protoc` or add your own arguments in the index.js: +```JavaScript + switch (language) { + case 'go': + // Example for Go --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative + command = `npx protoc --go_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'java': + // Example for Java + command = `npx protoc --java_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + break; + case 'python': +``` From de0771abcce4b5e95de259c962f545979aa30d79 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:12:10 +0100 Subject: [PATCH 25/49] Update README.md --- README.md | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d198f47..a46316c 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,11 @@ uses the protoc binary and supports multiple platforms and processors. Please se - **local:** `npm i @ji-podhead/protoc-helper` - **cli-tool:** `npx install protoch` ## How to use -### CLI (via npx global install) +**CLI (via npx global install)** ```JavaScript -npx install protoch npx protoch ``` --- - -### LOCAL - **Import** ```JavaScript const {ProtobuffGenerator,createProtobuff} = require("@ji-podhead/protoc-helper") @@ -24,21 +21,19 @@ npx protoch ```JavaScript const dir = String(__dirname)+"/" ``` -### generate the protobuffs - -- **`without instance` (array is supported)** +- **generate the protobuffs `without instance` (array is supported)** ```JavaScript createProtobuff("js",dir,path.join(dir,"helloworld.proto")) ``` -- **`using class instance`** +- **generate the protobuffs `using class instance`** ```JavaScript const generator = new ProtobuffGenerator() generator.generateProtobuf("js",dir,"helloworld.proto",dir) ``` -- **`usings array` for multiple files** +- **generate the protobuffs `usings array` for multiple files** ```JavaScript generator.generateProtobuf([["go",dir,"helloworld.proto",dir],["python",dir,"helloworld.proto",dir]]) From cbf6452259e44d7c581d40050590d31c4427161d Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:13:20 +0100 Subject: [PATCH 26/49] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a46316c..dbd21b4 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ generator.generateProtobuf("js",dir,"helloworld.proto",dir) - **generate the protobuffs `usings array` for multiple files** ```JavaScript +const generator = new ProtobuffGenerator() generator.generateProtobuf([["go",dir,"helloworld.proto",dir],["python",dir,"helloworld.proto",dir]]) ``` --- From 1f62eb648588c4acd94b42ee08a6a8a8cddec4b3 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:39:59 +0100 Subject: [PATCH 27/49] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index dbd21b4..d3ad18b 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,12 @@ generator.generateProtobuf("js",dir,"helloworld.proto",dir) const generator = new ProtobuffGenerator() generator.generateProtobuf([["go",dir,"helloworld.proto",dir],["python",dir,"helloworld.proto",dir]]) ``` + **@param language** — The programming language for which the Protobuf file should be generated. +
**@param proto_path** — The path to the Proto file that should be used as the source. +
**@param outputPath** — The path where the generated Protobuf file should be saved +
**@returns** — A promise that resolves with the output of the command execution or rejects with an error. + + --- - here were are using the helloworld protofile from the current directory. - you can find a demoscript and the proto file in the scripts folder. From 23905dbd50b88d014820cc1b60b7e41e8c3dbb3b Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:43:00 +0100 Subject: [PATCH 28/49] Update README.md --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d3ad18b..a7bb7db 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,10 @@ uses the protoc binary and supports multiple platforms and processors. Please se ## Install - **local:** `npm i @ji-podhead/protoc-helper` - **cli-tool:** `npx install protoch` -## How to use +## How to use +- you can find a demoscript and the proto file in the scripts folder. +--- + **CLI (via npx global install)** ```JavaScript npx protoch @@ -46,9 +49,7 @@ generator.generateProtobuf([["go",dir,"helloworld.proto",dir],["python",dir,"hel --- -- here were are using the helloworld protofile from the current directory. -- you can find a demoscript and the proto file in the scripts folder. ---- + if you like this package, pls consider giving Jeppe’s and my repo a Star on github --- From 610413b581a2481bf8e55e7df8361abab574bcf6 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:43:28 +0100 Subject: [PATCH 29/49] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a7bb7db..90521af 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ multilanguage grpc protobuff generator for node. forked from [node-protoc](http uses the protoc binary and supports multiple platforms and processors. Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/edit/master/README.md#protobuf-plugin-installation) to install the required plugins for your target language. ## Install -- **local:** `npm i @ji-podhead/protoc-helper` +- **local:** `npm i protoc-helper` - **cli-tool:** `npx install protoch` ## How to use - you can find a demoscript and the proto file in the scripts folder. From f9576518d95ec4a3ae0e56464966f6c2167cbc22 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:43:58 +0100 Subject: [PATCH 30/49] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 90521af..a4e27c1 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ createProtobuff("js",dir,path.join(dir,"helloworld.proto")) ```JavaScript const generator = new ProtobuffGenerator() -generator.generateProtobuf("js",dir,"helloworld.proto",dir) +generator.generateProtobuf("python",dir,"helloworld.proto",dir) ``` - **generate the protobuffs `usings array` for multiple files** From 553421da1c1988c5f6d00e77043a89dbc07956d9 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Thu, 14 Mar 2024 21:09:30 +0100 Subject: [PATCH 31/49] a --- README.md | 5 +++-- package.json | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a4e27c1..f43289b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -[![npm version](https://badge.fury.io/js/@ji-podhead%2Fprotoc-helper.svg)](https://badge.fury.io/js/@ji-podhead%2Fprotoc-helper) +[![npm version](https://badge.fury.io/js/protoc-helper.svg)](https://badge.fury.io/js/protoc-helper) + # protoc-helper multilanguage grpc protobuff generator for node. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. uses the protoc binary and supports multiple platforms and processors. Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/edit/master/README.md#protobuf-plugin-installation) to install the required plugins for your target language. @@ -17,7 +18,7 @@ npx protoch --- - **Import** ```JavaScript - const {ProtobuffGenerator,createProtobuff} = require("@ji-podhead/protoc-helper") + const {ProtobuffGenerator,createProtobuff} = require("protoc-helper") ``` - **create a path** diff --git a/package.json b/package.json index f215dd3..db5e33c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "@ji-podhead/protoc-helper", - "version": "1.0.7", - "description": "multilanguage grpc protobuff generator for node. forked from node-protoc.git. ", + "name": "protoc-helper", + "version": "1.0.10", + "description": "multilanguage grpc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from node-protoc.git. ", "main": "index.js", "scripts": { "postinstall": "node scripts/postinstall.js", @@ -34,6 +34,7 @@ }, "keywords": [ "protobuff_gen for node", + "protoc binary for node", "grpc", "protoc", "protoc-gen", From ec93d016bd3e24eb53300a18b075531a1d5824a1 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Thu, 14 Mar 2024 21:11:19 +0100 Subject: [PATCH 32/49] a --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index db5e33c..023ea70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "protoc-helper", - "version": "1.0.10", + "version": "1.0.11", "description": "multilanguage grpc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from node-protoc.git. ", "main": "index.js", "scripts": { From 283254b50520d0a6b202ca5a70d6b7a5771c1ba7 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Thu, 14 Mar 2024 23:08:41 +0100 Subject: [PATCH 33/49] Update README.md --- README.md | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index f43289b..ffe706e 100644 --- a/README.md +++ b/README.md @@ -13,40 +13,40 @@ uses the protoc binary and supports multiple platforms and processors. Please se **CLI (via npx global install)** ```JavaScript -npx protoch +npx protoch +npx protoc --go_out= --proto_path= // exchange --go_out is using another lamguage ``` --- -- **Import** +**via Script**
+`without instance` (array is supported) ```JavaScript - const {ProtobuffGenerator,createProtobuff} = require("protoc-helper") - ``` +createProtobuff( ) +createProtobuff( ) -- **create a path** -```JavaScript -const dir = String(__dirname)+"/" ``` -- **generate the protobuffs `without instance` (array is supported)** - +`using class instance` ```JavaScript -createProtobuff("js",dir,path.join(dir,"helloworld.proto")) +generator.generateProtobuf( ) ``` - -- **generate the protobuffs `using class instance`** +`usings array` for multiple files ```JavaScript -const generator = new ProtobuffGenerator() -generator.generateProtobuf("python",dir,"helloworld.proto",dir) +generator.generateProtobuf([[ ],[ ]]) ``` -- **generate the protobuffs `usings array` for multiple files** + **lang** — The programming language for which the Protobuf file should be generated. +
**total_proto_file_path** — The path to the Proto file that should be used as the source. +
**output_path** — The path where the generated Protobuf file should be saved +
**proto_file** — The name of the proto file including the extension. +
**proto_file_folder** — A path to a folder that holds a proto file. +- **Example** ```JavaScript +const {ProtobuffGenerator,createProtobuff} = require("protoc-helper") const generator = new ProtobuffGenerator() +const dir = String(__dirname)+"/" generator.generateProtobuf([["go",dir,"helloworld.proto",dir],["python",dir,"helloworld.proto",dir]]) -``` - **@param language** — The programming language for which the Protobuf file should be generated. -
**@param proto_path** — The path to the Proto file that should be used as the source. -
**@param outputPath** — The path where the generated Protobuf file should be saved -
**@returns** — A promise that resolves with the output of the command execution or rejects with an error. + ``` + --- From 53ceb4358ded979bd7c4bcb46f507be5b531f01a Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Thu, 14 Mar 2024 23:10:45 +0100 Subject: [PATCH 34/49] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index ffe706e..3dbb388 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ generator.generateProtobuf( ],[ ]]) ``` +--- +**Arguments**
**lang** — The programming language for which the Protobuf file should be generated.
**total_proto_file_path** — The path to the Proto file that should be used as the source.
**output_path** — The path where the generated Protobuf file should be saved From 707af1a2cf72a1a436b3992e0fcd528db9f40fd4 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Thu, 14 Mar 2024 23:17:50 +0100 Subject: [PATCH 35/49] Update README.md --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3dbb388..b0b8af6 100644 --- a/README.md +++ b/README.md @@ -34,14 +34,14 @@ generator.generateProtobuf( ],[ ]]) ``` --- -**Arguments**
- **lang** — The programming language for which the Protobuf file should be generated. -
**total_proto_file_path** — The path to the Proto file that should be used as the source. -
**output_path** — The path where the generated Protobuf file should be saved -
**proto_file** — The name of the proto file including the extension. -
**proto_file_folder** — A path to a folder that holds a proto file. - -- **Example** +### Arguments + **lang** The programming language for which the Protobuf file should be generated. +
**total_proto_file_path** The path to the Proto file that should be used as the source. +
**output_path** The path where the generated Protobuf file should be saved +
**proto_file** The name of the proto file including the extension. +
**proto_file_folder** A path to a folder that holds a proto file. + +### Example ```JavaScript const {ProtobuffGenerator,createProtobuff} = require("protoc-helper") const generator = new ProtobuffGenerator() From 970501595a453b0da7dcdab8652fb1d618642886 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Thu, 14 Mar 2024 23:22:14 +0100 Subject: [PATCH 36/49] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b0b8af6..24c0007 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ [![npm version](https://badge.fury.io/js/protoc-helper.svg)](https://badge.fury.io/js/protoc-helper) # protoc-helper -multilanguage grpc protobuff generator for node. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. -uses the protoc binary and supports multiple platforms and processors. Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/edit/master/README.md#protobuf-plugin-installation) to install the required plugins for your target language. +A multilanguage protoc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. +. Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/edit/master/README.md#protobuf-plugin-installation) to install the required plugins for your target language. ## Install - **local:** `npm i protoc-helper` From 105d4f3ea96225e4e083374afa742f9ba92e261f Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Thu, 14 Mar 2024 23:23:17 +0100 Subject: [PATCH 37/49] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 24c0007..8e0cd06 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # protoc-helper A multilanguage protoc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. -. Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/edit/master/README.md#protobuf-plugin-installation) to install the required plugins for your target language. +. Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/tree/master?tab=readme-ov-file#protobuf-plugin-installation) to install the required plugins for your target language. ## Install - **local:** `npm i protoc-helper` From 3ebd3dee799863ba840e7f0646e081d6ce509234 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Fri, 15 Mar 2024 09:03:51 +0100 Subject: [PATCH 38/49] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e0cd06..9e08b5b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![npm version](https://badge.fury.io/js/protoc-helper.svg)](https://badge.fury.io/js/protoc-helper) - +> why is my syntax so oldschool. guess i havent worked with js in a while. i need to use {args} for constructor and get rid of the super old import syntax # protoc-helper A multilanguage protoc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. . Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/tree/master?tab=readme-ov-file#protobuf-plugin-installation) to install the required plugins for your target language. From 268c47b96445f8209196502d25d5d92120551214 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Fri, 15 Mar 2024 09:04:33 +0100 Subject: [PATCH 39/49] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9e08b5b..b644edf 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![npm version](https://badge.fury.io/js/protoc-helper.svg)](https://badge.fury.io/js/protoc-helper) -> why is my syntax so oldschool. guess i havent worked with js in a while. i need to use {args} for constructor and get rid of the super old import syntax + # protoc-helper A multilanguage protoc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. . Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/tree/master?tab=readme-ov-file#protobuf-plugin-installation) to install the required plugins for your target language. @@ -48,7 +48,7 @@ const generator = new ProtobuffGenerator() const dir = String(__dirname)+"/" generator.generateProtobuf([["go",dir,"helloworld.proto",dir],["python",dir,"helloworld.proto",dir]]) ``` - +> why is my syntax so oldschool. guess i havent worked with js in a while. i need to use {args} for constructor and get rid of the super old import syntax. but it works, so i just leave that for now --- From 8d6274db798e50c9b5031d2027869fd2c9a8d7dc Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Sat, 16 Mar 2024 10:53:48 +0100 Subject: [PATCH 40/49] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b644edf..c3a0b89 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![npm version](https://badge.fury.io/js/protoc-helper.svg)](https://badge.fury.io/js/protoc-helper) - +![NPM Downloads](https://img.shields.io/npm/dw/protoc-helper.svg) +![npm version](https://img.shields.io/badge/protoc-binary-blue) # protoc-helper A multilanguage protoc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. . Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/tree/master?tab=readme-ov-file#protobuf-plugin-installation) to install the required plugins for your target language. From f92db0ab8c18e1b5179711493b8d6b9c2e05f8d5 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Sat, 16 Mar 2024 10:55:30 +0100 Subject: [PATCH 41/49] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c3a0b89..b879aa7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![npm version](https://badge.fury.io/js/protoc-helper.svg)](https://badge.fury.io/js/protoc-helper) -![NPM Downloads](https://img.shields.io/npm/dw/protoc-helper.svg) -![npm version](https://img.shields.io/badge/protoc-binary-blue) +[![NPM Downloads](https://img.shields.io/npm/dw/protoc-helper.svg)](https://www.npmjs.com/package/protoc-helper) +[![npm version](https://img.shields.io/badge/protoc-binary-blue)](https://www.npmjs.com/package/protoc-helper) # protoc-helper A multilanguage protoc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. . Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/tree/master?tab=readme-ov-file#protobuf-plugin-installation) to install the required plugins for your target language. From 211276a30ffc0e5e9762dd4001ad036ec40da35f Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Sat, 16 Mar 2024 11:48:19 +0100 Subject: [PATCH 42/49] better description --- README.md | 2 + index.js | 89 ++++++++++++++------------ package.json | 2 +- scripts/postinstall.js | 2 +- scripts/test.js | 137 +---------------------------------------- 5 files changed, 56 insertions(+), 176 deletions(-) diff --git a/README.md b/README.md index 8e0cd06..af1f979 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ [![npm version](https://badge.fury.io/js/protoc-helper.svg)](https://badge.fury.io/js/protoc-helper) # protoc-helper +> WAS MOVED TO [PROTOC-HELPER!!](https://www.npmjs.com/package/protoc-helper) + A multilanguage protoc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. . Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/tree/master?tab=readme-ov-file#protobuf-plugin-installation) to install the required plugins for your target language. diff --git a/index.js b/index.js index ed9a469..3cea824 100644 --- a/index.js +++ b/index.js @@ -6,20 +6,30 @@ const cp = require("child_process"); const { type } = require("os"); - -function createProtobuff(language,outputPath,proto_file,proto_path){ +/** + * @description Generate your protobuf files. Array is not supported. + * Use the function in one of the following ways: + * - Absolute path:`createProtobuff(,,)` + * - Name and Path:`createProtobuff(,,,)` + * @param {string} lang - Target language + * @param {string} output_path - The folder where your protobuf files are getting placed + * @param {string} proto_file - The name of the proto file (used when specifying the folder and file name separately) + * @param {string} proto_file_folder - The folder where your proto file is located (used when specifying the folder and file name separately) + * @param {string} absolute_proto_file_path - The folder path and the proto file in one string (used when specifying the `.proto` file path directly) + */ +function createProtobuff(lang,output_path,proto_file_folder,proto_file){ let directoryPath,fileName - if(proto_path==undefined) { - directoryPath = path.dirname(proto_file); - fileName = path.basename(proto_file); + if(proto_file==undefined) { + directoryPath = path.dirname(proto_file_folder); + fileName = path.basename(proto_file_folder); console.log(`Directory: ${directoryPath}`); console.log(`File Name: ${fileName}`); } else{ - directoryPath=proto_path - fileName=proto_file + directoryPath=proto_file + fileName=proto_file_folder } - new ProtobuffGenerator().generateProtobuf(language,directoryPath,fileName,outputPath) + new ProtobuffGenerator().generateProtobuff(lang,output_path,fileName,directoryPath) } function mycallback(){ @@ -36,89 +46,90 @@ class ProtobuffGenerator { } /** - * Generates a Protobuf file for a specified programming language. - * @param {string} language - The programming language for which the Protobuf file should be generated. - * @param {string} proto_path - The path to the Proto file that should be used as the source. + * @description Generate your protobuf files. Array is not supported. + * Use the function in one of the following ways: + * - no Array:`generateProtobuff( )` + * - with Array:`generateProtobuff([[,,,],...])` + * @param {string|Array} lang - The programming language for which the Protobuf file should be generated. * @param {string} outputPath - The path where the generated Protobuf file should be saved. - * @returns {Promise} A promise that resolves with the output of the command execution or rejects with an error. + * @param {string} proto_file - The name of the Proto file that should be used as the source. + * @param {string} proto_file_folder - The folder where the Proto file is located that should be used as the source. * @throws {Error} If the specified language is not supported. */ - - - generateProtobuf(language, proto_path,proto_file, outputPath, additionalCommands) { + generateProtobuff(lang,output_path, proto_file,proto_file_folder,additionalCommands) { let command; let arr - switch (language) { + switch (lang) { case 'go': // Example for Go --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative - command = `npx protoc --go_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + command = `npx protoc --go_out=${output_path} ${additionalCommands?additionalCommands:""} --proto_path=${proto_file_folder} ${proto_file}`; break; case 'java': // Example for Java - command = `npx protoc --java_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + command = `npx protoc --java_out=${output_path} ${additionalCommands?additionalCommands:""} --proto_path=${proto_file_folder} ${proto_file}`; break; case 'python': // Example for Python - command = `npx protoc --python_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + command = `npx protoc --python_out=${output_path} ${additionalCommands?additionalCommands:""} --proto_path=${proto_file_folder} ${proto_file}`; break; case 'csharp': // Example for C# - command = `npx protoc --objc_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + command = `npx protoc --objc_out=${output_path} ${additionalCommands?additionalCommands:""} --proto_path=${proto_file_folder} ${proto_file}`; break; case 'ruby': // Example for Ruby - command = `npx protoc --ruby_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + command = `npx protoc --ruby_out=${output_path} ${additionalCommands?additionalCommands:""} --proto_path=${proto_file_folder} ${proto_file}`; break; case 'objc': // Example for Objective-C - command = `npx protoc --objc_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + command = `npx protoc --objc_out=${output_path} ${additionalCommands?additionalCommands:""} --proto_path=${proto_file_folder} ${proto_file}`; break; case 'php': // Example for PHP - command = `npx protoc --php_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + command = `npx protoc --php_out=${output_path} ${additionalCommands?additionalCommands:""} --proto_path=${proto_file_folder} ${proto_file}`; break; case 'dart': // Example for Dart - command = `npx protoc --dart_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + command = `npx protoc --dart_out=${output_path} ${additionalCommands?additionalCommands:""} --proto_path=${proto_file_folder} ${proto_file}`; break; case 'rust': // Example for Rust - command = `npx protoc --rust_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + command = `npx protoc --rust_out=${output_path} ${additionalCommands?additionalCommands:""} --proto_path=${proto_file_folder} ${proto_file}`; break; case 'swift': // Example for Swift - command = `npx protoc --swift_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + command = `npx protoc --swift_out=${output_path} ${additionalCommands?additionalCommands:""} --proto_path=${proto_file_folder} ${proto_file}`; break; case 'kotlin': // Example for Kotlin - command = `npx protoc --kotlin_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + command = `npx protoc --kotlin_out=${output_path} ${additionalCommands?additionalCommands:""} --proto_path=${proto_file_folder} ${proto_file}`; break; case 'scala': // Example for Scala - command = `npx protoc --scala_out=${outputPath} ${additionalCommands?additionalCommands:""} --proto_path=${proto_path} ${proto_file}`; + command = `npx protoc --scala_out=${output_path} ${additionalCommands?additionalCommands:""} --proto_path=${proto_file_folder} ${proto_file}`; break; case 'js': - command = `npx protoc --js_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; + command = `npx protoc --js_out=${output_path} --proto_path=${proto_file_folder} ${proto_file}`; break; case 'ts': // Example for JavaScript/TypeScript - command= `npx protoc --ts_out=${outputPath} --proto_path=${proto_path} ${proto_file}` + command= `npx protoc --ts_out=${output_path} --proto_path=${proto_file_folder} ${proto_file}` break; default: - if(Array.isArray(language)){ + if(Array.isArray(lang)){ arr = true; - for (let arg of language){ - this.generateProtobuf(...arg); + for (let arg of lang){ + this.generateProtobuff(...arg); } - } else if(typeof(language) == 'object'){ + } else if(typeof(lang) == 'object'){ arr = true; - for (let arg in language){ - this.generateProtobuf(...arg); + for (let arg in lang){ + this.generateProtobuff(...arg); } } else { - throw new Error(`Unsupported language: ${language}`); + throw new Error(`Unsupported language: ${lang}`); } } if(arr!=true){ @@ -129,11 +140,11 @@ if(arr!=true) console.error(err); return; } - console.log("__________\n"+"finished command: " + JSON.stringify([language, proto_path,proto_file, outputPath, additionalCommands])) + console.log("__________\n"+"finished command: " + JSON.stringify([lang,output_path, proto_file,proto_file_folder, additionalCommands])) // mycallback(null, stdout, stderr); } ) } } } -module.exports ={createProtobuff,ProtobuffGenerator,cli} +module.exports ={createProtobuff,ProtobuffGenerator} diff --git a/package.json b/package.json index 023ea70..291e6e4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "protoc-helper", - "version": "1.0.11", + "version": "1.0.15", "description": "multilanguage grpc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from node-protoc.git. ", "main": "index.js", "scripts": { diff --git a/scripts/postinstall.js b/scripts/postinstall.js index a606585..02c2080 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -4,7 +4,7 @@ const unzip = require("unzipper"); const mkdirp = require("mkdirp"); const protoc = require("../protoc.js"); -const protoVersion = "3.20.3"; +const protoVersion = "26.0"; const releases = { "win32_x86_32": `https://github.com/protocolbuffers/protobuf/releases/download/v${protoVersion}/protoc-${protoVersion}-win32.zip`, diff --git a/scripts/test.js b/scripts/test.js index 30bd672..bd86e07 100644 --- a/scripts/test.js +++ b/scripts/test.js @@ -9,141 +9,8 @@ createProtobuff("js",dir,path.join(dir,"helloworld.proto")) console.log("_______ CLASS _________") const generator = new ProtobuffGenerator() -generator.generateProtobuf("js",dir,"helloworld.proto",dir) +generator.generateProtobuff("js",dir,"helloworld.proto",dir) console.log("_______ CLASS + ARRAY ARGUMENTS_________") -generator.generateProtobuf([["go",dir,"helloworld.proto",dir],["python",dir,"helloworld.proto",dir]]) +generator.generateProtobuff([["go",dir,"helloworld.proto",dir],["python",dir,"helloworld.proto",dir]]) -[![npm version](https://badge.fury.io/js/@ji-podhead%2Fprotoc-helper.svg)](https://badge.fury.io/js/@ji-podhead%2Fprotoc-helper) -# protoc-helper -multilanguage grpc protobuff generator for node. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. -uses the protoc binary and supports multiple platforms and processors. Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/edit/master/README.md#protobuf-plugin-installation) to install the required plugins for your target language. - -## Install -`npm i @ji-podhead/protoc-helper` - -## How to use -- import via npm install -```JavaScript - const {ProtobuffGenerator} = require("@ji-podhead/protoc-helper") - ``` - -

import via git clone

-```JavaScript - const { ProtobuffGenerator } = require('../index'); - ``` -

generate the protobuffs `WITHOUT CLASS` (array is supported)

- -```JavaScript -createProtobuff("js",dir,path.join(dir,"helloworld.proto")) -``` -

-generate the protobuffs `WITH CLASS`

-```JavaScript -const generator = new ProtobuffGenerator() -generator.generateProtobuf("js",dir,"helloworld.proto",dir) -``` -

generate the protobuffs `CLASS + ARRAY ARGUMENTS`

-```JavaScript -generator.generateProtobuf([["go",dir,"helloworld.proto",dir],["python",dir,"helloworld.proto",dir]]) -``` -- here were are using the helloworld protofile from the current directory. -- you can find a demoscript and the proto file in the scripts folder. - -## Protobuf Plugin Installation - -### Go -- **Repository**: [https://github.com/golang/protobuf](https://github.com/golang/protobuf) -- **Installation**: -bash go get -u github.com/golang/protobuf/protoc-gen-go - - -### Java -- **Repository**: [https://github.com/google/protobuf-gradle-plugin](https://github.com/google/protobuf-gradle-plugin) -- **Installation**: -gradle plugins { id 'com.google.protobuf' version '0.8.17' } - - -### Python -- **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) -- **Installation**: -bash pip install protobuf - - -### C# -- **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) -- **Installation**: -powershell Install-Package Google.Protobuf.Tools - - -### Ruby -- **Repository**: [https://github.com/localshred/protobuf](https://github.com/localshred/protobuf) -- **Installation**: -bash gem install protobuf - - -### Objective-C -- **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) -- **Installation**: -ruby pod '!ProtoCompiler-gRPCPlugin' - - -### PHP -- **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) -- **Installation**: -bash composer require google/protobuf - - -### Dart -- **Repository**: [https://github.com/dart-lang/protobuf](https://github.com/dart-lang/protobuf) -- **Installation**: -bash dart pub global activate protoc_plugin - - -### Rust -- **Repository**: (https://github.com/neoeinstein/protoc-gen-prost](https://github.com/neoeinstein/protoc-gen-prost) -- **Installation**: -*see repo - - -### Swift -- **Repository**: [https://github.com/apple/swift-protobuf](https://github.com/apple/swift-protobuf) -- **Installation**: -swift // Add SwiftProtobuf as a dependency to your Xcode project - - -### Kotlin -- **Repository**: [https://github.com/grpc/grpc-kotlin/tree/master/compiler](https://github.com/grpc/grpc-kotlin/tree/master/compiler) -- **Installation**: -bash - -Clone and build the plugin -git clone https://github.com/grpc/grpc-kotlin.git cd grpc-kotlin/compiler ./gradlew installDist - - -### Scala -- **Repository**: [https://github.com/scalapb/ScalaPB](https://github.com/scalapb/ScalaPB) -- **Installation**: -scala // Add ScalaPB as a dependency to your sbt project libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.1" - - -### JavaScript/TypeScript -- **Repository**: [https://github.com/improbable-eng/ts-protoc-gen](https://github.com/improbable-eng/ts-protoc-gen) -- **Installation**: -bash npm install ts-protoc-gen - -## NPX and additional args - -you can use `npx protoc` or add your own arguments in the index.js: -```JavaScript - switch (language) { - case 'go': - // Example for Go --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative - command = `npx protoc --go_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'java': - // Example for Java - command = `npx protoc --java_out=${outputPath} --proto_path=${proto_path} ${proto_file}`; - break; - case 'python': -``` From 455a296f55b4798e06dc74adfc176ef519c1abf8 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Sat, 16 Mar 2024 11:50:37 +0100 Subject: [PATCH 43/49] Update README.md --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 418b9d6..9a51b3a 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ [![NPM Downloads](https://img.shields.io/npm/dw/protoc-helper.svg)](https://www.npmjs.com/package/protoc-helper) [![npm version](https://img.shields.io/badge/protoc-binary-blue)](https://www.npmjs.com/package/protoc-helper) # protoc-helper -> WAS MOVED TO [PROTOC-HELPER!!](https://www.npmjs.com/package/protoc-helper) - A multilanguage protoc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. . Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/tree/master?tab=readme-ov-file#protobuf-plugin-installation) to install the required plugins for your target language. @@ -23,7 +21,7 @@ npx protoc --go_out= --proto_path= // **via Script**
`without instance` (array is supported) ```JavaScript -createProtobuff( ) +createProtobuff( ) createProtobuff( ) ``` From 8f745d96a993203a91be0eca60c7ae3f712062e6 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Sat, 16 Mar 2024 11:51:02 +0100 Subject: [PATCH 44/49] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 9a51b3a..86445b8 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,6 @@ const generator = new ProtobuffGenerator() const dir = String(__dirname)+"/" generator.generateProtobuf([["go",dir,"helloworld.proto",dir],["python",dir,"helloworld.proto",dir]]) ``` -> why is my syntax so oldschool. guess i havent worked with js in a while. i need to use {args} for constructor and get rid of the super old import syntax. but it works, so i just leave that for now --- From 912980e9904ccd84ec4d0a1b9a9b2ec1e07e6d43 Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Sat, 16 Mar 2024 12:09:03 +0100 Subject: [PATCH 45/49] added versionbadge --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 291e6e4..ad366f6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "protoc-helper", - "version": "1.0.15", + "version": "1.0.17", "description": "multilanguage grpc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from node-protoc.git. ", "main": "index.js", "scripts": { From 17327c1ff4f020e988d577c1fcbcd85d2d80609b Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Sat, 16 Mar 2024 12:09:49 +0100 Subject: [PATCH 46/49] added version badge --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 86445b8..b5dd90b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ [![npm version](https://badge.fury.io/js/protoc-helper.svg)](https://badge.fury.io/js/protoc-helper) [![NPM Downloads](https://img.shields.io/npm/dw/protoc-helper.svg)](https://www.npmjs.com/package/protoc-helper) -[![npm version](https://img.shields.io/badge/protoc-binary-blue)](https://www.npmjs.com/package/protoc-helper) +[![npm version](https://img.shields.io/badge/protoc_v26.0-binary-blue)](https://www.npmjs.com/package/protoc-helper) + # protoc-helper A multilanguage protoc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. . Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/tree/master?tab=readme-ov-file#protobuf-plugin-installation) to install the required plugins for your target language. From c1c937cf5e8f7d76fd41b292c8c7cda9977c397a Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-soft@users.noreply.github.com> Date: Sat, 16 Mar 2024 12:12:41 +0100 Subject: [PATCH 47/49] changed typo --- README.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b5dd90b..77d4f10 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ npx protoc --go_out= --proto_path= // ``` --- **via Script**
-`without instance` (array is supported) +`without instance` (array not supported) ```JavaScript createProtobuff( ) createProtobuff( ) diff --git a/package.json b/package.json index ad366f6..63455d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "protoc-helper", - "version": "1.0.17", + "version": "1.0.18", "description": "multilanguage grpc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from node-protoc.git. ", "main": "index.js", "scripts": { From 8e0486280721e3224c7b540df28789ea9da8c3fa Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Sun, 17 Mar 2024 09:12:14 +0100 Subject: [PATCH 48/49] Update README.md --- README.md | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 77d4f10..d339f4a 100644 --- a/README.md +++ b/README.md @@ -59,85 +59,69 @@ if you like this package, pls consider giving Jeppe’s and my repo a Star on gi --- ## Protobuf Plugin Installation +### JavaScript/TypeScript +- **Repository**: [https://github.com/improbable-eng/ts-protoc-gen](https://github.com/improbable-eng/ts-protoc-gen) +- **Installation**: npm install ts-protoc-gen `already added to dependencies` ### Go - **Repository**: [https://github.com/golang/protobuf](https://github.com/golang/protobuf) -- **Installation**: -bash go get -u github.com/golang/protobuf/protoc-gen-go +- **Installation**: bash go get -u github.com/golang/protobuf/protoc-gen-go ### Java - **Repository**: [https://github.com/google/protobuf-gradle-plugin](https://github.com/google/protobuf-gradle-plugin) -- **Installation**: -gradle plugins { id 'com.google.protobuf' version '0.8.17' } +- **Installation**: gradle plugins { id 'com.google.protobuf' version '0.8.17' } ### Python - **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) -- **Installation**: -bash pip install protobuf +- **Installation**:`may doesnt need plugin` see https://protobuf.dev/reference/python/python-generated/ ### C# - **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) -- **Installation**: -powershell Install-Package Google.Protobuf.Tools +- **Installation**: powershell Install-Package Google.Protobuf.Tools `or it may doesnt need plugin` ### Ruby - **Repository**: [https://github.com/localshred/protobuf](https://github.com/localshred/protobuf) -- **Installation**: -bash gem install protobuf +- **Installation**: doesnt need plugin, but might check out https://github.com/ruby-protobuf/protobuf ### Objective-C -- **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) -- **Installation**: -ruby pod '!ProtoCompiler-gRPCPlugin' +- **Repository**: [[https://github.com/alexeyxo/protobuf-objc](https://github.com/protocolbuffers/protobuf](https://github.com/alexeyxo/protobuf-objc) +- **Installation**: may require cocoapod. see repo above ### PHP - **Repository**: [https://github.com/protocolbuffers/protobuf](https://github.com/protocolbuffers/protobuf) -- **Installation**: -bash composer require google/protobuf +- **Installation**: doesnt need plugin ### Dart - **Repository**: [https://github.com/dart-lang/protobuf](https://github.com/dart-lang/protobuf) -- **Installation**: -bash dart pub global activate protoc_plugin +- **Installation**: bash dart pub global activate protoc_plugin ### Rust - **Repository**: (https://github.com/neoeinstein/protoc-gen-prost](https://github.com/neoeinstein/protoc-gen-prost) -- **Installation**: -*see repo +- **Installation**:*see repo ### Swift - **Repository**: [https://github.com/apple/swift-protobuf](https://github.com/apple/swift-protobuf) -- **Installation**: -swift // Add SwiftProtobuf as a dependency to your Xcode project +- **Installation**: swift // Add SwiftProtobuf as a dependency to your Xcode project ### Kotlin - **Repository**: [https://github.com/grpc/grpc-kotlin/tree/master/compiler](https://github.com/grpc/grpc-kotlin/tree/master/compiler) -- **Installation**: -bash - -Clone and build the plugin -git clone https://github.com/grpc/grpc-kotlin.git cd grpc-kotlin/compiler ./gradlew installDist +- **Installation**:Clone and build the plugin; it clone https://github.com/grpc/grpc-kotlin.git cd grpc-kotlin/compiler ./gradlew installDist ### Scala - **Repository**: [https://github.com/scalapb/ScalaPB](https://github.com/scalapb/ScalaPB) -- **Installation**: -scala // Add ScalaPB as a dependency to your sbt project libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.1" +- **Installation**:Add ScalaPB as a dependency to your sbt project libraryDependencies += "com.thesamet.scalapb" %% "compilerplugin" % "0.11.1" -### JavaScript/TypeScript -- **Repository**: [https://github.com/improbable-eng/ts-protoc-gen](https://github.com/improbable-eng/ts-protoc-gen) -- **Installation**: -bash npm install ts-protoc-gen ## NPX and additional args From f432b93635f4da18b229a7de6e593ea8931bad2e Mon Sep 17 00:00:00 2001 From: "J.I. /podhead" <117015142+ji-podhead@users.noreply.github.com> Date: Mon, 25 Mar 2024 15:49:25 +0100 Subject: [PATCH 49/49] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d339f4a..56c75ee 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ + +# protoc-helper [![npm version](https://badge.fury.io/js/protoc-helper.svg)](https://badge.fury.io/js/protoc-helper) [![NPM Downloads](https://img.shields.io/npm/dw/protoc-helper.svg)](https://www.npmjs.com/package/protoc-helper) [![npm version](https://img.shields.io/badge/protoc_v26.0-binary-blue)](https://www.npmjs.com/package/protoc-helper) -# protoc-helper A multilanguage protoc protobuff generator for node. uses the protoc binary and supports multiple platforms and processors. forked from [node-protoc](https://github.com/YePpHa/node-protoc) to add additional languages. . Please see [Protobuf Plugin Installation](https://github.com/ji-podhead/protoc-helper/tree/master?tab=readme-ov-file#protobuf-plugin-installation) to install the required plugins for your target language.