@@ -8,39 +8,39 @@ export async function downloadZip(wc: WebContainer, ignoredFiles?: StringOrRegEx
88 const { default : JSZip } = await import ( 'jszip' )
99 const zip = new JSZip ( )
1010
11- type Zip = typeof zip
12- const crawlFiles = async ( dir : string , zip : Zip ) => {
13- const files = await wc . fs . readdir ( dir , { withFileTypes : true } )
11+ type Zip = typeof zip
12+ const crawlFiles = async ( dir : string , zip : Zip ) => {
13+ const files = await wc . fs . readdir ( dir , { withFileTypes : true } )
1414
15- await Promise . all (
16- files . map ( async ( file ) => {
17- if ( isFileIgnored ( file . name , ignoredFiles ) )
18- return
15+ await Promise . all (
16+ files . map ( async ( file ) => {
17+ if ( isFileIgnored ( file . name , ignoredFiles ) )
18+ return
1919
20- if ( file . isFile ( ) ) {
21- // TODO: If it's package.json, we modify to remove some fields
22- const content = await wc . fs . readFile ( `${ dir } /${ file . name } ` , 'utf8' )
23- zip . file ( file . name , content )
24- }
25- else if ( file . isDirectory ( ) ) {
26- const folder = zip . folder ( file . name ) !
27- return crawlFiles ( `${ dir } /${ file . name } ` , folder )
28- }
29- } ) ,
30- )
31- }
20+ if ( file . isFile ( ) ) {
21+ // TODO: If it's package.json, we modify to remove some fields
22+ const content = await wc . fs . readFile ( `${ dir } /${ file . name } ` , 'utf8' )
23+ zip . file ( file . name , content )
24+ }
25+ else if ( file . isDirectory ( ) ) {
26+ const folder = zip . folder ( file . name ) !
27+ return crawlFiles ( `${ dir } /${ file . name } ` , folder )
28+ }
29+ } ) ,
30+ )
31+ }
3232
33- await crawlFiles ( '.' , zip )
33+ await crawlFiles ( '.' , zip )
3434
35- const blob = await zip . generateAsync ( { type : 'blob' } )
36- const url = URL . createObjectURL ( blob )
37- const date = new Date ( )
38- const dateString = `${ date . getFullYear ( ) } -${ date . getMonth ( ) + 1 } -${ date . getDate ( ) } -${ date . getHours ( ) } -${ date . getMinutes ( ) } -${ date . getSeconds ( ) } `
39- const link = document . createElement ( 'a' )
40- link . href = url
41- // TODO: have a better name with the current tutorial name
42- link . download = `nuxt-playground-${ dateString } .zip`
43- link . click ( )
44- link . remove ( )
45- URL . revokeObjectURL ( url )
35+ const blob = await zip . generateAsync ( { type : 'blob' } )
36+ const url = URL . createObjectURL ( blob )
37+ const date = new Date ( )
38+ const dateString = `${ date . getFullYear ( ) } -${ date . getMonth ( ) + 1 } -${ date . getDate ( ) } -${ date . getHours ( ) } -${ date . getMinutes ( ) } -${ date . getSeconds ( ) } `
39+ const link = document . createElement ( 'a' )
40+ link . href = url
41+ // TODO: have a better name with the current tutorial name
42+ link . download = `nuxt-playground-${ dateString } .zip`
43+ link . click ( )
44+ link . remove ( )
45+ URL . revokeObjectURL ( url )
4646}
0 commit comments