@@ -11,27 +11,6 @@ const __filename = fileURLToPath(import.meta.url)
1111const __dirname = path . dirname ( __filename )
1212const packageRoot = path . resolve ( __dirname , '..' )
1313
14- /**
15- * Format a success message.
16- */
17- function success ( msg ) {
18- return `${ colors . green ( '✓' ) } ${ msg } `
19- }
20-
21- /**
22- * Format an error message.
23- */
24- function error ( msg ) {
25- return `${ colors . red ( '✗' ) } ${ msg } `
26- }
27-
28- /**
29- * Format an info message.
30- */
31- function info ( msg ) {
32- return `${ colors . blue ( 'ℹ' ) } ${ msg } `
33- }
34-
3514/**
3615 * Check if a file exists and is readable.
3716 */
@@ -57,12 +36,12 @@ async function validate() {
5736 const errors = [ ]
5837
5938 // Check package.json exists and has correct files array.
60- logger . log ( info ( 'Checking package.json...' ) )
39+ logger . info ( 'Checking package.json...' )
6140 const pkgPath = path . join ( packageRoot , 'package.json' )
6241 if ( ! ( await fileExists ( pkgPath ) ) ) {
6342 errors . push ( 'package.json does not exist' )
6443 } else {
65- logger . log ( success ( 'package.json exists' ) )
44+ logger . success ( 'package.json exists' )
6645
6746 // Validate files array.
6847 const pkg = JSON . parse ( await fs . readFile ( pkgPath , 'utf-8' ) )
@@ -80,54 +59,54 @@ async function validate() {
8059 }
8160 }
8261 if ( errors . length === 0 ) {
83- logger . log ( success ( 'package.json files array is correct' ) )
62+ logger . success ( 'package.json files array is correct' )
8463 }
8564 }
8665
8766 // Check root files exist (LICENSE, CHANGELOG.md).
8867 const rootFiles = [ 'LICENSE' , 'CHANGELOG.md' ]
8968 for ( const file of rootFiles ) {
90- logger . log ( info ( `Checking ${ file } ...` ) )
69+ logger . info ( `Checking ${ file } ...` )
9170 const filePath = path . join ( packageRoot , file )
9271 if ( ! ( await fileExists ( filePath ) ) ) {
9372 errors . push ( `${ file } does not exist` )
9473 } else {
95- logger . log ( success ( `${ file } exists` ) )
74+ logger . success ( `${ file } exists` )
9675 }
9776 }
9877
9978 // Check dist files exist.
10079 const distFiles = [ 'index.js' , 'cli.js.bz' , 'shadow-npm-inject.js' ]
10180 for ( const file of distFiles ) {
102- logger . log ( info ( `Checking dist/${ file } ...` ) )
81+ logger . info ( `Checking dist/${ file } ...` )
10382 const filePath = path . join ( packageRoot , 'dist' , file )
10483 if ( ! ( await fileExists ( filePath ) ) ) {
10584 errors . push ( `dist/${ file } does not exist` )
10685 } else {
107- logger . log ( success ( `dist/${ file } exists` ) )
86+ logger . success ( `dist/${ file } exists` )
10887 }
10988 }
11089
11190 // Check data directory exists.
112- logger . log ( info ( 'Checking data directory...' ) )
91+ logger . info ( 'Checking data directory...' )
11392 const dataPath = path . join ( packageRoot , 'data' )
11493 if ( ! ( await fileExists ( dataPath ) ) ) {
11594 errors . push ( 'data directory does not exist' )
11695 } else {
117- logger . log ( success ( 'data directory exists' ) )
96+ logger . success ( 'data directory exists' )
11897
11998 // Check data files.
12099 const dataFiles = [
121100 'alert-translations.json' ,
122101 'command-api-requirements.json' ,
123102 ]
124103 for ( const file of dataFiles ) {
125- logger . log ( info ( `Checking data/${ file } ...` ) )
104+ logger . info ( `Checking data/${ file } ...` )
126105 const filePath = path . join ( dataPath , file )
127106 if ( ! ( await fileExists ( filePath ) ) ) {
128107 errors . push ( `data/${ file } does not exist` )
129108 } else {
130- logger . log ( success ( `data/${ file } exists` ) )
109+ logger . success ( `data/${ file } exists` )
131110 }
132111 }
133112 }
@@ -145,20 +124,20 @@ async function validate() {
145124 logger . log ( ` ${ error ( err ) } ` )
146125 }
147126 logger . log ( '' )
148- logger . log ( error ( 'Package validation FAILED' ) )
127+ logger . fail ( 'Package validation FAILED' )
149128 logger . log ( '' )
150129 process . exit ( 1 )
151130 }
152131
153- logger . log ( success ( 'Package validation PASSED' ) )
132+ logger . success ( 'Package validation PASSED' )
154133 logger . log ( '' )
155134 process . exit ( 0 )
156135}
157136
158137// Run validation.
159138validate ( ) . catch ( e => {
160139 logger . error ( '' )
161- logger . error ( error ( `Unexpected error: ${ e . message } ` ) )
140+ logger . fail ( `Unexpected error: ${ e . message } ` )
162141 logger . error ( '' )
163142 process . exit ( 1 )
164143} )
0 commit comments