11import { chooseFunction , functionFlags , getOrGenerateSchemaPath } from '../../../services/function/common.js'
22import { functionRunnerBinary , downloadBinary } from '../../../services/function/binaries.js'
3+ import { functionInfo } from '../../../services/function/info.js'
34import { localAppContext } from '../../../services/app-context.js'
45import { appFlags } from '../../../flags.js'
56import AppUnlinkedCommand , { AppUnlinkedCommandOutput } from '../../../utilities/app-unlinked-command.js'
67import { globalFlags , jsonFlag } from '@shopify/cli-kit/node/cli'
7- import { outputContent , outputResult , outputToken } from '@shopify/cli-kit/node/output'
8- import { InlineToken , renderInfo } from '@shopify/cli-kit/node/ui'
8+ import { outputResult } from '@shopify/cli-kit/node/output'
9+ import { AlertCustomSection , renderInfo } from '@shopify/cli-kit/node/ui'
910
1011export default class FunctionInfo extends AppUnlinkedCommand {
1112 static summary = 'Print basic information about your function.'
@@ -41,16 +42,6 @@ export default class FunctionInfo extends AppUnlinkedCommand {
4142 const functionRunner = functionRunnerBinary ( )
4243 await downloadBinary ( functionRunner )
4344
44- const targeting : { [ key : string ] : { inputQueryPath ?: string ; export ?: string } } = { }
45- ourFunction ?. configuration . targeting ?. forEach ( ( target ) => {
46- if ( target . target ) {
47- targeting [ target . target ] = {
48- ...( target . input_query && { inputQueryPath : `${ ourFunction . directory } /${ target . input_query } ` } ) ,
49- ...( target . export && { export : target . export } ) ,
50- }
51- }
52- } )
53-
5445 const schemaPath = await getOrGenerateSchemaPath (
5546 ourFunction ,
5647 flags . path ,
@@ -59,81 +50,17 @@ export default class FunctionInfo extends AppUnlinkedCommand {
5950 flags . config ,
6051 )
6152
53+ const result = functionInfo ( ourFunction , {
54+ format : flags . json ? 'json' : 'text' ,
55+ functionRunnerPath : functionRunner . path ,
56+ schemaPath,
57+ } )
58+
6259 if ( flags . json ) {
63- outputResult (
64- JSON . stringify (
65- {
66- handle : ourFunction . configuration . handle ,
67- name : ourFunction . name ,
68- apiVersion : ourFunction . configuration . api_version ,
69- targeting,
70- schemaPath,
71- wasmPath : ourFunction . outputPath ,
72- functionRunnerPath : functionRunner . path ,
73- } ,
74- null ,
75- 2 ,
76- ) ,
77- )
60+ outputResult ( result as string )
7861 } else {
79- const configData : InlineToken [ ] [ ] = [
80- [ 'Handle' , ourFunction . configuration . handle ?? 'N/A' ] ,
81- [ 'Name' , ourFunction . name ?? 'N/A' ] ,
82- [ 'API Version' , ourFunction . configuration . api_version ?? 'N/A' ] ,
83- ]
84-
85- const sections : { title : string ; body : { tabularData : InlineToken [ ] [ ] ; firstColumnSubdued ?: boolean } } [ ] = [
86- {
87- title : 'CONFIGURATION\n' ,
88- body : {
89- tabularData : configData ,
90- firstColumnSubdued : true ,
91- } ,
92- } ,
93- ]
94-
95- if ( Object . keys ( targeting ) . length > 0 ) {
96- const targetingData : InlineToken [ ] [ ] = [ ]
97- Object . entries ( targeting ) . forEach ( ( [ target , config ] ) => {
98- targetingData . push ( [ outputContent `${ outputToken . cyan ( target ) } ` . value , '' ] )
99- if ( config . inputQueryPath ) {
100- targetingData . push ( [ { subdued : ' Input Query Path' } , { filePath : config . inputQueryPath } ] )
101- }
102- if ( config . export ) {
103- targetingData . push ( [ { subdued : ' Export' } , config . export ] )
104- }
105- } )
106-
107- sections . push ( {
108- title : '\nTARGETING\n' ,
109- body : {
110- tabularData : targetingData ,
111- } ,
112- } )
113- }
114-
115- sections . push (
116- {
117- title : '\nBUILD\n' ,
118- body : {
119- tabularData : [
120- [ 'Schema Path' , { filePath : schemaPath ?? 'N/A' } ] ,
121- [ 'Wasm Path' , { filePath : ourFunction . outputPath } ] ,
122- ] ,
123- firstColumnSubdued : true ,
124- } ,
125- } ,
126- {
127- title : '\nFUNCTION RUNNER\n' ,
128- body : {
129- tabularData : [ [ 'Path' , { filePath : functionRunner . path } ] ] ,
130- firstColumnSubdued : true ,
131- } ,
132- } ,
133- )
134-
13562 renderInfo ( {
136- customSections : sections ,
63+ customSections : result as AlertCustomSection [ ] ,
13764 } )
13865 }
13966
0 commit comments