import Fs from 'fs/promises' ; import { createWriteStream } from 'fs' ; import Path from 'path' ; import { pipeline } from 'stream' ; import { promisify } from 'util' ; import archiver from 'archiver' ; const asyncPipeline = promisify ( pipeline ) ; export async function zip ( dirs , files , outputPath ) { const archive = archiver ( 'zip' , { zlib : { level : 9 , } , } ) ; for ( const [ absolute , relative ] of dirs ) { archive . directory ( absolute , relative ) ; } for ( const [ absolute , relative ] of files ) { archive . file ( absolute , { name : relative , } ) ; } await Fs . mkdir ( Path . dirname ( outputPath ) , { recursive : true } ) ; await Promise . all ( [ asyncPipeline ( archive , createWriteStream ( outputPath ) ) , archive . finalize ( ) ] ) ; }