11cb0ef41Sopenharmony_ciconst { cleanUrl } = require('npm-registry-fetch')
21cb0ef41Sopenharmony_ciconst log = require('../utils/log-shim')
31cb0ef41Sopenharmony_ciconst pingUtil = require('../utils/ping.js')
41cb0ef41Sopenharmony_ciconst BaseCommand = require('../base-command.js')
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ciclass Ping extends BaseCommand {
71cb0ef41Sopenharmony_ci  static description = 'Ping npm registry'
81cb0ef41Sopenharmony_ci  static params = ['registry']
91cb0ef41Sopenharmony_ci  static name = 'ping'
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci  async exec (args) {
121cb0ef41Sopenharmony_ci    const cleanRegistry = cleanUrl(this.npm.config.get('registry'))
131cb0ef41Sopenharmony_ci    log.notice('PING', cleanRegistry)
141cb0ef41Sopenharmony_ci    const start = Date.now()
151cb0ef41Sopenharmony_ci    const details = await pingUtil({ ...this.npm.flatOptions })
161cb0ef41Sopenharmony_ci    const time = Date.now() - start
171cb0ef41Sopenharmony_ci    log.notice('PONG', `${time}ms`)
181cb0ef41Sopenharmony_ci    if (this.npm.config.get('json')) {
191cb0ef41Sopenharmony_ci      this.npm.output(JSON.stringify({
201cb0ef41Sopenharmony_ci        registry: cleanRegistry,
211cb0ef41Sopenharmony_ci        time,
221cb0ef41Sopenharmony_ci        details,
231cb0ef41Sopenharmony_ci      }, null, 2))
241cb0ef41Sopenharmony_ci    } else if (Object.keys(details).length) {
251cb0ef41Sopenharmony_ci      log.notice('PONG', `${JSON.stringify(details, null, 2)}`)
261cb0ef41Sopenharmony_ci    }
271cb0ef41Sopenharmony_ci  }
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_cimodule.exports = Ping
30