How to use the typescript-json-schema.TJS.programFromConfig function in typescript-json-schema

To help you get started, we’ve selected a few typescript-json-schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse / eclipse.jdt.ls / lang-protocol-generator / Gruntfile.js View on Github external
grunt.registerTask('copyTypes','copy types to be generated', function(){
      grunt.file.delete('./nodeClient/vscode-languageserver-node/client/src/generatedTypes.ts');
      grunt.file.copy('./generatedTypes.ts' ,'./nodeClient/vscode-languageserver-node/client/src/generatedTypes.ts');
  });

  grunt.registerTask('generate_schema', 'Generate schema from .ts', function () {
      var filename = './ls-protocol/types.json'
      createJSONSchema('AllTypes', filename);
      var filename2 = './ls-protocol/messages.json'
      createJSONSchema('AllMessages', filename2);
      var filename3 = './ls-protocol/everything.json'
      createJSONSchema('AllProtocol', filename3);
  });
  grunt.registerTask('generate', ['copyTypes','generate_schema']);

var program = TJS.programFromConfig('./nodeClient/vscode-languageserver-node/client/src/tsconfig.json');
function createJSONSchema(element, destFile) {
  var args = {
    useRef: true,
    useTypeAliasRef: false,
    useRootRef: false,
    useTitle: false,
    useDefaultProperties: false,
    disableExtraProperties: true,
    usePropertyOrder: false,
    generateRequired: true,
    out: undefined
  };
  args.out = destFile;
  var definition = TJS.generateSchema(program, element, args);
  grunt.file.write(destFile,JSON.stringify(definition, null, 4) + "\n" );
}