Skip to content

I added support for more languages via npx and child process#14

Open
ji-podhead wants to merge 52 commits intoYePpHa:masterfrom
ji-podhead:master
Open

I added support for more languages via npx and child process#14
ji-podhead wants to merge 52 commits intoYePpHa:masterfrom
ji-podhead:master

Conversation

@ji-podhead
Copy link

@ji-podhead ji-podhead commented Mar 11, 2024

hey thanks for your repo, works fine for me. i added an additional protobuffgenerator that lets you generate the files generically via cp. you just need to pass the language, path and protofile.
i also added a test file and demoproto

   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':
...          

i simply hardcoded this because i may would change some plugins and i use protogents für typescript:

           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}
            `;
            

@ji-podhead ji-podhead changed the title added support via npx and child process I added support for more languages via npx and child process Mar 11, 2024
@ji-podhead
Copy link
Author

ji-podhead commented Mar 13, 2024

ill made a npm package. i think ill ad an option to pass your own args and make a additional typescript category.
here a re some file extensions and relative flaggs:

const languageFileExtensions = {
    go: {
        fileExtension: '.go',
        command: '--go_out'
    },
    java: {
        fileExtension: '.java',
        command: '--java_out'
    },
    python: {
        fileExtension: '.py',
        command: '--python_out'
    },
    csharp: {
        fileExtension: '.cs',
        command: '--csharp_out'
    },
    ruby: {
        fileExtension: '.rb',
        command: '--ruby_out'
    },
    objc: {
        fileExtension: '.m',
        command: '--objc_out'
    },
    php: {
        fileExtension: '.php',
        command: '--php_out'
    },
    dart: {
        fileExtension: '.dart',
        command: '--dart_out'
    },
    rust: {
        fileExtension: '.rs',
        command: '--rust_out'
    },
    swift: {
        fileExtension: '.swift',
        command: '--swift_out'
    },
    kotlin: {
        fileExtension: '.kt',
        command: '--kotlin_out'
    },
    scala: {
        fileExtension: '.scala',
        command: '--scala_out'
    },
    js: {
        fileExtension: '.js',
        command: '--js_out'
    }
};

@ji-podhead
Copy link
Author

and ill add commandline support in addition so no need for npx.
its really cool to have a tool that works out of the box for all languages for this, so thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant