Skip to content

Commit 44edfa4

Browse files
rubystargos
authored andcommitted
tools: convert addon-verify to remark
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 <anna@addaleax.net> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent e80c646 commit 44edfa4

3 files changed

Lines changed: 30 additions & 16 deletions

File tree

‎tools/doc/addon-verify.js‎

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
'use strict';
22

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');
410
const{ resolve }=require('path');
5-
const{ lexer }=require('marked');
11+
constvfile=require('to-vfile');
12+
constunified=require('unified');
13+
constremarkParse=require('remark-parse');
614

715
constrootDir=resolve(__dirname,'..','..');
816
constdoc=resolve(rootDir,'doc','api','addons.md');
917
constverifyDir=resolve(rootDir,'test','addons');
1018

11-
consttokens=lexer(readFileSync(doc,'utf8'));
19+
constfile=vfile.readSync(doc,'utf8');
20+
consttree=unified().use(remarkParse).parse(file);
1221
constaddons={};
1322
letid=0;
1423
letcurrentHeader;
1524

1625
constvalidNames=/^\/\/\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);
2031
addons[currentHeader]={files: {}};
21-
}
22-
if(type==='code'){
23-
constmatch=text.match(validNames);
32+
}elseif(node.type==='code'){
33+
constmatch=node.value.match(validNames);
2434
if(match!==null){
25-
addons[currentHeader].files[match[1]]=text;
35+
addons[currentHeader].files[match[1]]=node.value;
2636
}
2737
}
2838
});

‎tools/doc/package-lock.json‎

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tools/doc/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
"node": ">=6"
88
},
99
"dependencies": {
10-
"marked": "^0.4.0",
1110
"rehype-raw": "^2.0.0",
1211
"rehype-stringify": "^3.0.0",
1312
"remark-html": "^7.0.0",
1413
"remark-parse": "^5.0.0",
1514
"remark-rehype": "^3.0.0",
15+
"to-vfile": "^5.0.0",
1616
"unified": "^7.0.0",
1717
"unist-util-find": "^1.0.1",
1818
"unist-util-select": "^1.5.0",

0 commit comments

Comments
 (0)