Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows automated builds #91

Merged
merged 3 commits into from
Jan 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 43 additions & 10 deletions src/cli/cmds/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,31 @@ import Log from '../../lib/Log';
import * as inquirer from 'inquirer';
import {validatePassword} from '../inputHelpers';

export async function build(config: Config, log = new Log('build')): Promise<void> {
const jdkHelper = new JdkHelper(process, config);
const androidSdkTools = new AndroidSdkTools(process, config, jdkHelper);
interface SigningKeyPasswords {
keystorePassword: string;
keyPassword: string;
}

if (!await androidSdkTools.checkBuildTools()) {
console.log('Installing Android Build Tools. Please, read and accept the license agreement');
await androidSdkTools.installBuildTools();
}
/**
* Checks if the keystore password and the key password are part of the environment prompts the
* user for a password otherwise.
*
* @returns {Promise<SigningKeyPasswords} the password information collected from enviromental
* variables or user input.
*/
async function getPasswords(log: Log): Promise<SigningKeyPasswords> {
// Check if passwords are set as environment variables.
const envKeystorePass = process.env['LLAMA_PACK_KEYSTORE_PASSWORD'];
const envKeyPass = process.env['LLAMA_PACK_KEY_PASSWORD'];

const twaManifest = await TwaManifest.fromFile('./twa-manifest.json');
if (envKeyPass !== undefined && envKeystorePass !== undefined) {
log.info('Using passwords set in the LLAMA_PACK_KEYSTORE_PASSWORD and ' +
'LLAMA_PACK_KEY_PASSWORD environmental variables.');
return {
keystorePassword: envKeystorePass,
keyPassword: envKeyPass,
};
}

// Ask user for the keystore password
const result = await inquirer.prompt([
Expand All @@ -51,6 +66,24 @@ export async function build(config: Config, log = new Log('build')): Promise<voi
},
]);

return {
keystorePassword: result.password,
keyPassword: result.keypassword,
};
}

export async function build(config: Config, log = new Log('build')): Promise<void> {
const jdkHelper = new JdkHelper(process, config);
const androidSdkTools = new AndroidSdkTools(process, config, jdkHelper);

if (!await androidSdkTools.checkBuildTools()) {
console.log('Installing Android Build Tools. Please, read and accept the license agreement');
await androidSdkTools.installBuildTools();
}

const twaManifest = await TwaManifest.fromFile('./twa-manifest.json');
const passwords = await getPasswords(log);

// Builds the Android Studio Project
log.info('Building the Android App...');
const gradleWraper = new GradleWrapper(process, androidSdkTools);
Expand All @@ -68,9 +101,9 @@ export async function build(config: Config, log = new Log('build')): Promise<voi
const outputFile = './app-release-signed.apk';
await androidSdkTools.apksigner(
twaManifest.signingKey.path,
result.password, // keystore password
passwords.keystorePassword, // keystore password
twaManifest.signingKey.alias, // alias
result.keypassword, // key password
passwords.keystorePassword, // key password
'./app-release-unsigned-aligned.apk', // input file path
outputFile, // output file path
);
Expand Down