Skip to content

Commit 281b50b

Browse files
committed
Update theme rename command for multi-environment
Previously `theme rename` command could only be in in a single environment at a time. This commit allows `rename` to be run in multiple environments in a single command run.
1 parent a12a7cc commit 281b50b

File tree

5 files changed

+45
-31
lines changed

5 files changed

+45
-31
lines changed

.changeset/great-dragons-float.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+
Allow theme rename command to be run with multiple environments

packages/cli/oclif.manifest.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6762,6 +6762,16 @@
67626762
"hiddenAliases": [
67636763
],
67646764
"id": "theme:rename",
6765+
"multiEnvironmentsFlags": [
6766+
"store",
6767+
"password",
6768+
"name",
6769+
[
6770+
"live",
6771+
"development",
6772+
"theme"
6773+
]
6774+
],
67656775
"pluginAlias": "@shopify/cli",
67666776
"pluginName": "@shopify/cli",
67676777
"pluginType": "core",

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

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import ThemeCommand from '../../utilities/theme-command.js'
2-
import {RenameOptions, renameTheme} from '../../services/rename.js'
3-
import {ensureThemeStore} from '../../utilities/theme-store.js'
1+
import ThemeCommand, {RequiredFlags} from '../../utilities/theme-command.js'
42
import {themeFlags} from '../../flags.js'
3+
import {RenameOptions, renameTheme} from '../../services/rename.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'
8-
import {promptThemeName} from '@shopify/cli-kit/node/themes/utils'
6+
import {AdminSession} from '@shopify/cli-kit/node/session'
97

108
export default class Rename extends ThemeCommand {
119
static summary = 'Renames an existing theme.'
@@ -43,21 +41,9 @@ export default class Rename extends ThemeCommand {
4341
}),
4442
}
4543

46-
public async run(): Promise<void> {
47-
const {flags} = await this.parse(Rename)
48-
const {password, development, name, theme, live} = flags
49-
50-
const store = ensureThemeStore(flags)
51-
const adminSession = await ensureAuthenticatedThemes(store, password)
52-
const newName = name || (await promptThemeName('New name for the theme'))
53-
54-
const renameOptions: RenameOptions = {
55-
newName,
56-
development,
57-
theme,
58-
live,
59-
}
44+
static multiEnvironmentsFlags: RequiredFlags = ['store', 'password', 'name', ['live', 'development', 'theme']]
6045

61-
await renameTheme(adminSession, renameOptions)
46+
async command(flags: RenameOptions, adminSession: AdminSession) {
47+
await renameTheme(flags, adminSession)
6248
}
6349
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const developmentTheme = {
2323

2424
const options: RenameOptions = {
2525
development: false,
26-
newName: 'Renamed Theme',
26+
name: 'Renamed Theme',
2727
live: false,
2828
}
2929

@@ -33,10 +33,10 @@ describe('renameTheme', () => {
3333
vi.mocked(findOrSelectTheme).mockResolvedValue(developmentTheme)
3434

3535
// When
36-
await renameTheme(adminSession, {...options, development: true})
36+
await renameTheme({...options, development: true}, adminSession)
3737

3838
// Then
39-
expect(themeUpdate).toBeCalledWith(developmentTheme.id, {name: options.newName}, adminSession)
39+
expect(themeUpdate).toBeCalledWith(developmentTheme.id, {name: options.name}, adminSession)
4040
expect(renderSuccess).toBeCalledWith({
4141
body: ['The theme', "'my development theme'", {subdued: '(#1)'}, 'was renamed to', "'Renamed Theme'"],
4242
})
@@ -52,10 +52,10 @@ describe('renameTheme', () => {
5252
vi.mocked(findOrSelectTheme).mockResolvedValue(theme1)
5353

5454
// When
55-
await renameTheme(adminSession, {...options, theme: '2'})
55+
await renameTheme({...options, theme: '2'}, adminSession)
5656

5757
// Then
58-
expect(themeUpdate).toBeCalledWith(theme1.id, {name: options.newName}, adminSession)
58+
expect(themeUpdate).toBeCalledWith(theme1.id, {name: options.name}, adminSession)
5959
expect(renderSuccess).toBeCalledWith({
6060
body: ['The theme', "'my theme'", {subdued: '(#2)'}, 'was renamed to', "'Renamed Theme'"],
6161
})
@@ -71,10 +71,10 @@ describe('renameTheme', () => {
7171
vi.mocked(findOrSelectTheme).mockResolvedValue(theme1)
7272

7373
// When
74-
await renameTheme(adminSession, {...options, live: true})
74+
await renameTheme({...options, live: true}, adminSession)
7575

7676
// Then
77-
expect(themeUpdate).toBeCalledWith(theme1.id, {name: options.newName}, adminSession)
77+
expect(themeUpdate).toBeCalledWith(theme1.id, {name: options.name}, adminSession)
7878
expect(renderSuccess).toBeCalledWith({
7979
body: ['The theme', "'live theme'", {subdued: '(#2)'}, 'was renamed to', "'Renamed Theme'"],
8080
})

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ import {themeComponent} from '../utilities/theme-ui.js'
33
import {themeUpdate} from '@shopify/cli-kit/node/themes/api'
44
import {AdminSession} from '@shopify/cli-kit/node/session'
55
import {renderSuccess} from '@shopify/cli-kit/node/ui'
6+
import {promptThemeName} from '@shopify/cli-kit/node/themes/utils'
67

78
export interface RenameOptions {
8-
newName: string
9+
name?: string
910
development?: boolean
1011
theme?: string
1112
live?: boolean
13+
environment?: string
1214
}
1315

14-
export async function renameTheme(adminSession: AdminSession, options: RenameOptions) {
16+
export async function renameTheme(options: RenameOptions, adminSession: AdminSession) {
17+
const newName = options.name || (await promptThemeName('New name for the theme'))
18+
1519
const theme = await findOrSelectTheme(adminSession, {
1620
header: 'Select a theme to rename',
1721
filter: {
@@ -20,8 +24,16 @@ export async function renameTheme(adminSession: AdminSession, options: RenameOpt
2024
live: options.live,
2125
},
2226
})
23-
await themeUpdate(theme.id, {name: options.newName}, adminSession)
27+
28+
await themeUpdate(theme.id, {name: newName}, adminSession)
29+
2430
renderSuccess({
25-
body: ['The theme', ...themeComponent(theme), 'was renamed to', `'${options.newName}'`],
31+
body: [
32+
...(options.environment ? [{subdued: `Environment: ${options.environment}\n\n`}] : []),
33+
'The theme',
34+
...themeComponent(theme),
35+
'was renamed to',
36+
`'${newName}'`,
37+
],
2638
})
2739
}

0 commit comments

Comments
 (0)