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

Commitbf94ae1

Browse files
committed
add schema validation
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parentf29235a commitbf94ae1

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

‎src/build.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as util from "util";
66
import{parse}from"./utils/parse";
77
import{getArg}from"./utils/args";
88
import{getCommits,CommitLogObject}from"./utils/commits";
9+
import{validateSchema}from"./utils/validate";
910
import*asTfrom"../typings/tutorial";
1011

1112
constwrite=util.promisify(fs.writeFile);
@@ -58,7 +59,7 @@ async function build(args: string[]) {
5859
// path to run build from
5960
constlocalPath=path.join(process.cwd(),options.dir);
6061

61-
// load files
62+
// loadmarkdown andfiles
6263
let_markdown:string;
6364
let_yaml:string;
6465
try{
@@ -72,6 +73,7 @@ async function build(args: string[]) {
7273
return;
7374
}
7475

76+
// parse yaml config
7577
letconfig;
7678
try{
7779
config=yamlParser.load(_yaml);
@@ -80,6 +82,7 @@ async function build(args: string[]) {
8082
console.error(e.message);
8183
}
8284

85+
// load git commits to use in parse step
8386
letcommits:CommitLogObject;
8487
try{
8588
commits=awaitgetCommits({
@@ -92,7 +95,7 @@ async function build(args: string[]) {
9295
return;
9396
}
9497

95-
//Otherwise, continue with the other options
98+
//parse tutorial from markdown and yaml
9699
lettutorial:T.Tutorial;
97100
try{
98101
tutorial=awaitparse({
@@ -106,11 +109,25 @@ async function build(args: string[]) {
106109
return;
107110
}
108111

112+
// validate tutorial based on json schema
113+
try{
114+
constvalid=validateSchema(tutorial);
115+
if(!valid){
116+
console.error("Tutorial validation failed. See above to see what to fix");
117+
return;
118+
}
119+
}catch(e){
120+
console.error("Error validating tutorial schema:");
121+
console.error(e.message);
122+
}
123+
124+
// write tutorial
109125
if(tutorial){
110126
try{
111127
awaitwrite(options.output,JSON.stringify(tutorial),"utf8");
128+
console.info(`Success! See output at${options.output}`);
112129
}catch(e){
113-
console.error("Error writing tutorial json:");
130+
console.error("Error writing tutorial json file:");
114131
console.error(e.message);
115132
}
116133
}

‎src/utils/logs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const _info = console.info;
77

88
console.error=function(){
99
//@ts-ignore
10-
_error(red.bold.apply(console,arguments));
10+
_error(red.apply(console,arguments));
1111
};
1212

1313
console.warn=function(){
1414
//@ts-ignore
15-
_warn(yellow.bold.apply(console,arguments));
15+
_warn(yellow.apply(console,arguments));
1616
};
1717

1818
console.info=function(){

‎src/utils/validate.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export function validateSchema(json: any): boolean | PromiseLike<boolean> {
1616
if(!valid){
1717
// log errors
1818
if(process.env.NODE_ENV!=="test"){
19-
console.error("Validation failed. See below for details");
2019
jsonSchema.errors?.forEach((error:JsonSchema.ErrorObject)=>{
2120
console.warn(
2221
`Validation error at${error.dataPath} -${error.message}`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp