@@ -2,17 +2,46 @@ import { exec } from 'node:child_process';
22
33const run = ( cmd ) => new Promise ( ( resolve , reject ) => exec (
44 cmd ,
5- ( error , stdout , stderr ) => {
5+ ( error , stdout ) => {
66 if ( error ) reject ( error ) ;
7- if ( stderr ) reject ( new Error ( stderr ) ) ;
8- resolve ( stdout ) ;
7+ else resolve ( stdout ) ;
98 } ,
109) ) ;
1110
1211const changeset = await run ( 'git diff --cached --name-only --diff-filter=ACMR' ) ;
1312const modifiedFiles = changeset . split ( '\n' ) . filter ( Boolean ) ;
1413
15- // Check if there are any model files staged
14+ // Auto-fix and lint staged JS files
15+ const jsFiles = modifiedFiles . filter ( ( f ) => f . endsWith ( '.js' ) ) ;
16+ if ( jsFiles . length > 0 ) {
17+ const fileList = jsFiles . join ( ' ' ) ;
18+ try {
19+ await run ( `npx eslint --fix ${ fileList } ` ) ;
20+ } catch {
21+ // fix ran; lint check below will surface unfixable errors
22+ }
23+ await run ( `git add ${ fileList } ` ) ;
24+ // Fail the commit if unfixable lint errors remain
25+ const output = await run ( `npx eslint ${ fileList } ` ) ;
26+ if ( output ) console . log ( output ) ;
27+ }
28+
29+ // Auto-fix and lint staged CSS files
30+ const cssFiles = modifiedFiles . filter ( ( f ) => f . endsWith ( '.css' ) ) ;
31+ if ( cssFiles . length > 0 ) {
32+ const fileList = cssFiles . join ( ' ' ) ;
33+ try {
34+ await run ( `npx stylelint --fix ${ fileList } ` ) ;
35+ } catch {
36+ // fix ran; lint check below will surface unfixable errors
37+ }
38+ await run ( `git add ${ fileList } ` ) ;
39+ // Fail the commit if unfixable lint errors remain
40+ const output = await run ( `npx stylelint ${ fileList } ` ) ;
41+ if ( output ) console . log ( output ) ;
42+ }
43+
44+ // Rebuild UE JSON bundles when model files are staged
1645const modifiedPartials = modifiedFiles . filter ( ( file ) => file . match ( / ^ u e \/ m o d e l s \/ .* \. j s o n / ) ) ;
1746if ( modifiedPartials . length > 0 ) {
1847 const output = await run ( 'npm run build:json --silent' ) ;
0 commit comments