avro-typescript
avro-typescript copied to clipboard
Webpack integration
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;
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.
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 :)