1 | // Load dependencies
|
---|
2 | const fs = require('fs');
|
---|
3 | const aws = require('aws-sdk');
|
---|
4 | const Glob = require('glob');
|
---|
5 |
|
---|
6 | const spaces_endpoint = new aws.Endpoint('ams3.digitaloceanspaces.com');
|
---|
7 | const s3 = new aws.S3({
|
---|
8 | endpoint: spaces_endpoint
|
---|
9 | });
|
---|
10 |
|
---|
11 | const pkg_json = fs.readFileSync('package.json');
|
---|
12 | let version = JSON.parse(pkg_json).version;
|
---|
13 |
|
---|
14 | const upload = (v, type) => {
|
---|
15 | let key = '';
|
---|
16 | if (type === '-mac.zip') {
|
---|
17 | key = `genius2-app-v${version}-mac.zip`;
|
---|
18 | }
|
---|
19 | if (type === '.AppImage') {
|
---|
20 | key = `genius2-app-v${version}-linux.AppImage`;
|
---|
21 | }
|
---|
22 | if (type === '.exe') {
|
---|
23 | key = `genius2-app-v${version}-setup-windows.exe`;
|
---|
24 | }
|
---|
25 | if (key.length === 0) return;
|
---|
26 |
|
---|
27 | console.log('uploading', v, 'as', key);
|
---|
28 |
|
---|
29 | fs.readFile(v, (err, data) => {
|
---|
30 | if (err) throw err;
|
---|
31 |
|
---|
32 | const b64d = Buffer.from(data, 'binary');
|
---|
33 |
|
---|
34 | const params = {
|
---|
35 | Bucket: 'erancihan',
|
---|
36 | ACL: 'public-read',
|
---|
37 | Body: b64d,
|
---|
38 | Key: `genius/v${version}/${key}`
|
---|
39 | };
|
---|
40 |
|
---|
41 | s3.putObject(params, (err, data) => {
|
---|
42 | if (err) throw err;
|
---|
43 | console.log('success', key);
|
---|
44 | });
|
---|
45 | });
|
---|
46 | };
|
---|
47 |
|
---|
48 | const mac_zips = new Glob(`${__dirname}/dist/*-mac.zip`, (e, f) => {
|
---|
49 | f.forEach(v => {
|
---|
50 | upload(v, '-mac.zip');
|
---|
51 | });
|
---|
52 | });
|
---|
53 |
|
---|
54 | const linux_releases = new Glob(`${__dirname}/dist/*.AppImage`, (e, f) => {
|
---|
55 | f.forEach(v => {
|
---|
56 | upload(v, '.AppImage');
|
---|
57 | });
|
---|
58 | });
|
---|
59 |
|
---|
60 | const win_exe = new Glob(`${__dirname}/dist/*.exe`, (e, f) => {
|
---|
61 | f.forEach(v => {
|
---|
62 | upload(v, '.exe');
|
---|
63 | });
|
---|
64 | });
|
---|