Skip to content

Commit 18c534d

Browse files
authored
Merge pull request #6314 from Shopify/fix-741
Improve `shopify theme dev` to prevent accidental updates to live themes
2 parents 88e2c3a + 0d0c8b1 commit 18c534d

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

.changeset/sour-clocks-suffer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/theme': patch
3+
---
4+
5+
Improve `shopify theme dev` to prevent accidental updates to live themes

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {dev} from '../../services/dev.js'
55
import {DevelopmentThemeManager} from '../../utilities/development-theme-manager.js'
66
import {findOrSelectTheme} from '../../utilities/theme-selector.js'
77
import {metafieldsPull} from '../../services/metafields-pull.js'
8+
import {ensureLiveThemeConfirmed} from '../../utilities/theme-ui.js'
89
import {validateThemePassword} from '../../services/flags-validation.js'
910
import {Flags} from '@oclif/core'
1011
import {globalFlags} from '@shopify/cli-kit/node/cli'
@@ -146,6 +147,11 @@ You can run this command only in a directory that matches the [default Shopify t
146147
flags = {...flags, theme: theme.id.toString(), 'overwrite-json': overwriteJson}
147148
}
148149

150+
const confirmed = await ensureLiveThemeConfirmed(theme, 'start development mode')
151+
if (!confirmed) {
152+
return
153+
}
154+
149155
await dev({
150156
adminSession,
151157
directory: flags.path,

packages/theme/src/cli/utilities/theme-ui.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {recordEvent} from '@shopify/cli-kit/node/analytics'
22
import {Theme} from '@shopify/cli-kit/node/themes/types'
3+
import {LIVE_THEME_ROLE} from '@shopify/cli-kit/node/themes/utils'
34
import {Task, renderConfirmationPrompt, renderTasks, renderWarning} from '@shopify/cli-kit/node/ui'
45

56
export function themeComponent(theme: Theme) {
@@ -40,6 +41,26 @@ export async function ensureDirectoryConfirmed(
4041
return confirm
4142
}
4243

44+
export async function ensureLiveThemeConfirmed(theme: Theme, action: string) {
45+
if (theme.role !== LIVE_THEME_ROLE || !process.stdout.isTTY) {
46+
return true
47+
}
48+
49+
const message =
50+
`You're about to ${action} on your live theme "${theme.name}". ` +
51+
`This will make changes visible to customers. Are you sure you want to proceed?`
52+
53+
const confirm = await renderConfirmationPrompt({
54+
message,
55+
confirmationMessage: 'Yes, proceed with live theme',
56+
cancellationMessage: 'No, cancel',
57+
})
58+
59+
recordEvent(`theme-service:confirm-live-theme:${confirm}`)
60+
61+
return confirm
62+
}
63+
4364
// This prevents the progress bar from polluting stdout (important for pipe operations)
4465
export async function renderTasksToStdErr(tasks: Task[]) {
4566
if (tasks.length > 0) {

0 commit comments

Comments
 (0)