Skip to content
This repository was archived by the owner on Jul 28, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure you could use libnpm.log.

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'), {}),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense if these arguments were reversed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, don't know why I did it that way... Not that it matters, at the moment.

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