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

Commit

Permalink
feat(view): add 'view' command (#27)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
larsgw authored and zkat committed Nov 13, 2018
1 parent 97e7880 commit 500207c
Show file tree
Hide file tree
Showing 5 changed files with 540 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bin/tink.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const CMDS = new Map([
['org', require('../lib/commands/org.jsx')],
['prepare', require('../lib/commands/prepare.js')],
['ping', require('../lib/commands/ping.js')],
['deprecate', require('../lib/commands/deprecate.js')]
['deprecate', require('../lib/commands/deprecate.js')],
['view', require('../lib/commands/view.js')]
])

if (require.main === module) {
Expand Down
51 changes: 51 additions & 0 deletions lib/commands/view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
'use strict'

const npmlog = require('npmlog')
const libnpm = require('libnpm')

const { h, renderToString } = require('ink')
const { PackageView, PackageFields } = require('../components/view.jsx')

const View = module.exports = {
command: 'view [<pkg>[@<version>]] [<field>...]',
aliases: ['v', 'info', 'show'],
describe: 'Show information about a package',
builder (yargs) {
return yargs.help().alias('help', 'h').options(View.options)
},
options: Object.assign(require('../common-opts'), {}),
handler: view
}

async function view (argv) {
npmlog.heading = 'tink'

let { 'pkg@version': spec, field: fields } = argv

if (!spec) { spec = '.' }
if (!fields) { fields = [] }

let packument = await libnpm.packument(spec, Object.assign({}, argv, {
fullMetadata: true,
log: npmlog
}))
let { rawSpec } = libnpm.parseArg(spec)

let options = {
packument,
fields,
spec: rawSpec && rawSpec !== '.' ? rawSpec : null,
json: argv.json
}

try {
let view = h(
fields.length ? PackageFields : PackageView,
options
)
console.log(renderToString(view))
} catch (e) {
npmlog.error('view', e.message)
npmlog.error('view', e.stack)
}
}
Loading

0 comments on commit 500207c

Please sign in to comment.