forked from npm/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathping.js
28 lines (24 loc) · 917 Bytes
/
ping.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const log = require('npmlog')
const npm = require('./npm.js')
const output = require('./utils/output.js')
const usageUtil = require('./utils/usage.js')
const usage = usageUtil('ping', 'npm ping\nping registry')
const completion = require('./utils/completion/none.js')
const cmd = (args, cb) => ping(args).then(() => cb()).catch(cb)
const pingUtil = require('./utils/ping.js')
const ping = async args => {
log.notice('PING', npm.flatOptions.registry)
const start = Date.now()
const details = await pingUtil(npm.flatOptions)
const time = Date.now() - start
log.notice('PONG', `${time / 1000}ms`)
if (npm.flatOptions.json) {
output(JSON.stringify({
registry: npm.flatOptions.registry,
time,
details,
}, null, 2))
} else if (Object.keys(details).length)
log.notice('PONG', `${JSON.stringify(details, null, 2)}`)
}
module.exports = Object.assign(cmd, { completion, usage })