This repository was archived by the owner on Jul 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
feat(view): add 'view' command #27
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
62cae1f
feat(view): add a first draft of `tink view`
larsgw b9c5471
fix(view): move to jsx, register command
larsgw 60b1171
fix(view): use common opts
larsgw 1c7a057
style(view): use jsx, improve components
larsgw 52d4be6
fix(view): fix error handling
larsgw 95ff9bd
fix(view): fix dist-tag handling
larsgw 52b7416
fix(view): use libnpm instead of npa
larsgw b59497e
fix(view): improve error handling
larsgw 7f80b08
feat(view): allow unlimited items for specified fields
larsgw 6e5010e
feat(view): add packument info
larsgw 8481a64
feat(view): allow dots in props
larsgw 9461d5a
fix(view): properly show error stack
larsgw 4de4f2e
feat(view): show deps as columns
larsgw 41aa8c2
chore(git): clean merge conflict
larsgw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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'), {}), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it make more sense if these arguments were reversed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.