1
1
#!/usr/bin/env node
2
2
3
- var fs = require ( 'fs' ) ,
4
- path = require ( 'path' ) ;
3
+ var fs = require ( 'fs' ) ;
4
+ var path = require ( 'path' ) ;
5
5
6
6
// Lectura de parametros pasados e inicializamos variables requeridas
7
- var options = process . argv . slice ( 2 ) ,
8
- dir ,
9
- ext = [ 'html' , 'js' , 'py' , 'php' ] ,
10
- regexp = / ( < \? ) ( \W | $ ) / g;
7
+ var options = process . argv . slice ( 2 ) ;
8
+ var dir ;
9
+ var ext = [ 'html' , 'js' , 'py' , 'php' ] ;
10
+ var regexp = / ( < \? ) ( \W | $ ) / g;
11
11
12
12
//Asignamos la ruta del directoria según los parametros o se asigna la actual
13
13
if ( options . length >= 1 ) {
14
14
dir = options [ 0 ] ;
15
15
} else {
16
16
dir = '.' ;
17
- } ;
17
+ }
18
18
19
19
//Llamada inical a la lectura del directorio
20
20
readDir ( dir + path . sep ) ;
@@ -29,14 +29,14 @@ function readDir (dirpath) {
29
29
readDir ( dirpath + file + path . sep ) ;
30
30
}
31
31
if ( stats && stats . isFile ( ) ) {
32
- var type = file . split ( '.' ) [ 1 ] ;
33
- if ( ext . indexOf ( type ) >= 0 && file . split ( '.' ) . length == 1 ) {
32
+ var type_ = file . split ( '.' ) ;
33
+ if ( ext . indexOf ( type_ [ type_ . length - 1 ] ) >= 0 ) {
34
34
readfile ( dirpath + file ) ;
35
- } ;
36
- } ;
35
+ }
36
+ }
37
37
} ) ;
38
38
} ) ;
39
- } ;
39
+ }
40
40
} ) ;
41
41
}
42
42
@@ -50,13 +50,13 @@ function readfile (filepath) {
50
50
if ( re ) {
51
51
lines [ i ] = lines [ i ] . replace ( regexp , re [ 0 ] . trim ( ) + "php " , "gi" ) ;
52
52
flag = true ;
53
- } ;
54
- } ;
53
+ }
54
+ }
55
55
if ( flag ) {
56
56
data = lines . join ( '\n' ) ;
57
57
fs . writeFile ( filepath , data , function ( err ) {
58
58
if ( err ) throw err ;
59
59
console . log ( filepath + " Saved!" ) ;
60
- } )
61
- } ;
60
+ } ) ;
61
+ }
62
62
}
0 commit comments