-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
37 lines (32 loc) · 999 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const fs = require('fs')
const path = require('path')
var fsextra = require('fs-extra')
const archiver = require('archiver')
module.exports = bundler => {
bundler.on('bundled', async (bundle) => {
if (process.env.NODE_ENV === 'production') {
const dir = path.dirname(bundle.name)
function zipFile() {
return new Promise(resolve => {
var output = fs.createWriteStream(path.parse(dir).name + '.zip')
var archive = archiver('zip')
archive.on('error', err => { throw err })
output.on('close', function () {
resolve('Data has been close')
})
archive.pipe(output);
archive.directory(path.parse(dir).name, false)
archive.finalize()
})
}
async function removeDir() {
await zipFile()
fsextra.remove(dir, function (err) {
if (err) return console.error(err)
console.log("success!")
})
}
removeDir()
}
})
}