• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict'
2
3const { EOL } = require('os')
4
5const computeMetadata = require('./deps.js').computeMetadata
6const mutateIntoLogicalTree = require('./mutate-into-logical-tree.js')
7var { getFundingInfo } = require('../utils/funding.js')
8
9exports.getPrintFundingReport = getPrintFundingReport
10exports.getPrintFundingReportJSON = getPrintFundingReportJSON
11
12function getFundingResult ({ fund, idealTree }) {
13  if (fund) {
14    const fundingInfoTree =
15      mutateIntoLogicalTree.asReadInstalled(
16        computeMetadata(idealTree)
17      )
18    const fundResult = getFundingInfo(fundingInfoTree, { countOnly: true })
19    return fundResult
20  } else {
21    return {}
22  }
23}
24
25function getPrintFundingReport ({ fund, idealTree }, opts) {
26  const fundResult = getFundingResult({ fund, idealTree })
27  const { length } = fundResult || {}
28  const { json } = opts || {}
29
30  function padding (msg) {
31    return json ? '' : (EOL + msg)
32  }
33
34  function packageQuantity (amount) {
35    return `package${amount > 1 ? 's are' : ' is'}`
36  }
37
38  if (!length) return ''
39
40  return padding('') + length + ' ' +
41    packageQuantity(length) +
42    ' looking for funding' +
43    padding('  run `npm fund` for details\n')
44}
45
46function getPrintFundingReportJSON ({ fund, idealTree }) {
47  return getPrintFundingReport({ fund, idealTree }, { json: true })
48}
49