-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.js
50 lines (41 loc) · 1.55 KB
/
deploy.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
(async function() {
try {
const yargs = require('yargs');
const {exec} = require('./utils');
// Define required arguments, help section and get arguments
const argv = yargs
.usage(`Usage: $0 <environment> [options]`) // help "Usage" description
.demandCommand(1) // requiring 1 argument to be passed
.option('skip-build', {
describe: 'To skip build process',
})
.help() // for --help and -h to work
.argv;
const ENVIRONMENT = argv._[0];
let BUILD_OPTIONS = '';
// Set options based on environment
switch (ENVIRONMENT) {
case 'integration':
break;
case 'staging':
BUILD_OPTIONS = '--config config/webpack.staging.js';
break;
case 'production':
BUILD_OPTIONS = '--config config/webpack.prod.js';
break;
default:
throw new Error(`ERROR: wrong env as first argument: ${ENVIRONMENT}`);
}
if (!argv['skip-build']) {
console.log('[CLEANUP]');
await exec('rm -rf ./dist');
console.log('[BUILDING]');
await exec(`webpack --progress --profile --bail ${BUILD_OPTIONS}`);
}
console.log('[UPLOADING]');
await exec('aws --region eu-west-1 s3 sync --acl public-read dist/ s3://my-bucket/');
} catch (error) {
console.error(error);
process.exit(error && error.code || 1); // properly exit with error code (useful for CI or chaining)
}
})();