Skip to content

Commit 68dff49

Browse files
wire up new watch UI to execute command
1 parent bc801df commit 68dff49

3 files changed

Lines changed: 69 additions & 5 deletions

File tree

‎packages/app/src/cli/commands/app/execute.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default class Execute extends AppLinkedCommand {
3838
app: appContextResult.app,
3939
storeFqdn: store.shopDomain,
4040
query: flags.query,
41+
watch: flags.watch,
4142
})
4243

4344
return {app: appContextResult.app}

‎packages/app/src/cli/flags.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,9 @@ export const bulkOperationFlags = {
4848
env: 'SHOPIFY_FLAG_STORE',
4949
parse: async (input) => normalizeStoreFqdn(input),
5050
}),
51+
watch: Flags.boolean({
52+
description: 'Wait for bulk operation results before exiting.',
53+
env: 'SHOPIFY_FLAG_WATCH',
54+
default: false,
55+
}),
5156
}

‎packages/app/src/cli/services/bulk-operations/execute-bulk-operation.ts‎

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {runBulkOperationQuery} from './run-query.js'
2+
import {watchBulkOperation} from './watch-bulk-operation.js'
23
import {AppLinkedInterface} from '../../models/app/app.js'
34
import {renderSuccess, renderInfo, renderWarning} from '@shopify/cli-kit/node/ui'
45
import {outputContent, outputToken} from '@shopify/cli-kit/node/output'
@@ -7,10 +8,11 @@ interface ExecuteBulkOperationInput {
78
app: AppLinkedInterface
89
storeFqdn: string
910
query: string
11+
watch?: boolean
1012
}
1113

1214
export async function executeBulkOperation(input: ExecuteBulkOperationInput): Promise<void> {
13-
const {app, storeFqdn, query} = input
15+
const {app, storeFqdn, query, watch = false} = input
1416

1517
renderInfo({
1618
headline: 'Starting bulk operation.',
@@ -57,9 +59,65 @@ export async function executeBulkOperation(input: ExecuteBulkOperationInput): Pr
5759

5860
renderInfo({customSections: infoSections})
5961

60-
renderSuccess({
61-
headline: 'Bulk operation started successfully!',
62-
body: 'Congrats!',
63-
})
62+
if (watch) {
63+
const finalOperation = await watchBulkOperation({
64+
id: result.id,
65+
storeFqdn,
66+
})
67+
68+
if (!finalOperation) {
69+
renderWarning({
70+
headline: 'Operation not found.',
71+
body: 'The bulk operation could not be found',
72+
})
73+
return
74+
}
75+
76+
if (!('status' in finalOperation) || !('objectCount' in finalOperation)) {
77+
renderWarning({
78+
headline: 'Operation incomplete.',
79+
body: 'The bulk operation did not return complete data',
80+
})
81+
return
82+
}
83+
84+
const count = finalOperation.objectCount
85+
switch (finalOperation.status) {
86+
case 'COMPLETED':
87+
renderSuccess({
88+
headline: 'Query complete!',
89+
body: `${count} objects processed`,
90+
})
91+
break
92+
case 'FAILED':
93+
renderWarning({
94+
headline: 'Query failed.',
95+
body: `${count} objects processed before failure`,
96+
})
97+
break
98+
case 'CANCELED':
99+
renderWarning({
100+
headline: 'Query canceled.',
101+
body: `${count} objects processed before cancellation`,
102+
})
103+
break
104+
case 'EXPIRED':
105+
renderWarning({
106+
headline: 'Query expired.',
107+
body: `${count} objects processed before expiration`,
108+
})
109+
break
110+
default:
111+
renderWarning({
112+
headline: `Query ${finalOperation.status.toLowerCase()}.`,
113+
body: `${count} objects processed`,
114+
})
115+
}
116+
} else {
117+
renderSuccess({
118+
headline: 'Bulk operation started successfully!',
119+
body: 'Congrats!',
120+
})
121+
}
64122
}
65123
}

0 commit comments

Comments
 (0)