Skip to content

Commit

Permalink
fix(view): convert command to use output instead of console
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Jan 1, 2023
1 parent dc52222 commit 69f5ff8
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 137 deletions.
67 changes: 31 additions & 36 deletions lib/commands/view.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/* eslint-disable no-console */
// XXX: remove console.log later

// npm view [pkg [pkg ...]]

const chalk = require('chalk')
const columns = require('cli-columns')
const fs = require('fs')
Expand Down Expand Up @@ -127,7 +122,7 @@ class View extends BaseCommand {

const msg = await this.jsonData(reducedData, pckmnt._id)
if (msg !== '') {
console.log(msg)
this.npm.output(msg)
}
}
}
Expand Down Expand Up @@ -166,10 +161,10 @@ class View extends BaseCommand {
if (wholePackument) {
data.map((v) => this.prettyView(pckmnt, v[Object.keys(v)[0]]['']))
} else {
console.log(`${name}:`)
this.npm.output(`${name}:`)
const msg = await this.jsonData(reducedData, pckmnt._id)
if (msg !== '') {
console.log(msg)
this.npm.output(msg)
}
}
} else {
Expand All @@ -180,7 +175,7 @@ class View extends BaseCommand {
}
}
if (Object.keys(results).length > 0) {
console.log(JSON.stringify(results, null, 2))
this.npm.output(JSON.stringify(results, null, 2))
}
}

Expand Down Expand Up @@ -376,61 +371,61 @@ class View extends BaseCommand {
info.license = chalk.green(info.license)
}

console.log('')
console.log(
this.npm.output('')
this.npm.output(
chalk.underline.bold(`${info.name}@${info.version}`) +
' | ' + info.license +
' | deps: ' + (info.deps.length ? chalk.cyan(info.deps.length) : chalk.green('none')) +
' | versions: ' + info.versions
)
info.description && console.log(info.description)
info.description && this.npm.output(info.description)
if (info.repo || info.site) {
info.site && console.log(chalk.cyan(info.site))
info.site && this.npm.output(chalk.cyan(info.site))
}

const warningSign = unicode ? ' ⚠️ ' : '!!'
info.deprecated && console.log(
info.deprecated && this.npm.output(
`\n${chalk.bold.red('DEPRECATED')}${
warningSign
} - ${info.deprecated}`
)

if (info.keywords.length) {
console.log('')
console.log('keywords:', chalk.yellow(info.keywords.join(', ')))
this.npm.output('')
this.npm.output('keywords:', chalk.yellow(info.keywords.join(', ')))
}

if (info.bins.length) {
console.log('')
console.log('bin:', chalk.yellow(info.bins.join(', ')))
this.npm.output('')
this.npm.output('bin:', chalk.yellow(info.bins.join(', ')))
}

console.log('')
console.log('dist')
console.log('.tarball:', info.tarball)
console.log('.shasum:', info.shasum)
info.integrity && console.log('.integrity:', info.integrity)
info.unpackedSize && console.log('.unpackedSize:', info.unpackedSize)
this.npm.output('')
this.npm.output('dist')
this.npm.output('.tarball:', info.tarball)
this.npm.output('.shasum:', info.shasum)
info.integrity && this.npm.output('.integrity:', info.integrity)
info.unpackedSize && this.npm.output('.unpackedSize:', info.unpackedSize)

const maxDeps = 24
if (info.deps.length) {
console.log('')
console.log('dependencies:')
console.log(columns(info.deps.slice(0, maxDeps), { padding: 1 }))
this.npm.output('')
this.npm.output('dependencies:')
this.npm.output(columns(info.deps.slice(0, maxDeps), { padding: 1 }))
if (info.deps.length > maxDeps) {
console.log(`(...and ${info.deps.length - maxDeps} more.)`)
this.npm.output(`(...and ${info.deps.length - maxDeps} more.)`)
}
}

if (info.maintainers && info.maintainers.length) {
console.log('')
console.log('maintainers:')
info.maintainers.forEach((u) => console.log('-', u))
this.npm.output('')
this.npm.output('maintainers:')
info.maintainers.forEach((u) => this.npm.output('-', u))
}

console.log('')
console.log('dist-tags:')
console.log(columns(info.tags))
this.npm.output('')
this.npm.output('dist-tags:')
this.npm.output(columns(info.tags))

if (info.publisher || info.modified) {
let publishInfo = 'published'
Expand All @@ -440,8 +435,8 @@ class View extends BaseCommand {
if (info.publisher) {
publishInfo += ` by ${info.publisher}`
}
console.log('')
console.log(publishInfo)
this.npm.output('')
this.npm.output(publishInfo)
}
}
}
Expand Down
Loading

0 comments on commit 69f5ff8

Please sign in to comment.