Skip to content

Webpack integration #1

Description

@benneq

This is a really nice project.

I wonder if it's possible to have some small webpack plugin, which watches avsc files and generates typescript files on the fly.

EDIT: I've written some minimal plugin example code, which reads a single avsc file and writes a ts file (never written a webpack plugin before)

var avroTypescript = require("avro-typescript");
var fs = require('fs');
var path = require('path');

function AvroTypescriptPlugin(options) {

}

AvroTypescriptPlugin.prototype.apply = function(compiler) {
  compiler.plugin('done', function() {
    var file = fs.readFileSync(path.join(__dirname, './schema.avsc'), 'utf8');
    var json = JSON.parse(file);
    var ts = avroTypescript.avroToTypeScript(json);
    fs.writeFileSync(path.join(__dirname, './schema.ts'), ts);
  });
};

module.exports = AvroTypescriptPlugin;

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions