Giter Club home page Giter Club logo

plugin's Introduction

capnp-js-plugin Build Status

Generate Javascript serialization classes for Capnproto.

Installation and preferred use

  • Ensure that you have up-to-date versions of libtool, autoconf, and automake.
    • On OSX: brew upgrade libtool autoconf automake
  • Install by npm: npm install capnp-js-plugin.
  • This plugin checks out and then builds the Capnproto compiler.
    • The build takes about 5 minutes on my system, so I use a global install: npm install -g capnp-js-plugin.
    • For each project that uses a Capnproto schema, I include the plugin as a devDependency: npm install --save-dev capnp-js-plugin.
    • I avoid including the plugin as a dependency, because this would result in absurdly long build times for non-dev users.
    • Under this arrangement, I must distribute generated-code instead of creating it client-side--I feel that the build time-savings warrants the source-of-truth confusion.

Usage

  • The compiler is invoked with capnp compile -ojs someSchema.capnp to generate a someSchema.capnp.d directory that contains the schema's AMD files.
  • Run capnp help compile for additional options.
  • To obtain Node modules, I convert the generated AMD modules with a fork of Nodefy called Nfy. See this nfy script for an example. I suspect that AMDefine provides an alternate solution, but I won't chase any upstream bugs related to the use of AMDefine.

Serialization Classes

This plugin generates serialization classes similar to those of the c++ reference implementation. Given a schema someSchema.capnp, capnp compile -ojs someSchema.capnp will generate someSchema.capnp.d/readers.js, someSchema.capnp.d/builders.js, and some internal files:

Readers (someSchema.capnp.d/readers.js)

Javascript implementation of readers for members of someSchema.capnp. See Readers from the reference implementation's documentation.

Builders (someSchema.capnp.d/builders.js)

Javascript implementation of builders for members of someSchema.capnp. See Builders from the reference implementation's documentation.

Internal Files

The following files exist under someSchema.capnp.d/, but should not be imported by user code. These files facilitate circular reference resolution by creating types and accumulating them, without calling any prototype methods.

  • someSchema.capnp.d/rTypes.js: Reader types defined in someSchema.capnp.
  • someSchema.capnp.d/rScope.js: Merge all Reader types imported by someSchema.capnp with those created within someSchema.capnp.
  • someSchema.capnp.d/bTypes.js: Analogous to rTypes.js.
  • someSchema.capnp.d/bScope.js: Analogous to rScope.js.

Absolute Imports

The Javascript plugin maps absolute imports to absolute AMD paths. Consider the messaging example from the rtc-github repository:

Production Builds

You should minify the generated code for production builds. The generated code contains console.warn calls for development purposes--use something like uglifyjs -c drop_console to eliminate them.

plugin's People

Contributors

popham avatar

Watchers

Pooja Bansal avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.