Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit183a5cd

Browse files
committed
add markdown validation to build script
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent3feef7c commit183a5cd

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

‎package.json

Lines changed: 2 additions & 2 deletions
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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getCommits, CommitLogObject } from "./utils/commits";
88
importskeletonSchemafrom"./schema/skeleton";
99
importtutorialSchemafrom"./schema/tutorial";
1010
import{validateSchema}from"./utils/validateSchema";
11+
import{validateMarkdown}from"./utils/validateMarkdown";
1112
import*asTfrom"../typings/tutorial";
1213

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

76+
// validate markdown loosely
77+
try{
78+
constisValid=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
letskeleton;
7790
try{

‎src/utils/validateMarkdown.ts

Lines changed: 3 additions & 5 deletions
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
constheaders=t.match(/^#{2}\s(.+)$/gm)||[];
30-
console.log("level headers",headers);
3130
for(constheaderofheaders){
3231
if(!header.match(/^#{2}\s(L\d+)\s(.+)$/)){
3332
returnfalse;
@@ -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
constheaders=t.match(/^#{3}\s(.+)$/gm)||[];
43-
console.log("step headers",headers);
4442
for(constheaderofheaders){
4543
if(!header.match(/^#{3}\s(L\d+)S\d+/)){
4644
returnfalse;
@@ -62,9 +60,9 @@ export function validateMarkdown(md: string): boolean {
6260
for(constvofvalidations){
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)

[8]ページ先頭

©2009-2025 Movatter.jp