codekingpro/portable-devtools
114k
1const { redact } = require('@npmcli/redact')
2const { log, output } = require('proc-log')
3const pingUtil = require('../utils/ping.js')
4const BaseCommand = require('../base-cmd.js')
5
6class Ping extends BaseCommand {
7 static description = 'Ping npm registry'
8 static params = ['registry']
9 static name = 'ping'
10
11 async exec () {
12 const cleanRegistry = redact(this.npm.config.get('registry'))
13 log.notice('PING', cleanRegistry)
14 const start = Date.now()
15 const details = await pingUtil({ ...this.npm.flatOptions })
16 const time = Date.now() - start
17 log.notice('PONG', `${time}ms`)
18 if (this.npm.config.get('json')) {
19 output.buffer({
20 registry: cleanRegistry,
21 time,
22 details,
23 })
24 } else if (Object.keys(details).length) {
25 log.notice('PONG', JSON.stringify(details, null, 2))
26 }
27 }
28}
29
30module.exports = Ping
31 