File tree Expand file tree Collapse file tree 3 files changed +18
-9
lines changed Expand file tree Collapse file tree 3 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import type {
1010import { folderPathToFilesRef , interpolateString } from '@tutorialkit/types' ;
1111import { getCollection } from 'astro:content' ;
1212import glob from 'fast-glob' ;
13- import mm from 'micromatch' ;
13+ import micromatch from 'micromatch' ;
1414import path from 'node:path' ;
1515import { IGNORED_FILES } from './constants' ;
1616import { DEFAULT_LOCALIZATION } from './content/default-localization' ;
@@ -265,14 +265,14 @@ export async function getTutorial(): Promise<Tutorial> {
265265 } ;
266266
267267 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 ) ;
269269
270- for ( const filename of templateFilesRef [ 1 ] ) {
270+ for ( const filename of tempalteFiles ) {
271271 if ( lesson . files [ 1 ] . includes ( filename ) ) {
272272 continue ;
273273 }
274274
275- if ( mm . isMatch ( filename , lesson . data . template . visibleFiles , { format : formatTemplateFile } ) ) {
275+ if ( micromatch . isMatch ( filename , lesson . data . template . visibleFiles , { format : formatTemplateFile } ) ) {
276276 lesson . files [ 1 ] . push ( filename ) ;
277277 }
278278 }
Original file line number Diff line number Diff line change @@ -176,7 +176,7 @@ export class TutorialStore {
176176 this . _lessonFiles = files ;
177177 this . _lessonSolution = solution ;
178178 this . _lessonTemplate = template ;
179- this . _visibleTemplateFiles = filterEntries ( template , lesson . files [ 1 ] ) ;
179+ this . _visibleTemplateFiles = pick ( template , lesson . files [ 1 ] ) ;
180180
181181 const editorFiles = { ...this . _visibleTemplateFiles , ...this . _lessonFiles } ;
182182 this . _editorStore . setDocuments ( editorFiles ) ;
@@ -366,6 +366,14 @@ export class TutorialStore {
366366 }
367367}
368368
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 ;
371379}
Original file line number Diff line number Diff line change @@ -172,16 +172,17 @@ export const webcontainerSchema = commandsSchema.extend({
172172 template : z
173173 . union ( [
174174 // name of the template
175- z . string ( ) . optional ( ) ,
175+ z . string ( ) ,
176176
177177 z . strictObject ( {
178178 // name of the template
179179 name : z . string ( ) ,
180180
181181 // 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' ) ,
183183 } ) ,
184184 ] )
185+ . optional ( )
185186 . describe (
186187 '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.' ,
187188 ) ,
You can’t perform that action at this time.
0 commit comments