Skip to content

Commit 477bd9a

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 477bd9a

File tree

2 files changed

+37
-33
lines changed

2 files changed

+37
-33
lines changed

bin/cmd.js

+2-33
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
const fs = require('fs')
66
const nopt = require('nopt')
77
const path = require('path')
8-
const formatTap = require('../lib/format-tap')
98
const Validator = require('../lib')
10-
const Tap = require('../lib/tap')
119
const utils = require('../lib/utils')
1210
const subsystem = require('../lib/rules/subsystem')
1311
const knownOpts = { help: Boolean
@@ -76,37 +74,8 @@ if (parsed.list) {
7674

7775
// The --tap or -t flag was used
7876
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-
77+
utils.parseTap(v, parsed, args)
78+
return
11079
} else {
11180
// no --flags used, defaults to --validate-metadata
11281
utils.validateMetadata(v, args)

lib/utils.js

+35
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const exec = require('child_process').exec
44
const http = require('http')
55
const https = require('https')
66
const url = require('url')
7+
const formatTap = require('../lib/format-tap')
8+
const Tap = require('../lib/tap')
79
const pretty = require('../lib/format-pretty')
810
const chalk = require('chalk')
911
const CHECK = chalk.green('✔')
@@ -124,3 +126,36 @@ exports.validateMetadata = function(validator, args) {
124126

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

0 commit comments

Comments
 (0)