-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathbuild-espresso.js
56 lines (45 loc) · 2.1 KB
/
build-espresso.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
const _ = require('lodash');
const path = require('path');
const { logger, fs } = require('appium/support');
const { ServerBuilder } = require('../build/lib/server-builder.js');
const LOG = new logger.getLogger('EspressoBuild');
const ROOT_DIR = path.resolve(__dirname, '..');
const ESPRESSO_SERVER_ROOT = path.join(ROOT_DIR, 'espresso-server');
const ESPRESSO_SERVER_BUILD = path.join(ESPRESSO_SERVER_ROOT, 'app', 'build');
async function buildEspressoServer () {
LOG.info(`Deleting the build directory ${ESPRESSO_SERVER_BUILD}`);
const opts = {
serverPath: ESPRESSO_SERVER_ROOT,
showGradleLog: !_.isEmpty(process.env.SHOW_GRADLE_LOG) && ['1', 'true'].includes(_.toLower(process.env.SHOW_GRADLE_LOG))
};
if (process.env.TEST_APP_PACKAGE) {
opts.testAppPackage = process.env.TEST_APP_PACKAGE;
}
if (process.env.ESPRESSO_BUILD_CONFIG) {
if (!(await fs.exists(process.env.ESPRESSO_BUILD_CONFIG))) {
throw new Error(`'${process.env.ESPRESSO_BUILD_CONFIG}' did not exist. Please set the path as an absolute path.`);
}
try {
const buildConfigurationStr = await fs.readFile(process.env.ESPRESSO_BUILD_CONFIG, 'utf8');
opts.buildConfiguration = JSON.parse(buildConfigurationStr);
LOG.info(`The espresso build config is ${JSON.stringify(opts.buildConfiguration)}`);
} catch (e) {
throw new Error(`Failed to parse the ${process.env.ESPRESSO_BUILD_CONFIG}. ` +
`Please make sure that the JSON is valid format. Error: ${e}`);
}
}
const builder = new ServerBuilder(LOG, opts);
try {
await builder.build();
} catch (e) {
throw new Error(`Failed to build the espresso server. ` +
`SHOW_GRADLE_LOG=true environment variable helps to check the gradle log. Error: ${e}`);
}
const dstPath = path.resolve(ESPRESSO_SERVER_ROOT, 'app', 'build', 'outputs', 'apk', 'androidTest', 'debug', 'app-debug-androidTest.apk');
if (await fs.exists(dstPath)) {
LOG.info(`Full path to the server APK: ${dstPath}`);
} else {
LOG.info(`Full path to the server build folder: ${ESPRESSO_SERVER_BUILD}`);
}
}
(async () => await buildEspressoServer())();