-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcustomSet.js
49 lines (39 loc) · 1.43 KB
/
customSet.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
require('dotenv').config();
const fs = require('fs');
const path = require('path');
const { PassThrough } = require('stream');
const tar = require('tar');
const config = require('./config');
const { logProgress, sumDurations, getLocaleDirs } = require('./helpers');
const outBucketName = config.get('outBucket');
const { db, clipBucket, bundlerBucket } = require('./init').initialize();
const { processAndDownloadClips } = require('./getClips');
const releaseDir = config.get('releaseName');
const zipAndUpload = async () => {
const stream = new PassThrough();
const name = 'eng_anon_25h_valid';
const archiveName = `${releaseDir}/${name}.tar.gz`;
console.log('archiving & uploading', archiveName);
const managedUpload = bundlerBucket.bucket.upload({
Body: stream,
Bucket: outBucketName,
Key: archiveName,
ACL: 'public-read',
});
logProgress(managedUpload);
const cwd = path.join(releaseDir);
tar.c({ gzip: true, cwd }, fs.readdirSync(cwd)).pipe(stream);
return managedUpload
.promise()
.then(() => bundlerBucket.bucket
.headObject({ Bucket: bundlerBucket.name, Key: archiveName })
.promise())
.then(({ ContentLength }) => {
console.log('');
return ContentLength;
})
.catch((err) => console.error(err));
};
processAndDownloadClips(db, clipBucket)
.then((stats) => Promise.all([stats, sumDurations(getLocaleDirs()), zipAndUpload()]))
.catch((e) => console.error(e));