@@ -2,17 +2,17 @@ import {themeFlags} from '../../flags.js'
22import {
33 formatOffensesJson ,
44 formatSummary ,
5- handleExit ,
65 initConfig ,
76 outputActiveChecks ,
87 outputActiveConfig ,
98 performAutoFixes ,
109 renderOffensesText ,
1110 sortOffenses ,
1211 isExtendedWriteStream ,
12+ handleExit ,
1313 type FailLevel ,
1414} from '../../services/check.js'
15- import ThemeCommand from '../../utilities/theme-command.js'
15+ import ThemeCommand , { RequiredFlags } from '../../utilities/theme-command.js'
1616import { Flags } from '@oclif/core'
1717import { globalFlags } from '@shopify/cli-kit/node/cli'
1818import { outputResult , outputDebug } from '@shopify/cli-kit/node/output'
@@ -21,7 +21,10 @@ import {themeCheckRun, LegacyIdentifiers} from '@shopify/theme-check-node'
2121import { findPathUp } from '@shopify/cli-kit/node/fs'
2222import { moduleDirectory , joinPath } from '@shopify/cli-kit/node/path'
2323import { getPackageVersion } from '@shopify/cli-kit/node/node-package-manager'
24+ import { InferredFlags } from '@oclif/core/interfaces'
25+ import { AdminSession } from '@shopify/cli-kit/node/session'
2426
27+ type CheckFlags = InferredFlags < typeof Check . flags >
2528export default class Check extends ThemeCommand {
2629 static summary = 'Validate the theme.'
2730
@@ -86,11 +89,12 @@ export default class Check extends ThemeCommand {
8689 environment : themeFlags . environment ,
8790 }
8891
89- async run ( ) : Promise < void > {
90- const { flags} = await this . parse ( Check )
92+ static multiEnvironmentsFlags : RequiredFlags = [ 'path' ]
9193
94+ async command ( flags : CheckFlags , _session : AdminSession , multiEnvironment : boolean ) : Promise < void > {
9295 // Its not clear to typescript that path will always be defined
9396 const path = flags . path
97+ const environment = flags . environment ?. [ 0 ]
9498 // To support backwards compatibility for legacy configs
9599 const isLegacyConfig = flags . config ?. startsWith ( ':' ) && LegacyIdentifiers . has ( flags . config . slice ( 1 ) )
96100 // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
@@ -121,30 +125,32 @@ export default class Check extends ThemeCommand {
121125 }
122126
123127 if ( flags . print ) {
124- await outputActiveConfig ( path , config )
128+ await outputActiveConfig ( path , config , environment )
125129
126130 // --print should not trigger full theme check operation
127131 return
128132 }
129133
130134 if ( flags . list ) {
131- await outputActiveChecks ( path , config )
135+ await outputActiveChecks ( path , config , environment )
132136
133137 // --list should not trigger full theme check operation
134138 return
135139 }
136140
137- const { offenses, theme} = await runThemeCheck ( path , flags . output , config )
141+ const { offenses, theme} = await runThemeCheck ( path , flags . output , config , environment )
138142
139143 if ( flags [ 'auto-correct' ] ) {
140144 await performAutoFixes ( theme , offenses )
141145 }
142146
143- return handleExit ( offenses , flags [ 'fail-level' ] as FailLevel )
147+ if ( ! multiEnvironment ) {
148+ return handleExit ( offenses , flags [ 'fail-level' ] as FailLevel )
149+ }
144150 }
145151}
146152
147- export async function runThemeCheck ( path : string , outputFormat : string , config ?: string ) {
153+ export async function runThemeCheck ( path : string , outputFormat : string , config ?: string , environment ?: string ) {
148154 const { offenses, theme} = await themeCheckRun ( path , config , ( message ) => {
149155 if ( process . env . SHOPIFY_TMP_FLAG_DEBUG ) {
150156 outputDebug ( message )
@@ -154,13 +160,13 @@ export async function runThemeCheck(path: string, outputFormat: string, config?:
154160 const offensesByFile = sortOffenses ( offenses )
155161
156162 if ( outputFormat === 'text' ) {
157- renderOffensesText ( offensesByFile , path )
163+ renderOffensesText ( offensesByFile , path , environment )
158164
159165 // Use renderSuccess when theres no offenses
160166 const render = offenses . length ? renderInfo : renderSuccess
161167
162168 render ( {
163- headline : 'Theme Check Summary.' ,
169+ headline : environment ? `[ ${ environment } ] Theme Check Summary.` : 'Theme Check Summary.' ,
164170 body : formatSummary ( offenses , offensesByFile , theme ) ,
165171 } )
166172 }
@@ -181,7 +187,7 @@ export async function runThemeCheck(path: string, outputFormat: string, config?:
181187 stdout . _handle . setBlocking ( true )
182188 }
183189
184- outputResult ( JSON . stringify ( formatOffensesJson ( offensesByFile ) ) )
190+ outputResult ( JSON . stringify ( formatOffensesJson ( offensesByFile , environment ) ) )
185191 }
186192
187193 return { offenses, theme}
0 commit comments