avro-typescript icon indicating copy to clipboard operation
avro-typescript copied to clipboard

Webpack integration

Open benneq opened this issue 8 years ago • 2 comments

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;

benneq avatar May 30 '17 04:05 benneq

Great idea @benneq - I'll include this in the repo.

The general idea of this is to use the package as a module (actually against a Confluent Platform schema repository) at runtime to feed to Monaco, but as a build tool it makes more sense as a webpack plugin.

joewood avatar May 30 '17 12:05 joewood

I hope I'll find some time the next 2 weeks, to write a more comprehensive webpack plugin. Or maybe someone else has some experience with that and can do it within 2 hours :)

benneq avatar May 30 '17 14:05 benneq