Skip to content

Commit 183a5cd

Browse files
committed
add markdown validation to build script
Signed-off-by: shmck <[email protected]>
1 parent 3feef7c commit 183a5cd

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coderoad/cli",
3-
"version": "0.2.0",
3+
"version": "0.2.1",
44
"description": "A CLI to build the configuration file for Coderoad Tutorials",
55
"keywords": [
66
"coderoad",
@@ -25,7 +25,7 @@
2525
],
2626
"main": "bin/coderoad",
2727
"bin": {
28-
"@coderoad/coderoad": "bin/coderoad",
28+
"@coderoad/cli": "bin/coderoad",
2929
"coderoad": "bin/coderoad"
3030
},
3131
"scripts": {

src/build.ts

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getCommits, CommitLogObject } from "./utils/commits";
88
import skeletonSchema from "./schema/skeleton";
99
import tutorialSchema from "./schema/tutorial";
1010
import { validateSchema } from "./utils/validateSchema";
11+
import { validateMarkdown } from "./utils/validateMarkdown";
1112
import * as T from "../typings/tutorial";
1213

1314
const write = util.promisify(fs.writeFile);
@@ -72,6 +73,18 @@ async function build(args: string[]) {
7273
return;
7374
}
7475

76+
// validate markdown loosely
77+
try {
78+
const isValid = validateMarkdown(_markdown);
79+
if (!isValid) {
80+
console.warn("Invalid markdown");
81+
}
82+
} catch (e) {
83+
console.error("Error validating markdown:");
84+
console.error(e.message);
85+
return;
86+
}
87+
7588
// parse yaml skeleton config
7689
let skeleton;
7790
try {

src/utils/validateMarkdown.ts

+3-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const validations: Validation[] = [
2727
message: "should have a level `##` with a format of `L[0-9]+`",
2828
validate: (t) => {
2929
const headers = t.match(/^#{2}\s(.+)$/gm) || [];
30-
console.log("level headers", headers);
3130
for (const header of headers) {
3231
if (!header.match(/^#{2}\s(L\d+)\s(.+)$/)) {
3332
return false;
@@ -40,7 +39,6 @@ const validations: Validation[] = [
4039
message: "should have a step `###` with a format of `L[0-9]+S[0-9]+`",
4140
validate: (t) => {
4241
const headers = t.match(/^#{3}\s(.+)$/gm) || [];
43-
console.log("step headers", headers);
4442
for (const header of headers) {
4543
if (!header.match(/^#{3}\s(L\d+)S\d+/)) {
4644
return false;
@@ -62,9 +60,9 @@ export function validateMarkdown(md: string): boolean {
6260
for (const v of validations) {
6361
if (!v.validate(text)) {
6462
valid = false;
65-
// if (process.env.NODE_ENV !== "test") {
66-
console.warn(v.message);
67-
// }
63+
if (process.env.NODE_ENV !== "test") {
64+
console.warn(v.message);
65+
}
6866
}
6967
}
7068

0 commit comments

Comments
 (0)