@@ -11,29 +11,29 @@ const verifyDir = path.resolve(rootDir, 'test', 'addons');
|
11 | 11 | const contents = fs.readFileSync(doc).toString(); |
12 | 12 | |
13 | 13 | const tokens = marked.lexer(contents); |
14 | | -let files = null; |
15 | 14 | let id = 0; |
16 | 15 | |
17 | | -// Just to make sure that all examples will be processed |
18 | | -tokens.push({ type: 'heading' }); |
19 | | - |
20 | | -for (var i = 0; i < tokens.length; i++) { |
21 | | -var token = tokens[i]; |
| 16 | +let currentHeader; |
| 17 | +const addons = {}; |
| 18 | +tokens.forEach((token) => { |
22 | 19 | if (token.type === 'heading' && token.text) { |
23 | | -const blockName = token.text; |
24 | | -if (files && Object.keys(files).length !== 0) { |
25 | | -verifyFiles(files, |
26 | | -blockName, |
27 | | -console.log.bind(null, 'wrote'), |
28 | | -function(err) { if (err) throw err; }); |
29 | | -} |
30 | | -files = {}; |
31 | | -} else if (token.type === 'code') { |
| 20 | +currentHeader = token.text; |
| 21 | +addons[currentHeader] = { |
| 22 | +files: {} |
| 23 | +}; |
| 24 | +} |
| 25 | +if (token.type === 'code') { |
32 | 26 | var match = token.text.match(/^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/); |
33 | | -if (match === null) |
34 | | -continue; |
35 | | -files[match[1]] = token.text; |
| 27 | +if (match !== null) { |
| 28 | +addons[currentHeader].files[match[1]] = token.text; |
| 29 | +} |
36 | 30 | } |
| 31 | +}); |
| 32 | +for (var header in addons) { |
| 33 | +verifyFiles(addons[header].files, |
| 34 | +header, |
| 35 | +console.log.bind(null, 'wrote'), |
| 36 | +function(err) { if (err) throw err; }); |
37 | 37 | } |
38 | 38 | |
39 | 39 | function once(fn) { |
|