@accility/protoc-tools
TypeScript icon, indicating that this package has built-in type declarations

0.15.0 • Public • Published

Protocol Buffer Tools

⚠️ This package is still in early days and the interfaces might change back and forth. When stable enough it will be released as v1.0.

protoc-tools is a wrapper package for Google's .proto compiler protoc executable. The package manages installing and calling protoc both from the command line and programmatically from node.

What problems do we solve?

  • No need to pre-install the protoc executable file globally on your machine.
  • On a build server, the correct architecture for the executable is automatically used.
  • Simplify calling protoc. You do not need to know the location of the exectuable or the core proto-files. You only need to reference your own protobuffer files.
  • Better conformance to the "npm-way" of doing things.

Installing

npm install -D @accility/protoc-tools

Alternatively Install globally

npm install -g @accility/protoc-tools

Usage

Calling protoc on the command line

(Assuming you are located where the node_modules package can be reached.)

protoc --version

Calling protoc programmatically

const tools = require('@accility/protoc-tools');
const path = require('path');

// Generate client code for all supported languages
tools.protoc({
    includeDirs: [
        path.resolve('./test/protos')
    ],
    files: ['simple.proto'],
    outDir: path.resolve(__dirname, 'generated'),
    outOptions: [
        tools.generators.cpp({ outPath: path.resolve(__dirname, 'generated/cpp') }), // Override output folder for the C++ files
        tools.generators.csharp({ outOptions: 'file_extension=.g.cs' }), // Use generator specific options
        tools.generators.java(),
        tools.generators.js(),
        tools.generators.kotlin(),
        tools.generators.objc(),
        tools.generators.php(),
        tools.generators.python(),
        tools.generators.ruby()
    ]
});

ℹ️ The directory include/google/protobuf includes all core .proto-files, and is automatically added to the include directories.

For more API examples, see the test suite.

Code Generators

protoc can output C++, C#, Java, Javascript, Kotlin, Objective-C, PHP, Python and Ruby serialization code by default.

ℹ️ See Generator Options for information about available options for each of the built-in generators.

With the help of plugins we can generate code for additional situations. See also:

@accility/protoc-swagger-plugin

Dependencies (2)

Dev Dependencies (5)

Package Sidebar

Install

npm i @accility/protoc-tools

Weekly Downloads

2

Version

0.15.0

License

MIT

Unpacked Size

18.7 kB

Total Files

9

Last publish

Collaborators

  • acc-mart