Skip to content

Commit c328a36

Browse files
committed
fix(promises): update har-validator and remove dependency on bluebird
1 parent ac7edfb commit c328a36

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

bin/httpsnippet

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
'use strict'
44

5-
var Promise = require('bluebird')
6-
75
var chalk = require('chalk')
86
var cmd = require('commander')
9-
var fs = Promise.promisifyAll(require('fs'))
7+
var fs = require('fs')
8+
var readFile = require('fs-readfile-promise')
9+
var writeFile = require('fs-writefile-promise')
1010
var HTTPSnippet = require('..')
1111
var path = require('path')
1212
var pkg = require('../package.json')
13-
var ValidationError = require('har-validator/lib/error')
1413

1514
cmd
1615
.version(pkg.version)
@@ -35,14 +34,27 @@ if (cmd.output) {
3534
cmd.args.forEach(function (fileName) {
3635
var file = path.basename(fileName)
3736

38-
fs.readFileAsync(fileName)
37+
readFile(fileName)
3938
.then(JSON.parse)
39+
40+
.catch(function (e) {
41+
console.error('%s %s failed to read JSON: %s', chalk.red('✖'), chalk.cyan.bold(file), chalk.red(e.message))
42+
})
43+
4044
.then(function (data) {
4145
return new HTTPSnippet(data)
4246
})
47+
48+
.catch(function (e) {
49+
e.errors.forEach(function (err) {
50+
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))
51+
})
52+
})
53+
4354
.then(function (snippet) {
4455
return snippet.convert(cmd.target, cmd.client)
4556
})
57+
4658
.then(function (output) {
4759
// print
4860
if (!cmd.output) {
@@ -57,18 +69,11 @@ cmd.args.forEach(function (fileName) {
5769
base: name + HTTPSnippet.extname(cmd.target)
5870
})
5971

60-
fs.writeFile(filename, output + '\n', function () {
72+
return writeFile(filename, output + '\n', function () {
6173
console.log('%s %s > %s', chalk.green('✓'), chalk.cyan.bold(file), filename)
6274
})
6375
})
64-
.catch(SyntaxError, function (e) {
65-
console.error('%s %s failed to read JSON: %s', chalk.red('✖'), chalk.cyan.bold(file), chalk.red(e.message))
66-
})
67-
.catch(ValidationError, function (e) {
68-
e.errors.forEach(function (err) {
69-
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))
70-
})
71-
})
76+
7277
.catch(function (e) {
7378
console.error('%s %s fail: %s', chalk.red('✖'), chalk.cyan.bold(file), chalk.red(e.message))
7479
})

package.json

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,24 @@
6666
]
6767
},
6868
"devDependencies": {
69-
"codeclimate-test-reporter": "0.1.0",
69+
"codeclimate-test-reporter": "0.1.1",
7070
"echint": "^1.5.0",
71-
"glob": "^5.0.14",
72-
"istanbul": "^0.3.17",
73-
"mocha": "^2.2.5",
71+
"glob": "^6.0.1",
72+
"istanbul": "^0.4.0",
73+
"mocha": "^2.3.4",
7474
"require-directory": "^2.1.1",
75-
"should": "^7.0.2",
76-
"standard": "^5.0.0"
75+
"should": "^7.1.1",
76+
"standard": "^5.4.1"
7777
},
7878
"dependencies": {
79-
"bluebird": "^2.9.34",
80-
"chalk": "^1.1.0",
81-
"commander": "^2.8.1",
79+
"chalk": "^1.1.1",
80+
"commander": "^2.9.0",
8281
"debug": "^2.2.0",
83-
"event-stream": "^3.3.1",
82+
"event-stream": "^3.3.2",
8483
"form-data": "^1.0.0-rc3",
85-
"har-validator": "^1.8.0"
84+
"fs-readfile-promise": "^2.0.1",
85+
"fs-writefile-promise": "^1.0.3",
86+
"har-validator": "^2.0.2",
87+
"pinkie-promise": "^2.0.0"
8688
}
8789
}

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var reducer = require('./helpers/reducer')
88
var targets = require('./targets')
99
var url = require('url')
1010
var util = require('util')
11-
var validate = require('har-validator')
11+
var validate = require('har-validator/lib/async')
1212

1313
// constructor
1414
var HTTPSnippet = function (data) {

0 commit comments

Comments
 (0)