This repository has been archived by the owner on Jul 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict' | ||
|
||
const npmConfig = require('../config.js') | ||
const libnpm = require('libnpm') | ||
const figgyPudding = require('figgy-pudding') | ||
const log = require('npmlog') | ||
|
||
module.exports = ping | ||
|
||
const PingConfig = figgyPudding({ | ||
json: {}, | ||
registry: {}, | ||
silent: {} | ||
}) | ||
|
||
function ping (argv) { | ||
const opts = PingConfig(npmConfig().concat(argv)) | ||
|
||
log.notice('PING', opts.registry) | ||
const start = Date.now() | ||
return libnpm.fetch.json('/-/ping?write=true', opts).catch(() => ({})).then(details => { | ||
if (opts.silent) { | ||
} else { | ||
const time = Date.now() - start | ||
log.notice('PONG', `${time / 1000}ms`) | ||
if (opts.json) { | ||
console.log(JSON.stringify({ | ||
registry: opts.registry, | ||
time, | ||
details | ||
}, null, 2)) | ||
} else if (Object.keys(details).length) { | ||
log.notice('PONG', `${JSON.stringify(details, null, 2)}`) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict' | ||
|
||
module.exports = { | ||
command: 'ping', | ||
describe: 'ping registry', | ||
builder (yargs) { | ||
return yargs.help().alias('help', 'h').options({ | ||
json: { | ||
alias: 'j', | ||
default: false, | ||
describe: 'Output in JSON format', | ||
choices: [false, true] | ||
}, | ||
loglevel: { | ||
default: 'warn', | ||
describe: 'Logger output level', | ||
choices: ['silent', 'error', 'warn', 'http', 'verbose', 'info', 'notice'] | ||
}, | ||
silent: { | ||
alias: 's', | ||
default: false, | ||
describe: 'Do not display the PONG response', | ||
choices: [false, true] | ||
}, | ||
registry: { | ||
alias: 'r', | ||
default: 'https://registry.npmjs.org', | ||
describe: 'Registry to ping' | ||
} | ||
}) | ||
}, | ||
// lazy-load subcommands | ||
handler (argv) { return require('../commands/ping.js')(argv) } | ||
} |