-
Notifications
You must be signed in to change notification settings - Fork 47
/
webpack-helpers.js
106 lines (96 loc) · 2.27 KB
/
webpack-helpers.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import packageJSON from './package.json';
import { resolve } from 'path';
const getAppConfig = (env) => {
const envVars = [
'ANALYTICS_WRITE_KEY',
'CIRCLE_BRANCH',
'CIRCLE_SHA1',
'FACEBOOK_ID',
'GITHUB_ID',
'GOOGLE_ID',
'SENTRY_DSN',
'STRIPE_PUBLISHABLE_KEY',
'SYNCANO_BASE_DOMAIN',
'SYNCANO_BILLING_EMAIL',
'SYNCANO_DEMO_APPS_ACCOUNT_KEY',
'SYNCANO_SUPPORT_EMAIL',
'SYNCANO_BASE_URL',
'SYNCANO_OLD_DASHBOARD',
'SYNCANO5_RELEASE_DATE'
];
const config = {
ENV: Object.keys(env)[0],
VERSION: packageJSON.version,
SYNCANO_BASE_URL: 'https://api.syncano.io'
};
envVars.forEach((key) => {
const envName = `${config.ENV.toUpperCase()}_${key}`;
const value = process.env[envName] || process.env[key];
if (value) {
config[key] = value;
}
});
return config;
};
const getS3Config = (env) => {
const { CIRCLE_BRANCH } = process.env;
if (!CIRCLE_BRANCH) {
throw new Error('"CIRCLE_BRANCH" env variable is required');
}
const branch = CIRCLE_BRANCH.toLowerCase();
const config = {
beta: {
directory: resolve('dist'),
s3Options: {
region: 'us-east-1'
},
s3UploadOptions: {
Bucket: process.env.BETA_AWS_BUCKET_NAME
}
},
devel: {
directory: resolve('dist'),
s3Options: {
region: 'us-west-2'
},
s3UploadOptions: {
Bucket: process.env.SYN5_STAGING_AWS_BUCKET_NAME
},
cloudfrontInvalidateOptions: {
DistributionId: process.env.SYN5_STAGING_AWS_DISTRIBUTION_ID,
Items: ['/*']
}
},
master: {
directory: resolve('dist'),
s3Options: {
region: 'us-west-2'
},
s3UploadOptions: {
Bucket: process.env.PRODUCTION_AWS_BUCKET_NAME
},
cloudfrontInvalidateOptions: {
DistributionId: process.env.PRODUCTION_AWS_DISTRIBUTION_ID,
Items: ['/*']
}
},
default: {
directory: resolve('dist'),
s3Options: {
region: 'us-west-2'
},
s3UploadOptions: {
Bucket: process.env.SYN5_STAGING_AWS_BUCKET_NAME
},
basePath: branch
}
};
if (env.beta) {
return config.beta;
}
return config[branch] || config.default;
};
export {
getAppConfig,
getS3Config
};