"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/request/node_modules/har-validator/bin/har-validator" (7 Feb 2017, 1578 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 chalk = require('chalk')
    6 var cmd = require('commander')
    7 var fs = require('fs')
    8 var path = require('path')
    9 var pkg = require('../package.json')
   10 var Promise = require('pinkie-promise')
   11 var validate = require('..')
   12 var ValidationError = require('../lib/error')
   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 cmd.args.map(function (fileName) {
   25   var file = chalk.yellow.italic(path.basename(fileName))
   26 
   27   new Promise(function (resolve, reject) {
   28     fs.readFile(fileName, function (err, data) {
   29       return err === null ? resolve(data) : reject(err)
   30     })
   31   })
   32 
   33     .then(JSON.parse)
   34 
   35     .then(cmd.schema ? validate[cmd.schema] : validate)
   36 
   37     .then(function (data) {
   38       console.log('%s [%s] is valid', chalk.green('✓'), file)
   39     })
   40 
   41     .catch(function (err) {
   42       if (err instanceof SyntaxError) {
   43         return console.error('%s [%s] failed to read JSON: %s', chalk.red('✖'), file, chalk.red(err.message))
   44       }
   45 
   46       if (err instanceof ValidationError) {
   47         err.errors.forEach(function (details) {
   48           console.error('%s [%s] failed validation: (%s: %s) %s', chalk.red('✖'), file, chalk.cyan.italic(details.field), chalk.magenta.italic(details.value), chalk.red(details.message))
   49         })
   50 
   51         return
   52       }
   53 
   54       console.error('%s [%s] an unknown error has occured: %s', chalk.red('✖'), file, chalk.red(err.message))
   55     })
   56 })