Parse a ParsableFile using a specific method @param {FS} fs @param {ParsableFile} file @param {String} type @return {Promise >}
(fs, file, type)
| 11 | @return {Promise<Array<String, List|Map>>} |
| 12 | */ |
| 13 | function parseFile(fs, file, type) { |
| 14 | var filepath = file.getPath(); |
| 15 | var parser = file.getParser(); |
| 16 | |
| 17 | if (!parser) { |
| 18 | return Promise.reject( |
| 19 | error.FileNotParsableError({ |
| 20 | filename: filepath |
| 21 | }) |
| 22 | ); |
| 23 | } |
| 24 | |
| 25 | return fs.readAsString(filepath) |
| 26 | .then(function(content) { |
| 27 | if (type === 'readme') { |
| 28 | return parser.parseReadme(content); |
| 29 | } else if (type === 'glossary') { |
| 30 | return parser.parseGlossary(content); |
| 31 | } else if (type === 'summary') { |
| 32 | return parser.parseSummary(content); |
| 33 | } else if (type === 'langs') { |
| 34 | return parser.parseLanguages(content); |
| 35 | } else { |
| 36 | throw new Error('Parsing invalid type "' + type + '"'); |
| 37 | } |
| 38 | }) |
| 39 | .then(function(result) { |
| 40 | return [ |
| 41 | file, |
| 42 | result |
| 43 | ]; |
| 44 | }); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | /** |
no outgoing calls
no test coverage detected
searching dependent graphs…