File tree 6 files changed +25
-4
lines changed
template/src/content/tutorial/1-basics/1-introduction/1-welcome
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> {
242
242
const partMetadata = _tutorial . parts [ lesson . part . id ] . data ;
243
243
const chapterMetadata = _tutorial . parts [ lesson . part . id ] . chapters [ lesson . chapter . id ] . data ;
244
244
245
+ // now we inherit options from upper levels
245
246
lesson . data = {
246
247
...lesson . data ,
247
248
...squash (
Original file line number Diff line number Diff line change @@ -78,7 +78,7 @@ function getTemplateName(file: string) {
78
78
) ;
79
79
80
80
if ( meta . attributes . template ) {
81
- return meta . attributes . template ;
81
+ return typeof meta . attributes . template === 'string' ? meta . attributes . template : meta . attributes . template . name ;
82
82
}
83
83
84
84
/**
Original file line number Diff line number Diff line change @@ -42,7 +42,8 @@ export class LessonFilesFetcher {
42
42
}
43
43
44
44
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` ;
46
47
47
48
if ( this . _map . has ( templatePathname ) ) {
48
49
return this . _map . get ( templatePathname ) ! ;
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ prepareCommands:
11
11
- ['node -e setTimeout(()=>{process.exit(1)},5000)', 'This is going to fail']
12
12
terminal :
13
13
panels : ['terminal', 'output']
14
+ template :
15
+ name : default
14
16
---
15
17
16
18
# Kitchen Sink [ Heading 1]
Original file line number Diff line number Diff line change @@ -350,13 +350,22 @@ describe('webcontainerSchema', () => {
350
350
} ) . not . toThrow ( ) ;
351
351
} ) ;
352
352
353
- it ( 'should allow specifying the template' , ( ) => {
353
+ it ( 'should allow specifying the template by name ' , ( ) => {
354
354
expect ( ( ) => {
355
355
webcontainerSchema . parse ( {
356
356
template : 'default' ,
357
357
} ) ;
358
358
} ) . not . toThrow ( ) ;
359
359
} ) ;
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
+ } ) ;
360
369
it ( 'should allow specifying the terminal' , ( ) => {
361
370
expect ( ( ) => {
362
371
webcontainerSchema . parse ( {
Original file line number Diff line number Diff line change @@ -138,7 +138,15 @@ export type TerminalSchema = z.infer<typeof terminalSchema>;
138
138
export const webcontainerSchema = commandsSchema . extend ( {
139
139
previews : previewSchema . optional ( ) ,
140
140
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
+ ] ) ,
142
150
terminal : terminalSchema . optional ( ) ,
143
151
focus : z . string ( ) . optional ( ) ,
144
152
editor : z . union ( [
You can’t perform that action at this time.
0 commit comments