Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.

Commit 28c32b5

Browse files
emkayzkat
authored andcommitted
1 parent 0135065 commit 28c32b5

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

bin/tink.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ if (require.main === module) {
77
}
88
module.exports = main
99
function main () {
10+
require('npmlog').heading = 'tink'
1011
return require('yargs')
1112
.commandDir('../lib/yargs-modules')
1213
.demandCommand()

lib/commands/ping.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict'
2+
3+
const npmConfig = require('../config.js')
4+
const libnpm = require('libnpm')
5+
const figgyPudding = require('figgy-pudding')
6+
const log = require('npmlog')
7+
8+
module.exports = ping
9+
10+
const PingConfig = figgyPudding({
11+
json: {},
12+
registry: {},
13+
silent: {}
14+
})
15+
16+
function ping (argv) {
17+
const opts = PingConfig(npmConfig().concat(argv))
18+
19+
log.notice('PING', opts.registry)
20+
const start = Date.now()
21+
return libnpm.fetch.json('/-/ping?write=true', opts).catch(() => ({})).then(details => {
22+
if (opts.silent) {
23+
} else {
24+
const time = Date.now() - start
25+
log.notice('PONG', `${time / 1000}ms`)
26+
if (opts.json) {
27+
console.log(JSON.stringify({
28+
registry: opts.registry,
29+
time,
30+
details
31+
}, null, 2))
32+
} else if (Object.keys(details).length) {
33+
log.notice('PONG', `${JSON.stringify(details, null, 2)}`)
34+
}
35+
}
36+
})
37+
}

lib/yargs-modules/ping.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict'
2+
3+
module.exports = {
4+
command: 'ping',
5+
describe: 'ping registry',
6+
builder (yargs) {
7+
return yargs.help().alias('help', 'h').options({
8+
json: {
9+
alias: 'j',
10+
default: false,
11+
describe: 'Output in JSON format',
12+
choices: [false, true]
13+
},
14+
loglevel: {
15+
default: 'warn',
16+
describe: 'Logger output level',
17+
choices: ['silent', 'error', 'warn', 'http', 'verbose', 'info', 'notice']
18+
},
19+
silent: {
20+
alias: 's',
21+
default: false,
22+
describe: 'Do not display the PONG response',
23+
choices: [false, true]
24+
},
25+
registry: {
26+
alias: 'r',
27+
default: 'https://registry.npmjs.org',
28+
describe: 'Registry to ping'
29+
}
30+
})
31+
},
32+
// lazy-load subcommands
33+
handler (argv) { return require('../commands/ping.js')(argv) }
34+
}

0 commit comments

Comments
 (0)