build/generate.js
function generateFromProto(outputDir, inputProto, protoDir) {
    try {
        fs.accessSync(path.format({
            dir: protoDir,
            base: inputProto
        }));

        if (!protoDir) {
            const absolutePath = fs.realpathSync(inputProto);
            protoDir = path.dirname(absolutePath);
            inputProto = path.basename(absolutePath);
        }
    } catch (e) {
        throw new Error('Can not locate proto file - ' + inputProto, e);
    }

    let jsonDescriptor;

    try {
        class ImportBuilder extends ProtoBuf.Builder {

            import(json, filename) {
                this._imported = this._imported || [];

                this._imported.push({
                    filename: filename,
                    json: json
                });
                super['import'](json, filename);
            }
        }

        const importBuilder = new ImportBuilder();
        // This validates that proto is parsable
        const builder = ProtoBuf.loadProtoFile({
            root: protoDir,
            file: inputProto
        }, importBuilder);
        jsonDescriptor = JSON.stringify(builder._imported, undefined, 2);
    } catch (e) {
        console.error('Proto Parsing Failed', e);
        throw new Error('Generation Failed');
    }

    Namespace.reset();
    const namespace = processProto(inputProto, protoDir);
    const code = namespace.generate(
        jsonDescriptor, {
            render: data => mustache.render(fs.readFileSync(path.format({
                dir: templateDir,
                base: 'module.js.mt'
            }), 'utf8'), data)
        }, {
            render: data => mustache.render(fs.readFileSync(path.format({
                dir: templateDir,
                base: 'root.js.mt'
            }), 'utf8'), data)
        }
    );

    for (const key of Object.keys(code)) {
        const dir = path.format({
            dir: outputDir,
            base: key
        });
        fs.ensureDirSync(dir);
        const file = path.format({
            dir: dir,
            base: 'index.js'
        });
        fs.writeFileSync(file, code[key], {encoding: 'utf8'});
    }

}
function generateFromProto(outputDir, inputProto, protoDir) {
    try {
        fs.accessSync(path.format({
            dir: protoDir,
            base: inputProto
        }));

        if (!protoDir) {
            const absolutePath = fs.realpathSync(inputProto);
            protoDir = path.dirname(absolutePath);
            inputProto = path.basename(absolutePath);
        }
    } catch (e) {
        throw new Error('Can not locate proto file - ' + inputProto, e);
    }

    let jsonDescriptor;

    try {
        class ImportBuilder extends ProtoBuf.Builder {

            import(json, filename) {
                this._imported = this._imported || [];

                this._imported.push({
                    filename: filename,
                    json: json
                });
                super['import'](json, filename);
            }
        }

        const importBuilder = new ImportBuilder();
        // This validates that proto is parsable
        const builder = ProtoBuf.loadProtoFile({
            root: protoDir,
            file: inputProto
        }, importBuilder);
        jsonDescriptor = JSON.stringify(builder._imported, undefined, 2);
    } catch (e) {
        console.error('Proto Parsing Failed', e);
        throw new Error('Generation Failed');
    }

    Namespace.reset();
    const namespace = processProto(inputProto, protoDir);
    const code = namespace.generate(
        jsonDescriptor, {
            render: data => mustache.render(fs.readFileSync(path.format({
                dir: templateDir,
                base: 'module.js.mt'
            }), 'utf8'), data)
        }, {
            render: data => mustache.render(fs.readFileSync(path.format({
                dir: templateDir,
                base: 'root.js.mt'
            }), 'utf8'), data)
        }
    );

    for (const key of Object.keys(code)) {
        const dir = path.format({
            dir: outputDir,
            base: key
        });
        fs.ensureDirSync(dir);
        const file = path.format({
            dir: dir,
            base: 'index.js'
        });
        fs.writeFileSync(file, code[key], {encoding: 'utf8'});
    }

}
function generateFromProto ( outputDir , inputProto , protoDir ) { try { fs . accessSync ( path . format ( { dir : protoDir , base : inputProto } ) ) ; if ( ! protoDir ) { const absolutePath = fs . realpathSync ( inputProto ) ; protoDir = path . dirname ( absolutePath ) ; inputProto = path . basename ( absolutePath ) ; } } catch ( e ) { throw new Error ( 'Can not locate proto file - ' + inputProto , e ) ; } let jsonDescriptor ; try { class ImportBuilder extends ProtoBuf . Builder { import ( json , filename ) { this . _imported = this . _imported || [ ] ; this . _imported . push ( { filename : filename , json : json } ) ; super [ 'import' ] ( json , filename ) ; } } const importBuilder = new ImportBuilder ( ) ; // This validates that proto is parsable const builder = ProtoBuf . loadProtoFile ( { root : protoDir , file : inputProto } , importBuilder ) ; jsonDescriptor = JSON . stringify ( builder . _imported , undefined , 2 ) ; } catch ( e ) { console . error ( 'Proto Parsing Failed' , e ) ; throw new Error ( 'Generation Failed' ) ; } Namespace . reset ( ) ; const namespace = processProto ( inputProto , protoDir ) ; const code = namespace . generate ( jsonDescriptor , { render : data => mustache . render ( fs . readFileSync ( path . format ( { dir : templateDir , base : 'module.js.mt' } ) , 'utf8' ) , data ) } , { render : data => mustache . render ( fs . readFileSync ( path . format ( { dir : templateDir , base : 'root.js.mt' } ) , 'utf8' ) , data ) } ) ; for ( const key of Object . keys ( code ) ) { const dir = path . format ( { dir : outputDir , base : key } ) ; fs . ensureDirSync ( dir ) ; const file = path . format ( { dir : dir , base : 'index.js' } ) ; fs . writeFileSync ( file , code [ key ] , { encoding : 'utf8' } ) ; } }
Exported function from this module

Given the proto input will generate the modules with flowtype bindings in outputDir

@param outputDir - Directory to output files
@param inputProto - Root proto file
@param protoDir - directory to load proto files from - can be ommited and absolute path used in inputProto if imports
are relative to the directory of inputProto
Exported function from this module