| 44 | } |
| 45 | |
| 46 | function readFiles(basepath, pathname, files, condenseDots) { |
| 47 | basepath = basepath || '.'; |
| 48 | pathname = pathname || '.'; |
| 49 | condenseDots = !!condenseDots; |
| 50 | return fs.readdirSync(path.join(basepath, pathname)).reduce((files, filename) => { |
| 51 | let savename = (condenseDots && filename.substr(0, 2) === '..') ? |
| 52 | filename.substr(1) : |
| 53 | filename; |
| 54 | let savepath = path.join(pathname, savename).split(path.sep).join('/'); |
| 55 | let filepath = path.join(pathname, filename); |
| 56 | let fullpath = path.join(basepath, filepath); |
| 57 | if (fs.statSync(fullpath).isDirectory()) { |
| 58 | return readFiles(basepath, filepath, files, condenseDots); |
| 59 | } else { |
| 60 | files[savepath] = fs.readFileSync(fullpath); |
| 61 | return files; |
| 62 | } |
| 63 | }, files || {}); |
| 64 | |
| 65 | }; |
| 66 | |
| 67 | module.exports = { |
| 68 | readTemplateFiles: (directory) => readFiles(directory, '.', {}, true), |