Skip to content

Possible to perform batch compilation from CLI? #62

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

Closed
RickCarlino opened this issue Feb 28, 2017 · 2 comments
Closed

Possible to perform batch compilation from CLI? #62

RickCarlino opened this issue Feb 28, 2017 · 2 comments
Labels

Comments

@RickCarlino
Copy link

Hi,

Thanks for the great library, and sorry if this question has already been answered in the docs (I was not able to find anything as far as I know).

Is it possible to perform batch compilation? For example, with the following directory structure:

+- json_schema
  +-foo.json
  +-bar.json

is it possible to create the following output?

+- json_schema
  +-foo.json
  +-foo.d.ts
  +-bar.json
  +-bar.d.ts

Thanks again for all the great work on this project. It's very much appreciated.

@RickCarlino
Copy link
Author

RickCarlino commented Feb 28, 2017

As a side note, I was able to solve the problem using the script below, but am still curious if the CLI supports the functionality natively:

// RUN THIS FROM THE ROOT OF THE JSON SCHEMA DIRECTORY.


var JS2TS = require("json-schema-to-typescript");
var glob = require("glob"); // npm install glob --save
var fs = require("fs");
glob("./*.json", function (err, files) {
  if (err) {
    console.log(err);
    console.log(files);
  }
  else {
    files.map(function (file) {
      JS2TS
        .compileFromFile(file)
        .then(function (data) {
          var newFile = file.split(".")
          newFile.pop();
          fs.writeFileSync("./" + newFile.join("") + ".d.ts", data);
        });
    });
  }
});

@bcherny
Copy link
Owner

bcherny commented Feb 28, 2017

Hi @RickCarlino! There is no way to do this today, but feel free to PR this feature. Also see #16.

cc @erykpiast

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

No branches or pull requests

2 participants