validate-schema.ts 766 B

1234567891011121314151617181920212223242526272829
  1. /**
  2. * Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. */
  6. import * as argparse from 'argparse'
  7. import * as fs from 'fs'
  8. import { validate } from './util/validate'
  9. function runValidateSchema (path: string) {
  10. const str = fs.readFileSync(path, 'utf8')
  11. const result = validate(JSON.parse(str))
  12. console.log(result === true ? 'valid json schema' : `invalid json schema: "${result}"`)
  13. }
  14. const parser = new argparse.ArgumentParser({
  15. addHelp: true,
  16. description: 'Validate json schema'
  17. });
  18. parser.addArgument([ 'path' ], {
  19. help: 'path to json schema'
  20. });
  21. const args = parser.parseArgs();
  22. if (args.path) {
  23. runValidateSchema(args.path)
  24. }