(directory)
| 114 | |
| 115 | //recurseThroughFileTree is called and passed the object that exists at fileTree |
| 116 | function recurseThroughFileTree(directory) { |
| 117 | //Loop through files and fill files property array |
| 118 | //fs.readdir reads the contents of a directory |
| 119 | //entire directory exists at directory.path |
| 120 | fs.readdir(directory.path, (err, files) => { |
| 121 | |
| 122 | //I'm not sure what the purpose of pending is |
| 123 | pending += files.length; |
| 124 | |
| 125 | //this conditional is assessing pending after it's decremented to see if it's a false/falsy value |
| 126 | //should only be true after being decremented several times |
| 127 | if (!--pending) { |
| 128 | //if it is, we call writeFileSync and pass the file stored at projInfoPath |
| 129 | //we write the stringified value of projInfo to whatever file exists at projInfoPath |
| 130 | fs.writeFileSync(projInfoPath, JSON.stringify(projInfo)); |
| 131 | //inputted callback to getTree is then fired and passed the fileTree object |
| 132 | callback(fileTree); |
| 133 | } |
| 134 | //files is an array of files that exist in the directory passed to the fs.readdir method |
| 135 | //forEach is used to iterate over that array |
| 136 | files.forEach((file) => { |
| 137 | //filePath uses path.join() to join the path and file names together |
| 138 | const filePath = path.join(directory.path, file); |
| 139 | //fs.stat is a method that checks for file details associated with the inputted file |
| 140 | //if status is good, it's details are available at the 'stats' variable |
| 141 | fs.stat(filePath, (err, stats) => { |
| 142 | if (err) { |
| 143 | //this conditional is assessing pending after it's decremented to see if it's a false/falsy value |
| 144 | //should only be true after being decremented several times |
| 145 | if (!--pending) { |
| 146 | //if it is, we call writeFileSync and pass the file stored at projInfoPath |
| 147 | //we write the stringified value of projInfo to whatever file exists at projInfoPath |
| 148 | fs.writeFileSync(projInfoPath, JSON.stringify(projInfo)); |
| 149 | //inputted callback to getTree is then fired and passed the fileTree object |
| 150 | callback(fileTree); |
| 151 | } |
| 152 | } |
| 153 | //checks if stats is true or truthy & stats.isFile() resolves to true |
| 154 | if (stats && stats.isFile()) { |
| 155 | //insertSorted pushes an object into the directory.files array |
| 156 | //object pushed into the array has the following parameters: |
| 157 | //path, type, name, ext, id |
| 158 | insertSorted(new File(filePath, file, getFileExt), directory.files); |
| 159 | //checks if the filePath is the same as the resolved value as path.join(...) & if the file contains the text of webpack.config.js |
| 160 | if (filePath === path.join(projInfo.rootPath, file) && file.search(/webpack.config.js/) !== -1) { |
| 161 | //if it does, then we invoke the readFile method to access the data in the file |
| 162 | fs.readFile(filePath, { encoding: 'utf-8' }, (err, data) => { |
| 163 | //created a regExp to check for a pattern that matches entry... |
| 164 | const regExp = new RegExp('entry(.*?),', 'g'); |
| 165 | //file is stringified and then searched for the match assigned to the regExp |
| 166 | let entry = JSON.stringify(data).match(regExp); |
| 167 | |
| 168 | //????? |
| 169 | let reactEntry = String(entry[0].split('\'')[1]); |
| 170 | //reactEntry property inside of the projInfo object is updated to the resolved value of path.join(...) |
| 171 | projInfo.reactEntry = path.join(projInfo.rootPath, reactEntry); |
| 172 | }) |
| 173 | } |
no test coverage detected