-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
46 lines (37 loc) · 1 KB
/
build.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
38
39
40
41
42
43
44
45
46
const fs = require('fs');
const archiver = require('archiver');
const {Lambda} = require('aws-sdk');
const {region, lambdaFunction} = require('./config');
const isDev = process.argv[2] !== 'prod';
const lambda = new Lambda({region});
const output = fs.createWriteStream(`${process.argv[2] || 'dev'}.zip`);
const archive = archiver('zip', {
zlib: {level: 9}, // Sets the compression level.
});
output.on('close', async () => {
console.log(`${archive.pointer()} total bytes`);
if (isDev) {
console.log('uploading new lambda');
await lambda.updateFunctionCode({
FunctionName: lambdaFunction,
ZipFile: fs.readFileSync('./src.zip'),
}).promise();
}
console.log('finnish');
});
output.on('end', () => {
console.log('Data has been drained');
});
archive.on('warning', (err) => {
if (err.code === 'ENOENT') {
console.log(err);
} else {
throw err;
}
});
archive.on('error', (err) => {
throw err;
});
archive.pipe(output);
archive.directory('src/', false);
archive.finalize();