forked from amazon-archives/aws-ai-tracking-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmasterBuildAndroid.js
More file actions
executable file
·117 lines (98 loc) · 3.45 KB
/
Copy pathmasterBuildAndroid.js
File metadata and controls
executable file
·117 lines (98 loc) · 3.45 KB
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
107
108
109
110
/*
Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Licensed under the Amazon Software License (the "License"). You may not use this file
except in compliance with the License. A copy of the License is located at
http://aws.amazon.com/asl/
or in the "license" file accompanying this file. This file is distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. See the
License for the specific language governing permissions and limitations under the License.
*/
const cp = require('child_process');
const fs = require('fs');
const AWS = require('aws-sdk');
const UUID = require('uuid-js');
const argv = require('minimist')(process.argv.slice(2));
const bootstrap_bucket = (argv["bootstrap-bucket"] !== undefined) ? argv["bootstrap-bucket"] : undefined;
const bootstrap_bucket_artifacts = "artifacts";
const bootstrap_bucket_path = bootstrap_bucket + "/" + bootstrap_bucket_artifacts;
const botname = (argv.botname != undefined) ? argv.botname : process.env.BOTNAME;
const region = (argv.region != undefined) ? argv.region : process.env.AWS_DEFAULT_REGION;
const cognito_poolid = (argv["cognito-poolid"] !== undefined) ? argv["cognito-poolid"] : undefined;
function usage() {
console.error("Invalid options or environment");
console.error("node masterBuildAndroid.js " +
"--bootstrap-bucket bucket " +
"--botname botname " +
"--cognito-poolid poolid " +
"--region us-east-1 ");
}
if (bootstrap_bucket === undefined) {
usage();
return;
} else {
process.env.BOOTSTRAP_BUCKET_PATH = bootstrap_bucket_path;
}
if (region === undefined) {
usage();
return;
} else {
const awsConfig = {
region: region
};
AWS.config.update(awsConfig);
process.env.AWS_REGION = region;
}
if (botname === undefined) {
usage();
return;
} else {
process.env.BOT_NAME = botname;
}
if (cognito_poolid === undefined) {
usage();
return;
} else {
process.env.POOL_ID = cognito_poolid;
}
updateAndroidConfigFile(cognito_poolid, botname, region).then(function (data) {
makeAndroidApp(cp).then(function (data) {
if (data) {
console.log("finished building Android App");
}
}, function (error) {
console.log("failed to build Android App: " + error);
process.exitCode = 1;
})
}, function (error) {
console.log("failed to update Android configuration file: " + error);
process.exitCode = 1;
});
function updateAndroidConfigFile(poolId, botname, region) {
return new Promise(function (resolve) {
obj = {};
obj.config = {};
let uuid4 = UUID.create();
obj.config.BOTNAME = botname;
obj.config.AWS_MOBILEHUB_USER_AGENT = "MobileHub " + uuid4.toString() + " aws-my-sample-app-android-v0.17";
obj.config.AMAZON_COGNITO_REGION = region;
obj.config.AMAZON_COGNITO_IDENTITY_POOL_ID = poolId;
obj.config.AMAZON_DYNAMODB_REGION = region;
fs.writeFileSync('TrackingBot-aws-my-sample-app-android/MySampleApp/app/src/main/res/raw/awsconfig.json', JSON.stringify(obj, null, 2) , 'utf-8');
resolve("success");
});
}
function makeAndroidApp(cp) {
return new Promise(function (resolve, reject) {
console.log("starting to build android app");
let out = cp.spawnSync('sh', ['buildAndroid.sh']);
console.log("stdout");
console.log(out.stdout.toString("utf8"));
console.log("stderr");
console.log(out.stderr.toString("utf8"));
if (out.status !== 0) {
reject(out.error);
}
process.chdir('../..');
resolve();
});
}