Skip to content

Commit 9574ca8

Browse files
committed
Allow publish command to work with multiple environments
This commit uses the command function to pass multiple environments to the publish command.
1 parent 1028a88 commit 9574ca8

File tree

5 files changed

+41
-22
lines changed

5 files changed

+41
-22
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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6338,6 +6338,11 @@
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",

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

Lines changed: 15 additions & 11 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'
43
import {publish, renderArgumentsWarning} 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.'
@@ -37,16 +39,18 @@ If you want to publish your local theme, then you need to run \`shopify theme pu
3739
}),
3840
}
3941

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]
42+
static multiEnvironmentsFlags = ['store', 'password', 'theme']
4543

46-
if (argv.length > 0 && typeof argv[0] === 'string') {
47-
renderArgumentsWarning(argv[0])
48-
}
44+
async command(flags: PublishFlags, adminSession: AdminSession) {
45+
// Deprecated use of passing the theme id as an argument
46+
// ex: `shopify theme publish <themeid>`
47+
const positionalArgValue =
48+
this.argv && this.argv.length > 0 && typeof this.argv[0] === 'string' ? this.argv[0] : undefined
4949

50-
await publish(adminSession, themeId, flags)
50+
if (!flags.theme && positionalArgValue) {
51+
flags.theme = positionalArgValue
52+
renderArgumentsWarning(positionalArgValue)
53+
}
54+
await publish(adminSession, flags)
5155
}
5256
}

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: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,38 @@ export function renderArgumentsWarning(id: string) {
1818
})
1919
}
2020

21-
export async function publish(adminSession: AdminSession, themeId: string | undefined, options: {force: boolean}) {
22-
const theme = await findOrSelectTheme(adminSession, {
21+
interface PublishServiceOptions {
22+
theme: string | undefined
23+
force: boolean
24+
}
25+
26+
export async function publish(adminSession: AdminSession, options: PublishServiceOptions) {
27+
const themeToPublish = await findOrSelectTheme(adminSession, {
2328
header: 'Select a theme to publish',
2429
filter: {
2530
development: false,
2631
live: false,
27-
theme: themeId,
32+
theme: options.theme,
2833
},
2934
})
3035

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

3338
if (!options.force) {
3439
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`,
40+
message: `Do you want to make '${themeToPublish.name}' the new live theme on ${adminSession.storeFqdn}?`,
41+
confirmationMessage: `Yes, make '${themeToPublish.name}' the new live theme`,
3742
cancellationMessage: 'No, cancel publish',
3843
})
3944
if (!accept) return
4045
}
4146

42-
await themePublish(theme.id, adminSession)
47+
await themePublish(themeToPublish.id, adminSession)
4348

4449
renderSuccess({
4550
body: [
4651
'The theme',
47-
...themeComponent(theme),
52+
...themeComponent(themeToPublish),
4853
'is now live at',
4954
{
5055
link: {

0 commit comments

Comments
 (0)