Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack integration #1

Open
benneq opened this issue May 30, 2017 · 2 comments
Open

Webpack integration #1

benneq opened this issue May 30, 2017 · 2 comments

Comments

@benneq
Copy link

benneq commented May 30, 2017

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;
@joewood
Copy link
Owner

joewood commented May 30, 2017

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.

@benneq
Copy link
Author

benneq commented May 30, 2017

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants