Skip to content

Commit a657b4b

Browse files
committed
Add --allow-live flag to theme dev commands
Recently, a new confirmation prompt was added to prevent unintended development on live themes. This commit adds a new flag, `--allow-live`, to `theme dev` to skip this confirmation
1 parent 3f41579 commit a657b4b

File tree

8 files changed

+90
-7
lines changed

8 files changed

+90
-7
lines changed

.changeset/clean-cherries-cry.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@shopify/theme': minor
3+
'@shopify/cli': minor
4+
---
5+
6+
Add --allow-live flag to theme dev to allow development on live themes without confirmation

docs-shopify.dev/commands/interfaces/theme-dev.interface.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
// This is an autogenerated file. Don't edit this file manually.
22
export interface themedev {
3+
/**
4+
* Allow development on a live theme.
5+
* @environment SHOPIFY_FLAG_ALLOW_LIVE
6+
*/
7+
'-a, --allow-live'?: ''
8+
39
/**
410
* The environment to apply to the current command.
511
* @environment SHOPIFY_FLAG_ENVIRONMENT

docs-shopify.dev/generated/generated_docs_data.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5234,6 +5234,15 @@
52345234
"isOptional": true,
52355235
"environmentValue": "SHOPIFY_FLAG_VERBOSE"
52365236
},
5237+
{
5238+
"filePath": "docs-shopify.dev/commands/interfaces/theme-dev.interface.ts",
5239+
"syntaxKind": "PropertySignature",
5240+
"name": "-a, --allow-live",
5241+
"value": "\"\"",
5242+
"description": "Allow development on a live theme.",
5243+
"isOptional": true,
5244+
"environmentValue": "SHOPIFY_FLAG_ALLOW_LIVE"
5245+
},
52375246
{
52385247
"filePath": "docs-shopify.dev/commands/interfaces/theme-dev.interface.ts",
52395248
"syntaxKind": "PropertySignature",
@@ -5289,7 +5298,7 @@
52895298
"environmentValue": "SHOPIFY_FLAG_IGNORE"
52905299
}
52915300
],
5292-
"value": "export interface themedev {\n /**\n * The environment to apply to the current command.\n * @environment SHOPIFY_FLAG_ENVIRONMENT\n */\n '-e, --environment <value>'?: string\n\n /**\n * Controls the visibility of the error overlay when an theme asset upload fails:\n- silent Prevents the error overlay from appearing.\n- default Displays the error overlay.\n \n * @environment SHOPIFY_FLAG_ERROR_OVERLAY\n */\n '--error-overlay <value>'?: string\n\n /**\n * Set which network interface the web server listens on. The default value is 127.0.0.1.\n * @environment SHOPIFY_FLAG_HOST\n */\n '--host <value>'?: string\n\n /**\n * Skip hot reloading any files that match the specified pattern.\n * @environment SHOPIFY_FLAG_IGNORE\n */\n '-x, --ignore <value>'?: string\n\n /**\n * The live reload mode switches the server behavior when a file is modified:\n- hot-reload Hot reloads local changes to CSS and sections (default)\n- full-page Always refreshes the entire page\n- off Deactivate live reload\n * @environment SHOPIFY_FLAG_LIVE_RELOAD\n */\n '--live-reload <value>'?: string\n\n /**\n * Disable color output.\n * @environment SHOPIFY_FLAG_NO_COLOR\n */\n '--no-color'?: ''\n\n /**\n * Prevents files from being deleted in the remote theme when a file has been deleted locally. This applies to files that are deleted while the command is running, and files that have been deleted locally before the command is run.\n * @environment SHOPIFY_FLAG_NODELETE\n */\n '-n, --nodelete'?: ''\n\n /**\n * The file path or URL. The file path is to a file that you want updated on idle. The URL path is where you want a webhook posted to report on file changes.\n * @environment SHOPIFY_FLAG_NOTIFY\n */\n '--notify <value>'?: string\n\n /**\n * Hot reload only files that match the specified pattern.\n * @environment SHOPIFY_FLAG_ONLY\n */\n '-o, --only <value>'?: string\n\n /**\n * Automatically launch the theme preview in your default web browser.\n * @environment SHOPIFY_FLAG_OPEN\n */\n '--open'?: ''\n\n /**\n * Password generated from the Theme Access app.\n * @environment SHOPIFY_CLI_THEME_TOKEN\n */\n '--password <value>'?: string\n\n /**\n * The path where you want to run the command. Defaults to the current working directory.\n * @environment SHOPIFY_FLAG_PATH\n */\n '--path <value>'?: string\n\n /**\n * Local port to serve theme preview from.\n * @environment SHOPIFY_FLAG_PORT\n */\n '--port <value>'?: string\n\n /**\n * Store URL. It can be the store prefix (example) or the full myshopify.com URL (example.myshopify.com, https://example.myshopify.com).\n * @environment SHOPIFY_FLAG_STORE\n */\n '-s, --store <value>'?: string\n\n /**\n * The password for storefronts with password protection.\n * @environment SHOPIFY_FLAG_STORE_PASSWORD\n */\n '--store-password <value>'?: string\n\n /**\n * Theme ID or name of the remote theme.\n * @environment SHOPIFY_FLAG_THEME_ID\n */\n '-t, --theme <value>'?: string\n\n /**\n * Synchronize Theme Editor updates in the local theme files.\n * @environment SHOPIFY_FLAG_THEME_EDITOR_SYNC\n */\n '--theme-editor-sync'?: ''\n\n /**\n * Increase the verbosity of the output.\n * @environment SHOPIFY_FLAG_VERBOSE\n */\n '--verbose'?: ''\n}"
5301+
"value": "export interface themedev {\n /**\n * Allow development on a live theme.\n * @environment SHOPIFY_FLAG_ALLOW_LIVE\n */\n '-a, --allow-live'?: ''\n\n /**\n * The environment to apply to the current command.\n * @environment SHOPIFY_FLAG_ENVIRONMENT\n */\n '-e, --environment <value>'?: string\n\n /**\n * Controls the visibility of the error overlay when an theme asset upload fails:\n- silent Prevents the error overlay from appearing.\n- default Displays the error overlay.\n \n * @environment SHOPIFY_FLAG_ERROR_OVERLAY\n */\n '--error-overlay <value>'?: string\n\n /**\n * Set which network interface the web server listens on. The default value is 127.0.0.1.\n * @environment SHOPIFY_FLAG_HOST\n */\n '--host <value>'?: string\n\n /**\n * Skip hot reloading any files that match the specified pattern.\n * @environment SHOPIFY_FLAG_IGNORE\n */\n '-x, --ignore <value>'?: string\n\n /**\n * The live reload mode switches the server behavior when a file is modified:\n- hot-reload Hot reloads local changes to CSS and sections (default)\n- full-page Always refreshes the entire page\n- off Deactivate live reload\n * @environment SHOPIFY_FLAG_LIVE_RELOAD\n */\n '--live-reload <value>'?: string\n\n /**\n * Disable color output.\n * @environment SHOPIFY_FLAG_NO_COLOR\n */\n '--no-color'?: ''\n\n /**\n * Prevents files from being deleted in the remote theme when a file has been deleted locally. This applies to files that are deleted while the command is running, and files that have been deleted locally before the command is run.\n * @environment SHOPIFY_FLAG_NODELETE\n */\n '-n, --nodelete'?: ''\n\n /**\n * The file path or URL. The file path is to a file that you want updated on idle. The URL path is where you want a webhook posted to report on file changes.\n * @environment SHOPIFY_FLAG_NOTIFY\n */\n '--notify <value>'?: string\n\n /**\n * Hot reload only files that match the specified pattern.\n * @environment SHOPIFY_FLAG_ONLY\n */\n '-o, --only <value>'?: string\n\n /**\n * Automatically launch the theme preview in your default web browser.\n * @environment SHOPIFY_FLAG_OPEN\n */\n '--open'?: ''\n\n /**\n * Password generated from the Theme Access app.\n * @environment SHOPIFY_CLI_THEME_TOKEN\n */\n '--password <value>'?: string\n\n /**\n * The path where you want to run the command. Defaults to the current working directory.\n * @environment SHOPIFY_FLAG_PATH\n */\n '--path <value>'?: string\n\n /**\n * Local port to serve theme preview from.\n * @environment SHOPIFY_FLAG_PORT\n */\n '--port <value>'?: string\n\n /**\n * Store URL. It can be the store prefix (example) or the full myshopify.com URL (example.myshopify.com, https://example.myshopify.com).\n * @environment SHOPIFY_FLAG_STORE\n */\n '-s, --store <value>'?: string\n\n /**\n * The password for storefronts with password protection.\n * @environment SHOPIFY_FLAG_STORE_PASSWORD\n */\n '--store-password <value>'?: string\n\n /**\n * Theme ID or name of the remote theme.\n * @environment SHOPIFY_FLAG_THEME_ID\n */\n '-t, --theme <value>'?: string\n\n /**\n * Synchronize Theme Editor updates in the local theme files.\n * @environment SHOPIFY_FLAG_THEME_EDITOR_SYNC\n */\n '--theme-editor-sync'?: ''\n\n /**\n * Increase the verbosity of the output.\n * @environment SHOPIFY_FLAG_VERBOSE\n */\n '--verbose'?: ''\n}"
52935302
}
52945303
}
52955304
}

