Skip to content

Commit 32126d9

Browse files
authored
Merge pull request #5874 from Shopify/publish-command-multi-env
Allow publish command to work with multiple environments
2 parents 1028a88 + 5773c84 commit 32126d9

File tree

5 files changed

+37
-40
lines changed

5 files changed

+37
-40
lines changed

.changeset/hot-fishes-develop.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+
Allow publish command to be called with multiple environments

packages/cli/oclif.manifest.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6338,10 +6338,15 @@
63386338
"hiddenAliases": [
63396339
],
63406340
"id": "theme:publish",
6341+
"multiEnvironmentsFlags": [
6342+
"store",
6343+
"password",
6344+
"theme"
6345+
],
63416346
"pluginAlias": "@shopify/cli",
63426347
"pluginName": "@shopify/cli",
63436348
"pluginType": "core",
6344-
"strict": false,
6349+
"strict": true,
63456350
"summary": "Set a remote theme as the live theme."
63466351
},
63476352
"theme:pull": {
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import {ensureThemeStore} from '../../utilities/theme-store.js'
21
import ThemeCommand from '../../utilities/theme-command.js'
32
import {themeFlags} from '../../flags.js'
4-
import {publish, renderArgumentsWarning} from '../../services/publish.js'
3+
import {publish} from '../../services/publish.js'
54
import {Flags} from '@oclif/core'
65
import {globalFlags} from '@shopify/cli-kit/node/cli'
7-
import {ensureAuthenticatedThemes} from '@shopify/cli-kit/node/session'
6+
import {OutputFlags} from '@oclif/core/interfaces'
7+
import {AdminSession} from '@shopify/cli-kit/node/session'
8+
9+
type PublishFlags = OutputFlags<typeof Publish.flags>
810

911
export default class Publish extends ThemeCommand {
1012
static summary = 'Set a remote theme as the live theme.'
@@ -19,9 +21,6 @@ If you want to publish your local theme, then you need to run \`shopify theme pu
1921

2022
static description = this.descriptionWithoutMarkdown()
2123

22-
// Accept any number of args without naming them
23-
static strict = false
24-
2524
static flags = {
2625
...globalFlags,
2726
...themeFlags,
@@ -37,16 +36,9 @@ If you want to publish your local theme, then you need to run \`shopify theme pu
3736
}),
3837
}
3938

40-
async run(): Promise<void> {
41-
const {flags, argv} = await this.parse(Publish)
42-
const store = await ensureThemeStore(flags)
43-
const adminSession = await ensureAuthenticatedThemes(store, flags.password)
44-
const themeId = flags.theme || argv[0]
45-
46-
if (argv.length > 0 && typeof argv[0] === 'string') {
47-
renderArgumentsWarning(argv[0])
48-
}
39+
static multiEnvironmentsFlags = ['store', 'password', 'theme']
4940

50-
await publish(adminSession, themeId, flags)
41+
async command(flags: PublishFlags, adminSession: AdminSession, multiEnvironment?: boolean) {
42+
await publish(adminSession, flags, multiEnvironment)
5143
}
5244
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('publish', () => {
3333
vi.mocked(renderConfirmationPrompt).mockResolvedValue(true)
3434

3535
// When
36-
await publish(session, '1', options)
36+
await publish(session, options)
3737

3838
// Then
3939
expect(renderConfirmationPrompt).toBeCalledWith({
@@ -66,7 +66,7 @@ describe('publish', () => {
6666
vi.mocked(renderConfirmationPrompt).mockResolvedValue(false)
6767

6868
// When
69-
await publish(session, '1', options)
69+
await publish(session, options)
7070

7171
// Then
7272
expect(renderConfirmationPrompt).toBeCalledWith({
@@ -84,7 +84,7 @@ describe('publish', () => {
8484
vi.mocked(renderConfirmationPrompt).mockResolvedValue(false)
8585

8686
// When
87-
await publish(session, '1', {...options, force: true})
87+
await publish(session, {...options, force: true})
8888

8989
// Then
9090
expect(renderConfirmationPrompt).not.toBeCalled()

packages/theme/src/cli/services/publish.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,43 @@ import {themeComponent} from '../utilities/theme-ui.js'
33
import {themePublish} from '@shopify/cli-kit/node/themes/api'
44
import {themePreviewUrl} from '@shopify/cli-kit/node/themes/urls'
55
import {Theme} from '@shopify/cli-kit/node/themes/types'
6-
import {renderConfirmationPrompt, renderSuccess, renderWarning} from '@shopify/cli-kit/node/ui'
6+
import {renderConfirmationPrompt, renderSuccess} from '@shopify/cli-kit/node/ui'
77
import {AdminSession} from '@shopify/cli-kit/node/session'
88

9-
export function renderArgumentsWarning(id: string) {
10-
renderWarning({
11-
body: [
12-
'The theme ID positional argument is deprecated. Use the',
13-
{command: '--theme'},
14-
'flag instead:\n\n',
15-
{command: `$ shopify theme publish --theme ${id}`},
16-
{char: '.'},
17-
],
18-
})
9+
interface PublishServiceOptions {
10+
theme: string | undefined
11+
force: boolean
12+
environment?: string
1913
}
2014

21-
export async function publish(adminSession: AdminSession, themeId: string | undefined, options: {force: boolean}) {
22-
const theme = await findOrSelectTheme(adminSession, {
15+
export async function publish(adminSession: AdminSession, options: PublishServiceOptions, multiEnvironment?: boolean) {
16+
const themeToPublish = await findOrSelectTheme(adminSession, {
2317
header: 'Select a theme to publish',
2418
filter: {
2519
development: false,
2620
live: false,
27-
theme: themeId,
21+
theme: options.theme,
2822
},
2923
})
3024

31-
const previewUrl = themePreviewUrl({...theme, role: 'live'} as Theme, adminSession)
25+
const previewUrl = themePreviewUrl({...themeToPublish, role: 'live'} as Theme, adminSession)
3226

33-
if (!options.force) {
27+
if (!options.force && !multiEnvironment) {
3428
const accept = await renderConfirmationPrompt({
35-
message: `Do you want to make '${theme.name}' the new live theme on ${adminSession.storeFqdn}?`,
36-
confirmationMessage: `Yes, make '${theme.name}' the new live theme`,
29+
message: `Do you want to make '${themeToPublish.name}' the new live theme on ${adminSession.storeFqdn}?`,
30+
confirmationMessage: `Yes, make '${themeToPublish.name}' the new live theme`,
3731
cancellationMessage: 'No, cancel publish',
3832
})
3933
if (!accept) return
4034
}
4135

42-
await themePublish(theme.id, adminSession)
36+
await themePublish(themeToPublish.id, adminSession)
4337

4438
renderSuccess({
39+
headline: options.environment ? `Environment: ${options.environment}` : undefined,
4540
body: [
4641
'The theme',
47-
...themeComponent(theme),
42+
...themeComponent(themeToPublish),
4843
'is now live at',
4944
{
5045
link: {

0 commit comments

Comments
 (0)