Skip to content

Commit cf6bd6d

Browse files
committed
Document theme info JSON schema
Assisted-By: devx/9dd3b67e-58e9-4a01-a721-43265d02ccd2
1 parent 0c6843a commit cf6bd6d

6 files changed

Lines changed: 55 additions & 21 deletions

File tree

‎packages/cli/README.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4922,6 +4922,38 @@ FLAGS
49224922
DESCRIPTION
49234923
Displays information about your theme environment, including your current store. Can also retrieve information about a
49244924
specific theme.
4925+
4926+
Use `--json` for machine-readable output.
4927+
4928+
Output from `--json` conforms to the `ThemeInfoResult` schema.
4929+
4930+
Use `--json-schema` to print the schema directly:
4931+
4932+
```ts
4933+
type ThemeInfoResult = ThemeInfoThemeResult | ThemeEnvironmentInfo
4934+
4935+
interface ThemeInfoTheme {
4936+
id: number
4937+
name: string
4938+
role: string
4939+
shop: string
4940+
preview_url: string
4941+
editor_url: string
4942+
}
4943+
4944+
interface ThemeInfoThemeResult {
4945+
theme: ThemeInfoTheme
4946+
}
4947+
4948+
interface ThemeEnvironmentInfo {
4949+
store: string
4950+
development_theme_id: number | null
4951+
cli_version: string
4952+
os: string
4953+
shell: string
4954+
node_version: string
4955+
}
4956+
```
49254957
```
49264958
49274959
## `shopify theme init [name] [flags]`

‎packages/cli/oclif.manifest.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9797,7 +9797,8 @@
97979797
"args": {
97989798
},
97999799
"customPluginName": "@shopify/theme",
9800-
"description": "Displays information about your theme environment, including your current store. Can also retrieve information about a specific theme.",
9800+
"description": "Displays information about your theme environment, including your current store. Can also retrieve information about a specific theme.\n\nUse `--json` for machine-readable output.\n\nOutput from `--json` conforms to the `ThemeInfoResult` schema.\n\nUse `--json-schema` to print the schema directly:\n\n```ts\ntype ThemeInfoResult = ThemeInfoThemeResult | ThemeEnvironmentInfo\n\ninterface ThemeInfoTheme {\n id: number\n name: string\n role: string\n shop: string\n preview_url: string\n editor_url: string\n}\n\ninterface ThemeInfoThemeResult {\n theme: ThemeInfoTheme\n}\n\ninterface ThemeEnvironmentInfo {\n store: string\n development_theme_id: number | null\n cli_version: string\n os: string\n shell: string\n node_version: string\n}\n```",
9801+
"descriptionWithMarkdown": "Displays information about your theme environment, including your current store. Can also retrieve information about a specific theme.\n\nUse `--json` for machine-readable output.",
98019802
"enableJsonFlag": false,
98029803
"flags": {
98039804
"auth-alias": {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ describe('Info', () => {
134134
expect(Info.jsonOutputSchema).toBe(themeInfoJsonOutputSchema)
135135
})
136136

137+
test('includes the JSON output schema in the help description', () => {
138+
expect(Info.description).toContain('ThemeInfoResult')
139+
expect(Info.description).toContain('--json-schema')
140+
})
141+
137142
test('is removed from the JSON legacy exemption list', () => {
138143
const legacyCommandPaths = readFileSync(
139144
new URL('../../../../../eslint-plugin-cli/rules/json-output-legacy-command-paths.js', import.meta.url),

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@ import {recordTiming} from '@shopify/cli-kit/node/analytics'
1313
type InfoFlags = OutputFlags<typeof Info.flags>
1414

1515
export default class Info extends ThemeCommand {
16-
static description =
17-
'Displays information about your theme environment, including your current store. Can also retrieve information about a specific theme.'
16+
static get jsonOutputSchema() {
17+
return themeInfoJsonOutputSchema
18+
}
19+
20+
static descriptionWithMarkdown = `Displays information about your theme environment, including your current store. Can also retrieve information about a specific theme.
21+
22+
Use \`--json\` for machine-readable output.`
23+
24+
static description = this.descriptionForHelp()
1825

1926
static flags = {
2027
...globalFlags,
@@ -34,10 +41,6 @@ export default class Info extends ThemeCommand {
3441

3542
static multiEnvironmentsFlags = ['store', 'password']
3643

37-
static get jsonOutputSchema() {
38-
return themeInfoJsonOutputSchema
39-
}
40-
4144
async command(flags: InfoFlags, adminSession: AdminSession): Promise<void> {
4245
recordTiming('theme-command:info')
4346
if (flags.theme || flags.development) {

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ describe('info', () => {
7171
})
7272
})
7373

74-
test('uses the JSON fallback values when no store or development theme is configured', () => {
74+
test('uses the JSON fallback values without reading the development theme when no store is configured', () => {
7575
vi.mocked(getThemeStore).mockReturnValue(undefined)
76-
vi.mocked(getDevelopmentTheme).mockReturnValue(undefined)
76+
vi.mocked(getDevelopmentTheme).mockImplementation(() => {
77+
throw new Error('The development theme needs a configured store')
78+
})
7779

7880
expect(themeEnvironmentInfoJSON({cliVersion: '3.91.0'})).toMatchObject({
7981
store: 'Not configured',
@@ -82,6 +84,7 @@ describe('info', () => {
8284
shell: process.env.SHELL ?? 'unknown',
8385
node_version: process.version,
8486
})
87+
expect(getDevelopmentTheme).not.toHaveBeenCalled()
8588
})
8689

8790
test('retains the raw development theme ID for text presentation', () => {
@@ -94,16 +97,6 @@ describe('info', () => {
9497
})
9598
})
9699

97-
test('retains the raw development theme ID for text presentation when no store is configured', () => {
98-
vi.mocked(getThemeStore).mockReturnValue(undefined)
99-
vi.mocked(getDevelopmentTheme).mockReturnValue('123')
100-
101-
expect(getThemeEnvironmentInfo({cliVersion: '3.91.0'})).toMatchObject({
102-
result: {development_theme_id: null},
103-
developmentTheme: '123',
104-
})
105-
})
106-
107100
test('fetch theme info by id', async () => {
108101
// Given
109102
vi.mocked(findOrSelectTheme).mockResolvedValue(theme)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export function getThemeEnvironmentInfo(config: {cliVersion: string}): {
3939
} {
4040
const {platform, arch} = platformAndArch()
4141
const store = getThemeStore()
42-
const developmentTheme = getDevelopmentTheme()
43-
const developmentThemeID = store ? Number(developmentTheme) || null : null
42+
const developmentTheme = store ? getDevelopmentTheme() : undefined
43+
const developmentThemeID = Number(developmentTheme) || null
4444

4545
return {
4646
result: {

0 commit comments

Comments
 (0)