@@ -6,6 +6,7 @@ import * as util from "util";
6
6
import { parse } from "./utils/parse" ;
7
7
import { getArg } from "./utils/args" ;
8
8
import { getCommits , CommitLogObject } from "./utils/commits" ;
9
+ import { validateSchema } from "./utils/validate" ;
9
10
import * as T from "../typings/tutorial" ;
10
11
11
12
const write = util . promisify ( fs . writeFile ) ;
@@ -58,7 +59,7 @@ async function build(args: string[]) {
58
59
// path to run build from
59
60
const localPath = path . join ( process . cwd ( ) , options . dir ) ;
60
61
61
- // load files
62
+ // load markdown and files
62
63
let _markdown : string ;
63
64
let _yaml : string ;
64
65
try {
@@ -72,6 +73,7 @@ async function build(args: string[]) {
72
73
return ;
73
74
}
74
75
76
+ // parse yaml config
75
77
let config ;
76
78
try {
77
79
config = yamlParser . load ( _yaml ) ;
@@ -80,6 +82,7 @@ async function build(args: string[]) {
80
82
console . error ( e . message ) ;
81
83
}
82
84
85
+ // load git commits to use in parse step
83
86
let commits : CommitLogObject ;
84
87
try {
85
88
commits = await getCommits ( {
@@ -92,7 +95,7 @@ async function build(args: string[]) {
92
95
return ;
93
96
}
94
97
95
- // Otherwise, continue with the other options
98
+ // parse tutorial from markdown and yaml
96
99
let tutorial : T . Tutorial ;
97
100
try {
98
101
tutorial = await parse ( {
@@ -106,11 +109,25 @@ async function build(args: string[]) {
106
109
return ;
107
110
}
108
111
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
109
125
if ( tutorial ) {
110
126
try {
111
127
await write ( options . output , JSON . stringify ( tutorial ) , "utf8" ) ;
128
+ console . info ( `Success! See output at ${ options . output } ` ) ;
112
129
} catch ( e ) {
113
- console . error ( "Error writing tutorial json:" ) ;
130
+ console . error ( "Error writing tutorial json file :" ) ;
114
131
console . error ( e . message ) ;
115
132
}
116
133
}
0 commit comments