@@ -32,9 +32,10 @@ const walk = async dir => {
3232 // Exclude 'dist' directories
3333 await walk ( fromPath ) ;
3434 }
35- } else if ( / ( p n g | j p g | j p e g ) $ / i. test ( file ) ) {
35+ } else if ( / ( p n g | j p g | j p e g | g i f ) $ / i. test ( file ) ) {
3636 Object . entries ( SIZES ) . forEach ( ( [ size , [ width , height ] ] ) => {
37- Jimp . read ( fromPath )
37+ if ( ! file . endsWith ( '.gif' ) ) {
38+ Jimp . read ( fromPath )
3839 . then ( img => {
3940 const distDir = path . join ( dir , 'dist' , size ) ;
4041
@@ -55,15 +56,16 @@ const walk = async dir => {
5556 . catch ( err => {
5657 console . error ( err ) ;
5758 } ) ;
58- } ) ;
59- } else if ( / ( g i f ) $ / i. test ( file ) ) {
60- Object . entries ( SIZES ) . forEach ( ( [ size , [ width , height ] ] ) => {
61- const distDir = path . join ( dir , 'dist' , size ) ;
62- GifUtil . read ( fromPath ) . then ( gif => {
63- gif . width = width ;
64- gif . height = height ?? Math . ceil ( ( width * gif . height ) / gif . width ) ;
65- GifUtil . write ( path . join ( distDir , file ) , gif . frames , gif )
66- } ) ;
59+ } else {
60+ GifUtil . read ( fromPath ) . then ( gif => {
61+ const distDir = path . join ( dir , 'dist' , size ) ;
62+ fs . ensureDir ( distDir ) . then ( ( ) => {
63+ gif . width = width ;
64+ gif . height = height ?? Math . ceil ( ( width * gif . height ) / gif . width ) ;
65+ return GifUtil . write ( path . join ( distDir , file ) , gif . frames , gif )
66+ } ) ;
67+ } ) ;
68+ }
6769 } ) ;
6870 }
6971 }
0 commit comments