1
- const { readdir, lstatSync, readdirSync} = require ( "fs" ) ;
1
+ const { readdir, lstatSync, readdirSync, createReadStream , createWriteStream } = require ( "fs" ) ;
2
2
const { promisify} = require ( "util" ) ;
3
3
const { join} = require ( "path" ) ;
4
4
const chalk = require ( "chalk" ) ;
@@ -23,31 +23,46 @@ module.exports = async (directory, options) => {
23
23
24
24
dir . forEach ( element => {
25
25
if ( element . isDirectory ( ) ) return loopDeep ( element . name ) ;
26
- parseAndCreateFile ( ) ;
26
+ parseAndCreateFile ( join ( directory , element . name ) ) ;
27
27
} )
28
28
} else {
29
29
throw new Error ( `The path enter is not a directory ${ chalk . red ( directory ) } ` ) ;
30
30
}
31
31
32
+ /**
33
+ *
34
+ * @param {String } dirToLoop
35
+ */
32
36
function loopDeep ( dirToLoop ) {
33
37
functionHandler . subFolder . push ( dirToLoop ) ;
34
38
35
39
functionHandler . path = join ( directory , `${ functionHandler . subFolder . join ( "/" ) } ` )
36
40
37
- console . log ( functionHandler . subFolder , functionHandler . path ) ;
38
41
const newDir = readdirSync ( functionHandler . path , { withFileTypes : true } ) ;
39
42
40
43
newDir . forEach ( item => {
41
44
if ( item . isDirectory ( ) ) {
42
45
return loopDeep ( item . name )
43
46
}
44
-
45
- console . log ( item . name ) ;
46
- parseAndCreateFile ( ) ;
47
+ parseAndCreateFile ( join ( functionHandler . path , item . name ) ) ;
47
48
} )
48
49
49
50
functionHandler . subFolder = [ ] ;
50
51
}
51
52
52
- function parseAndCreateFile ( ) { } ;
53
+ /**
54
+ *
55
+ * @param {String } pathToFile
56
+ */
57
+ function parseAndCreateFile ( pathToFile ) {
58
+ const fileToRead = createReadStream ( pathToFile ) ;
59
+ const fileToWrite = createWriteStream ( ) ;
60
+ let data ;
61
+
62
+ fileToRead . on ( 'data' , d => {
63
+ data = d . toString ( ) ;
64
+ } ) . on ( "end" , ( ) => {
65
+ // console.log(data);
66
+ } ) ;
67
+ } ;
53
68
} ;
0 commit comments