Skip to content

Commit

Permalink
Merge pull request #4716 from Shopify/jm/fix-push-live
Browse files Browse the repository at this point in the history
[Themes] Connect `allowLive` flag to `theme push` execution
  • Loading branch information
jamesmengo authored Oct 23, 2024
2 parents b8b3346 + eccb52d commit e15b615
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-icons-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/theme': patch
---

Fixes an issue in the `theme push` command where a confirmation prompt is rendered to users who provide the `--allow-live` flag
18 changes: 9 additions & 9 deletions packages/theme/src/cli/services/push.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {createOrSelectTheme, push, ThemeSelectionOptions} from './push.js'
import {createOrSelectTheme, push, PushFlags} from './push.js'
import {PullFlags} from './pull.js'
import {setDevelopmentTheme} from './local-storage.js'
import {uploadTheme} from '../utilities/theme-uploader.js'
Expand Down Expand Up @@ -67,7 +67,7 @@ describe('createOrSelectTheme', async () => {
vi.mocked(createTheme).mockResolvedValue(buildTheme({id: 2, name: 'Theme', role: UNPUBLISHED_THEME_ROLE}))
vi.mocked(fetchTheme).mockResolvedValue(undefined)

const flags: ThemeSelectionOptions = {unpublished: true}
const flags: PushFlags = {unpublished: true}

// When
const theme = await createOrSelectTheme(adminSession, flags)
Expand All @@ -81,7 +81,7 @@ describe('createOrSelectTheme', async () => {
// Given
vi.mocked(createTheme).mockResolvedValue(buildTheme({id: 1, name: 'Theme', role: DEVELOPMENT_THEME_ROLE}))
vi.mocked(fetchTheme).mockResolvedValue(undefined)
const flags: ThemeSelectionOptions = {development: true}
const flags: PushFlags = {development: true}

// When
const theme = await createOrSelectTheme(adminSession, flags)
Expand All @@ -95,7 +95,7 @@ describe('createOrSelectTheme', async () => {
// Given
vi.mocked(createTheme).mockResolvedValue(buildTheme({id: 1, name: 'Theme', role: DEVELOPMENT_THEME_ROLE}))
vi.mocked(fetchTheme).mockResolvedValue(undefined)
const flags: ThemeSelectionOptions = {development: true, unpublished: true}
const flags: PushFlags = {development: true, unpublished: true}

// When
const theme = await createOrSelectTheme(adminSession, flags)
Expand All @@ -107,7 +107,7 @@ describe('createOrSelectTheme', async () => {
test('returns live theme when live flag is provided', async () => {
// Given
vi.mocked(findOrSelectTheme).mockResolvedValue(buildTheme({id: 3, name: 'Live Theme', role: LIVE_THEME_ROLE})!)
const flags: ThemeSelectionOptions = {live: true, 'allow-live': true}
const flags: PushFlags = {live: true, allowLive: true}

// When
const theme = await createOrSelectTheme(adminSession, flags)
Expand All @@ -116,11 +116,11 @@ describe('createOrSelectTheme', async () => {
expect(theme).toMatchObject({role: LIVE_THEME_ROLE})
})

test("renders confirmation prompt if 'allow-live' flag is not provided and selected theme role is live", async () => {
test('renders confirmation prompt if allowLive flag is not provided and selected theme role is live', async () => {
// Given
vi.mocked(findOrSelectTheme).mockResolvedValue(buildTheme({id: 3, name: 'Live Theme', role: LIVE_THEME_ROLE})!)
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true)
const flags: ThemeSelectionOptions = {live: true}
const flags: PushFlags = {live: true}

// When
const theme = await createOrSelectTheme(adminSession, flags)
Expand All @@ -134,7 +134,7 @@ describe('createOrSelectTheme', async () => {
// Given
vi.mocked(findOrSelectTheme).mockResolvedValue(buildTheme({id: 3, name: 'Live Theme', role: LIVE_THEME_ROLE})!)
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true)
const flags: ThemeSelectionOptions = {theme: '3'}
const flags: PushFlags = {theme: '3'}

// When
const theme = await createOrSelectTheme(adminSession, flags)
Expand All @@ -148,7 +148,7 @@ describe('createOrSelectTheme', async () => {
// Given
vi.mocked(findOrSelectTheme).mockResolvedValue(buildTheme({id: 3, name: 'Live Theme', role: LIVE_THEME_ROLE})!)
vi.mocked(renderConfirmationPrompt).mockResolvedValue(false)
const flags: ThemeSelectionOptions = {live: true}
const flags: PushFlags = {live: true}

// When
const theme = await createOrSelectTheme(adminSession, flags)
Expand Down
27 changes: 8 additions & 19 deletions packages/theme/src/cli/services/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@ import {themeEditorUrl, themePreviewUrl} from '@shopify/cli-kit/node/themes/urls
import {cwd, resolvePath} from '@shopify/cli-kit/node/path'
import {LIVE_THEME_ROLE, promptThemeName, UNPUBLISHED_THEME_ROLE} from '@shopify/cli-kit/node/themes/utils'

export interface ThemeSelectionOptions {
live?: boolean
development?: boolean
unpublished?: boolean
theme?: string
'allow-live'?: boolean
}

interface PushOptions {
path: string
nodelete?: boolean
Expand Down Expand Up @@ -134,12 +126,12 @@ export async function push(flags: PushFlags): Promise<void> {

await executePush(selectedTheme, adminSession, {
path: workingDirectory,
nodelete: flags.nodelete || false,
publish: flags.publish || false,
json: flags.json || false,
nodelete: flags.nodelete ?? false,
publish: flags.publish ?? false,
json: flags.json ?? false,
force,
ignore: flags.ignore || [],
only: flags.only || [],
ignore: flags.ignore ?? [],
only: flags.only ?? [],
})
}

Expand Down Expand Up @@ -291,17 +283,14 @@ function handleOutput(theme: Theme, hasErrors: boolean, session: AdminSession) {
}
}

export async function createOrSelectTheme(
adminSession: AdminSession,
flags: ThemeSelectionOptions,
): Promise<Theme | undefined> {
export async function createOrSelectTheme(adminSession: AdminSession, flags: PushFlags): Promise<Theme | undefined> {
const {live, development, unpublished, theme} = flags

if (development) {
const themeManager = new DevelopmentThemeManager(adminSession)
return themeManager.findOrCreate()
} else if (unpublished) {
const themeName = theme || (await promptThemeName('Name of the new theme'))
const themeName = theme ?? (await promptThemeName('Name of the new theme'))
return createTheme(
{
name: themeName,
Expand All @@ -319,7 +308,7 @@ export async function createOrSelectTheme(
},
})

if (await confirmPushToTheme(selectedTheme.role as Role, flags['allow-live'], adminSession.storeFqdn)) {
if (await confirmPushToTheme(selectedTheme.role as Role, flags.allowLive, adminSession.storeFqdn)) {
return selectedTheme
}
}
Expand Down

0 comments on commit e15b615

Please sign in to comment.