Skip to content

Commit 070e0fa

Browse files
committed
fix missing json output for theme info command when dev and theme flags are missing
1 parent 4d26220 commit 070e0fa

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

.changeset/silver-clouds-smell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/cli': patch
3+
---
4+
5+
fix missing json output for theme info when no theme or dev flag is present

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {themeFlags} from '../../flags.js'
2-
import {fetchThemeInfo, fetchDevInfo, formatThemeInfo} from '../../services/info.js'
2+
import {fetchThemeInfo, fetchDevInfo, formatThemeInfo, devInfoJSON} from '../../services/info.js'
33
import ThemeCommand from '../../utilities/theme-command.js'
44
import {Flags} from '@oclif/core'
55
import {AdminSession} from '@shopify/cli-kit/node/session'
@@ -50,6 +50,9 @@ export default class Info extends ThemeCommand {
5050
renderInfo(formattedInfo)
5151
} else {
5252
const infoMessage = await fetchDevInfo({cliVersion: this.config.version})
53+
if (flags.json) {
54+
return outputResult(JSON.stringify(devInfoJSON({cliVersion: this.config.version}), null, 2))
55+
}
5356
renderInfo({customSections: infoMessage})
5457
}
5558
recordTiming('theme-command:info')

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import {themeInfoJSON, fetchThemeInfo} from './info.js'
1+
import {themeInfoJSON, fetchThemeInfo, devInfoJSON} from './info.js'
2+
import {getDevelopmentTheme, getThemeStore} from './local-storage.js'
23
import {findOrSelectTheme} from '../utilities/theme-selector.js'
34
import {DevelopmentThemeManager} from '../utilities/development-theme-manager.js'
45
import {themePreviewUrl, themeEditorUrl} from '@shopify/cli-kit/node/themes/urls'
56
import {Theme} from '@shopify/cli-kit/node/themes/types'
67
import {describe, vi, test, expect} from 'vitest'
78

9+
vi.mock('./local-storage.js')
810
vi.mock('../utilities/development-theme-manager.js')
911
vi.mock('../utilities/theme-selector.js', () => {
1012
return {findOrSelectTheme: vi.fn()}
@@ -47,6 +49,23 @@ describe('info', () => {
4749
expect(output).toHaveProperty('theme.editor_url', expect.stringContaining(session.storeFqdn))
4850
})
4951

52+
test('generate dev info JSON when no theme or dev flag provided', () => {
53+
// Given
54+
vi.mocked(getThemeStore).mockReturnValue('my-shop.myshopify.com')
55+
vi.mocked(getDevelopmentTheme).mockReturnValue(undefined)
56+
57+
// When
58+
const output = devInfoJSON({cliVersion: '3.91.0'})
59+
60+
// Then
61+
expect(output).toHaveProperty('store', 'my-shop.myshopify.com')
62+
expect(output).toHaveProperty('development_theme_id', null)
63+
expect(output).toHaveProperty('cli_version', '3.91.0')
64+
expect(output).toHaveProperty('os', expect.stringContaining('-'))
65+
expect(output).toHaveProperty('shell', process.env.SHELL ?? 'unknown')
66+
expect(output).toHaveProperty('node_version', process.version)
67+
})
68+
5069
test('fetch theme info by id', async () => {
5170
// Given
5271
vi.mocked(findOrSelectTheme).mockResolvedValue(theme)

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ interface ThemeInfoOptions {
2828
json?: boolean
2929
}
3030

31+
interface DevInfo {
32+
store: string
33+
development_theme_id: string | null
34+
cli_version: string
35+
os: string
36+
shell: string
37+
node_version: string
38+
}
39+
3140
export function themeInfoJSON(theme: Theme, adminSession: AdminSession): ThemeInfo {
3241
return {
3342
theme: {
@@ -41,6 +50,18 @@ export function themeInfoJSON(theme: Theme, adminSession: AdminSession): ThemeIn
4150
}
4251
}
4352

53+
export function devInfoJSON(config: {cliVersion: string}): DevInfo {
54+
const {platform, arch} = platformAndArch()
55+
return {
56+
store: getThemeStore() ?? 'Not configured',
57+
development_theme_id: getDevelopmentTheme() ?? null,
58+
cli_version: config.cliVersion,
59+
os: `${platform}-${arch}`,
60+
shell: process.env.SHELL ?? 'unknown',
61+
node_version: process.version,
62+
}
63+
}
64+
4465
export async function fetchThemeInfo(
4566
adminSession: AdminSession,
4667
options: ThemeInfoOptions,

0 commit comments

Comments
 (0)