Skip to content

Commit 2375b66

Browse files
committed
Refactor dev command to use ThemeCommand's run method
Previously `theme dev` command implemented its own `run` logic. This commit refactors `dev` to use ThemeCommand's base `run()` method. This will help to standardize command architecture and allow for out of the box authentication and environments support
1 parent 92495a6 commit 2375b66

File tree

1 file changed

+16
-17
lines changed
  • packages/theme/src/cli/commands/theme

1 file changed

+16
-17
lines changed

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {themeFlags} from '../../flags.js'
2-
import {ensureThemeStore} from '../../utilities/theme-store.js'
3-
import ThemeCommand, {FlagValues} from '../../utilities/theme-command.js'
2+
import ThemeCommand, {RequiredFlags} from '../../utilities/theme-command.js'
43
import {dev} from '../../services/dev.js'
54
import {DevelopmentThemeManager} from '../../utilities/development-theme-manager.js'
65
import {findOrSelectTheme} from '../../utilities/theme-selector.js'
@@ -10,10 +9,13 @@ import {validateThemePassword} from '../../services/flags-validation.js'
109
import {Flags} from '@oclif/core'
1110
import {globalFlags} from '@shopify/cli-kit/node/cli'
1211
import {Theme} from '@shopify/cli-kit/node/themes/types'
13-
import {ensureAuthenticatedThemes} from '@shopify/cli-kit/node/session'
1412
import {recordEvent} from '@shopify/cli-kit/node/analytics'
13+
import {AdminSession} from '@shopify/cli-kit/node/session'
14+
import {InferredFlags} from '@oclif/core/interfaces'
1515
import type {ErrorOverlayMode, LiveReload} from '../../utilities/theme-environment/types.js'
1616

17+
type DevFlags = InferredFlags<typeof Dev.flags>
18+
1719
export default class Dev extends ThemeCommand {
1820
static summary =
1921
'Uploads the current theme as a development theme to the connected store, then prints theme editor and preview URLs to your terminal. While running, changes will push to the store in real time.'
@@ -124,30 +126,27 @@ You can run this command only in a directory that matches the [default Shopify t
124126
}),
125127
}
126128

127-
async run(): Promise<void> {
128-
const parsed = await this.parse(Dev)
129-
let flags = parsed.flags as typeof parsed.flags & FlagValues
130-
const {ignore = [], only = []} = flags
131-
132-
validateThemePassword(flags.password)
129+
static multiEnvironmentsFlags: RequiredFlags = null
133130

134-
const store = ensureThemeStore(flags)
135-
const adminSession = await ensureAuthenticatedThemes(store, flags.password)
131+
async command(devFlags: DevFlags, adminSession: AdminSession) {
132+
const {ignore = [], only = []} = devFlags
136133

134+
validateThemePassword(devFlags.password)
137135
recordEvent('theme-command:dev:single-env:authenticated')
138136

139137
let theme: Theme
138+
let flags
140139

141-
if (flags.theme) {
142-
const filter = {filter: {theme: flags.theme}}
140+
if (devFlags.theme) {
141+
const filter = {filter: {theme: devFlags.theme}}
143142
theme = await findOrSelectTheme(adminSession, filter)
144143

145-
flags = {...flags, theme: theme.id.toString()}
144+
flags = {...devFlags, theme: theme.id.toString(), store: adminSession.storeFqdn}
146145
} else {
147146
theme = await new DevelopmentThemeManager(adminSession).findOrCreate()
148-
const overwriteJson = flags['theme-editor-sync'] && theme.createdAtRuntime
147+
const overwriteJson = devFlags['theme-editor-sync'] && theme.createdAtRuntime
149148

150-
flags = {...flags, theme: theme.id.toString(), 'overwrite-json': overwriteJson}
149+
flags = {...devFlags, theme: theme.id.toString(), store: adminSession.storeFqdn, 'overwrite-json': overwriteJson}
151150
}
152151

153152
const confirmed = await ensureLiveThemeConfirmed(theme, 'start development mode')
@@ -158,7 +157,7 @@ You can run this command only in a directory that matches the [default Shopify t
158157
await dev({
159158
adminSession,
160159
directory: flags.path,
161-
store,
160+
store: flags.store,
162161
password: flags.password,
163162
storePassword: flags['store-password'],
164163
theme,

0 commit comments

Comments
 (0)