1
1
const fs = require ( 'fs' ) ;
2
+ const path = require ( 'path' ) ;
2
3
3
4
const args = process . argv . slice ( 2 ) ;
4
5
const dir = args [ 0 ] ;
@@ -222,21 +223,20 @@ var SourceFileOperations = [
222
223
] ;
223
224
224
225
var paths = listFiles ( dir ) ;
225
- paths . forEach ( function ( path ) {
226
- var filename = path . split ( '\\' ) . pop ( ) . split ( '/' ) . pop ( ) ;
226
+ paths . forEach ( function ( dirEntry ) {
227
+ var filename = dirEntry . split ( '\\' ) . pop ( ) . split ( '/' ) . pop ( ) ;
227
228
228
229
// Check whether the file is a source file or a config file
229
230
// then execute function accordingly
230
231
var sourcePattern = / .+ \. h | .+ \. c c | .+ \. c p p / ;
231
232
if ( sourcePattern . test ( filename ) ) {
232
- convertFile ( path , SourceFileOperations ) ;
233
+ convertFile ( dirEntry , SourceFileOperations ) ;
233
234
} else if ( ConfigFileOperations [ filename ] != null ) {
234
- convertFile ( path , ConfigFileOperations [ filename ] ) ;
235
+ convertFile ( dirEntry , ConfigFileOperations [ filename ] ) ;
235
236
}
236
237
} ) ;
237
238
238
239
function listFiles ( dir , filelist ) {
239
- var path = path || require ( 'path' ) ;
240
240
files = fs . readdirSync ( dir ) ;
241
241
filelist = filelist || [ ] ;
242
242
files . forEach ( function ( file ) {
@@ -257,13 +257,13 @@ function convert(content, operations) {
257
257
return content ;
258
258
}
259
259
260
- function convertFile ( path , operations ) {
261
- fs . readFile ( path , "utf-8" , function ( err , file ) {
260
+ function convertFile ( fileName , operations ) {
261
+ fs . readFile ( fileName , "utf-8" , function ( err , file ) {
262
262
if ( err ) throw err ;
263
263
264
264
file = convert ( file , operations ) ;
265
265
266
- fs . writeFile ( path , file , function ( err ) {
266
+ fs . writeFile ( fileName , file , function ( err ) {
267
267
if ( err ) throw err ;
268
268
} ) ;
269
269
} ) ;
0 commit comments