Skip to content

Commit 265b8fb

Browse files
authored
Merge pull request #6193 from Shopify/jb-multi-env-delete
Allow theme delete command to be called with multiple environments
2 parents 455946c + 1ee6a38 commit 265b8fb

File tree

6 files changed

+47
-63
lines changed

6 files changed

+47
-63
lines changed

.changeset/early-cobras-worry.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+
Remove deprecated positional arguments from theme delete command

.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": {
Lines changed: 19 additions & 23 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'
4-
import {themesDelete, renderDeprecatedArgsWarning} from '../../services/delete.js'
3+
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

@@ -17,9 +18,6 @@ export default class Delete extends ThemeCommand {
1718

1819
static description = this.descriptionWithoutMarkdown()
1920

20-
// Accept any number of args without naming them
21-
static strict = false
22-
2321
static flags = {
2422
...globalFlags,
2523
...themeFlags,
@@ -46,24 +44,22 @@ export default class Delete extends ThemeCommand {
4644
}),
4745
}
4846

49-
async run(): Promise<void> {
50-
const {flags, argv} = await this.parse(Delete)
51-
const {development, force, password, theme} = flags
52-
const themes = [...argv, ...(theme ?? [])]
53-
54-
const store = ensureThemeStore(flags)
55-
const adminSession = await ensureAuthenticatedThemes(store, password)
47+
static multiEnvironmentsFlags = ['store', 'password', ['development', 'theme']]
5648

57-
const hasDeprecatedArgs = argv.length > 0
58-
if (hasDeprecatedArgs) {
59-
renderDeprecatedArgsWarning(argv)
60-
}
49+
async command(flags: DeleteFlags, adminSession: AdminSession, multiEnvironment: boolean) {
50+
const {environment, development, force, theme} = flags
51+
const themes = theme ?? []
6152

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

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {themesDelete, renderDeprecatedArgsWarning} from './delete.js'
1+
import {themesDelete} from './delete.js'
22
import {findOrSelectTheme, findThemes} from '../utilities/theme-selector.js'
33
import {themeDelete} from '@shopify/cli-kit/node/themes/api'
44
import {Theme} from '@shopify/cli-kit/node/themes/types'
55
import {test, describe, expect, vi} from 'vitest'
6-
import {renderConfirmationPrompt, renderSuccess, renderWarning} from '@shopify/cli-kit/node/ui'
6+
import {renderConfirmationPrompt, renderSuccess} from '@shopify/cli-kit/node/ui'
77

88
vi.mock('@shopify/cli-kit/node/ui')
99
vi.mock('@shopify/cli-kit/node/themes/api')
@@ -142,21 +142,3 @@ describe('themesDelete', () => {
142142
expect(renderSuccess).not.toBeCalled()
143143
})
144144
})
145-
146-
describe('renderDeprecatedArgsWarning', () => {
147-
test('renders the the deprecated-args warning message', async () => {
148-
// Given/When
149-
renderDeprecatedArgsWarning(['1', '2'])
150-
151-
// Then
152-
expect(renderWarning).toBeCalledWith({
153-
body: [
154-
'Positional arguments are deprecated. Use the',
155-
{command: '--theme'},
156-
'flag instead:\n\n',
157-
{command: `$ shopify theme delete --theme 1 2`},
158-
{char: '.'},
159-
],
160-
})
161-
})
162-
})

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
renderConfirmationPrompt,
99
RenderConfirmationPromptOptions,
1010
renderSuccess,
11-
renderWarning,
1211
InlineToken,
1312
LinkToken,
1413
} from '@shopify/cli-kit/node/ui'
@@ -18,12 +17,13 @@ import {isDevelopmentTheme} from '@shopify/cli-kit/node/themes/utils'
1817

1918
interface DeleteOptions {
2019
selectTheme: boolean
20+
environment?: string[]
2121
development: boolean
2222
force: boolean
2323
themes: string[]
2424
}
2525

26-
export async function themesDelete(adminSession: AdminSession, options: DeleteOptions) {
26+
export async function themesDelete(adminSession: AdminSession, options: DeleteOptions, multiEnvironment?: boolean) {
2727
let themeIds = options.themes
2828
if (options.development) {
2929
const theme = await new DevelopmentThemeManager(adminSession).find()
@@ -33,7 +33,7 @@ export async function themesDelete(adminSession: AdminSession, options: DeleteOp
3333
const store = adminSession.storeFqdn
3434
const themes = await findThemesByDeleteOptions(adminSession, {...options, themes: themeIds, development: false})
3535

36-
if (!options.force && !(await isConfirmed(themes, store))) {
36+
if (!options.force && !multiEnvironment && !(await isConfirmed(themes, store))) {
3737
return
3838
}
3939

@@ -46,11 +46,13 @@ export async function themesDelete(adminSession: AdminSession, options: DeleteOp
4646
}),
4747
)
4848

49+
const environment = options.environment ? [{subdued: `Environment: ${options.environment}\n\n`}] : []
50+
4951
renderSuccess({
5052
body: pluralize(
5153
themes,
52-
(themes) => [`The following themes were deleted from ${store}:`, themesComponent(themes)],
53-
(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}.`],
5456
),
5557
})
5658
}
@@ -88,17 +90,3 @@ async function isConfirmed(themes: Theme[], store: string) {
8890

8991
return renderConfirmationPrompt(options)
9092
}
91-
92-
export function renderDeprecatedArgsWarning(argv: string[]) {
93-
const ids = argv.join(' ')
94-
95-
renderWarning({
96-
body: [
97-
'Positional arguments are deprecated. Use the',
98-
{command: '--theme'},
99-
'flag instead:\n\n',
100-
{command: `$ shopify theme delete --theme ${ids}`},
101-
{char: '.'},
102-
],
103-
})
104-
}

0 commit comments

Comments
 (0)