-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add util to list frontmatter from all
- Loading branch information
1 parent
0df230b
commit 4dd16f3
Showing
3 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2020 | ||
}, | ||
}, | ||
"overrides": [ | ||
{ | ||
"files": "test/**/*.js", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const argv = require('yargs').command('* [paths..]', 'list frontmatter from files', (yargs) => { | ||
return yargs | ||
.positional('paths', { | ||
describe: 'file paths to list frontmatter from', | ||
type: 'array', | ||
}) | ||
.demandOption('paths'); | ||
}).argv; | ||
|
||
const frontmatter = require('@github-docs/frontmatter'); | ||
const { readFileSync } = require('fs'); | ||
|
||
let results = []; | ||
for (let path of argv.paths) { | ||
let markdown = readFileSync(path, 'utf8'); | ||
const { data, errors } = frontmatter(markdown); | ||
if (errors.length) { | ||
console.error(JSON.stringify(errors)); | ||
process.exitCode = 1; | ||
return; | ||
} | ||
results.push({ name: path, ...data }); | ||
} | ||
|
||
console.log(JSON.stringify(results, null, 2)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,8 @@ | |
"semver": "^7.3.2", | ||
"simple-git": "^3.12.0", | ||
"yargs": "^16.0.3" | ||
}, | ||
"engines": { | ||
"node": ">= 12" | ||
} | ||
} |