Skip to content

Commit

Permalink
fix(promises): update har-validator and remove dependency on bluebird
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad Nassri committed Nov 24, 2015
1 parent ac7edfb commit c328a36
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 26 deletions.
33 changes: 19 additions & 14 deletions bin/httpsnippet
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

'use strict'

var Promise = require('bluebird')

var chalk = require('chalk')
var cmd = require('commander')
var fs = Promise.promisifyAll(require('fs'))
var fs = require('fs')
var readFile = require('fs-readfile-promise')
var writeFile = require('fs-writefile-promise')
var HTTPSnippet = require('..')
var path = require('path')
var pkg = require('../package.json')
var ValidationError = require('har-validator/lib/error')

cmd
.version(pkg.version)
Expand All @@ -35,14 +34,27 @@ if (cmd.output) {
cmd.args.forEach(function (fileName) {
var file = path.basename(fileName)

fs.readFileAsync(fileName)
readFile(fileName)
.then(JSON.parse)

.catch(function (e) {
console.error('%s %s failed to read JSON: %s', chalk.red('✖'), chalk.cyan.bold(file), chalk.red(e.message))
})

.then(function (data) {
return new HTTPSnippet(data)
})

.catch(function (e) {
e.errors.forEach(function (err) {
console.error('%s %s failed validation: (%s: %s) %s', chalk.red('✖'), chalk.cyan.bold(file), chalk.cyan.italic(err.field), chalk.magenta.italic(err.value), chalk.red(err.message))
})
})

.then(function (snippet) {
return snippet.convert(cmd.target, cmd.client)
})

.then(function (output) {
// print
if (!cmd.output) {
Expand All @@ -57,18 +69,11 @@ cmd.args.forEach(function (fileName) {
base: name + HTTPSnippet.extname(cmd.target)
})

fs.writeFile(filename, output + '\n', function () {
return writeFile(filename, output + '\n', function () {
console.log('%s %s > %s', chalk.green('✓'), chalk.cyan.bold(file), filename)
})
})
.catch(SyntaxError, function (e) {
console.error('%s %s failed to read JSON: %s', chalk.red('✖'), chalk.cyan.bold(file), chalk.red(e.message))
})
.catch(ValidationError, function (e) {
e.errors.forEach(function (err) {
console.error('%s %s failed validation: (%s: %s) %s', chalk.red('✖'), chalk.cyan.bold(file), chalk.cyan.italic(err.field), chalk.magenta.italic(err.value), chalk.red(err.message))
})
})

.catch(function (e) {
console.error('%s %s fail: %s', chalk.red('✖'), chalk.cyan.bold(file), chalk.red(e.message))
})
Expand Down
24 changes: 13 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,24 @@
]
},
"devDependencies": {
"codeclimate-test-reporter": "0.1.0",
"codeclimate-test-reporter": "0.1.1",
"echint": "^1.5.0",
"glob": "^5.0.14",
"istanbul": "^0.3.17",
"mocha": "^2.2.5",
"glob": "^6.0.1",
"istanbul": "^0.4.0",
"mocha": "^2.3.4",
"require-directory": "^2.1.1",
"should": "^7.0.2",
"standard": "^5.0.0"
"should": "^7.1.1",
"standard": "^5.4.1"
},
"dependencies": {
"bluebird": "^2.9.34",
"chalk": "^1.1.0",
"commander": "^2.8.1",
"chalk": "^1.1.1",
"commander": "^2.9.0",
"debug": "^2.2.0",
"event-stream": "^3.3.1",
"event-stream": "^3.3.2",
"form-data": "^1.0.0-rc3",
"har-validator": "^1.8.0"
"fs-readfile-promise": "^2.0.1",
"fs-writefile-promise": "^1.0.3",
"har-validator": "^2.0.2",
"pinkie-promise": "^2.0.0"
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var reducer = require('./helpers/reducer')
var targets = require('./targets')
var url = require('url')
var util = require('util')
var validate = require('har-validator')
var validate = require('har-validator/lib/async')

// constructor
var HTTPSnippet = function (data) {
Expand Down

0 comments on commit c328a36

Please sign in to comment.