Skip to content

Commit

Permalink
Merge pull request #265 from andreban/build-messages-string
Browse files Browse the repository at this point in the history
Clarifies passwords prompt on `build` command
  • Loading branch information
andreban authored Jul 24, 2020
2 parents 84f1007 + 983c938 commit 1671220
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 deletions.
30 changes: 14 additions & 16 deletions packages/cli/src/lib/cmds/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,22 @@ class Build {
* @returns {Promise<SigningKeyPasswords} the password information collected from enviromental
* variables or user input.
*/
async getPasswords(): Promise<SigningKeyPasswords> {
async getPasswords(signingKeyInfo: SigningKeyInfo): Promise<SigningKeyPasswords> {
// Check if passwords are set as environment variables.
const envKeystorePass = process.env['BUBBLEWRAP_KEYSTORE_PASSWORD'];
const envKeyPass = process.env['BUBBLEWRAP_KEY_PASSWORD'];

if (envKeyPass !== undefined && envKeystorePass !== undefined) {
this.log.info('Using passwords set in the BUBBLEWRAP_KEYSTORE_PASSWORD and ' +
'BUBBLEWRAP_KEY_PASSWORD environmental variables.');
this.prompt.printMessage(messages.messageUsingPasswordsFromEnv);
return {
keystorePassword: envKeystorePass,
keyPassword: envKeyPass,
};
}

// Ask user for the keystore password
this.prompt.printMessage(
messages.messageEnterPasswords(signingKeyInfo.path, signingKeyInfo.alias));
const keystorePassword =
await this.prompt.promptPassword(messages.promptKeystorePassword, createValidateString(6));
const keyPassword =
Expand Down Expand Up @@ -104,7 +105,7 @@ class Build {

const sha256Fingerprint = keyInfo.fingerprints.get('SHA256');
if (!sha256Fingerprint) {
this.log.warn('Could not find SHA256 fingerprint. Skipping generating "assetlinks.json"');
this.prompt.printMessage(messages.messageSha256FingerprintNotFound);
return;
}

Expand All @@ -113,11 +114,9 @@ class Build {

await fs.promises.writeFile(digitalAssetLinksFile, digitalAssetLinks);

this.log.info(`Digital Asset Links file generated at ${digitalAssetLinksFile}`);
this.log.info('Read more about setting up Digital Asset Links at https://developers.google.com' +
'/web/android/trusted-web-activity/quick-start#creating-your-asset-link-file');
this.prompt.printMessage(messages.messageDigitalAssetLinksSuccess(digitalAssetLinksFile));
} catch (e) {
this.log.warn('Error generating "assetlinks.json"', e);
this.prompt.printMessage(messages.errorAssetLinksGeneration);
}
}

Expand All @@ -136,7 +135,7 @@ class Build {
'./app-release-unsigned-aligned.apk', // input file path
outputFile,
);
this.log.info(`Generated Android APK at "${outputFile}"`);
this.prompt.printMessage(messages.messageApkSucess(outputFile));
}

async buildAppBundle(signingKey: SigningKeyInfo, passwords: SigningKeyPasswords): Promise<void> {
Expand All @@ -145,12 +144,12 @@ class Build {
const outputFile = './app-release-bundle.aab';
await this.jarSigner.sign(
signingKey, passwords.keystorePassword, passwords.keyPassword, inputFile, outputFile);
this.log.info(`Generated Android App Bundle at "${outputFile}"`);
this.prompt.printMessage(messages.messageAppBundleSuccess(outputFile));
}

async build(): Promise<boolean> {
if (!await this.androidSdkTools.checkBuildTools()) {
console.log('Installing Android Build Tools. Please, read and accept the license agreement');
this.prompt.printMessage(messages.messageInstallingBuildTools);
await this.androidSdkTools.installBuildTools();
}

Expand All @@ -160,10 +159,10 @@ class Build {
}

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

// Builds the Android Studio Project
this.log.info('Building the Android App...');
this.prompt.printMessage(messages.messageBuildingApp);
await this.buildApk(twaManifest.signingKey, passwords);

if (this.args.generateAppBundle) {
Expand All @@ -179,13 +178,12 @@ class Build {
printValidationResult(pwaValidationResult, this.log);

if (pwaValidationResult.status === 'FAIL') {
this.log.warn('PWA Quality Criteria check failed.');
this.prompt.printMessage(messages.warnPwaFailedQuality);
}
} else {
const e = result.unwrapError();
const message = 'Failed to run the PWA Quality Criteria checks. Skipping.';
this.log.debug(e.message);
this.log.warn(message);
this.prompt.printMessage(messages.errorFailedToRunQualityCriteria);
}
}
return true;
Expand Down
40 changes: 39 additions & 1 deletion packages/cli/src/lib/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
* limitations under the License.
*/

import {cyan, green, underline, bold, italic} from 'colors';
import {cyan, green, underline, bold, italic, red, yellow} from 'colors';

type Messages = {
errorAssetLinksGeneration: string;
errorFailedToRunQualityCriteria: string;
errorMaxLength: (maxLength: number, actualLength: number) => string;
errorMinLength: (minLength: number, actualLength: number) => string;
errorRequireHttps: string;
Expand All @@ -28,17 +30,25 @@ type Messages = {
messageInitializingWebManifest: (manifestUrl: string) => string;
messageAndroidAppDetails: string;
messageAndroidAppDetailsDesc: string;
messageApkSucess: (filename: string) => string;
messageAppBundleSuccess: (filename: string) => string;
messageBuildingApp: string;
messageDigitalAssetLinksSuccess: (filename: string) => string;
messageEnterPasswords: (keypath: string, keyalias: string) => string;
messageGeneratedNewVersion: (appVersionName: string, appVersionCode: number) => string;
messageGeneratingAndroidProject: string;
messageInstallingBuildTools: string;
messageLauncherIconAndSplash: string;
messageLauncherIconAndSplashDesc: string;
messageOptionFeatures: string;
messageOptionalFeaturesDesc: string;
messageProjectGeneratedSuccess: string;
messageSha256FingerprintNotFound: string;
messageSigningKeyCreation: string;
messageSigningKeyInformation: string;
messageSigningKeyInformationDesc: string;
messageSigningKeyNotFound: (path: string) => string;
messageUsingPasswordsFromEnv: string;
messageWebAppDetails: string;
messageWebAppDetailsDesc: string;
promptHostMessage: string;
Expand All @@ -63,9 +73,13 @@ type Messages = {
promptKeystorePassword: string;
promptKeyPassword: string;
promptNewAppVersionName: string;
warnPwaFailedQuality: string;
}

export const enUS: Messages = {
errorAssetLinksGeneration: 'Error generating "assetlinks.json"',
errorFailedToRunQualityCriteria:
yellow('\nFailed to run the PWA Quality Criteria checks. Skipping.'),
errorMaxLength: (maxLength, actualLength): string => {
return `Maximum length is ${maxLength} but input is ${actualLength}.`;
},
Expand Down Expand Up @@ -113,11 +127,30 @@ into a device:
\t- ${bold('Status bar color:')} sets the status bar color used when the
\t application is in foreground. Example: ${cyan('#7CC0FF')}\n`,
messageApkSucess: (filename: string): string => {
return `\t- Generated Android APK at ${cyan(filename)}`;
},
messageAppBundleSuccess: (filename: string): string => {
return `\t- Generated Android App Bundle at ${cyan(filename)}`;
},
messageBuildingApp: '\nBuilding the Android App...',
messageDigitalAssetLinksSuccess: (filename: string): string => {
return `\t- Generated Digital Asset Links file at ${cyan(filename)}
\nRead more about setting up Digital Asset Links at:
\t` + cyan('https://developers.google.com/web/android/trusted-web-activity/quick-start#creating' +
'-your-asset-link-file');
},
messageEnterPasswords: (keypath: string, keyalias: string): string => {
return `Please, enter passwords for the keystore ${cyan(keypath)} and alias \
${cyan(keyalias)}.\n`;
},
messageGeneratedNewVersion: (appVersionName: string, appVersionCode: number): string => {
return `Generated new version with versionName: ${appVersionName} and ` +
`versionCode: ${appVersionCode}`;
},
messageGeneratingAndroidProject: 'Generating Android Project.',
messageInstallingBuildTools: 'Installing Android Build Tools. Please, read and accept the ' +
'license agreement.',
messageLauncherIconAndSplash: underline(`\nLauncher icons and splash screen ${green('(3/5)')}`),
messageLauncherIconAndSplashDesc: `
The Android app requires an image for the launcher icon. It also displays a
Expand Down Expand Up @@ -153,6 +186,8 @@ a blank white page to users.
\t ${italic('theme_color')}. They will be used for notification icons.\n`,
messageProjectGeneratedSuccess: '\nProject generated successfully. Build it by running ' +
cyan('bubblewrap build'),
messageSha256FingerprintNotFound: 'Could not find SHA256 fingerprint. Skipping generating ' +
'"assetlinks.json"',
messageSigningKeyCreation: underline('\nSigning key creation'),
messageSigningKeyInformation: underline(`\nSigning key information ${green('(5/5)')}`),
messageSigningKeyInformationDesc: `
Expand All @@ -170,6 +205,8 @@ Read more about Android signing keys at:
messageSigningKeyNotFound: (path: string): string => {
return `\nAn existing key store could could not be found at "${path}".\n`;
},
messageUsingPasswordsFromEnv: 'Using passwords set in the BUBBLEWRAP_KEYSTORE_PASSWORD and ' +
'BUBBLEWRAP_KEY_PASSWORD environmental variables.',
messageWebAppDetails: underline(`\nWeb app details ${green('(1/5)')}`),
messageWebAppDetailsDesc: `
The application generated by Bubblewrap will open a Progressive Web App when
Expand Down Expand Up @@ -207,4 +244,5 @@ the PWA:
promptKeystorePassword: 'Password for the Key Store:',
promptKeyPassword: 'Password for the Key:',
promptNewAppVersionName: 'versionName for the new App version:',
warnPwaFailedQuality: red('PWA Quality Criteria check failed.'),
};

0 comments on commit 1671220

Please sign in to comment.