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

Commit 500207c

Browse files
larsgwzkat
authored andcommitted
feat(view): add 'view' command (#27)
* feat(view): add a first draft of `tink view` * fix(view): move to jsx, register command Move to use JSX and use register command. * fix(view): use common opts * style(view): use jsx, improve components * fix(view): fix error handling * fix(view): fix dist-tag handling * fix(view): use libnpm instead of npa * fix(view): improve error handling * feat(view): allow unlimited items for specified fields Allow unlimited items when field is specified. * feat(view): add packument info Add packument info to outputted JSON, as is custom in `npm view`. It's a bit double if multiple versions are queried, but that's just how it is. Also allows packument-specific props to be queried. * feat(view): allow dots in props Allow dots (.) in props with a special prop syntax: Data: { foo: { 'bar.baz': 1, bar: { baz: 2 } } } Query: foo[bar.baz] // -> 1 Useful to query versions, deps: time[0.10.1] dependencies[lodash.uniq] * fix(view): properly show error stack * feat(view): show deps as columns Show dependencies in columns, matching the old behaviour. * chore(git): clean merge conflict
1 parent 97e7880 commit 500207c

File tree

5 files changed

+540
-1
lines changed

5 files changed

+540
-1
lines changed

bin/tink.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const CMDS = new Map([
99
['org', require('../lib/commands/org.jsx')],
1010
['prepare', require('../lib/commands/prepare.js')],
1111
['ping', require('../lib/commands/ping.js')],
12-
['deprecate', require('../lib/commands/deprecate.js')]
12+
['deprecate', require('../lib/commands/deprecate.js')],
13+
['view', require('../lib/commands/view.js')]
1314
])
1415

1516
if (require.main === module) {

lib/commands/view.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'use strict'
2+
3+
const npmlog = require('npmlog')
4+
const libnpm = require('libnpm')
5+
6+
const { h, renderToString } = require('ink')
7+
const { PackageView, PackageFields } = require('../components/view.jsx')
8+
9+
const View = module.exports = {
10+
command: 'view [<pkg>[@<version>]] [<field>...]',
11+
aliases: ['v', 'info', 'show'],
12+
describe: 'Show information about a package',
13+
builder (yargs) {
14+
return yargs.help().alias('help', 'h').options(View.options)
15+
},
16+
options: Object.assign(require('../common-opts'), {}),
17+
handler: view
18+
}
19+
20+
async function view (argv) {
21+
npmlog.heading = 'tink'
22+
23+
let { 'pkg@version': spec, field: fields } = argv
24+
25+
if (!spec) { spec = '.' }
26+
if (!fields) { fields = [] }
27+
28+
let packument = await libnpm.packument(spec, Object.assign({}, argv, {
29+
fullMetadata: true,
30+
log: npmlog
31+
}))
32+
let { rawSpec } = libnpm.parseArg(spec)
33+
34+
let options = {
35+
packument,
36+
fields,
37+
spec: rawSpec && rawSpec !== '.' ? rawSpec : null,
38+
json: argv.json
39+
}
40+
41+
try {
42+
let view = h(
43+
fields.length ? PackageFields : PackageView,
44+
options
45+
)
46+
console.log(renderToString(view))
47+
} catch (e) {
48+
npmlog.error('view', e.message)
49+
npmlog.error('view', e.stack)
50+
}
51+
}

0 commit comments

Comments
 (0)