packages/cli/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1804,12 +1804,15 @@ Uploads the current theme as a development theme to the connected store, then pr
18041804

18051805
```
18061806
USAGE
1807-
$ shopify theme dev [-e <value>...] [--error-overlay silent|default] [--host <value>] [-x <value>...]
1807+
$ shopify theme dev [-a] [-e <value>...] [--error-overlay silent|default] [--host <value>] [-x <value>...]
18081808
[--live-reload hot-reload|full-page|off] [--no-color] [-n] [--notify <value>] [-o <value>...] [--open] [--password
18091809
<value>] [--path <value>] [--port <value>] [-s <value>] [--store-password <value>] [-t <value>]
18101810
[--theme-editor-sync] [--verbose]
18111811
18121812
FLAGS
1813+
-a, --allow-live
1814+
Allow development on a live theme.
1815+
18131816
-e, --environment=<value>...
18141817
The environment to apply to the current command.
18151818

packages/cli/oclif.manifest.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5241,6 +5241,14 @@
52415241
"description": "\n Uploads the current theme as the specified theme, or a \"development theme\" (https://shopify.dev/docs/themes/tools/cli#development-themes), to a store so you can preview it.\n\nThis command returns the following information:\n\n- A link to your development theme at http://127.0.0.1:9292. This URL can hot reload local changes to CSS and sections, or refresh the entire page when a file changes, enabling you to preview changes in real time using the store's data.\n\n You can specify a different network interface and port using `--host` and `--port`.\n\n- A link to the \"editor\" (https://shopify.dev/docs/themes/tools/online-editor) for the theme in the Shopify admin.\n\n- A \"preview link\" (https://help.shopify.com/manual/online-store/themes/adding-themes#share-a-theme-preview-with-others) that you can share with other developers.\n\nIf you already have a development theme for your current environment, then this command replaces the development theme with your local theme. You can override this using the `--theme-editor-sync` flag.\n\n> Note: You can't preview checkout customizations using http://127.0.0.1:9292.\n\nDevelopment themes are deleted when you run `shopify auth logout`. If you need a preview link that can be used after you log out, then you should \"share\" (https://shopify.dev/docs/api/shopify-cli/theme/theme-share) your theme or \"push\" (https://shopify.dev/docs/api/shopify-cli/theme/theme-push) to an unpublished theme on your store.\n\nYou can run this command only in a directory that matches the \"default Shopify theme folder structure\" (https://shopify.dev/docs/themes/tools/cli#directory-structure).",
52425242
"descriptionWithMarkdown": "\n Uploads the current theme as the specified theme, or a [development theme](https://shopify.dev/docs/themes/tools/cli#development-themes), to a store so you can preview it.\n\nThis command returns the following information:\n\n- A link to your development theme at http://127.0.0.1:9292. This URL can hot reload local changes to CSS and sections, or refresh the entire page when a file changes, enabling you to preview changes in real time using the store's data.\n\n You can specify a different network interface and port using `--host` and `--port`.\n\n- A link to the [editor](https://shopify.dev/docs/themes/tools/online-editor) for the theme in the Shopify admin.\n\n- A [preview link](https://help.shopify.com/manual/online-store/themes/adding-themes#share-a-theme-preview-with-others) that you can share with other developers.\n\nIf you already have a development theme for your current environment, then this command replaces the development theme with your local theme. You can override this using the `--theme-editor-sync` flag.\n\n> Note: You can't preview checkout customizations using http://127.0.0.1:9292.\n\nDevelopment themes are deleted when you run `shopify auth logout`. If you need a preview link that can be used after you log out, then you should [share](https://shopify.dev/docs/api/shopify-cli/theme/theme-share) your theme or [push](https://shopify.dev/docs/api/shopify-cli/theme/theme-push) to an unpublished theme on your store.\n\nYou can run this command only in a directory that matches the [default Shopify theme folder structure](https://shopify.dev/docs/themes/tools/cli#directory-structure).",
52435243
"flags": {
5244+
"allow-live": {
5245+
"allowNo": false,
5246+
"char": "a",
5247+
"description": "Allow development on a live theme.",
5248+
"env": "SHOPIFY_FLAG_ALLOW_LIVE",
5249+
"name": "allow-live",
5250+
"type": "boolean"
5251+
},
52445252
"environment": {
52455253
"char": "e",
52465254
"description": "The environment to apply to the current command.",
@@ -6731,6 +6739,14 @@
67316739
"description": "\n Uploads the current theme as the specified theme, or a \"development theme\" (https://shopify.dev/docs/themes/tools/cli#development-themes), to a store so you can preview it.\n\nThis command returns the following information:\n\n- A link to your development theme at http://127.0.0.1:9292. This URL can hot reload local changes to CSS and sections, or refresh the entire page when a file changes, enabling you to preview changes in real time using the store's data.\n\n You can specify a different network interface and port using `--host` and `--port`.\n\n- A link to the \"editor\" (https://shopify.dev/docs/themes/tools/online-editor) for the theme in the Shopify admin.\n\n- A \"preview link\" (https://help.shopify.com/manual/online-store/themes/adding-themes#share-a-theme-preview-with-others) that you can share with other developers.\n\nIf you already have a development theme for your current environment, then this command replaces the development theme with your local theme. You can override this using the `--theme-editor-sync` flag.\n\n> Note: You can't preview checkout customizations using http://127.0.0.1:9292.\n\nDevelopment themes are deleted when you run `shopify auth logout`. If you need a preview link that can be used after you log out, then you should \"share\" (https://shopify.dev/docs/api/shopify-cli/theme/theme-share) your theme or \"push\" (https://shopify.dev/docs/api/shopify-cli/theme/theme-push) to an unpublished theme on your store.\n\nYou can run this command only in a directory that matches the \"default Shopify theme folder structure\" (https://shopify.dev/docs/themes/tools/cli#directory-structure).",
67326740
"descriptionWithMarkdown": "\n Uploads the current theme as the specified theme, or a [development theme](https://shopify.dev/docs/themes/tools/cli#development-themes), to a store so you can preview it.\n\nThis command returns the following information:\n\n- A link to your development theme at http://127.0.0.1:9292. This URL can hot reload local changes to CSS and sections, or refresh the entire page when a file changes, enabling you to preview changes in real time using the store's data.\n\n You can specify a different network interface and port using `--host` and `--port`.\n\n- A link to the [editor](https://shopify.dev/docs/themes/tools/online-editor) for the theme in the Shopify admin.\n\n- A [preview link](https://help.shopify.com/manual/online-store/themes/adding-themes#share-a-theme-preview-with-others) that you can share with other developers.\n\nIf you already have a development theme for your current environment, then this command replaces the development theme with your local theme. You can override this using the `--theme-editor-sync` flag.\n\n> Note: You can't preview checkout customizations using http://127.0.0.1:9292.\n\nDevelopment themes are deleted when you run `shopify auth logout`. If you need a preview link that can be used after you log out, then you should [share](https://shopify.dev/docs/api/shopify-cli/theme/theme-share) your theme or [push](https://shopify.dev/docs/api/shopify-cli/theme/theme-push) to an unpublished theme on your store.\n\nYou can run this command only in a directory that matches the [default Shopify theme folder structure](https://shopify.dev/docs/themes/tools/cli#directory-structure).",
67336741
"flags": {
6742+
"allow-live": {
6743+
"allowNo": false,
6744+
"char": "a",
6745+
"description": "Allow development on a live theme.",
6746+
"env": "SHOPIFY_FLAG_ALLOW_LIVE",
6747+
"name": "allow-live",
6748+
"type": "boolean"
6749+
},
67346750
"environment": {
67356751
"char": "e",
67366752
"description": "The environment to apply to the current command.",

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ You can run this command only in a directory that matches the [default Shopify t
124124
description: 'The password for storefronts with password protection.',
125125
env: 'SHOPIFY_FLAG_STORE_PASSWORD',
126126
}),
127+
'allow-live': Flags.boolean({
128+
description: 'Allow development on a live theme.',
129+
char: 'a',
130+
env: 'SHOPIFY_FLAG_ALLOW_LIVE',
131+
default: false,
132+
}),
127133
}
128134

129135
static multiEnvironmentsFlags: RequiredFlags = null
@@ -149,7 +155,7 @@ You can run this command only in a directory that matches the [default Shopify t
149155
flags = {...devFlags, theme: theme.id.toString(), store: adminSession.storeFqdn, 'overwrite-json': overwriteJson}
150156
}
151157

152-
const confirmed = await ensureLiveThemeConfirmed(theme, 'start development mode')
158+
const confirmed = await ensureLiveThemeConfirmed(theme, 'start development mode', devFlags['allow-live'])
153159
if (!confirmed) {
154160
return
155161
}

packages/theme/src/cli/services/dev.test.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {openURLSafely, renderLinks} from './dev.js'
2+
import {ensureLiveThemeConfirmed} from '../utilities/theme-ui.js'
23
import {describe, expect, test, vi} from 'vitest'
34
import {buildTheme} from '@shopify/cli-kit/node/themes/factories'
4-
import {DEVELOPMENT_THEME_ROLE} from '@shopify/cli-kit/node/themes/utils'
5-
import {renderSuccess, renderWarning} from '@shopify/cli-kit/node/ui'
5+
import {DEVELOPMENT_THEME_ROLE, LIVE_THEME_ROLE} from '@shopify/cli-kit/node/themes/utils'
6+
import {renderConfirmationPrompt, renderSuccess, renderWarning} from '@shopify/cli-kit/node/ui'
67
import {openURL} from '@shopify/cli-kit/node/system'
78

89
vi.mock('@shopify/cli-kit/node/ui')
@@ -20,6 +21,7 @@ vi.mock('@shopify/cli-kit/node/system', () => ({
2021
describe('dev', () => {
2122
const store = 'my-store.myshopify.com'
2223
const theme = buildTheme({id: 123, name: 'My Theme', role: DEVELOPMENT_THEME_ROLE})!
24+
const liveTheme = buildTheme({id: 123, name: 'My Theme', role: LIVE_THEME_ROLE})!
2325

2426
test('renders "dev" command links', async () => {
2527
// Given
@@ -101,4 +103,39 @@ describe('dev', () => {
101103
})
102104
})
103105
})
106+
describe('ensureLiveThemeConfirmed', () => {
107+
vi.stubGlobal('process', {...process, stdout: {...process.stdout, isTTY: true}})
108+
109+
test('prompts for confirmation if acting on a live theme', async () => {
110+
// Given
111+
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true)
112+
113+
const result = await ensureLiveThemeConfirmed(liveTheme, 'start development mode', false)
114+
115+
// Then
116+
expect(renderConfirmationPrompt).toHaveBeenCalledWith({
117+
message:
118+
'You\'re about to start development mode on your live theme "My Theme". This will make changes visible to customers. Are you sure you want to proceed?',
119+
confirmationMessage: 'Yes, proceed with live theme',
120+
cancellationMessage: 'No, cancel',
121+
})
122+
expect(result).toBe(true)
123+
})
124+
125+
test('does not prompt for confirmation if acting on a non-live theme', async () => {
126+
// Given
127+
await ensureLiveThemeConfirmed(theme, 'start development mode', false)
128+
129+
// Then
130+
expect(renderConfirmationPrompt).not.toHaveBeenCalled()
131+
})
132+
133+
test('does not prompt for confirmation if acting on a live theme and allowLive flag is true', async () => {
134+
// Given
135+
await ensureLiveThemeConfirmed(liveTheme, 'start development mode', true)
136+
137+
// Then
138+
expect(renderConfirmationPrompt).not.toHaveBeenCalled()
139+
})
140+
})
104141
})

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ export async function ensureDirectoryConfirmed(
5252
return confirm
5353
}
5454

55-
export async function ensureLiveThemeConfirmed(theme: Theme, action: string) {
56-
if (theme.role !== LIVE_THEME_ROLE || !process.stdout.isTTY) {
55+
export async function ensureLiveThemeConfirmed(theme: Theme, action: string, allowLive: boolean) {
56+
if (theme.role !== LIVE_THEME_ROLE || !process.stdout.isTTY || allowLive) {
5757
return true
5858
}
5959

0 commit comments

Comments
 (0)