Skip to content

Commit d1590d8

Browse files
zzooeeyyRyanDJLee
andcommitted
Add production-mode flag to app dev command
- Added `--production-mode` flag to `shopify app dev` command with default false - Updated `DevSessionOptions` and `DevSessionPayload` interfaces to include `productionMode` parameter - Added `productionMode` parameter to GraphQL dev session create/update mutations - Modified all related interfaces and classes to pass the flag through the API chain - Updated `DevSessionDelete` signature to omit both `assetsUrl` and `productionMode` Co-authored-by: Ryan DJ Lee <[email protected]>
1 parent dc440ad commit d1590d8

File tree

11 files changed

+52
-11
lines changed

11 files changed

+52
-11
lines changed

packages/app/src/cli/api/graphql/app-dev/generated/dev-session-create.ts

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/co
77
export type DevSessionCreateMutationVariables = Types.Exact<{
88
appId: Types.Scalars['String']['input']
99
assetsUrl: Types.Scalars['String']['input']
10+
productionMode: Types.Scalars['Boolean']['input']
1011
}>
1112

1213
export type DevSessionCreateMutation = {
@@ -33,6 +34,11 @@ export const DevSessionCreate = {
3334
variable: {kind: 'Variable', name: {kind: 'Name', value: 'assetsUrl'}},
3435
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}}},
3536
},
37+
{
38+
kind: 'VariableDefinition',
39+
variable: {kind: 'Variable', name: {kind: 'Name', value: 'productionMode'}},
40+
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'Boolean'}}},
41+
},
3642
],
3743
selectionSet: {
3844
kind: 'SelectionSet',
@@ -51,6 +57,11 @@ export const DevSessionCreate = {
5157
name: {kind: 'Name', value: 'assetsUrl'},
5258
value: {kind: 'Variable', name: {kind: 'Name', value: 'assetsUrl'}},
5359
},
60+
{
61+
kind: 'Argument',
62+
name: {kind: 'Name', value: 'productionMode'},
63+
value: {kind: 'Variable', name: {kind: 'Name', value: 'productionMode'}},
64+
},
5465
],
5566
selectionSet: {
5667
kind: 'SelectionSet',

packages/app/src/cli/api/graphql/app-dev/generated/dev-session-update.ts

+11
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {TypedDocumentNode as DocumentNode} from '@graphql-typed-document-node/co
77
export type DevSessionUpdateMutationVariables = Types.Exact<{
88
appId: Types.Scalars['String']['input']
99
assetsUrl: Types.Scalars['String']['input']
10+
productionMode: Types.Scalars['Boolean']['input']
1011
}>
1112

1213
export type DevSessionUpdateMutation = {
@@ -33,6 +34,11 @@ export const DevSessionUpdate = {
3334
variable: {kind: 'Variable', name: {kind: 'Name', value: 'assetsUrl'}},
3435
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'String'}}},
3536
},
37+
{
38+
kind: 'VariableDefinition',
39+
variable: {kind: 'Variable', name: {kind: 'Name', value: 'productionMode'}},
40+
type: {kind: 'NonNullType', type: {kind: 'NamedType', name: {kind: 'Name', value: 'Boolean'}}},
41+
},
3642
],
3743
selectionSet: {
3844
kind: 'SelectionSet',
@@ -51,6 +57,11 @@ export const DevSessionUpdate = {
5157
name: {kind: 'Name', value: 'assetsUrl'},
5258
value: {kind: 'Variable', name: {kind: 'Name', value: 'assetsUrl'}},
5359
},
60+
{
61+
kind: 'Argument',
62+
name: {kind: 'Name', value: 'productionMode'},
63+
value: {kind: 'Variable', name: {kind: 'Name', value: 'productionMode'}},
64+
},
5465
],
5566
selectionSet: {
5667
kind: 'SelectionSet',

packages/app/src/cli/api/graphql/app-dev/queries/dev-session-create.graphql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
mutation DevSessionCreate($appId: String!, $assetsUrl: String!) {
2-
devSessionCreate(appId: $appId, assetsUrl: $assetsUrl) {
1+
mutation DevSessionCreate($appId: String!, $assetsUrl: String!, $productionMode: Boolean!) {
2+
devSessionCreate(appId: $appId, assetsUrl: $assetsUrl, productionMode: $productionMode) {
33
userErrors {
44
message
55
on

packages/app/src/cli/api/graphql/app-dev/queries/dev-session-update.graphql

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
mutation DevSessionUpdate($appId: String!, $assetsUrl: String!) {
2-
devSessionUpdate(appId: $appId, assetsUrl: $assetsUrl) {
1+
mutation DevSessionUpdate($appId: String!, $assetsUrl: String!, $productionMode: Boolean!) {
2+
devSessionUpdate(appId: $appId, assetsUrl: $assetsUrl, productionMode: $productionMode) {
33
userErrors {
44
message
55
on

packages/app/src/cli/commands/app/dev.ts

+7
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ If you're using the Ruby app template, then you need to complete the following s
123123
'Key used to authenticate GraphiQL requests. Should be specified if exposing GraphiQL on a publicly accessible URL. By default, no key is required.',
124124
env: 'SHOPIFY_FLAG_GRAPHIQL_KEY',
125125
}),
126+
'production-mode': Flags.boolean({
127+
hidden: false,
128+
description: 'Run the app in production mode.',
129+
env: 'SHOPIFY_FLAG_PRODUCTION_MODE',
130+
default: false,
131+
}),
126132
}
127133

128134
public static analyticsStopCommand(): string | undefined {
@@ -212,6 +218,7 @@ If you're using the Ruby app template, then you need to complete the following s
212218
graphiqlPort: flags['graphiql-port'],
213219
graphiqlKey: flags['graphiql-key'],
214220
tunnel,
221+
productionMode: flags['production-mode'],
215222
}
216223

217224
await dev(devOptions)

packages/app/src/cli/services/dev.ts

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface DevOptions {
8181
notify?: string
8282
graphiqlPort?: number
8383
graphiqlKey?: string
84+
productionMode: boolean
8485
}
8586

8687
export async function dev(commandOptions: DevOptions) {

packages/app/src/cli/services/dev/processes/dev-session/dev-session-process.ts

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface DevSessionProcessOptions {
1717
appPreviewURL: string
1818
appLocalProxyURL: string
1919
devSessionStatusManager: DevSessionStatusManager
20+
productionMode: boolean
2021
}
2122

2223
export interface DevSessionProcess extends BaseProcess<DevSessionProcessOptions> {

packages/app/src/cli/services/dev/processes/dev-session/dev-session.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface DevSessionPayload {
1616
shopFqdn: string
1717
appId: string
1818
assetsUrl: string
19+
productionMode: boolean
1920
}
2021

2122
export interface UserError {
@@ -246,7 +247,12 @@ export class DevSession {
246247
// Create or update the dev session
247248
if (currentBundleController.signal.aborted) return {status: 'aborted'}
248249
try {
249-
const payload = {shopFqdn: this.options.storeFqdn, appId: this.options.appId, assetsUrl: signedURL}
250+
const payload = {
251+
shopFqdn: this.options.storeFqdn,
252+
appId: this.options.appId,
253+
assetsUrl: signedURL,
254+
productionMode: this.options.productionMode
255+
}
250256
if (this.statusManager.status.isReady) {
251257
return this.devSessionUpdateWithRetry(payload)
252258
} else {
@@ -290,6 +296,7 @@ export class DevSession {
290296
* @param payload - The payload to update the dev session with
291297
*/
292298
private async devSessionUpdateWithRetry(payload: DevSessionPayload): Promise<DevSessionResult> {
299+
await this.logger.info(`Dev session update options: ${JSON.stringify(payload)}`)
293300
const result = await performActionWithRetryAfterRecovery(
294301
async () => this.options.developerPlatformClient.devSessionUpdate(payload),
295302
() => this.options.developerPlatformClient.refreshToken(),
@@ -306,6 +313,7 @@ export class DevSession {
306313
* @param payload - The payload to create the dev session with
307314
*/
308315
private async devSessionCreateWithRetry(payload: DevSessionPayload): Promise<DevSessionResult> {
316+
await this.logger.info(`Dev session create options: ${JSON.stringify(payload)}`)
309317
const result = await performActionWithRetryAfterRecovery(
310318
async () => this.options.developerPlatformClient.devSessionCreate(payload),
311319
() => this.options.developerPlatformClient.refreshToken(),

packages/app/src/cli/services/dev/processes/setup-dev-processes.ts

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export async function setupDevProcesses({
159159
appPreviewURL: appPreviewUrl,
160160
appLocalProxyURL: devConsoleURL,
161161
devSessionStatusManager,
162+
productionMode: commandOptions.productionMode,
162163
})
163164
: await setupDraftableExtensionsProcess({
164165
localApp: reloadedApp,

packages/app/src/cli/utilities/developer-platform-client.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ export interface DevSessionOptions {
197197
shopFqdn: string
198198
appId: string
199199
assetsUrl: string
200+
productionMode: boolean
200201
}
201202

202203
type WithUserErrors<T> = T & {
@@ -299,6 +300,6 @@ export interface DeveloperPlatformClient {
299300
appDeepLink: (app: MinimalAppIdentifiers) => Promise<string>
300301
devSessionCreate: (input: DevSessionOptions) => Promise<DevSessionCreateMutation>
301302
devSessionUpdate: (input: DevSessionOptions) => Promise<DevSessionUpdateMutation>
302-
devSessionDelete: (input: Omit<DevSessionOptions, 'assetsUrl'>) => Promise<DevSessionDeleteMutation>
303+
devSessionDelete: (input: Omit<DevSessionOptions, 'assetsUrl' | 'productionMode'>) => Promise<DevSessionDeleteMutation>
303304
getCreateDevStoreLink: (input: string) => Promise<string>
304305
}

packages/app/src/cli/utilities/developer-platform-client/app-management-client.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -940,17 +940,17 @@ export class AppManagementClient implements DeveloperPlatformClient {
940940
return appDeepLink({id, organizationId})
941941
}
942942

943-
async devSessionCreate({appId, assetsUrl, shopFqdn}: DevSessionOptions): Promise<DevSessionCreateMutation> {
943+
async devSessionCreate({appId, assetsUrl, shopFqdn, productionMode}: DevSessionOptions): Promise<DevSessionCreateMutation> {
944944
const appIdNumber = String(numberFromGid(appId))
945-
return appDevRequest(DevSessionCreate, shopFqdn, await this.token(), {appId: appIdNumber, assetsUrl})
945+
return appDevRequest(DevSessionCreate, shopFqdn, await this.token(), {appId: appIdNumber, assetsUrl, productionMode})
946946
}
947947

948-
async devSessionUpdate({appId, assetsUrl, shopFqdn}: DevSessionOptions): Promise<DevSessionUpdateMutation> {
948+
async devSessionUpdate({appId, assetsUrl, shopFqdn, productionMode}: DevSessionOptions): Promise<DevSessionUpdateMutation> {
949949
const appIdNumber = String(numberFromGid(appId))
950-
return appDevRequest(DevSessionUpdate, shopFqdn, await this.token(), {appId: appIdNumber, assetsUrl})
950+
return appDevRequest(DevSessionUpdate, shopFqdn, await this.token(), {appId: appIdNumber, assetsUrl, productionMode})
951951
}
952952

953-
async devSessionDelete({appId, shopFqdn}: Omit<DevSessionOptions, 'assetsUrl'>): Promise<DevSessionDeleteMutation> {
953+
async devSessionDelete({appId, shopFqdn}: Omit<DevSessionOptions, 'assetsUrl' | 'productionMode'>): Promise<DevSessionDeleteMutation> {
954954
const appIdNumber = String(numberFromGid(appId))
955955
return appDevRequest(DevSessionDelete, shopFqdn, await this.token(), {appId: appIdNumber})
956956
}

0 commit comments

Comments
 (0)