Skip to content

Commit

Permalink
tools: convert addon-verify to remark
Browse files Browse the repository at this point in the history
This is the last use of the remark *module*. tools/remark-cli and
tools/remark-preset-lint-node remain.

PR-URL: #21978
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
rubys authored and rvagg committed Aug 15, 2018
1 parent e75885f commit 0c67d32
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
30 changes: 20 additions & 10 deletions tools/doc/addon-verify.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
'use strict';

const { mkdir, readFileSync, writeFile } = require('fs');
// doc/api/addons.md has a bunch of code. Extract it for verification
// that the C++ code compiles and the js code runs.
// Add .gyp files which will be used to compile the C++ code.
// Modify the require paths in the js code to pull from the build tree.
// Triggered from the build-addons target in the Makefile and vcbuild.bat.

const { mkdir, writeFile } = require('fs');
const { resolve } = require('path');
const { lexer } = require('marked');
const vfile = require('to-vfile');
const unified = require('unified');
const remarkParse = require('remark-parse');

const rootDir = resolve(__dirname, '..', '..');
const doc = resolve(rootDir, 'doc', 'api', 'addons.md');
const verifyDir = resolve(rootDir, 'test', 'addons');

const tokens = lexer(readFileSync(doc, 'utf8'));
const file = vfile.readSync(doc, 'utf8');
const tree = unified().use(remarkParse).parse(file);
const addons = {};
let id = 0;
let currentHeader;

const validNames = /^\/\/\s+(.*\.(?:cc|h|js))[\r\n]/;
tokens.forEach(({ type, text }) => {
if (type === 'heading') {
currentHeader = text;
tree.children.forEach((node) => {
if (node.type === 'heading') {
currentHeader = file.contents.slice(
node.children[0].position.start.offset,
node.position.end.offset);
addons[currentHeader] = { files: {} };
}
if (type === 'code') {
const match = text.match(validNames);
} else if (node.type === 'code') {
const match = node.value.match(validNames);
if (match !== null) {
addons[currentHeader].files[match[1]] = text;
addons[currentHeader].files[match[1]] = node.value;
}
}
});
Expand Down
14 changes: 9 additions & 5 deletions tools/doc/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/doc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"node": ">=6"
},
"dependencies": {
"marked": "^0.4.0",
"rehype-raw": "^2.0.0",
"rehype-stringify": "^3.0.0",
"remark-html": "^7.0.0",
"remark-parse": "^5.0.0",
"remark-rehype": "^3.0.0",
"to-vfile": "^5.0.0",
"unified": "^7.0.0",
"unist-util-find": "^1.0.1",
"unist-util-select": "^1.5.0",
Expand Down

0 comments on commit 0c67d32

Please sign in to comment.