-
Notifications
You must be signed in to change notification settings - Fork 123
/
publish.js
77 lines (64 loc) · 1.71 KB
/
publish.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const fs = require('fs');
const AWS = require('aws-sdk');
const archiver = require('archiver');
require('dotenv').config();
// get version from package.json
const VERSION = require('./package.json').version;
const s3 = new AWS.S3({
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
});
const bucketName = 'cubecobra';
const zipFileName = `builds/${VERSION}.zip`;
const output = fs.createWriteStream('target.zip');
const archive = archiver('zip');
// first we delete the zip file if it exists
if (fs.existsSync('target.zip')) {
fs.unlinkSync('target.zip');
}
output.on('close', function () {
console.log(`${archive.pointer()} total bytes`);
console.log('archiver has been finalized and the output file descriptor has closed.');
// upload the zip file to s3
const fileStream = fs.createReadStream('target.zip');
fileStream.on('open', function () {
const params = {
Bucket: bucketName,
Key: zipFileName,
Body: fileStream,
};
s3.upload(params, function (err, data) {
if (err) {
console.log('Error', err);
}
if (data) {
console.log('Upload Success', data.Location);
}
});
});
});
archive.on('error', function (err) {
throw err;
});
archive.pipe(output);
// List of files or directories to ignore
const ignore = [
'**/node_modules/**',
'target.zip',
'upload.js',
'.env',
'.gitignore',
'.git/**',
'test/**',
'scripts/**',
'model/**',
'one_shot_scripts/**',
'scripts/**',
'temp/**',
'private/**',
'publish.js',
'README.md',
];
// append files from a sub-directory, putting its contents at the root of archive
archive.glob('**/*', { ignore, dot: true });
archive.finalize();