File tree Expand file tree Collapse file tree 6 files changed +25
-4
lines changed
template/src/content/tutorial/1-basics/1-introduction/1-welcome Expand file tree Collapse file tree 6 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -242,6 +242,7 @@ export async function getTutorial(): Promise<Tutorial> {
242242 const partMetadata = _tutorial . parts [ lesson . part . id ] . data ;
243243 const chapterMetadata = _tutorial . parts [ lesson . part . id ] . chapters [ lesson . chapter . id ] . data ;
244244
245+ // now we inherit options from upper levels
245246 lesson . data = {
246247 ...lesson . data ,
247248 ...squash (
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ function getTemplateName(file: string) {
7878 ) ;
7979
8080 if ( meta . attributes . template ) {
81- return meta . attributes . template ;
81+ return typeof meta . attributes . template === 'string' ? meta . attributes . template : meta . attributes . template . name ;
8282 }
8383
8484 /**
Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ export class LessonFilesFetcher {
4242 }
4343
4444 async getLessonTemplate ( lesson : Lesson ) : Promise < Files > {
45- const templatePathname = `template-${ lesson . data . template } .json` ;
45+ const templateName = typeof lesson . data . template === 'string' ? lesson . data . template : lesson . data . template ?. name ;
46+ const templatePathname = `template-${ templateName } .json` ;
4647
4748 if ( this . _map . has ( templatePathname ) ) {
4849 return this . _map . get ( templatePathname ) ! ;
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ prepareCommands:
1111 - ['node -e setTimeout(()=>{process.exit(1)},5000)', 'This is going to fail']
1212terminal :
1313 panels : ['terminal', 'output']
14+ template :
15+ name : default
1416---
1517
1618# Kitchen Sink [ Heading 1]
Original file line number Diff line number Diff line change @@ -350,13 +350,22 @@ describe('webcontainerSchema', () => {
350350 } ) . not . toThrow ( ) ;
351351 } ) ;
352352
353- it ( 'should allow specifying the template' , ( ) => {
353+ it ( 'should allow specifying the template by name ' , ( ) => {
354354 expect ( ( ) => {
355355 webcontainerSchema . parse ( {
356356 template : 'default' ,
357357 } ) ;
358358 } ) . not . toThrow ( ) ;
359359 } ) ;
360+ it ( 'should allow specifying the template by object type' , ( ) => {
361+ expect ( ( ) => {
362+ webcontainerSchema . parse ( {
363+ template : {
364+ name : 'default' ,
365+ } ,
366+ } ) ;
367+ } ) . not . toThrow ( ) ;
368+ } ) ;
360369 it ( 'should allow specifying the terminal' , ( ) => {
361370 expect ( ( ) => {
362371 webcontainerSchema . parse ( {
Original file line number Diff line number Diff line change @@ -138,7 +138,15 @@ export type TerminalSchema = z.infer<typeof terminalSchema>;
138138export const webcontainerSchema = commandsSchema . extend ( {
139139 previews : previewSchema . optional ( ) ,
140140 autoReload : z . boolean ( ) . optional ( ) ,
141- template : z . string ( ) . optional ( ) ,
141+ template : z . union ( [
142+ // name of the template
143+ z . string ( ) . optional ( ) ,
144+
145+ z . strictObject ( {
146+ // name of the template
147+ name : z . string ( ) ,
148+ } ) ,
149+ ] ) ,
142150 terminal : terminalSchema . optional ( ) ,
143151 focus : z . string ( ) . optional ( ) ,
144152 editor : z . union ( [
You can’t perform that action at this time.
0 commit comments