| 20 | }; |
| 21 | |
| 22 | function readFiles (base, properties, dir, data) { |
| 23 | |
| 24 | dir = dir || '/'; |
| 25 | data = data || []; |
| 26 | data._size = data._size || 0; |
| 27 | properties = properties || {}; |
| 28 | |
| 29 | let ignore = properties.ignore || {}; |
| 30 | |
| 31 | return fs.readdirSync(path.join(base, dir)).reduce((data, f) => { |
| 32 | |
| 33 | let pathname = path.join(dir, f); |
| 34 | let fullpath = path.join(base, pathname); |
| 35 | |
| 36 | for (let i = 0; i < ignore.length; i++) { |
| 37 | if (ignore[i][0] === '/') { |
| 38 | if (pathname.split(path.sep).join('/') === ignore[i]) { |
| 39 | return data; |
| 40 | } |
| 41 | } else { |
| 42 | if (f === ignore[i]) { |
| 43 | return data; |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | if (fs.statSync(fullpath).isDirectory()) { |
| 49 | return readFiles(base, properties, pathname, data); |
| 50 | } else { |
| 51 | let filename = pathname[0] === path.sep ? pathname.substr(1) : pathname; |
| 52 | let buffer = fs.readFileSync(fullpath); |
| 53 | filename = filename.split(path.sep).join('/'); // Windows |
| 54 | data._size += buffer.byteLength; |
| 55 | data.push({filename: filename, buffer: buffer}); |
| 56 | return data; |
| 57 | } |
| 58 | |
| 59 | }, data); |
| 60 | |
| 61 | }; |
| 62 | |
| 63 | module.exports = { |
| 64 | |