@@ -46,33 +46,72 @@ const parseArgs = (args: string[]): BuildArgs => {
46
46
} ;
47
47
48
48
async function build ( args : string [ ] ) {
49
- const options = parseArgs ( args ) ;
49
+ let options : BuildArgs ;
50
+ try {
51
+ options = parseArgs ( args ) ;
52
+ } catch ( e ) {
53
+ console . error ( "Error parsing build logs" ) ;
54
+ console . error ( e . message ) ;
55
+ return ;
56
+ }
50
57
51
58
// path to run build from
52
59
const localPath = path . join ( process . cwd ( ) , options . dir ) ;
53
60
54
61
// load files
55
- const [ _markdown , _yaml ] = await Promise . all ( [
56
- read ( path . join ( localPath , options . markdown ) , "utf8" ) ,
57
- read ( path . join ( localPath , options . yaml ) , "utf8" ) ,
58
- ] ) ;
62
+ let _markdown : string ;
63
+ let _yaml : string ;
64
+ try {
65
+ [ _markdown , _yaml ] = await Promise . all ( [
66
+ read ( path . join ( localPath , options . markdown ) , "utf8" ) ,
67
+ read ( path . join ( localPath , options . yaml ) , "utf8" ) ,
68
+ ] ) ;
69
+ } catch ( e ) {
70
+ console . error ( "Error reading file:" ) ;
71
+ console . error ( e . message ) ;
72
+ return ;
73
+ }
59
74
60
- const config = yamlParser . load ( _yaml ) ;
75
+ let config ;
76
+ try {
77
+ config = yamlParser . load ( _yaml ) ;
78
+ } catch ( e ) {
79
+ console . error ( "Error parsing yaml" ) ;
80
+ console . error ( e . message ) ;
81
+ }
61
82
62
- const commits : CommitLogObject = await getCommits ( config . config . repo . branch ) ;
83
+ let commits : CommitLogObject ;
84
+ try {
85
+ commits = await getCommits ( {
86
+ localDir : localPath ,
87
+ codeBranch : config . config . repo . branch ,
88
+ } ) ;
89
+ } catch ( e ) {
90
+ console . error ( "Error loading commits:" ) ;
91
+ console . error ( e . message ) ;
92
+ return ;
93
+ }
63
94
64
95
// Otherwise, continue with the other options
65
- const tutorial : T . Tutorial = await parse ( {
66
- text : _markdown ,
67
- config,
68
- commits,
69
- } ) ;
96
+ let tutorial : T . Tutorial ;
97
+ try {
98
+ tutorial = await parse ( {
99
+ text : _markdown ,
100
+ config,
101
+ commits,
102
+ } ) ;
103
+ } catch ( e ) {
104
+ console . error ( "Error parsing tutorial:" ) ;
105
+ console . error ( e . message ) ;
106
+ return ;
107
+ }
70
108
71
109
if ( tutorial ) {
72
- if ( options . output ) {
110
+ try {
73
111
await write ( options . output , JSON . stringify ( tutorial ) , "utf8" ) ;
74
- } else {
75
- console . log ( JSON . stringify ( tutorial , null , 2 ) ) ;
112
+ } catch ( e ) {
113
+ console . error ( "Error writing tutorial json:" ) ;
114
+ console . error ( e . message ) ;
76
115
}
77
116
}
78
117
}
0 commit comments