File tree 3 files changed +18
-9
lines changed
3 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import type {
10
10
import { folderPathToFilesRef , interpolateString } from '@tutorialkit/types' ;
11
11
import { getCollection } from 'astro:content' ;
12
12
import glob from 'fast-glob' ;
13
- import mm from 'micromatch' ;
13
+ import micromatch from 'micromatch' ;
14
14
import path from 'node:path' ;
15
15
import { IGNORED_FILES } from './constants' ;
16
16
import { DEFAULT_LOCALIZATION } from './content/default-localization' ;
@@ -265,14 +265,14 @@ export async function getTutorial(): Promise<Tutorial> {
265
265
} ;
266
266
267
267
if ( lesson . data . template && typeof lesson . data . template !== 'string' && lesson . data . template . visibleFiles ?. length ) {
268
- const templateFilesRef = await getFilesRefList ( lesson . data . template . name , TEMPLATES_DIR ) ;
268
+ const [ , tempalteFiles ] = await getFilesRefList ( lesson . data . template . name , TEMPLATES_DIR ) ;
269
269
270
- for ( const filename of templateFilesRef [ 1 ] ) {
270
+ for ( const filename of tempalteFiles ) {
271
271
if ( lesson . files [ 1 ] . includes ( filename ) ) {
272
272
continue ;
273
273
}
274
274
275
- if ( mm . isMatch ( filename , lesson . data . template . visibleFiles , { format : formatTemplateFile } ) ) {
275
+ if ( micromatch . isMatch ( filename , lesson . data . template . visibleFiles , { format : formatTemplateFile } ) ) {
276
276
lesson . files [ 1 ] . push ( filename ) ;
277
277
}
278
278
}
Original file line number Diff line number Diff line change @@ -176,7 +176,7 @@ export class TutorialStore {
176
176
this . _lessonFiles = files ;
177
177
this . _lessonSolution = solution ;
178
178
this . _lessonTemplate = template ;
179
- this . _visibleTemplateFiles = filterEntries ( template , lesson . files [ 1 ] ) ;
179
+ this . _visibleTemplateFiles = pick ( template , lesson . files [ 1 ] ) ;
180
180
181
181
const editorFiles = { ...this . _visibleTemplateFiles , ...this . _lessonFiles } ;
182
182
this . _editorStore . setDocuments ( editorFiles ) ;
@@ -366,6 +366,14 @@ export class TutorialStore {
366
366
}
367
367
}
368
368
369
- function filterEntries < T extends object > ( obj : T , filter : string [ ] ) {
370
- return Object . fromEntries ( Object . entries ( obj ) . filter ( ( [ entry ] ) => filter . includes ( entry ) ) ) ;
369
+ function pick < T > ( obj : Record < string , T > , entries : string [ ] ) {
370
+ const result : Record < string , T > = { } ;
371
+
372
+ for ( const entry of entries ) {
373
+ if ( entry in obj ) {
374
+ result [ entry ] = obj [ entry ] ;
375
+ }
376
+ }
377
+
378
+ return result ;
371
379
}
Original file line number Diff line number Diff line change @@ -172,16 +172,17 @@ export const webcontainerSchema = commandsSchema.extend({
172
172
template : z
173
173
. union ( [
174
174
// name of the template
175
- z . string ( ) . optional ( ) ,
175
+ z . string ( ) ,
176
176
177
177
z . strictObject ( {
178
178
// name of the template
179
179
name : z . string ( ) ,
180
180
181
181
// list of globs of files that should be visible
182
- visibleFiles : z . array ( z . string ( ) ) . optional ( ) ,
182
+ visibleFiles : z . array ( z . string ( ) ) . optional ( ) . describe ( 'Specifies which files from template should be visible' ) ,
183
183
} ) ,
184
184
] )
185
+ . optional ( )
185
186
. describe (
186
187
'Specifies which folder from the `src/templates/` directory should be used as the basis for the code. See the "Code templates" guide for a detailed explainer.' ,
187
188
) ,
You can’t perform that action at this time.
0 commit comments