@@ -14,20 +14,37 @@ import { printFlagList } from '../../utils/formatting.js'
1414import { createDebugLogger } from '../../utils/misc.js'
1515import { setupSdk } from '../../utils/sdk.js'
1616import { isErrnoException } from '../../utils/type-helpers.js'
17+ import { fetchReportData , formatReportDataOutput } from './view.js'
1718
1819/** @type {import('../../utils/meow-with-subcommands').CliSubcommand } */
1920export const create = {
2021 description : 'Create a project report' ,
2122 async run ( argv , importMeta , { parentName } ) {
22- const name = parentName + ' view '
23+ const name = parentName + ' create '
2324
2425 const input = await setupCommand ( name , create . description , argv , importMeta )
2526
2627 if ( input ) {
27- const { cwd, debugLog, dryRun, outputJson, outputMarkdown, packagePaths } = input
28+ const {
29+ cwd,
30+ debugLog,
31+ dryRun,
32+ outputJson,
33+ outputMarkdown,
34+ packagePaths,
35+ view,
36+ } = input
37+
2838 const result = input && await createReport ( packagePaths , { cwd, debugLog, dryRun } )
2939
30- if ( result ) {
40+ if ( result && view ) {
41+ const reportId = result . data . id
42+ const reportResult = input && await fetchReportData ( reportId )
43+
44+ if ( reportResult ) {
45+ formatReportDataOutput ( reportResult . data , { name, outputJson, outputMarkdown, reportId } )
46+ }
47+ } else if ( result ) {
3148 formatReportCreationOutput ( result . data , { outputJson, outputMarkdown } )
3249 }
3350 }
@@ -41,7 +58,7 @@ export const create = {
4158 * @param {string } description
4259 * @param {readonly string[] } argv
4360 * @param {ImportMeta } importMeta
44- * @returns {Promise<void|{ cwd: string, debugLog: typeof console.error, dryRun: boolean, outputJson: boolean, outputMarkdown: boolean, packagePaths: string[] }> }
61+ * @returns {Promise<void|{ cwd: string, debugLog: typeof console.error, dryRun: boolean, outputJson: boolean, outputMarkdown: boolean, packagePaths: string[], view: boolean }> }
4562 */
4663async function setupCommand ( name , description , argv , importMeta ) {
4764 const cli = meow ( `
@@ -54,6 +71,7 @@ async function setupCommand (name, description, argv, importMeta) {
5471 '--dry-run' : 'Only output what will be done without actually doing it' ,
5572 '--json' : 'Output result as json' ,
5673 '--markdown' : 'Output result as markdown' ,
74+ '--view' : 'Will wait for and return the created report'
5775 } , 6 ) }
5876
5977 Examples
@@ -84,13 +102,19 @@ async function setupCommand (name, description, argv, importMeta) {
84102 alias : 'm' ,
85103 default : false ,
86104 } ,
105+ view : {
106+ type : 'boolean' ,
107+ alias : 'v' ,
108+ default : false ,
109+ } ,
87110 }
88111 } )
89112
90113 const {
91114 dryRun,
92115 json : outputJson ,
93116 markdown : outputMarkdown ,
117+ view,
94118 } = cli . flags
95119
96120 if ( ! cli . input [ 0 ] ) {
@@ -109,7 +133,8 @@ async function setupCommand (name, description, argv, importMeta) {
109133 dryRun,
110134 outputJson,
111135 outputMarkdown,
112- packagePaths
136+ packagePaths,
137+ view,
113138 }
114139}
115140
0 commit comments