@@ -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
5960const localPath = path . join ( process . cwd ( ) , options . dir ) ;
6061
61- // load files
62+ // loadmarkdown and files
6263let _markdown :string ;
6364let _yaml :string ;
6465try {
@@ -72,6 +73,7 @@ async function build(args: string[]) {
7273return ;
7374}
7475
76+ // parse yaml config
7577let config ;
7678try {
7779config = yamlParser . load ( _yaml ) ;
@@ -80,6 +82,7 @@ async function build(args: string[]) {
8082console . error ( e . message ) ;
8183}
8284
85+ // load git commits to use in parse step
8386let commits :CommitLogObject ;
8487try {
8588commits = await getCommits ( {
@@ -92,7 +95,7 @@ async function build(args: string[]) {
9295return ;
9396}
9497
95- //Otherwise, continue with the other options
98+ //parse tutorial from markdown and yaml
9699let tutorial :T . Tutorial ;
97100try {
98101tutorial = await parse ( {
@@ -106,11 +109,25 @@ async function build(args: string[]) {
106109return ;
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
109125if ( tutorial ) {
110126try {
111127await 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 :" ) ;
114131console . error ( e . message ) ;
115132}
116133}