* Parses a file for metadata and stores result in data object. * @param {File} file - object provided by map-stream. * @param {function(?,File)} - callback provided by map-stream to * reply when done.
(file, callback)
| 37 | * reply when done. |
| 38 | */ |
| 39 | function parser(file, callback) { |
| 40 | // file exit conditions |
| 41 | if(file.isNull()) { |
| 42 | return callback(null, file); // pass along |
| 43 | } |
| 44 | |
| 45 | if(file.isStream()) { |
| 46 | return callback(new Error('Streaming not supported')); |
| 47 | } |
| 48 | |
| 49 | try { |
| 50 | |
| 51 | let |
| 52 | /** @type {string} */ |
| 53 | text = String(file.contents.toString('utf8')), |
| 54 | lines = text.split('\n'), |
| 55 | filename = file.path.substring(0, file.path.length - 4), |
| 56 | key = 'server/documents', |
| 57 | position = filename.indexOf(key) |
| 58 | ; |
| 59 | |
| 60 | // exit conditions |
| 61 | if(!lines) { |
| 62 | return; |
| 63 | } |
| 64 | if(position < 0) { |
| 65 | return callback(null, file); |
| 66 | } |
| 67 | |
| 68 | filename = filename.substring(position + key.length + 1, filename.length); |
| 69 | |
| 70 | let |
| 71 | lineCount = lines.length, |
| 72 | active = false, |
| 73 | yaml = [], |
| 74 | categories = [ |
| 75 | 'UI Element', |
| 76 | 'UI Global', |
| 77 | 'UI Collection', |
| 78 | 'UI View', |
| 79 | 'UI Module', |
| 80 | 'UI Behavior' |
| 81 | ], |
| 82 | index, |
| 83 | meta, |
| 84 | line |
| 85 | ; |
| 86 | |
| 87 | for(index = 0; index < lineCount; index++) { |
| 88 | |
| 89 | line = lines[index]; |
| 90 | |
| 91 | // Wait for metadata block to begin |
| 92 | if(!active) { |
| 93 | if(startsWith(line, '---')) { |
| 94 | active = true; |
| 95 | } |
| 96 | continue; |
nothing calls this directly
no test coverage detected
searching dependent graphs…