@@ -94,11 +94,11 @@ export function parseMdContent(md: string): TutorialFrame | never {
9494
9595type ParseParams = {
9696 text : string ;
97- config : T . Tutorial ;
97+ config : Partial < T . Tutorial | any > ;
9898 commits : CommitLogObject ;
9999} ;
100100
101- export function parse ( params : ParseParams ) : T . Tutorial {
101+ export function parse ( params : ParseParams ) : any {
102102 const parsed = { ...params . config } ;
103103
104104 const mdContent : TutorialFrame = parseMdContent ( params . text ) ;
@@ -110,71 +110,53 @@ export function parse(params: ParseParams): T.Tutorial {
110110 if ( parsed . levels ) {
111111 parsed . levels . forEach ( ( level : T . Level , levelIndex : number ) => {
112112 const levelContent = mdContent [ level . id ] ;
113+ console . log ( levelContent ) ;
113114 if ( ! levelContent ) {
114115 console . log ( `Markdown content not found for ${ level . id } ` ) ;
115116 return ;
116117 }
117- const { steps, ...content } = levelContent ;
118118
119- if ( steps ) {
120- steps . forEach ( ( step : T . Step , stepIndex : number ) => {
121- return _ . merge ( step , steps [ step . id ] ) ;
119+ // add level setup commits
120+ const levelSetupKey = `L${ levelIndex + 1 } S` ;
121+ if ( params . commits [ levelSetupKey ] ) {
122+ if ( ! level . setup ) {
123+ level . setup = {
124+ commits : [ ] ,
125+ } ;
126+ }
127+ level . setup . commits = params . commits [ levelSetupKey ] ;
128+ }
129+
130+ // add level step commits
131+ if ( levelContent . steps ) {
132+ levelContent . steps . forEach ( ( step : T . Step , stepIndex : number ) => {
133+ const stepSetupKey = `${ levelSetupKey } S${ stepIndex + `1` } Q` ;
134+ if ( params . commits [ stepSetupKey ] ) {
135+ if ( ! step . setup ) {
136+ step . setup = {
137+ commits : [ ] ,
138+ } ;
139+ }
140+ step . setup . commits = params . commits [ stepSetupKey ] ;
141+ }
142+
143+ const stepSolutionKey = `${ levelSetupKey } S${ stepIndex + `1` } A` ;
144+ if ( params . commits [ stepSolutionKey ] ) {
145+ if ( ! step . solution ) {
146+ step . solution = {
147+ commits : [ ] ,
148+ } ;
149+ }
150+ step . solution . commits = params . commits [ stepSolutionKey ] ;
151+ }
152+
153+ return _ . merge ( step , levelContent . steps [ step . id ] ) ;
122154 } ) ;
123155 }
124156
125- _ . merge ( level , content ) ;
157+ _ . merge ( level ) ;
126158 } ) ;
127159 }
128160
129161 return parsed ;
130162}
131-
132- /*
133- // Add the content and git hash to the tutorial
134- if (matches.groups.stepId) {
135- // If it's a step: add the content and the setup/solution hashes depending on the type
136- const level: T.Level | null =
137- tutorial.levels.find(
138- (level: T.Level) => level.id === matches.groups.levelId
139- ) || null;
140- if (!level) {
141- console.log(`Level ${matches.groups.levelId} not found`);
142- } else {
143- const theStep: T.Step | null =
144- level.steps.find(
145- (step: T.Step) => step.id === matches.groups.stepId
146- ) || null;
147-
148- if (!theStep) {
149- console.log(`Step ${matches.groups.stepId} not found`);
150- } else {
151- if (matches.groups.stepType === "Q") {
152- theStep.setup.commits.push(commit.hash.substr(0, 7));
153- } else if (
154- matches.groups.stepType === "A" &&
155- theStep.solution &&
156- theStep.solution.commits
157- ) {
158- theStep.solution.commits.push(commit.hash.substr(0, 7));
159- }
160- }
161- }
162- } else {
163- // If it's level: add the commit hash (if the level has the commit key) and the content to the tutorial
164- const theLevel: T.Level | null =
165- tutorial.levels.find(
166- (level: T.Level) => level.id === matches.groups.levelId
167- ) || null;
168-
169- if (!theLevel) {
170- console.log(`Level ${matches.groups.levelId} not found`);
171- } else {
172- if (_.has(theLevel, "tutorial.commits")) {
173- if (theLevel.setup) {
174- theLevel.setup.commits.push(commit.hash.substr(0, 7));
175- }
176- }
177- }
178- }
179- }
180- */
0 commit comments