@@ -21,21 +21,34 @@ const hasAllFlag = process.argv.includes('--all');
2121const hasCoreFlag = process . argv . includes ( '--core' ) ;
2222const hasExtFlag = process . argv . includes ( '--ext' ) ;
2323const hasNpmFlag = process . argv . includes ( '--npm' ) ;
24+ const hasTestFlag = process . argv . includes ( '--test' ) ;
2425const hasYalcFlag = process . argv . includes ( '--yalc' ) ;
2526
26- if ( ! hasAllFlag && ! hasCoreFlag && ! hasExtFlag && ! hasNpmFlag && ! hasYalcFlag ) {
27- console . error ( 'Usage: node delete-temp-files.cjs [--all] [--core] [--ext] [--npm] [--yalc]' ) ;
28- console . error ( ' --core Delete Electron and core caches (Electron, dev-appdata)' ) ;
29- console . error ( ' --ext Delete extension directories (coverage, dist, src/temp-build)' ) ;
30- console . error ( ' --npm Delete both node_modules and extension package-lock.json' ) ;
31- console . error ( ' --yalc Delete core yalc-related files' ) ;
32- console . error ( ' --all Delete all of the above' ) ;
33- process . exit ( 1 ) ;
27+ function printUsageAndExit ( code = 0 ) {
28+ console . info (
29+ 'Usage: node delete-temp-files.cjs [--all] [--core] [--ext] [--npm] [--test] [--yalc]' ,
30+ ) ;
31+ console . info ( ' --core Delete Electron and core caches (Electron, dev-appdata)' ) ;
32+ console . info ( ' --ext Delete extension builds (dist, src/temp-build)' ) ;
33+ console . info ( ' --npm Delete extension package-lock.json and both node_modules' ) ;
34+ console . info ( ' --test Delete extension test/lint-related files' ) ;
35+ console . info ( ' --yalc Delete core yalc-related files' ) ;
36+ console . info ( ' --all Delete all of the above' ) ;
37+ process . exit ( code ) ;
38+ }
39+
40+ if ( process . argv . length <= 2 || process . argv . includes ( '--help' ) || process . argv . includes ( '-h' ) ) {
41+ printUsageAndExit ( ) ;
42+ }
43+
44+ if ( ! hasAllFlag && ! hasCoreFlag && ! hasExtFlag && ! hasNpmFlag && ! hasTestFlag && ! hasYalcFlag ) {
45+ printUsageAndExit ( 1 ) ;
3446}
3547
3648const shouldDeleteCore = hasAllFlag || hasCoreFlag ;
3749const shouldDeleteExt = hasAllFlag || hasExtFlag ;
3850const shouldDeleteNpm = hasAllFlag || hasNpmFlag ;
51+ const shouldDeleteTest = hasAllFlag || hasTestFlag ;
3952const shouldDeleteYalc = hasAllFlag || hasYalcFlag ;
4053
4154// Define directory lists
@@ -66,7 +79,6 @@ const CORE_DIRS = [
6679] ;
6780
6881const EXT_DIRS = [
69- path . join ( __dirname , '..' , 'coverage' ) ,
7082 path . join ( __dirname , '..' , 'dist' ) ,
7183 path . join ( __dirname , '..' , 'src' , 'temp-build' ) ,
7284] ;
@@ -77,6 +89,11 @@ const NPM_PATHS = [
7789 path . join ( __dirname , '..' , 'package-lock.json' ) ,
7890] ;
7991
92+ const TEST_PATHS = [
93+ path . join ( __dirname , '..' , 'coverage' ) ,
94+ path . join ( __dirname , '..' , '.eslintcache' ) ,
95+ ] ;
96+
8097const YALC_PATHS = [
8198 path . join ( __dirname , '..' , '..' , 'paranext-core' , '.yalc' ) ,
8299 path . join ( __dirname , '..' , '..' , 'paranext-core' , 'dev-packages' ) ,
@@ -97,7 +114,7 @@ function deletePath(pathToDelete) {
97114 try {
98115 if ( fs . existsSync ( pathToDelete ) ) {
99116 fs . rmSync ( pathToDelete , { recursive : true , force : true } ) ;
100- console . log ( `✓ Deleted ${ pathToDelete } ` ) ;
117+ console . log ( `✓ ${ pathToDelete } deleted ` ) ;
101118 } else {
102119 console . log ( `⊘ ${ pathToDelete } does not exist` ) ;
103120 }
@@ -124,6 +141,11 @@ try {
124141 NPM_PATHS . forEach ( deletePath ) ;
125142 }
126143
144+ if ( shouldDeleteTest ) {
145+ console . log ( 'Deleting extension test- and lint-related files...' ) ;
146+ TEST_PATHS . forEach ( deletePath ) ;
147+ }
148+
127149 if ( shouldDeleteYalc ) {
128150 console . log ( 'Deleting core yalc-related files...' ) ;
129151 YALC_PATHS . forEach ( deletePath ) ;
0 commit comments