Skip to content
This repository has been archived by the owner on Mar 21, 2022. It is now read-only.

Commit

Permalink
feat: added outfile
Browse files Browse the repository at this point in the history
  • Loading branch information
cgreene-st committed Mar 2, 2022
1 parent d0207ab commit 948f2d9
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
'use strict'
const fs = require('fs')
const meow = require('meow')
const ora = require('ora')
const chalk = require('chalk')
Expand All @@ -19,6 +20,7 @@ Options
--packages The packages to return a usage report for. Is a glob.
--parser The parser you want to use: \`typescript\` or \`babel\` (default)
--exports The export to return a report for.
--outFile Specify where to write the report.
--version Prints the version.
--help Prints this message.
Expand All @@ -44,6 +46,17 @@ function toJSON(obj) {
return JSON.stringify(obj, null, 2)
}

function output(result) {
const outFile = cli.flags.outFile
? cli.flags.outFile
: './stui-dep-report.json'
if (outFile) {
fs.writeFileSync(outFile, toJSON(result))
} else {
console.log(toJSON(result))
}
}

async function main() {
const inputPackages = cli.flags.packages ? cli.flags.packages.split(',') : []
const inputExports = cli.flags.exports ? cli.flags.exports.split(',') : []
Expand Down Expand Up @@ -90,20 +103,23 @@ async function main() {
if (packages.length > 0) {
if (cli.flags.exports) {
const result = packages.map(pack => pack.exportReport(inputExports))
console.log(toJSON(result))
output(result)
} else {
const result = packages.map(pack => pack.toPlainObject())
// Const result = packages.map(pack => pack.usageReport())
console.log(toJSON(result))
// console.log(toJSON(result))
output(result)
}
} else {
chalk.red(`no packages found for: ${cli.flags.packages}`)
}
} else if (inputExports.length > 0) {
const exportsUsage = report.getByExportNames(inputExports)
console.log(toJSON(exportsUsage))
// Console.log(toJSON(exportsUsage))
output(exportsUsage)
} else {
console.log(toJSON(report.toPlainObject()))
// Console.log(toJSON(report.toPlainObject()))
output(report.toPlainObject())
}
}

Expand Down

0 comments on commit 948f2d9

Please sign in to comment.