1- #!/usr/bin/env node
1+ /* eslint-disable n/no-process-exit, unicorn/no-process-exit */
2+ import { spawn } from 'node:child_process' ;
3+ import fs from 'node:fs/promises' ;
4+ import path from 'node:path' ;
5+
26import chalk from 'chalk' ;
3- import { spawn } from 'child_process' ;
4- import fs from 'fs/promises' ;
5- import path from 'path' ;
67
78const debug = process . argv . includes ( '--debug' ) ;
89
@@ -14,21 +15,21 @@ const logDebug = (message) => {
1415
1516const newLine = ( ) => console . log ( ) ;
1617
17- const inputDir = './input' ;
18- const expectedOutputDir = './expected-output' ;
18+ const inputDirectory = './input' ;
19+ const expectedOutputDirectory = './expected-output' ;
1920
2021// NOTE: Run with `--debug` to get debug output (from both this script and prettier)
2122const run = async ( ) => {
2223 logDebug ( 'Reading input directory...' ) ;
2324
2425 try {
25- const inputFiles = await fs . readdir ( inputDir ) ;
26+ const inputFiles = await fs . readdir ( inputDirectory ) ;
2627 const originalFiles = new Map ( ) ;
2728
2829 logDebug ( 'Backing up input files...' ) ;
2930 for ( const file of inputFiles ) {
30- const filePath = path . join ( inputDir , file ) ;
31- const fileContent = await fs . readFile ( filePath , 'utf-8 ' ) ;
31+ const filePath = path . join ( inputDirectory , file ) ;
32+ const fileContent = await fs . readFile ( filePath , 'utf8 ' ) ;
3233 originalFiles . set ( file , fileContent ) ;
3334 }
3435
@@ -68,13 +69,13 @@ const run = async () => {
6869 let allFilesMatch = true ;
6970
7071 for ( const file of inputFiles ) {
71- const inputFilePath = path . join ( inputDir , file ) ;
72- const expectedOutputFilePath = path . join ( expectedOutputDir , file ) ;
72+ const inputFilePath = path . join ( inputDirectory , file ) ;
73+ const expectedOutputFilePath = path . join ( expectedOutputDirectory , file ) ;
7374
7475 try {
7576 const [ inputContent , expectedOutputContent ] = await Promise . all ( [
76- fs . readFile ( inputFilePath , 'utf-8 ' ) ,
77- fs . readFile ( expectedOutputFilePath , 'utf-8 ' ) ,
77+ fs . readFile ( inputFilePath , 'utf8 ' ) ,
78+ fs . readFile ( expectedOutputFilePath , 'utf8 ' ) ,
7879 ] ) ;
7980
8081 if ( inputContent === expectedOutputContent ) {
@@ -91,8 +92,8 @@ const run = async () => {
9192 ) ;
9293 allFilesMatch = false ;
9394 }
94- } catch ( err ) {
95- console . error ( chalk . red ( `Error processing ${ file } :` ) , err ) ;
95+ } catch ( error ) {
96+ console . error ( chalk . red ( `Error processing ${ file } :` ) , error ) ;
9697 allFilesMatch = false ;
9798 }
9899 }
@@ -107,8 +108,8 @@ const run = async () => {
107108 process . exit ( 1 ) ;
108109 }
109110 } ) ;
110- } catch ( err ) {
111- console . error ( chalk . red ( '💩 Error:' ) , err ) ;
111+ } catch ( error ) {
112+ console . error ( chalk . red ( '💩 Error:' ) , error ) ;
112113 process . exit ( 2 ) ;
113114 }
114115} ;
0 commit comments