File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { execFileSync } from "child_process" ;
2+ import { parseArgs } from "util" ;
23import fs from "fs" ;
34
45function formatAll ( ) {
@@ -26,8 +27,7 @@ function runPrettier(files) {
2627
2728function runEslint ( files ) {
2829 const jsTsFiles = files . filter ( ( f ) => / \. ( j s | m j s | j s x | t s | t s x ) $ / . test ( f ) ) ;
29- if ( jsTsFiles . length === 0 )
30- return ;
30+ if ( jsTsFiles . length === 0 ) return ;
3131 try {
3232 console . log ( `Running eslint on ${ jsTsFiles . length } file(s)` ) ;
3333 runInBatches ( "eslint" , [ "--fix" ] , jsTsFiles ) ;
@@ -46,9 +46,31 @@ function getChangedFiles() {
4646 return [ ...new Set ( files ) ] ;
4747}
4848
49- const isAll = process . argv . includes ( "--all" ) ;
49+ let values ;
50+ try {
51+ ( { values } = parseArgs ( {
52+ options : {
53+ all : { type : "boolean" } ,
54+ help : { type : "boolean" , short : "h" } ,
55+ } ,
56+ strict : true ,
57+ } ) ) ;
58+ } catch ( err ) {
59+ console . error ( err . message ) ;
60+ console . error ( "Run 'node tests/format.mjs --help' for usage." ) ;
61+ process . exit ( 1 ) ;
62+ }
63+
64+ if ( values . help ) {
65+ console . log ( `Usage: node tests/format.mjs [options]
66+
67+ Options:
68+ --all Format all files across the repository instead of just changed files
69+ -h, --help Show this help message` ) ;
70+ process . exit ( 0 ) ;
71+ }
5072
51- if ( isAll ) {
73+ if ( values . all ) {
5274 formatAll ( ) ;
5375 process . exit ( 0 ) ;
5476}
You can’t perform that action at this time.
0 commit comments