Skip to content

Commit b31953f

Browse files
committed
squash: move the tap logic to util
* This moves the tap logic out of cmd.js and into a separate function in utils
1 parent 5d8f5ca commit b31953f

File tree

2 files changed

+38
-34
lines changed

2 files changed

+38
-34
lines changed

bin/cmd.js

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
'use strict'
44

5-
const fs = require('fs')
65
const nopt = require('nopt')
76
const path = require('path')
8-
const formatTap = require('../lib/format-tap')
97
const Validator = require('../lib')
10-
const Tap = require('../lib/tap')
118
const utils = require('../lib/utils')
129
const subsystem = require('../lib/rules/subsystem')
1310
const knownOpts = { help: Boolean
@@ -76,37 +73,8 @@ if (parsed.list) {
7673

7774
// The --tap or -t flag was used
7875
if (parsed.tap) {
79-
const tap = new Tap()
80-
tap.pipe(process.stdout)
81-
if (parsed.out) tap.pipe(fs.createWriteStream(parsed.out))
82-
let count = 0
83-
let total = args.length
84-
85-
v.on('commit', (c) => {
86-
count++
87-
const test = tap.test(c.commit.sha)
88-
formatTap(test, c.commit, c.messages, v)
89-
if (count === total) {
90-
setImmediate(() => {
91-
tap.end()
92-
if (tap.status === 'fail')
93-
process.exitCode = 1
94-
})
95-
}
96-
})
97-
98-
function run() {
99-
if (!args.length) return
100-
const sha = args.shift()
101-
utils.load(sha, (err, data) => {
102-
if (err) throw err
103-
v.lint(data)
104-
run()
105-
})
106-
}
107-
108-
run()
109-
76+
utils.parseTap(v, parsed, args)
77+
return
11078
} else {
11179
// no --flags used, defaults to --validate-metadata
11280
utils.validateMetadata(v, args)

lib/utils.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
'use strict'
22

3+
const fs = require('fs')
34
const exec = require('child_process').exec
45
const http = require('http')
56
const https = require('https')
67
const url = require('url')
8+
const formatTap = require('../lib/format-tap')
9+
const Tap = require('../lib/tap')
710
const pretty = require('../lib/format-pretty')
811
const chalk = require('chalk')
912
const CHECK = chalk.green('✔')
@@ -124,3 +127,36 @@ exports.validateMetadata = function(validator, args) {
124127

125128
run()
126129
}
130+
131+
exports.parseTap = function(validator, parsed, args) {
132+
const tap = new Tap()
133+
tap.pipe(process.stdout)
134+
if (parsed.out) tap.pipe(fs.createWriteStream(parsed.out))
135+
let count = 0
136+
let total = args.length
137+
138+
validator.on('commit', (c) => {
139+
count++
140+
const test = tap.test(c.commit.sha)
141+
formatTap(test, c.commit, c.messages, validator)
142+
if (count === total) {
143+
setImmediate(() => {
144+
tap.end()
145+
if (tap.status === 'fail')
146+
process.exitCode = 1
147+
})
148+
}
149+
})
150+
151+
function run() {
152+
if (!args.length) return
153+
const sha = args.shift()
154+
exports.load(sha, (err, data) => {
155+
if (err) throw err
156+
validator.lint(data)
157+
run()
158+
})
159+
}
160+
161+
run()
162+
}

0 commit comments

Comments
 (0)