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

Documentation: Usage with gulp #19

Closed
simonschllng opened this issue Sep 9, 2016 · 1 comment
Closed

Documentation: Usage with gulp #19

simonschllng opened this issue Sep 9, 2016 · 1 comment

Comments

@simonschllng
Copy link

simonschllng commented Sep 9, 2016

This is how we use json-schema-to-typescript in gulp. Maybe helpful for others, could be added to the docs/wiki.

gulp task:

let gulp = require('gulp');
let jsonType = require('../util/json-to-typings');

gulp.task('schema', () => {
  return gulp.src('schema/*.schema.json')
    .pipe(jsonType())
    .pipe(gulp.dest('models'));
});

file json-to-typings.js

let through = require('through2');
let PluginError = require('gulp-util').PluginError;
let jsonToType = require('json-schema-to-typescript');

module.exports = function() {
  return through.obj(function(file, encoding, callback) {
    if (file.isNull()) {
      return callback(null, file);
    }

    if (file.isStream()) {
      this.emit('error', new PluginError(PLUGIN_NAME, 'Streams not supported!'));
    }

    file.path = file.path.replace('schema.json', 'ts');
    file.contents = Buffer.from(jsonToType.compile(JSON.parse(file.contents.toString())));

    callback(null, file);
  });
};

@bcherny
Copy link
Owner

bcherny commented Sep 12, 2016

@simonschllng Please feel free to publish that code as a separate gulp-json-schema-to-typescript package. It is outside the scope of json-schema-to-typescript.

@bcherny bcherny closed this as completed Sep 12, 2016
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