File tree 6 files changed +86
-11
lines changed
6 files changed +86
-11
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @coderoad/cli" ,
3
- "version" : " 0.4.1 " ,
3
+ "version" : " 0.4.2 " ,
4
4
"description" : " A CLI to build the configuration file for Coderoad Tutorials" ,
5
5
"keywords" : [
6
6
" coderoad" ,
Original file line number Diff line number Diff line change @@ -140,6 +140,7 @@ export function parse(params: ParseParams): any {
140
140
// add level step commits
141
141
const { steps, ...configLevelProps } = configLevel ;
142
142
level = { ...configLevelProps , ...level } ;
143
+
143
144
if ( steps ) {
144
145
steps . forEach ( ( step : T . Step , index : number ) => {
145
146
try {
@@ -151,12 +152,14 @@ export function parse(params: ParseParams): any {
151
152
} ;
152
153
153
154
const stepSetupKey = `${ step . id } :T` ;
155
+
156
+ if ( ! step ?. setup ) {
157
+ step . setup = { } ;
158
+ }
159
+ if ( ! step . setup . commits ) {
160
+ step . setup . commits = [ ] ;
161
+ }
154
162
if ( params . commits [ stepSetupKey ] ) {
155
- if ( ! step . setup ) {
156
- step . setup = {
157
- commits : [ ] ,
158
- } ;
159
- }
160
163
step . setup . commits = params . commits [ stepSetupKey ] ;
161
164
}
162
165
Original file line number Diff line number Diff line change @@ -53,16 +53,17 @@ const codeBlockRegex = /```[a-z]*\n[\s\S]*?\n```/gm;
53
53
54
54
export function validateMarkdown ( md : string ) : boolean {
55
55
// 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 ( ) ;
57
58
58
59
let valid = true ;
59
60
60
61
for ( const v of validations ) {
61
62
if ( ! v . validate ( text ) ) {
62
63
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
+ }
66
67
}
67
68
}
68
69
Original file line number Diff line number Diff line change @@ -132,4 +132,26 @@ Should not be an issue
132
132
First Step` ;
133
133
expect ( validateMarkdown ( md ) ) . toBe ( true ) ;
134
134
} ) ;
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
+ } ) ;
135
157
} ) ;
Original file line number Diff line number Diff line change @@ -786,6 +786,55 @@ The first step
786
786
} ;
787
787
expect ( result . levels ) . toEqual ( expected . levels ) ;
788
788
} ) ;
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
+ } ) ;
789
838
} ) ;
790
839
791
840
describe ( "config" , ( ) => {
You can’t perform that action at this time.
0 commit comments