"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/har-validator/bin/har-validator" (7 Feb 2017, 1236 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/env node
    2 
    3 'use strict'
    4 
    5 var Promise = require('bluebird')
    6 
    7 var chalk = require('chalk')
    8 var cmd = require('commander')
    9 var fs = Promise.promisifyAll(require('fs'))
   10 var path = require('path')
   11 var pkg = require('../package.json')
   12 var validate = Promise.promisifyAll(require('..'))
   13 
   14 cmd
   15   .version(pkg.version)
   16   .usage('[options] <files ...>')
   17   .option('-s, --schema [name]', 'validate schema name (log, request, response, etc ...)')
   18   .parse(process.argv)
   19 
   20 if (!cmd.args.length) {
   21   cmd.help()
   22 }
   23 
   24 if (!cmd.schema) {
   25   cmd.schema = 'har'
   26 }
   27 
   28 cmd.args.map(function (fileName) {
   29   var file = chalk.yellow.italic(path.basename(fileName))
   30 
   31   fs.readFileAsync(fileName)
   32     .then(JSON.parse)
   33     .then(validate[cmd.schema + 'Async'])
   34     .then(function () {
   35       console.log('%s [%s] is valid', chalk.green('✓'), file)
   36     })
   37     .catch(SyntaxError, function (e) {
   38       console.error('%s [%s] failed to read JSON: %s', chalk.red('✖'), file, chalk.red(e.message))
   39     })
   40     .catch(function (e) {
   41       e.errors.map(function (err) {
   42         console.error('%s [%s] failed validation: (%s: %s) %s', chalk.red('✖'), file, chalk.cyan.italic(err.field), chalk.magenta.italic(err.value), chalk.red(err.message))
   43       })
   44     })
   45 })