Skip to content

Commit 1ee6a38

Browse files
committed
Update theme delete command for multi-environment
Previously `theme delete` command could only be run in a single environment at a time. This commit allows `delete`to be run in multiple environments in a single command run
1 parent 84a7b10 commit 1ee6a38

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

.changeset/silver-worms-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/theme': minor
3+
---
4+
5+
Allow theme delete command to be called with multiple environments

packages/cli/oclif.manifest.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5291,10 +5291,18 @@
52915291
"hiddenAliases": [
52925292
],
52935293
"id": "theme:delete",
5294+
"multiEnvironmentsFlags": [
5295+
"store",
5296+
"password",
5297+
[
5298+
"development",
5299+
"theme"
5300+
]
5301+
],
52945302
"pluginAlias": "@shopify/cli",
52955303
"pluginName": "@shopify/cli",
52965304
"pluginType": "core",
5297-
"strict": false,
5305+
"strict": true,
52985306
"summary": "Delete remote themes from the connected store. This command can't be undone."
52995307
},
53005308
"theme:dev": {

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +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 {themesDelete} from '../../services/delete.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'
88

9+
type DeleteFlags = OutputFlags<typeof Delete.flags>
910
export default class Delete extends ThemeCommand {
1011
static summary = "Delete remote themes from the connected store. This command can't be undone."
1112

@@ -43,19 +44,22 @@ export default class Delete extends ThemeCommand {
4344
}),
4445
}
4546

46-
async run(): Promise<void> {
47-
const {flags} = await this.parse(Delete)
48-
const {development, force, password, theme} = flags
49-
const themes = [...(theme ?? [])]
47+
static multiEnvironmentsFlags = ['store', 'password', ['development', 'theme']]
5048

51-
const store = ensureThemeStore(flags)
52-
const adminSession = await ensureAuthenticatedThemes(store, password)
49+
async command(flags: DeleteFlags, adminSession: AdminSession, multiEnvironment: boolean) {
50+
const {environment, development, force, theme} = flags
51+
const themes = theme ?? []
5352

54-
await themesDelete(adminSession, {
55-
selectTheme: flags['show-all'],
56-
development,
57-
themes,
58-
force,
59-
})
53+
await themesDelete(
54+
adminSession,
55+
{
56+
selectTheme: flags['show-all'],
57+
environment,
58+
development,
59+
themes,
60+
force,
61+
},
62+
multiEnvironment,
63+
)
6064
}
6165
}

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ import {isDevelopmentTheme} from '@shopify/cli-kit/node/themes/utils'
1717

1818
interface DeleteOptions {
1919
selectTheme: boolean
20+
environment?: string[]
2021
development: boolean
2122
force: boolean
2223
themes: string[]
2324
}
2425

25-
export async function themesDelete(adminSession: AdminSession, options: DeleteOptions) {
26+
export async function themesDelete(adminSession: AdminSession, options: DeleteOptions, multiEnvironment?: boolean) {
2627
let themeIds = options.themes
2728
if (options.development) {
2829
const theme = await new DevelopmentThemeManager(adminSession).find()
@@ -32,7 +33,7 @@ export async function themesDelete(adminSession: AdminSession, options: DeleteOp
3233
const store = adminSession.storeFqdn
3334
const themes = await findThemesByDeleteOptions(adminSession, {...options, themes: themeIds, development: false})
3435

35-
if (!options.force && !(await isConfirmed(themes, store))) {
36+
if (!options.force && !multiEnvironment && !(await isConfirmed(themes, store))) {
3637
return
3738
}
3839

@@ -45,11 +46,13 @@ export async function themesDelete(adminSession: AdminSession, options: DeleteOp
4546
}),
4647
)
4748

49+
const environment = options.environment ? [{subdued: `Environment: ${options.environment}\n\n`}] : []
50+
4851
renderSuccess({
4952
body: pluralize(
5053
themes,
51-
(themes) => [`The following themes were deleted from ${store}:`, themesComponent(themes)],
52-
(theme) => ['The theme', ...themeComponent(theme), `was deleted from ${store}.`],
54+
(themes) => [...environment, `The following themes were deleted from ${store}:`, themesComponent(themes)],
55+
(theme) => [...environment, 'The theme', ...themeComponent(theme), `was deleted from ${store}.`],
5356
),
5457
})
5558
}

0 commit comments

Comments
 (0)