@@ -6,6 +6,7 @@ import * as util from "util";
66import { parse } from "./utils/parse" ;
77import { getArg } from "./utils/args" ;
88import { getCommits , CommitLogObject } from "./utils/commits" ;
9+ import { validateSchema } from "./utils/validate" ;
910import * as T from "../typings/tutorial" ;
1011
1112const write = util . promisify ( fs . writeFile ) ;
@@ -58,7 +59,7 @@ async function build(args: string[]) {
5859 // path to run build from
5960 const localPath = path . join ( process . cwd ( ) , options . dir ) ;
6061
61- // load files
62+ // load markdown and files
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 let config ;
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 let commits : CommitLogObject ;
8487 try {
8588 commits = await getCommits ( {
@@ -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 let tutorial : T . Tutorial ;
97100 try {
98101 tutorial = await parse ( {
@@ -106,11 +109,25 @@ async function build(args: string[]) {
106109 return ;
107110 }
108111
112+ // validate tutorial based on json schema
113+ try {
114+ const valid = 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 await write ( 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 }
0 commit comments