mirror of
https://github.com/serverless/serverless.git
synced 2025-12-08 19:46:03 +00:00
* fix: remove bluebird from zip-service * fix: remove bluebird and set concurrency limits for packaging
39 lines
980 B
JavaScript
39 lines
980 B
JavaScript
import fs from 'fs'
|
|
import path from 'path'
|
|
import archiver from 'archiver'
|
|
import walkDirSync from './walk-dir-sync.js'
|
|
|
|
async function createZipFile(srcDirPath, outputFilePath) {
|
|
const files = walkDirSync(srcDirPath).map((file) => ({
|
|
input: file,
|
|
output: file.replace(path.join(srcDirPath, path.sep), ''),
|
|
}))
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const output = fs.createWriteStream(outputFilePath)
|
|
const archive = archiver('zip', {
|
|
zlib: { level: 9 },
|
|
})
|
|
|
|
output.on('open', () => {
|
|
archive.pipe(output)
|
|
|
|
files.forEach((file) => {
|
|
// TODO: update since this is REALLY slow
|
|
if (fs.lstatSync(file.input).isFile()) {
|
|
archive.append(fs.createReadStream(file.input), {
|
|
name: file.output,
|
|
})
|
|
}
|
|
})
|
|
|
|
archive.finalize()
|
|
})
|
|
|
|
archive.on('error', (err) => reject(err))
|
|
output.on('close', () => resolve(outputFilePath))
|
|
})
|
|
}
|
|
|
|
export default createZipFile
|