| const pacote = require('pacote')
|
| const { openUrl } = require('./utils/open-url.js')
|
| const { log } = require('proc-log')
|
| const BaseCommand = require('./base-cmd.js')
|
|
|
|
|
| class PackageUrlCommand extends BaseCommand {
|
| static params = [
|
| 'browser',
|
| 'registry',
|
| 'workspace',
|
| 'workspaces',
|
| 'include-workspace-root',
|
| ]
|
|
|
| static workspaces = true
|
| static ignoreImplicitWorkspace = false
|
| static usage = ['[<pkgname> [<pkgname> ...]]']
|
|
|
| async exec (args) {
|
| if (!args || !args.length) {
|
| args = ['.']
|
| }
|
|
|
| for (const arg of args) {
|
|
|
| const opts = {
|
| ...this.npm.flatOptions,
|
| where: this.npm.localPrefix,
|
| fullMetadata: true,
|
| _isRoot: true,
|
| }
|
| const mani = await pacote.manifest(arg, opts)
|
| const url = this.getUrl(arg, mani)
|
| log.silly(this.name, 'url', url)
|
| await openUrl(this.npm, url, `${mani.name} ${this.name} available at the following URL`)
|
| }
|
| }
|
|
|
| async execWorkspaces (args) {
|
| if (args && args.length) {
|
| return this.exec(args)
|
| }
|
| await this.setWorkspaces()
|
| return this.exec(this.workspacePaths)
|
| }
|
|
|
|
|
|
|
| hostedFromMani (mani) {
|
| const hostedGitInfo = require('hosted-git-info')
|
| const r = mani.repository
|
| const rurl = !r ? null
|
| : typeof r === 'string' ? r
|
| : typeof r === 'object' && typeof r.url === 'string' ? r.url
|
| : null
|
|
|
|
|
| return (rurl && hostedGitInfo.fromUrl(rurl.replace(/^git\+/, ''))) || null
|
| }
|
| }
|
|
|
| module.exports = PackageUrlCommand
|
|
|