File tree Expand file tree Collapse file tree 6 files changed +86
-11
lines changed Expand file tree Collapse file tree 6 files changed +86
-11
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @coderoad/cli" ,
3- "version" : " 0.4.1 " ,
3+ "version" : " 0.4.2 " ,
44 "description" : " A CLI to build the configuration file for Coderoad Tutorials" ,
55 "keywords" : [
66 " coderoad" ,
Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ export function parse(params: ParseParams): any {
140140 // add level step commits
141141 const { steps, ...configLevelProps } = configLevel ;
142142 level = { ...configLevelProps , ...level } ;
143+
143144 if ( steps ) {
144145 steps . forEach ( ( step : T . Step , index : number ) => {
145146 try {
@@ -151,12 +152,14 @@ export function parse(params: ParseParams): any {
151152 } ;
152153
153154 const stepSetupKey = `${ step . id } :T` ;
155+
156+ if ( ! step ?. setup ) {
157+ step . setup = { } ;
158+ }
159+ if ( ! step . setup . commits ) {
160+ step . setup . commits = [ ] ;
161+ }
154162 if ( params . commits [ stepSetupKey ] ) {
155- if ( ! step . setup ) {
156- step . setup = {
157- commits : [ ] ,
158- } ;
159- }
160163 step . setup . commits = params . commits [ stepSetupKey ] ;
161164 }
162165
Original file line number Diff line number Diff line change @@ -53,16 +53,17 @@ const codeBlockRegex = /```[a-z]*\n[\s\S]*?\n```/gm;
5353
5454export function validateMarkdown ( md : string ) : boolean {
5555 // remove codeblocks which might contain any valid combinations
56- const text = md . replace ( codeBlockRegex , "" ) ;
56+ // trim white space
57+ const text = md . replace ( codeBlockRegex , "" ) . trim ( ) ;
5758
5859 let valid = true ;
5960
6061 for ( const v of validations ) {
6162 if ( ! v . validate ( text ) ) {
6263 valid = false ;
63- // if (process.env.NODE_ENV !== "test") {
64- console . warn ( v . message ) ;
65- // }
64+ if ( process . env . NODE_ENV !== "test" ) {
65+ console . warn ( v . message ) ;
66+ }
6667 }
6768 }
6869
Original file line number Diff line number Diff line change @@ -132,4 +132,26 @@ Should not be an issue
132132First Step` ;
133133 expect ( validateMarkdown ( md ) ) . toBe ( true ) ;
134134 } ) ;
135+ it ( "should ignore empty space at the top" , ( ) => {
136+ const md = `
137+
138+ # Title
139+
140+ Description.` ;
141+ expect ( validateMarkdown ( md ) ) . toBe ( true ) ;
142+ } ) ;
143+ it ( "should ignore empty space at the bottom" , ( ) => {
144+ const md = `
145+
146+ # Title
147+
148+ Description.
149+
150+
151+
152+
153+
154+ ` ;
155+ expect ( validateMarkdown ( md ) ) . toBe ( true ) ;
156+ } ) ;
135157} ) ;
Original file line number Diff line number Diff line change @@ -786,6 +786,55 @@ The first step
786786 } ;
787787 expect ( result . levels ) . toEqual ( expected . levels ) ;
788788 } ) ;
789+ it ( "should load no commits if none found for a step" , ( ) => {
790+ const md = `# Title
791+
792+ Description.
793+
794+ ## 1. Title
795+
796+ First line
797+
798+ ### 1.1
799+
800+ The first step
801+ ` ;
802+ const skeleton = {
803+ levels : [
804+ {
805+ id : "1" ,
806+ steps : [ { id : "1" } ] ,
807+ } ,
808+ ] ,
809+ } ;
810+ const result = parse ( {
811+ text : md ,
812+ skeleton,
813+ commits : { } ,
814+ } ) ;
815+ const expected = {
816+ summary : {
817+ description : "Description." ,
818+ } ,
819+ levels : [
820+ {
821+ id : "1" ,
822+ summary : "First line" ,
823+ content : "First line" ,
824+ steps : [
825+ {
826+ id : "1.1" ,
827+ content : "The first step" ,
828+ setup : {
829+ commits : [ ] ,
830+ } ,
831+ } ,
832+ ] ,
833+ } ,
834+ ] ,
835+ } ;
836+ expect ( result . levels [ 0 ] . steps [ 0 ] ) . toEqual ( expected . levels [ 0 ] . steps [ 0 ] ) ;
837+ } ) ;
789838 } ) ;
790839
791840 describe ( "config" , ( ) => {
You can’t perform that action at this time.
0 commit comments