@@ -14,20 +14,37 @@ import { printFlagList } from '../../utils/formatting.js'
14
14
import { createDebugLogger } from '../../utils/misc.js'
15
15
import { setupSdk } from '../../utils/sdk.js'
16
16
import { isErrnoException } from '../../utils/type-helpers.js'
17
+ import { fetchReportData , formatReportDataOutput } from './view.js'
17
18
18
19
/** @type {import('../../utils/meow-with-subcommands').CliSubcommand } */
19
20
export const create = {
20
21
description : 'Create a project report' ,
21
22
async run ( argv , importMeta , { parentName } ) {
22
- const name = parentName + ' view '
23
+ const name = parentName + ' create '
23
24
24
25
const input = await setupCommand ( name , create . description , argv , importMeta )
25
26
26
27
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
+
28
38
const result = input && await createReport ( packagePaths , { cwd, debugLog, dryRun } )
29
39
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 ) {
31
48
formatReportCreationOutput ( result . data , { outputJson, outputMarkdown } )
32
49
}
33
50
}
@@ -41,7 +58,7 @@ export const create = {
41
58
* @param {string } description
42
59
* @param {readonly string[] } argv
43
60
* @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 }> }
45
62
*/
46
63
async function setupCommand ( name , description , argv , importMeta ) {
47
64
const cli = meow ( `
@@ -54,6 +71,7 @@ async function setupCommand (name, description, argv, importMeta) {
54
71
'--dry-run' : 'Only output what will be done without actually doing it' ,
55
72
'--json' : 'Output result as json' ,
56
73
'--markdown' : 'Output result as markdown' ,
74
+ '--view' : 'Will wait for and return the created report'
57
75
} , 6 ) }
58
76
59
77
Examples
@@ -84,13 +102,19 @@ async function setupCommand (name, description, argv, importMeta) {
84
102
alias : 'm' ,
85
103
default : false ,
86
104
} ,
105
+ view : {
106
+ type : 'boolean' ,
107
+ alias : 'v' ,
108
+ default : false ,
109
+ } ,
87
110
}
88
111
} )
89
112
90
113
const {
91
114
dryRun,
92
115
json : outputJson ,
93
116
markdown : outputMarkdown ,
117
+ view,
94
118
} = cli . flags
95
119
96
120
if ( ! cli . input [ 0 ] ) {
@@ -109,7 +133,8 @@ async function setupCommand (name, description, argv, importMeta) {
109
133
dryRun,
110
134
outputJson,
111
135
outputMarkdown,
112
- packagePaths
136
+ packagePaths,
137
+ view,
113
138
}
114
139
}
115
140
0 commit comments