Skip to content

Commit 4dd16f3

Browse files
committed
Add util to list frontmatter from all
1 parent 0df230b commit 4dd16f3

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

.eslintrc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"parserOptions": {
1818
"ecmaVersion": 2020
19-
},
19+
},
2020
"overrides": [
2121
{
2222
"files": "test/**/*.js",

list-frontmatter.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const argv = require('yargs').command('* [paths..]', 'list frontmatter from files', (yargs) => {
2+
return yargs
3+
.positional('paths', {
4+
describe: 'file paths to list frontmatter from',
5+
type: 'array',
6+
})
7+
.demandOption('paths');
8+
}).argv;
9+
10+
const frontmatter = require('@github-docs/frontmatter');
11+
const { readFileSync } = require('fs');
12+
13+
let results = [];
14+
for (let path of argv.paths) {
15+
let markdown = readFileSync(path, 'utf8');
16+
const { data, errors } = frontmatter(markdown);
17+
if (errors.length) {
18+
console.error(JSON.stringify(errors));
19+
process.exitCode = 1;
20+
return;
21+
}
22+
results.push({ name: path, ...data });
23+
}
24+
25+
console.log(JSON.stringify(results, null, 2));

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@
2626
"semver": "^7.3.2",
2727
"simple-git": "^3.12.0",
2828
"yargs": "^16.0.3"
29+
},
30+
"engines": {
31+
"node": ">= 12"
2932
}
3033
}

0 commit comments

Comments
 (0)