11import { join } from 'node:path' ;
22import { color } from 'rslog' ;
33import { getConfigState } from '../config.ts' ;
4- import { insertConfigArg , parseCliArgs } from './args.ts' ;
4+ import { insertConfigArg , parseArgs , parseCliArgs } from './args.ts' ;
55
66declare global {
77 const RSTACK_VERSION : string ;
@@ -20,6 +20,7 @@ ${color.cyan('Commands')}:
2020 doc Serve or build docs
2121 fmt, format Format code
2222 lint Lint code
23+ check Run static checks, including linting and formatting
2324 test Run tests
2425 staged Run tasks on staged Git files
2526 setup Install Git hooks
@@ -32,6 +33,17 @@ ${color.cyan('Options')}:
3233 -h, --help Display this help message
3334 -v, --version Display version number` ;
3435
36+ const checkHelpMessage = `Rstack v${ RSTACK_VERSION }
37+
38+ ${ color . cyan ( 'Usage' ) } :
39+ ${ color . yellow ( ' $ rs check [options]' ) }
40+
41+ Run static checks, including linting and formatting.
42+
43+ ${ color . cyan ( 'Options' ) } :
44+ --type-check Enable TypeScript type checking
45+ -h, --help Display this help message` ;
46+
3547async function runRsbuildCLI ( args : string [ ] ) : Promise < void > {
3648 const argv = [
3749 process . execPath ,
@@ -106,6 +118,34 @@ async function runRslintCLI(args: string[]): Promise<void> {
106118 await runCLI ( { argv } ) ;
107119}
108120
121+ async function runCheckCLI ( args : string [ ] ) : Promise < void > {
122+ const { values } = parseArgs ( {
123+ args,
124+ options : {
125+ 'type-check' : { type : 'boolean' } ,
126+ help : { type : 'boolean' , short : 'h' } ,
127+ } ,
128+ allowPositionals : false ,
129+ strict : true ,
130+ } ) ;
131+
132+ if ( values . help ) {
133+ console . log ( checkHelpMessage ) ;
134+ return ;
135+ }
136+
137+ await runRslintCLI ( values . typeCheck ? [ '--type-check' ] : [ ] ) ;
138+ if ( process . exitCode ) {
139+ return ;
140+ }
141+
142+ const { runFmtCLI } = await import (
143+ /* rspackChunkName: 'fmt' */
144+ '../fmt/cli.ts'
145+ ) ;
146+ await runFmtCLI ( [ '--check' ] ) ;
147+ }
148+
109149export async function setupCommands ( ) : Promise < void > {
110150 const { args, configPath } = parseCliArgs ( process . argv . slice ( 2 ) ) ;
111151 const command = args [ 0 ] ;
@@ -142,6 +182,11 @@ export async function setupCommands(): Promise<void> {
142182 return ;
143183 }
144184
185+ if ( command === 'check' ) {
186+ await runCheckCLI ( args . slice ( 1 ) ) ;
187+ return ;
188+ }
189+
145190 if ( command === 'fmt' || command === 'format' ) {
146191 const { runFmtCLI } = await import (
147192 /* rspackChunkName: 'fmt' */
0 commit comments