From f27ba1091dcbecf2be03a9d8b4992a03714f1582 Mon Sep 17 00:00:00 2001 From: Chen Levy Date: Mon, 17 Aug 2020 11:16:12 +0000 Subject: [PATCH 1/5] Changed Log into an interface and added ConsoleLog --- packages/cli/src/index.ts | 4 +- packages/cli/src/lib/cmds/build.ts | 4 +- packages/cli/src/lib/cmds/help.ts | 4 +- packages/cli/src/lib/cmds/init.ts | 5 ++- packages/cli/src/lib/cmds/install.ts | 4 +- packages/cli/src/lib/cmds/update.ts | 4 +- packages/cli/src/lib/cmds/validate.ts | 4 +- packages/cli/src/lib/cmds/version.ts | 4 +- packages/core/src/index.ts | 3 +- packages/core/src/lib/Log.ts | 43 +++++++++++++++++-- packages/core/src/lib/TwaGenerator.ts | 4 +- packages/core/src/lib/TwaManifest.ts | 4 +- .../src/lib/androidSdk/AndroidSdkTools.ts | 4 +- packages/core/src/lib/jdk/KeyTool.ts | 4 +- packages/core/src/lib/util.ts | 2 +- .../lib/androidSdk/AndroidSdkToolsSpec.ts | 6 +-- 16 files changed, 70 insertions(+), 33 deletions(-) diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 1d0e6a11..5b1b100e 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -15,11 +15,11 @@ */ import {Cli} from './lib/Cli'; -import {Log} from '@bubblewrap/core'; +import {Log, ConsoleLog} from '@bubblewrap/core'; module.exports = async (): Promise => { const cli = new Cli(); - const log = new Log('cli'); + const log: Log = new ConsoleLog('cli'); const args = process.argv.slice(2); let success; diff --git a/packages/cli/src/lib/cmds/build.ts b/packages/cli/src/lib/cmds/build.ts index 9b574953..801eafa6 100644 --- a/packages/cli/src/lib/cmds/build.ts +++ b/packages/cli/src/lib/cmds/build.ts @@ -15,7 +15,7 @@ */ import {AndroidSdkTools, Config, DigitalAssetLinks, GradleWrapper, JdkHelper, KeyTool, Log, - TwaManifest} from '@bubblewrap/core'; + ConsoleLog, TwaManifest} from '@bubblewrap/core'; import * as inquirer from 'inquirer'; import * as path from 'path'; import * as fs from 'fs'; @@ -110,7 +110,7 @@ async function generateAssetLinks(keyTool: KeyTool, twaManifest: TwaManifest, } export async function build( - config: Config, args: ParsedArgs, log = new Log('build')): Promise { + config: Config, args: ParsedArgs, log: Log = new ConsoleLog('build')): Promise { let pwaValidationPromise; if (!args.skipPwaValidation) { pwaValidationPromise = startValidation(); diff --git a/packages/cli/src/lib/cmds/help.ts b/packages/cli/src/lib/cmds/help.ts index d98769c7..3fa42e5a 100644 --- a/packages/cli/src/lib/cmds/help.ts +++ b/packages/cli/src/lib/cmds/help.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {Log} from '@bubblewrap/core'; +import {Log, ConsoleLog} from '@bubblewrap/core'; import {ParsedArgs} from 'minimist'; const HELP_MESSAGES = new Map( @@ -86,7 +86,7 @@ const HELP_MESSAGES = new Map( ], ); -export async function help(args: ParsedArgs, log = new Log('help')): Promise { +export async function help(args: ParsedArgs, log: Log = new ConsoleLog('help')): Promise { // minimist uses an `_` object to store details. const command = args._[1]; const message = HELP_MESSAGES.get(command) || HELP_MESSAGES.get('main'); diff --git a/packages/cli/src/lib/cmds/init.ts b/packages/cli/src/lib/cmds/init.ts index 156461bb..2f4967cf 100644 --- a/packages/cli/src/lib/cmds/init.ts +++ b/packages/cli/src/lib/cmds/init.ts @@ -17,12 +17,13 @@ import * as fs from 'fs'; import Color = require('color'); import * as inquirer from 'inquirer'; -import {Config, JdkHelper, KeyTool, Log, TwaGenerator, TwaManifest, util} from '@bubblewrap/core'; +import {Config, JdkHelper, KeyTool, Log, TwaGenerator, TwaManifest, + ConsoleLog, util} from '@bubblewrap/core'; import {validateColor, validateKeyPassword, validateUrl, notEmpty} from '../inputHelpers'; import {ParsedArgs} from 'minimist'; import {APP_NAME} from '../constants'; -const log = new Log('init'); +const log: Log = new ConsoleLog('init'); export interface InitArgs { manifest: string; diff --git a/packages/cli/src/lib/cmds/install.ts b/packages/cli/src/lib/cmds/install.ts index c4582c89..8a2fed24 100644 --- a/packages/cli/src/lib/cmds/install.ts +++ b/packages/cli/src/lib/cmds/install.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import {AndroidSdkTools, Config, JdkHelper, Log} from '@bubblewrap/core'; +import {AndroidSdkTools, Config, JdkHelper, Log, ConsoleLog} from '@bubblewrap/core'; import {ParsedArgs} from 'minimist'; const APK_FILE_PARAM = '--apkFile'; @@ -23,7 +23,7 @@ const DEFAULT_APK_FILE = './app-release-signed.apk'; const PARAMETERS_TO_IGNORE = ['--verbose', '-r']; export async function install( - args: ParsedArgs, config: Config, log = new Log('install')): Promise { + args: ParsedArgs, config: Config, log: Log = new ConsoleLog('install')): Promise { const jdkHelper = new JdkHelper(process, config); const androidSdkTools = new AndroidSdkTools(process, config, jdkHelper, log); const apkFile = args.apkFile || DEFAULT_APK_FILE; diff --git a/packages/cli/src/lib/cmds/update.ts b/packages/cli/src/lib/cmds/update.ts index 55648ba5..59ba8800 100644 --- a/packages/cli/src/lib/cmds/update.ts +++ b/packages/cli/src/lib/cmds/update.ts @@ -16,12 +16,12 @@ import * as inquirer from 'inquirer'; import * as path from 'path'; -import {Log, TwaGenerator, TwaManifest} from '@bubblewrap/core'; +import {Log, ConsoleLog, TwaGenerator, TwaManifest} from '@bubblewrap/core'; import {ParsedArgs} from 'minimist'; import {APP_NAME} from '../constants'; import {notEmpty} from '../inputHelpers'; -const log = new Log('update'); +const log: Log = new ConsoleLog('update'); async function updateVersions(twaManifest: TwaManifest, appVersionNameArg: string): Promise<{ appVersionName: string; diff --git a/packages/cli/src/lib/cmds/validate.ts b/packages/cli/src/lib/cmds/validate.ts index 71d4a16b..b71290b9 100644 --- a/packages/cli/src/lib/cmds/validate.ts +++ b/packages/cli/src/lib/cmds/validate.ts @@ -15,11 +15,11 @@ */ import {PwaValidator} from '@bubblewrap/validator'; -import {Log} from '@bubblewrap/core'; +import {Log, ConsoleLog} from '@bubblewrap/core'; import {ParsedArgs} from 'minimist'; import {printValidationResult} from '../pwaValidationHelper'; -const log = new Log('validate'); +const log: Log = new ConsoleLog('validate'); /** * Runs the PwaValidator to check a given URL agains the Quality criteria. More information on the diff --git a/packages/cli/src/lib/cmds/version.ts b/packages/cli/src/lib/cmds/version.ts index f3ed01f2..f741668f 100644 --- a/packages/cli/src/lib/cmds/version.ts +++ b/packages/cli/src/lib/cmds/version.ts @@ -16,9 +16,9 @@ import * as fs from 'fs'; import * as path from 'path'; -import {Log} from '@bubblewrap/core'; +import {Log, ConsoleLog} from '@bubblewrap/core'; -export async function version(log = new Log('version')): Promise { +export async function version(log: Log = new ConsoleLog('version')): Promise { const packageJsonFile = path.join(__dirname, '../../../package.json'); const packageJsonContents = await (await fs.promises.readFile(packageJsonFile)).toString(); const packageJson = JSON.parse(packageJsonContents); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 0fe2e10a..136f6d21 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -17,7 +17,7 @@ import {AndroidSdkTools} from './lib/androidSdk/AndroidSdkTools'; import {Config} from './lib/Config'; import {GradleWrapper} from './lib/GradleWrapper'; -import Log from './lib/Log'; +import {Log, ConsoleLog} from './lib/Log'; import {JdkHelper} from './lib/jdk/JdkHelper'; import {KeyTool} from './lib/jdk/KeyTool'; import {TwaManifest} from './lib/TwaManifest'; @@ -32,6 +32,7 @@ export {AndroidSdkTools, JdkHelper, KeyTool, Log, + ConsoleLog, TwaGenerator, TwaManifest, util, diff --git a/packages/core/src/lib/Log.ts b/packages/core/src/lib/Log.ts index 796bc7ff..7445f0b2 100644 --- a/packages/core/src/lib/Log.ts +++ b/packages/core/src/lib/Log.ts @@ -1,5 +1,5 @@ /* - * Copyright 2019 Google Inc. All Rights Reserved. + * Copyright 2020 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,10 +14,45 @@ * limitations under the License. */ +/** + * An interface for loggers. + */ +export interface Log { + + verbose: boolean; + + /** + * Prints a debug message to the Log. message is ignored if the Log is not set to verbose. + * @param message the message the be printed. + * @param args extra arguments for the console. + */ + debug(message: string, ...args: string[]): void; + + /** + * Prints an info message to the Log. message is ignored if the Log is not set to verbose. + * @param message the message the be printed. + * @param args extra arguments for the console. + */ + info(message: string, ...args: string[]): void; + + /** + * Prints an warning message to the Log. message is ignored if the Log is not set to verbose. + * @param message the message the be printed. + * @param args extra arguments for the console. + */ + warn(message: string, ...args: string[]): void; + /** + * Prints an error message to the Log. message is ignored if the Log is not set to verbose. + * @param message the message the be printed. + * @param args extra arguments for the console. + */ + error(message: string, ...args: string[]): void; +}; + /** * An utility class to print nice Log messages. */ -export default class Log { +export class ConsoleLog implements Log { private tag: string; private prefix: string; private output: Console; @@ -85,11 +120,11 @@ export default class Log { * Creates a new Log using the same output and verbositity of the current Log. * @param newTag the tag the be used on the new Log instance. */ - newLog(newTag: string): Log { + newLog(newTag: string): ConsoleLog { if (this.tag) { newTag = this.tag + ' ' + newTag; } - return new Log(newTag, this.verbose, this.output); + return new ConsoleLog(newTag, this.verbose, this.output); } private log(fn: Function, message: string, ...args: string[]): void { diff --git a/packages/core/src/lib/TwaGenerator.ts b/packages/core/src/lib/TwaGenerator.ts index bd86a229..d36167f1 100644 --- a/packages/core/src/lib/TwaGenerator.ts +++ b/packages/core/src/lib/TwaGenerator.ts @@ -21,7 +21,7 @@ import fetch from 'node-fetch'; import {template} from 'lodash'; import {promisify} from 'util'; import {TwaManifest, ShortcutInfo} from './TwaManifest'; -import Log from './Log'; +import {Log, ConsoleLog} from './Log'; const COPY_FILE_LIST = [ 'settings.gradle', @@ -101,7 +101,7 @@ interface Icon { export class TwaGenerator { private log: Log; - constructor(log = new Log('twa-generator')) { + constructor(log: Log = new ConsoleLog('twa-generator')) { this.log = log; } diff --git a/packages/core/src/lib/TwaManifest.ts b/packages/core/src/lib/TwaManifest.ts index f79ca41a..25d05439 100644 --- a/packages/core/src/lib/TwaManifest.ts +++ b/packages/core/src/lib/TwaManifest.ts @@ -20,7 +20,7 @@ import * as fs from 'fs'; import fetch from 'node-fetch'; import {findSuitableIcon, generatePackageId, validateNotEmpty} from './util'; import Color = require('color'); -import Log from './Log'; +import {Log, ConsoleLog} from './Log'; import {WebManifestIcon, WebManifestJson} from './types/WebManifest'; // The minimum size needed for the app icon. @@ -107,7 +107,7 @@ export class TwaManifest { webManifestUrl?: URL; fallbackType: FallbackType; - private static log: Log = new Log('twa-manifest'); + private static log: Log = new ConsoleLog('twa-manifest'); constructor(data: TwaManifestJson) { this.packageId = data.packageId; diff --git a/packages/core/src/lib/androidSdk/AndroidSdkTools.ts b/packages/core/src/lib/androidSdk/AndroidSdkTools.ts index d1ff77f4..28e9995e 100644 --- a/packages/core/src/lib/androidSdk/AndroidSdkTools.ts +++ b/packages/core/src/lib/androidSdk/AndroidSdkTools.ts @@ -19,7 +19,7 @@ import * as path from 'path'; import util = require('../util'); import {Config} from '../Config'; import {JdkHelper} from '../jdk/JdkHelper'; -import Log from '../../lib/Log'; +import {Log, ConsoleLog} from '../../lib/Log'; const BUILD_TOOLS_VERSION = '29.0.2'; @@ -40,7 +40,7 @@ export class AndroidSdkTools { * @param {jdkHelper} jdkHelper the JDK information to be used by the Android SDK */ constructor(process: NodeJS.Process, config: Config, jdkHelper: JdkHelper, - readonly log = new Log('AndroidSdkTools')) { + readonly log: Log = new ConsoleLog('AndroidSdkTools')) { if (!fs.existsSync(config.androidSdkPath)) { throw new Error(`androidSdkPath does not exist: ${config.androidSdkPath}`); } diff --git a/packages/core/src/lib/jdk/KeyTool.ts b/packages/core/src/lib/jdk/KeyTool.ts index 4f85e715..1a1180f9 100644 --- a/packages/core/src/lib/jdk/KeyTool.ts +++ b/packages/core/src/lib/jdk/KeyTool.ts @@ -17,7 +17,7 @@ import {existsSync, promises} from 'fs'; import {execute} from '../util'; import {JdkHelper} from './JdkHelper'; -import Log from '../Log'; +import {Log, ConsoleLog} from '../Log'; export interface KeyInfo { fingerprints: Map; @@ -44,7 +44,7 @@ export class KeyTool { private jdkHelper: JdkHelper; private log: Log; - constructor(jdkHelper: JdkHelper, log = new Log('keytool')) { + constructor(jdkHelper: JdkHelper, log: Log = new ConsoleLog('keytool')) { this.jdkHelper = jdkHelper; this.log = log; } diff --git a/packages/core/src/lib/util.ts b/packages/core/src/lib/util.ts index 3a8ba25e..ded42c12 100644 --- a/packages/core/src/lib/util.ts +++ b/packages/core/src/lib/util.ts @@ -21,7 +21,7 @@ import {promisify} from 'util'; import {exec, spawn} from 'child_process'; import {x as extractTar} from 'tar'; import {WebManifestIcon} from './types/WebManifest'; -import Log from './Log'; +import {Log} from './Log'; const execPromise = promisify(exec); const extractZipPromise = promisify(extractZip); diff --git a/packages/core/src/spec/lib/androidSdk/AndroidSdkToolsSpec.ts b/packages/core/src/spec/lib/androidSdk/AndroidSdkToolsSpec.ts index 99b33467..d8dda3e7 100644 --- a/packages/core/src/spec/lib/androidSdk/AndroidSdkToolsSpec.ts +++ b/packages/core/src/spec/lib/androidSdk/AndroidSdkToolsSpec.ts @@ -19,7 +19,7 @@ import {JdkHelper} from '../../../lib/jdk/JdkHelper'; import {AndroidSdkTools} from '../../../lib/androidSdk/AndroidSdkTools'; import util = require('../../../lib/util'); import * as fs from 'fs'; -import {Log} from '../../..'; +import {Log, ConsoleLog} from '../../..'; function buildMockConfig(platform: string): Config { if (platform === 'linux' || platform == 'darwin') { @@ -179,7 +179,7 @@ describe('AndroidSdkTools', () => { const config = buildMockConfig(test.platform); const process = buildMockProcess(test.platform); const jdkHelper = new JdkHelper(process, config); - const log = new Log('test'); + const log: Log = new ConsoleLog('test'); const androidSdkTools = new AndroidSdkTools(process, config, jdkHelper, log); spyOn(util, 'execute').and.stub(); await androidSdkTools.install('app-release-signed.apk'); @@ -244,7 +244,7 @@ describe('AndroidSdkTools', () => { const config = buildMockConfig(test.platform); const process = buildMockProcess(test.platform); const jdkHelper = new JdkHelper(process, config); - const log = new Log('test'); + const log: Log = new ConsoleLog('test'); const androidSdkTools = new AndroidSdkTools(process, config, jdkHelper, log); spyOn(util, 'execute').and.stub(); await androidSdkTools.apksigner( From 613cdf2a46fc3e94c466070ab447a0f56a9d76e9 Mon Sep 17 00:00:00 2001 From: Chen Levy Date: Mon, 17 Aug 2020 13:35:06 +0000 Subject: [PATCH 2/5] solved all of merge conflict --- packages/cli/package-lock.json | 15 --------------- packages/cli/src/lib/cmds/build.ts | 19 +++---------------- packages/cli/src/lib/cmds/init.ts | 12 ------------ packages/cli/src/lib/cmds/update.ts | 10 ---------- packages/cli/src/lib/config.ts | 4 ++-- packages/core/package-lock.json | 8 ++------ packages/core/package.json | 4 +++- 7 files changed, 10 insertions(+), 62 deletions(-) diff --git a/packages/cli/package-lock.json b/packages/cli/package-lock.json index ebd71718..931eed02 100644 --- a/packages/cli/package-lock.json +++ b/packages/cli/package-lock.json @@ -42,12 +42,6 @@ "rxjs": "^6.4.0" } }, - "@types/jasmine": { - "version": "3.5.11", - "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-3.5.11.tgz", - "integrity": "sha512-fg1rOd/DehQTIJTifGqGVY6q92lDgnLfs7C6t1ccSwQrMyoTGSoH6wWzhJDZb6ezhsdwAX4EIBLe8w5fXWmEng==", - "dev": true - }, "@types/mime-types": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.0.tgz", @@ -58,15 +52,6 @@ "resolved": "https://registry.npmjs.org/@types/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=" }, - "@types/mock-fs": { - "version": "4.10.0", - "resolved": "https://registry.npmjs.org/@types/mock-fs/-/mock-fs-4.10.0.tgz", - "integrity": "sha512-FQ5alSzmHMmliqcL36JqIA4Yyn9jyJKvRSGV3mvPh108VFatX7naJDzSG4fnFQNZFq9dIx0Dzoe6ddflMB2Xkg==", - "dev": true, - "requires": { - "@types/node": "*" - } - }, "@types/node": { "version": "12.12.30", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.30.tgz", diff --git a/packages/cli/src/lib/cmds/build.ts b/packages/cli/src/lib/cmds/build.ts index 3e95734d..ea755280 100644 --- a/packages/cli/src/lib/cmds/build.ts +++ b/packages/cli/src/lib/cmds/build.ts @@ -15,12 +15,7 @@ */ import {AndroidSdkTools, Config, DigitalAssetLinks, GradleWrapper, JdkHelper, KeyTool, Log, -<<<<<<< HEAD - TwaManifest, JarSigner, SigningKeyInfo, Result} from '@bubblewrap/core'; -======= - ConsoleLog, TwaManifest} from '@bubblewrap/core'; -import * as inquirer from 'inquirer'; ->>>>>>> master + ConsoleLog, TwaManifest, JarSigner, SigningKeyInfo, Result} from '@bubblewrap/core'; import * as path from 'path'; import * as fs from 'fs'; import {enUS as messages} from '../strings'; @@ -43,7 +38,7 @@ class Build { private jarSigner: JarSigner; constructor(private config: Config, private args: ParsedArgs, - private log = new Log('build'), private prompt: Prompt = new InquirerPrompt()) { + private log: Log = new ConsoleLog('build'), private prompt: Prompt = new InquirerPrompt()) { this.jdkHelper = new JdkHelper(process, this.config); this.androidSdkTools = new AndroidSdkTools(process, this.config, this.jdkHelper, this.log); this.keyTool = new KeyTool(this.jdkHelper, this.log); @@ -119,18 +114,10 @@ class Build { await fs.promises.writeFile(digitalAssetLinksFile, digitalAssetLinks); -<<<<<<< HEAD this.prompt.printMessage(messages.messageDigitalAssetLinksSuccess(digitalAssetLinksFile)); } catch (e) { this.prompt.printMessage(messages.errorAssetLinksGeneration); } -======= -export async function build( - config: Config, args: ParsedArgs, log: Log = new ConsoleLog('build')): Promise { - let pwaValidationPromise; - if (!args.skipPwaValidation) { - pwaValidationPromise = startValidation(); ->>>>>>> master } async buildApk(signingKey: SigningKeyInfo, passwords: SigningKeyPasswords): Promise { @@ -204,7 +191,7 @@ export async function build( } export async function build(config: Config, args: ParsedArgs, - log = new Log('build'), prompt: Prompt = new InquirerPrompt()): Promise { + log: Log = new ConsoleLog('build'), prompt: Prompt = new InquirerPrompt()): Promise { const build = new Build(config, args, log, prompt); return build.build(); } diff --git a/packages/cli/src/lib/cmds/init.ts b/packages/cli/src/lib/cmds/init.ts index c13be35b..7c112e51 100644 --- a/packages/cli/src/lib/cmds/init.ts +++ b/packages/cli/src/lib/cmds/init.ts @@ -15,7 +15,6 @@ */ import * as fs from 'fs'; -<<<<<<< HEAD import {Config, DisplayModes, JdkHelper, KeyTool, TwaGenerator, TwaManifest} from '@bubblewrap/core'; import {validateHost, validateColor, createValidateString, validateDisplayMode, validatePackageId, @@ -25,17 +24,6 @@ import {APP_NAME} from '../constants'; import {Prompt, InquirerPrompt} from '../Prompt'; import {enUS as messages} from '../strings'; import {generateTwaProject} from './shared'; -======= -import Color = require('color'); -import * as inquirer from 'inquirer'; -import {Config, JdkHelper, KeyTool, Log, TwaGenerator, TwaManifest, - ConsoleLog, util} from '@bubblewrap/core'; -import {validateColor, validateKeyPassword, validateUrl, notEmpty} from '../inputHelpers'; -import {ParsedArgs} from 'minimist'; -import {APP_NAME} from '../constants'; - -const log: Log = new ConsoleLog('init'); ->>>>>>> master export interface InitArgs { manifest: string; diff --git a/packages/cli/src/lib/cmds/update.ts b/packages/cli/src/lib/cmds/update.ts index d0ae9791..a021af41 100644 --- a/packages/cli/src/lib/cmds/update.ts +++ b/packages/cli/src/lib/cmds/update.ts @@ -15,26 +15,16 @@ */ import * as path from 'path'; -<<<<<<< HEAD import {Prompt, InquirerPrompt} from '../Prompt'; import {TwaGenerator, TwaManifest} from '@bubblewrap/core'; -======= -import {Log, ConsoleLog, TwaGenerator, TwaManifest} from '@bubblewrap/core'; ->>>>>>> master import {ParsedArgs} from 'minimist'; import {APP_NAME} from '../constants'; import {createValidateString} from '../inputHelpers'; import {enUS as messages} from '../strings'; import {generateTwaProject} from './shared'; -<<<<<<< HEAD async function updateVersions( twaManifest: TwaManifest, appVersionNameArg: string, prompt: Prompt): Promise<{ -======= -const log: Log = new ConsoleLog('update'); - -async function updateVersions(twaManifest: TwaManifest, appVersionNameArg: string): Promise<{ ->>>>>>> master appVersionName: string; appVersionCode: number; }> { diff --git a/packages/cli/src/lib/config.ts b/packages/cli/src/lib/config.ts index 7a650bb3..367d3f7f 100644 --- a/packages/cli/src/lib/config.ts +++ b/packages/cli/src/lib/config.ts @@ -17,7 +17,7 @@ import {join} from 'path'; import {homedir} from 'os'; -import {Config, Log} from '@bubblewrap/core'; +import {Config, Log, ConsoleLog} from '@bubblewrap/core'; import * as inquirer from 'inquirer'; import {existsSync} from 'fs'; import {promises as fsPromises} from 'fs'; @@ -44,7 +44,7 @@ async function createConfig(): Promise { return new Config(result.jdkPath, result.androidSdkPath); } -async function renameConfigIfNeeded(log = new Log('config')): Promise { +async function renameConfigIfNeeded(log: Log = new ConsoleLog('config')): Promise { if (existsSync(DEFAULT_CONFIG_FILE_PATH)) return; // No new named config file found. if (!existsSync(LEGACY_CONFIG_FILE_PATH)) return; diff --git a/packages/core/package-lock.json b/packages/core/package-lock.json index a8f7450e..355df312 100644 --- a/packages/core/package-lock.json +++ b/packages/core/package-lock.json @@ -368,11 +368,6 @@ "rxjs": "^6.4.0" } }, - "@types/jasmine": { - "version": "3.5.11", - "resolved": "https://registry.npmjs.org/@types/jasmine/-/jasmine-3.5.11.tgz", - "integrity": "sha512-fg1rOd/DehQTIJTifGqGVY6q92lDgnLfs7C6t1ccSwQrMyoTGSoH6wWzhJDZb6ezhsdwAX4EIBLe8w5fXWmEng==" - }, "@types/lodash": { "version": "4.14.157", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.157.tgz", @@ -389,7 +384,8 @@ "@types/mime-types": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.0.tgz", - "integrity": "sha1-nKUs2jY/aZxpRmwqbM2q2RPqenM=" + "integrity": "sha1-nKUs2jY/aZxpRmwqbM2q2RPqenM=", + "dev": true }, "@types/minipass": { "version": "2.2.0", diff --git a/packages/core/package.json b/packages/core/package.json index 41fcf9e9..86b2bce5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -33,7 +33,6 @@ "@types/extract-zip": "^1.6.2", "@types/inquirer": "^6.5.0", "@types/lodash.template": "^4.5.0", - "@types/mime-types": "^2.1.0", "@types/node": "^12.12.50", "@types/node-fetch": "^2.5.7", "@types/tar": "^4.0.3", @@ -47,5 +46,8 @@ "node-fetch": "^2.6.0", "tar": "^6.0.2", "valid-url": "^1.0.9" + }, + "devDependencies": { + "@types/mime-types": "^2.1.0" } } From 80c8e3af90f88c2b68a806a4265d60ffd4d364c8 Mon Sep 17 00:00:00 2001 From: Chen Levy Date: Mon, 17 Aug 2020 15:46:23 +0000 Subject: [PATCH 3/5] Added 'setVerbose' function to 'Log' --- packages/cli/src/index.ts | 2 +- packages/cli/src/lib/cmds/install.ts | 2 +- packages/cli/src/lib/cmds/validate.ts | 2 +- packages/core/src/lib/Log.ts | 64 +++++++++++-------- packages/core/src/lib/TwaManifest.ts | 4 +- .../lib/androidSdk/AndroidSdkToolsSpec.ts | 6 +- 6 files changed, 44 insertions(+), 36 deletions(-) diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 5b1b100e..c8bbe2d6 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -19,7 +19,7 @@ import {Log, ConsoleLog} from '@bubblewrap/core'; module.exports = async (): Promise => { const cli = new Cli(); - const log: Log = new ConsoleLog('cli'); + const log = new ConsoleLog('cli'); const args = process.argv.slice(2); let success; diff --git a/packages/cli/src/lib/cmds/install.ts b/packages/cli/src/lib/cmds/install.ts index 8a2fed24..eef4a4ef 100644 --- a/packages/cli/src/lib/cmds/install.ts +++ b/packages/cli/src/lib/cmds/install.ts @@ -28,7 +28,7 @@ export async function install( const androidSdkTools = new AndroidSdkTools(process, config, jdkHelper, log); const apkFile = args.apkFile || DEFAULT_APK_FILE; if (args.verbose) { - log.verbose = true; + log.setVerbose(true); } // parameter 0 would be the path to 'node', followed by `bubblewrap.js` at 1, then `install` at diff --git a/packages/cli/src/lib/cmds/validate.ts b/packages/cli/src/lib/cmds/validate.ts index b71290b9..2721f366 100644 --- a/packages/cli/src/lib/cmds/validate.ts +++ b/packages/cli/src/lib/cmds/validate.ts @@ -19,7 +19,7 @@ import {Log, ConsoleLog} from '@bubblewrap/core'; import {ParsedArgs} from 'minimist'; import {printValidationResult} from '../pwaValidationHelper'; -const log: Log = new ConsoleLog('validate'); +const log = new ConsoleLog('validate'); /** * Runs the PwaValidator to check a given URL agains the Quality criteria. More information on the diff --git a/packages/core/src/lib/Log.ts b/packages/core/src/lib/Log.ts index 7445f0b2..1253e1a7 100644 --- a/packages/core/src/lib/Log.ts +++ b/packages/core/src/lib/Log.ts @@ -19,34 +19,34 @@ */ export interface Log { - verbose: boolean; - /** - * Prints a debug message to the Log. message is ignored if the Log is not set to verbose. + * Prints a debug message to the Log. Message is ignored if the Log is not set to verbose. * @param message the message the be printed. * @param args extra arguments for the console. */ debug(message: string, ...args: string[]): void; /** - * Prints an info message to the Log. message is ignored if the Log is not set to verbose. - * @param message the message the be printed. - * @param args extra arguments for the console. + * Prints an info message to the Log. Message is ignored if the Log is not set to verbose. + * @param message The message the be printed. + * @param args Extra arguments for the console. */ info(message: string, ...args: string[]): void; /** - * Prints an warning message to the Log. message is ignored if the Log is not set to verbose. - * @param message the message the be printed. - * @param args extra arguments for the console. + * Prints an warning message to the Log. Message is ignored if the Log is not set to verbose. + * @param message The message the be printed. + * @param args Extra arguments for the console. */ warn(message: string, ...args: string[]): void; /** - * Prints an error message to the Log. message is ignored if the Log is not set to verbose. - * @param message the message the be printed. - * @param args extra arguments for the console. + * Prints an error message to the Log. Message is ignored if the Log is not set to verbose. + * @param message The message the be printed. + * @param args Extra arguments for the console. */ error(message: string, ...args: string[]): void; + + setVerbose(verbose: boolean): void; }; /** @@ -64,9 +64,9 @@ export class ConsoleLog implements Log { /** * Creates a new Log instance - * @param tag the tag used when logging. Printed at the beggining of a log message. - * @param verbose if the Log is verbose. Debug messages are only printed on verbose logs. - * @param output where to output the log messages. + * @param tag The tag used when logging. Printed at the beggining of a log message. + * @param verbose If the Log is verbose. Debug messages are only printed on verbose logs. + * @param output Where to output the log messages. */ constructor(tag = '', verbose = false, output = console) { this.tag = tag; @@ -76,9 +76,9 @@ export class ConsoleLog implements Log { } /** - * Prints a debug message to the Log. message is ignored if the Log is not set to verbose. - * @param message the message the be printed. - * @param args extra arguments for the console. + * Prints a debug message to the Log. Message is ignored if the Log is not set to verbose. + * @param message The message the be printed. + * @param args Extra arguments for the console. */ debug(message: string, ...args: string[]): void { if (!this.verbose) { @@ -88,27 +88,27 @@ export class ConsoleLog implements Log { } /** - * Prints an info message to the Log. message is ignored if the Log is not set to verbose. - * @param message the message the be printed. - * @param args extra arguments for the console. + * Prints an info message to the Log. Message is ignored if the Log is not set to verbose. + * @param message The message the be printed. + * @param args Extra arguments for the console. */ info(message: string, ...args: string[]): void { this.log(this.output.log, message, ...args); } /** - * Prints an warning message to the Log. message is ignored if the Log is not set to verbose. - * @param message the message the be printed. - * @param args extra arguments for the console. + * Prints an warning message to the Log. Message is ignored if the Log is not set to verbose. + * @param message The message the be printed. + * @param args Extra arguments for the console. */ warn(message: string, ...args: string[]): void { this.log(this.output.warn, this.yellow('WARNING ' + message), ...args); } /** - * Prints an error message to the Log. message is ignored if the Log is not set to verbose. - * @param message the message the be printed. - * @param args extra arguments for the console. + * Prints an error message to the Log. Message is ignored if the Log is not set to verbose. + * @param message The message the be printed. + * @param args Extra arguments for the console. */ error(message: string, ...args: string[]): void { this.output.error('\n'); @@ -116,9 +116,17 @@ export class ConsoleLog implements Log { this.output.error('\n'); } + /** + * Sets the verbose. + * @param verbose The verbose value to set. + */ + setVerbose(verbose: boolean): void { + this.verbose = verbose; + } + /** * Creates a new Log using the same output and verbositity of the current Log. - * @param newTag the tag the be used on the new Log instance. + * @param newTag The tag the be used on the new Log instance. */ newLog(newTag: string): ConsoleLog { if (this.tag) { diff --git a/packages/core/src/lib/TwaManifest.ts b/packages/core/src/lib/TwaManifest.ts index 9fca6a04..cb8073b8 100644 --- a/packages/core/src/lib/TwaManifest.ts +++ b/packages/core/src/lib/TwaManifest.ts @@ -20,7 +20,7 @@ import * as fs from 'fs'; import fetch from 'node-fetch'; import {findSuitableIcon, generatePackageId, validateNotEmpty} from './util'; import Color = require('color'); -import {Log, ConsoleLog} from './Log'; +import {ConsoleLog} from './Log'; import {WebManifestIcon, WebManifestJson} from './types/WebManifest'; import {ShortcutInfo} from './ShortcutInfo'; @@ -108,7 +108,7 @@ export class TwaManifest { fallbackType: FallbackType; enableSiteSettingsShortcut: boolean; - private static log: Log = new ConsoleLog('twa-manifest'); + private static log = new ConsoleLog('twa-manifest'); constructor(data: TwaManifestJson) { this.packageId = data.packageId; diff --git a/packages/core/src/spec/lib/androidSdk/AndroidSdkToolsSpec.ts b/packages/core/src/spec/lib/androidSdk/AndroidSdkToolsSpec.ts index e7495fc6..8fa507af 100644 --- a/packages/core/src/spec/lib/androidSdk/AndroidSdkToolsSpec.ts +++ b/packages/core/src/spec/lib/androidSdk/AndroidSdkToolsSpec.ts @@ -19,7 +19,7 @@ import {JdkHelper} from '../../../lib/jdk/JdkHelper'; import {AndroidSdkTools} from '../../../lib/androidSdk/AndroidSdkTools'; import util = require('../../../lib/util'); import * as fs from 'fs'; -import {Log, ConsoleLog} from '../../..'; +import {ConsoleLog} from '../../..'; function buildMockConfig(platform: string): Config { if (platform === 'linux' || platform == 'darwin') { @@ -179,7 +179,7 @@ describe('AndroidSdkTools', () => { const config = buildMockConfig(test.platform); const process = buildMockProcess(test.platform); const jdkHelper = new JdkHelper(process, config); - const log: Log = new ConsoleLog('test'); + const log = new ConsoleLog('test'); const androidSdkTools = new AndroidSdkTools(process, config, jdkHelper, log); spyOn(util, 'execute').and.stub(); await androidSdkTools.install('app-release-signed.apk'); @@ -244,7 +244,7 @@ describe('AndroidSdkTools', () => { const config = buildMockConfig(test.platform); const process = buildMockProcess(test.platform); const jdkHelper = new JdkHelper(process, config); - const log: Log = new ConsoleLog('test'); + const log = new ConsoleLog('test'); const androidSdkTools = new AndroidSdkTools(process, config, jdkHelper, log); spyOn(util, 'executeFile').and.stub(); await androidSdkTools.apksigner( From d5a8af888403b84da3e57e0be37106c546a21d86 Mon Sep 17 00:00:00 2001 From: Chen Levy Date: Tue, 18 Aug 2020 08:16:35 +0000 Subject: [PATCH 4/5] Fixed the dependencies on core/packages.json --- packages/cli/src/index.ts | 2 +- packages/cli/src/lib/cmds/validate.ts | 2 +- packages/core/package.json | 18 ++++++++---------- packages/core/src/lib/Log.ts | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index c8bbe2d6..87b3f56c 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -15,7 +15,7 @@ */ import {Cli} from './lib/Cli'; -import {Log, ConsoleLog} from '@bubblewrap/core'; +import {ConsoleLog} from '@bubblewrap/core'; module.exports = async (): Promise => { const cli = new Cli(); diff --git a/packages/cli/src/lib/cmds/validate.ts b/packages/cli/src/lib/cmds/validate.ts index 2721f366..db91e407 100644 --- a/packages/cli/src/lib/cmds/validate.ts +++ b/packages/cli/src/lib/cmds/validate.ts @@ -15,7 +15,7 @@ */ import {PwaValidator} from '@bubblewrap/validator'; -import {Log, ConsoleLog} from '@bubblewrap/core'; +import {ConsoleLog} from '@bubblewrap/core'; import {ParsedArgs} from 'minimist'; import {printValidationResult} from '../pwaValidationHelper'; diff --git a/packages/core/package.json b/packages/core/package.json index 86b2bce5..6753600b 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@bubblewrap/core", - "version": "1.5.0", + "version": "1.3.1", "description": "Core Library to generate, build and sign TWA projects", "scripts": { "build": "tsc", @@ -32,22 +32,20 @@ "@types/color": "^3.0.0", "@types/extract-zip": "^1.6.2", "@types/inquirer": "^6.5.0", - "@types/lodash.template": "^4.5.0", - "@types/node": "^12.12.50", + "@types/jasmine": "^3.5.10", + "@types/lodash.template": "^4.4.6", + "@types/node": "^12.12.39", "@types/node-fetch": "^2.5.7", "@types/tar": "^4.0.3", "@types/valid-url": "^1.0.3", + "@types/sharp": "^0.25.0", "color": "^3.1.2", "extract-zip": "^1.7.0", - "inquirer": "^7.3.2", - "jimp": "^0.14.0", + "inquirer": "^7.0.4", + "sharp": "^0.23.2", "lodash.template": "^4.5.0", - "mime-types": "^2.1.27", "node-fetch": "^2.6.0", "tar": "^6.0.2", "valid-url": "^1.0.9" - }, - "devDependencies": { - "@types/mime-types": "^2.1.0" } -} +} \ No newline at end of file diff --git a/packages/core/src/lib/Log.ts b/packages/core/src/lib/Log.ts index 1253e1a7..beef5037 100644 --- a/packages/core/src/lib/Log.ts +++ b/packages/core/src/lib/Log.ts @@ -1,5 +1,5 @@ /* - * Copyright 2020 Google Inc. All Rights Reserved. + * Copyright 2019 Google Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From 9783686ddf6ca0059265afaa19020c09207f6552 Mon Sep 17 00:00:00 2001 From: Chen Levy Date: Tue, 18 Aug 2020 09:21:38 +0000 Subject: [PATCH 5/5] Fixed the dependencies to match master. --- packages/core/package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 6753600b..85251060 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@bubblewrap/core", - "version": "1.3.1", + "version": "1.5.0", "description": "Core Library to generate, build and sign TWA projects", "scripts": { "build": "tsc", @@ -32,18 +32,18 @@ "@types/color": "^3.0.0", "@types/extract-zip": "^1.6.2", "@types/inquirer": "^6.5.0", - "@types/jasmine": "^3.5.10", - "@types/lodash.template": "^4.4.6", - "@types/node": "^12.12.39", + "@types/lodash.template": "^4.5.0", + "@types/mime-types": "^2.1.0", + "@types/node": "^12.12.50", "@types/node-fetch": "^2.5.7", "@types/tar": "^4.0.3", "@types/valid-url": "^1.0.3", - "@types/sharp": "^0.25.0", "color": "^3.1.2", "extract-zip": "^1.7.0", - "inquirer": "^7.0.4", - "sharp": "^0.23.2", + "inquirer": "^7.3.2", + "jimp": "^0.14.0", "lodash.template": "^4.5.0", + "mime-types": "^2.1.27", "node-fetch": "^2.6.0", "tar": "^6.0.2", "valid-url": "^1.0.9"