Skip to content

Commit 34e4342

Browse files
committed
using function runner info to provide necessary info about function for function run
1 parent ba52e0c commit 34e4342

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {chooseFunction, functionFlags, getOrGenerateSchemaPath} from '../../../services/function/common.js'
2+
import {functionRunnerBinary, downloadBinary} from '../../../services/function/binaries.js'
3+
import {localAppContext} from '../../../services/app-context.js'
4+
import {appFlags} from '../../../flags.js'
5+
import AppUnlinkedCommand, {AppUnlinkedCommandOutput} from '../../../utilities/app-unlinked-command.js'
6+
import {globalFlags, jsonFlag} from '@shopify/cli-kit/node/cli'
7+
import {outputResult} from '@shopify/cli-kit/node/output'
8+
9+
export default class FunctionInfo extends AppUnlinkedCommand {
10+
static summary = 'Get information about the function.'
11+
12+
static description = 'Returns information about the function.'
13+
14+
static hidden = true
15+
16+
static flags = {
17+
...globalFlags,
18+
...appFlags,
19+
...functionFlags,
20+
...jsonFlag,
21+
}
22+
23+
public async run(): Promise<AppUnlinkedCommandOutput> {
24+
const {flags} = await this.parse(FunctionInfo)
25+
26+
const app = await localAppContext({
27+
directory: flags.path,
28+
userProvidedConfigName: flags.config,
29+
})
30+
31+
const ourFunction = await chooseFunction(app, flags.path)
32+
const functionRunner = functionRunnerBinary()
33+
await downloadBinary(functionRunner)
34+
35+
const inputQueryPath = ourFunction?.configuration.targeting?.[0]?.input_query
36+
const queryPath = inputQueryPath && `${ourFunction?.directory}/${inputQueryPath}`
37+
const schemaPath = await getOrGenerateSchemaPath(
38+
ourFunction,
39+
flags.path,
40+
flags['client-id'],
41+
flags.reset,
42+
flags.config,
43+
)
44+
45+
if (flags.json) {
46+
outputResult(
47+
JSON.stringify({
48+
functionRunnerPath: functionRunner.path,
49+
functionRunnerVersion: functionRunner.version,
50+
functionInputQueryPath: queryPath,
51+
functionSchemaPath: schemaPath,
52+
functionWasmPath: ourFunction.outputPath,
53+
}),
54+
)
55+
} else {
56+
outputResult(`functionRunnerPath: ${functionRunner.path}`)
57+
outputResult(`functionRunnerVersion: ${functionRunner.version}`)
58+
outputResult(`functionInputQueryPath: ${queryPath}`)
59+
outputResult(`functionSchemaPath: ${schemaPath}`)
60+
}
61+
62+
return {app}
63+
}
64+
}

packages/app/src/cli/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import gatherSensitiveMetadata from './hooks/sensitive_metadata.js'
2828
import AppLinkedCommand from './utilities/app-linked-command.js'
2929
import DevClean from './commands/app/dev/clean.js'
3030
import AppUnlinkedCommand from './utilities/app-unlinked-command.js'
31+
import FunctionInfo from './commands/app/function/info.js'
3132

3233
/**
3334
* All app commands should extend AppCommand.
@@ -51,6 +52,7 @@ export const commands: {[key: string]: typeof AppLinkedCommand | typeof AppUnlin
5152
'app:function:build': FunctionBuild,
5253
'app:function:replay': FunctionReplay,
5354
'app:function:run': FunctionRun,
55+
'app:function:info': FunctionInfo,
5456
'app:function:schema': FetchSchema,
5557
'app:function:typegen': FunctionTypegen,
5658
'app:generate:extension': AppGenerateExtension,

packages/cli/oclif.manifest.json

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,94 @@
887887
"strict": true,
888888
"summary": "Compile a function to wasm."
889889
},
890+
"app:function:info": {
891+
"aliases": [
892+
],
893+
"args": {
894+
},
895+
"customPluginName": "@shopify/app",
896+
"description": "Returns information about the function.",
897+
"flags": {
898+
"client-id": {
899+
"description": "The Client ID of your app.",
900+
"env": "SHOPIFY_FLAG_CLIENT_ID",
901+
"exclusive": [
902+
"config"
903+
],
904+
"hasDynamicHelp": false,
905+
"hidden": false,
906+
"multiple": false,
907+
"name": "client-id",
908+
"type": "option"
909+
},
910+
"config": {
911+
"char": "c",
912+
"description": "The name of the app configuration.",
913+
"env": "SHOPIFY_FLAG_APP_CONFIG",
914+
"hasDynamicHelp": false,
915+
"hidden": false,
916+
"multiple": false,
917+
"name": "config",
918+
"type": "option"
919+
},
920+
"json": {
921+
"allowNo": false,
922+
"char": "j",
923+
"description": "Output the result as JSON.",
924+
"env": "SHOPIFY_FLAG_JSON",
925+
"hidden": false,
926+
"name": "json",
927+
"type": "boolean"
928+
},
929+
"no-color": {
930+
"allowNo": false,
931+
"description": "Disable color output.",
932+
"env": "SHOPIFY_FLAG_NO_COLOR",
933+
"hidden": false,
934+
"name": "no-color",
935+
"type": "boolean"
936+
},
937+
"path": {
938+
"description": "The path to your function directory.",
939+
"env": "SHOPIFY_FLAG_PATH",
940+
"hasDynamicHelp": false,
941+
"hidden": false,
942+
"multiple": false,
943+
"name": "path",
944+
"noCacheDefault": true,
945+
"type": "option"
946+
},
947+
"reset": {
948+
"allowNo": false,
949+
"description": "Reset all your settings.",
950+
"env": "SHOPIFY_FLAG_RESET",
951+
"exclusive": [
952+
"config"
953+
],
954+
"hidden": false,
955+
"name": "reset",
956+
"type": "boolean"
957+
},
958+
"verbose": {
959+
"allowNo": false,
960+
"description": "Increase the verbosity of the output.",
961+
"env": "SHOPIFY_FLAG_VERBOSE",
962+
"hidden": false,
963+
"name": "verbose",
964+
"type": "boolean"
965+
}
966+
},
967+
"hasDynamicHelp": false,
968+
"hidden": true,
969+
"hiddenAliases": [
970+
],
971+
"id": "app:function:info",
972+
"pluginAlias": "@shopify/cli",
973+
"pluginName": "@shopify/cli",
974+
"pluginType": "core",
975+
"strict": true,
976+
"summary": "Get information about the function."
977+
},
890978
"app:function:replay": {
891979
"aliases": [
892980
],

0 commit comments

Comments
 (0)