| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e80c646 commit 44edfa4
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,28 +1,38 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | ||
| 3 | - const { mkdir, readFileSync, writeFile } = require('fs'); | ||
| 3 | + // doc/api/addons.md has a bunch of code. Extract it for verification | ||
| 4 | + // that the C++ code compiles and the js code runs. | ||
| 5 | + // Add .gyp files which will be used to compile the C++ code. | ||
| 6 | + // Modify the require paths in the js code to pull from the build tree. | ||
| 7 | + // Triggered from the build-addons target in the Makefile and vcbuild.bat. | ||
| 8 | + | ||
| 9 | + const { mkdir, writeFile } = require('fs'); | ||
| 4 | 10 | const { resolve } = require('path'); | |
| 5 | - const { lexer } = require('marked'); | ||
| 11 | + const vfile = require('to-vfile'); | ||
| 12 | + const unified = require('unified'); | ||
| 13 | + const remarkParse = require('remark-parse'); | ||
| 6 | 14 | ||
| 7 | 15 | const rootDir = resolve(__dirname, '..', '..'); | |
| 8 | 16 | const doc = resolve(rootDir, 'doc', 'api', 'addons.md'); | |
| 9 | 17 | const verifyDir = resolve(rootDir, 'test', 'addons'); | |
| 10 | 18 | ||
| 11 | - const tokens = lexer(readFileSync(doc, 'utf8')); | ||
| 19 | + const file = vfile.readSync(doc, 'utf8'); | ||
| 20 | + const tree = unified().use(remarkParse).parse(file); | ||
| 12 | 21 | const addons = {}; | |
| 13 | 22 | let id = 0; | |
| 14 | 23 | let currentHeader; | |
| 15 | 24 | ||
| 16 | 25 | const validNames = /^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/; | |
| 17 | - tokens.forEach(({ type, text }) => { | ||
| 18 | - if (type === 'heading') { | ||
| 19 | - currentHeader = text; | ||
| 26 | + tree.children.forEach((node) => { | ||
| 27 | + if (node.type === 'heading') { | ||
| 28 | + currentHeader = file.contents.slice( | ||
| 29 | + node.children[0].position.start.offset, | ||
| 30 | + node.position.end.offset); | ||
| 20 | 31 | addons[currentHeader] = { files: {} }; | |
| 21 | - } | ||
| 22 | - if (type === 'code') { | ||
| 23 | - const match = text.match(validNames); | ||
| 32 | + } else if (node.type === 'code') { | ||
| 33 | + const match = node.value.match(validNames); | ||
| 24 | 34 | if (match !== null) { | |
| 25 | - addons[currentHeader].files[match[1]] = text; | ||
| 35 | + addons[currentHeader].files[match[1]] = node.value; | ||
| 26 | 36 | } | |
| 27 | 37 | } | |
| 28 | 38 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,12 +7,12 @@ | |||
| 7 | 7 | "node": ">=6" | |
| 8 | 8 | }, | |
| 9 | 9 | "dependencies": { | |
| 10 | - "marked": "^0.4.0", | ||
| 11 | 10 | "rehype-raw": "^2.0.0", | |
| 12 | 11 | "rehype-stringify": "^3.0.0", | |
| 13 | 12 | "remark-html": "^7.0.0", | |
| 14 | 13 | "remark-parse": "^5.0.0", | |
| 15 | 14 | "remark-rehype": "^3.0.0", | |
| 15 | + "to-vfile": "^5.0.0", | ||
| 16 | 16 | "unified": "^7.0.0", | |
| 17 | 17 | "unist-util-find": "^1.0.1", | |
| 18 | 18 | "unist-util-select": "^1.5.0", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments