diff --git a/lib/cmds/initialize.ts b/lib/cmds/initialize.ts index 6eef2c82..751eb857 100644 --- a/lib/cmds/initialize.ts +++ b/lib/cmds/initialize.ts @@ -14,11 +14,14 @@ const noop = () => {}; // Make a function which configures a child process to automatically respond // to a certain question -function respondFactory(question: string, answer: string): Function { +function respondFactory(question: string, answer: string, verbose: boolean): Function { return (child: ChildProcess) => { (child.stdin).setDefaultEncoding('utf-8'); child.stdout.on('data', (data: Buffer | String) => { if (data != null) { + if (verbose) { + process.stdout.write(data as string); + } if (data.toString().indexOf(question) != -1) { child.stdin.write(answer + '\n'); } @@ -59,12 +62,13 @@ function runAndroidSDKCommand( // Download updates via the android SDK function downloadAndroidUpdates( - sdkPath: string, targets: string[], search_all: boolean, auto_accept: boolean): q.Promise { + sdkPath: string, targets: string[], search_all: boolean, auto_accept: boolean, + verbose: boolean): q.Promise { return runAndroidSDKCommand( sdkPath, 'update', ['sdk', '-u'].concat(search_all ? ['-a'] : []).concat(['-t', targets.join(',')]), auto_accept ? 'pipe' : 'inherit', - auto_accept ? respondFactory('Do you accept the license', 'y') : noop); + auto_accept ? respondFactory('Do you accept the license', 'y', verbose) : noop); } // Setup hardware acceleration for x86-64 emulation @@ -207,21 +211,24 @@ function configureAVDHardware(sdkPath: string, desc: AVDDescriptor): q.Promise { +function makeAVD( + sdkPath: string, desc: AVDDescriptor, version: string, verbose: boolean): q.Promise { return runAndroidSDKCommand(sdkPath, 'delete', ['avd', '--name', desc.avdName(version)]) .then(noop, noop) .then(() => { return runAndroidSDKCommand( sdkPath, 'create', ['avd', '--name', desc.avdName(version), '--target', desc.api, '--abi', desc.abi], - 'pipe', respondFactory('Do you wish to create a custom hardware profile', 'no')); + 'pipe', + respondFactory('Do you wish to create a custom hardware profile', 'no', verbose)); }); } // Initialize the android SDK export function android( sdkPath: string, apiLevels: string[], architectures: string[], platforms: string[], - acceptLicenses: boolean, version: string, oldAVDs: string[], logger: Logger): void { + acceptLicenses: boolean, version: string, oldAVDs: string[], logger: Logger, + verbose: boolean): void { let avdDescriptors: AVDDescriptor[]; let tools = ['platform-tool', 'tool']; if ((os.type() == 'Darwin') || (os.type() == 'Windows_NT')) { @@ -229,7 +236,7 @@ export function android( } logger.info('android-sdk: Downloading additional SDK updates'); - downloadAndroidUpdates(sdkPath, tools, false, acceptLicenses) + downloadAndroidUpdates(sdkPath, tools, false, acceptLicenses, verbose) .then(() => { return setupHardwareAcceleration(sdkPath); }) @@ -240,7 +247,7 @@ export function android( return downloadAndroidUpdates( sdkPath, ['build-tools-24.0.0'].concat( getAndroidSDKTargets(apiLevels, architectures, platforms, oldAVDs)), - true, acceptLicenses); + true, acceptLicenses, verbose); }) .then(() => { return getAVDDescriptors(sdkPath); @@ -255,7 +262,7 @@ export function android( .then(() => { return sequentialForEach(avdDescriptors, (descriptor: AVDDescriptor) => { logger.info('android-sdk: Setting up virtual device "' + descriptor.name + '"'); - return makeAVD(sdkPath, descriptor, version); + return makeAVD(sdkPath, descriptor, version, verbose); }); }) .then(() => { diff --git a/lib/cmds/opts.ts b/lib/cmds/opts.ts index cbc887e5..8f3c328b 100644 --- a/lib/cmds/opts.ts +++ b/lib/cmds/opts.ts @@ -34,6 +34,8 @@ export const AVD_USE_SNAPSHOTS = 'avd-use-snapshots'; export const STARTED_SIGNIFIER = 'started-signifier'; export const SIGNAL_VIA_IPC = 'signal-via-ipc'; export const DETACH = 'detach'; +export const QUIET = 'quiet'; +export const VERBOSE = 'verbose'; /** * The options used by the commands. @@ -108,5 +110,7 @@ opts[DETACH] = new Option( DETACH, 'Once the selenium server is up and running, return control to the parent process and continue running the server in the background.', 'boolean', false); +opts[VERBOSE] = new Option(VERBOSE, 'Extra console output', 'boolean', false); +opts[QUIET] = new Option(QUIET, 'Minimal console output', 'boolean', false); export var Opts = opts; diff --git a/lib/cmds/start.ts b/lib/cmds/start.ts index 57d17c09..576d60d2 100644 --- a/lib/cmds/start.ts +++ b/lib/cmds/start.ts @@ -36,6 +36,7 @@ let prog = new Program() .addOption(Opts[Opt.AVD_USE_SNAPSHOTS]) .addOption(Opts[Opt.STARTED_SIGNIFIER]) .addOption(Opts[Opt.SIGNAL_VIA_IPC]) + .addOption(Opts[Opt.QUIET]) .addOption(Opts[Opt.DETACH]); if (os.type() === 'Darwin') { @@ -72,6 +73,7 @@ function start(options: Options) { } let osType = os.type(); + let stdio = options[Opt.QUIET].getBoolean() ? 'pipe' : 'inherit'; let binaries = FileManager.setupBinaries(); let seleniumPort = options[Opt.SELENIUM_PORT].getString(); let appiumPort = options[Opt.APPIUM_PORT].getString(); @@ -176,13 +178,13 @@ function start(options: Options) { let avds = options[Opt.AVDS].getString(); startAndroid( outputDir, binaries[AndroidSDK.id], avds.split(','), - options[Opt.AVD_USE_SNAPSHOTS].getBoolean(), avdPort); + options[Opt.AVD_USE_SNAPSHOTS].getBoolean(), avdPort, stdio); } else { logger.warn('Not starting android because it is not installed'); } } if (downloadedBinaries[Appium.id] != null) { - startAppium(outputDir, binaries[Appium.id], binaries[AndroidSDK.id], appiumPort); + startAppium(outputDir, binaries[Appium.id], binaries[AndroidSDK.id], appiumPort, stdio); } // log the command to launch selenium server @@ -200,7 +202,7 @@ function start(options: Options) { } logger.info('java' + argsToString); - let seleniumProcess = spawn('java', args, 'inherit'); + let seleniumProcess = spawn('java', args, stdio); if (options[Opt.STARTED_SIGNIFIER].getString()) { signalWhenReady( options[Opt.STARTED_SIGNIFIER].getString(), options[Opt.SIGNAL_VIA_IPC].getBoolean(), @@ -225,7 +227,8 @@ function start(options: Options) { } function startAndroid( - outputDir: string, sdk: Binary, avds: string[], useSnapshots: boolean, port: number): void { + outputDir: string, sdk: Binary, avds: string[], useSnapshots: boolean, port: number, + stdio: string): void { let sdkPath = path.resolve(outputDir, sdk.executableFilename(os.type())); if (avds[0] == 'all') { avds = require(path.resolve(sdkPath, 'available_avds.json')); @@ -257,7 +260,7 @@ function startAndroid( if (emuBin !== 'emulator') { emuArgs = emuArgs.concat(['-qemu', '-enable-kvm']); } - androidProcesses.push(spawn(path.resolve(sdkPath, 'tools', emuBin), emuArgs, 'inherit')); + androidProcesses.push(spawn(path.resolve(sdkPath, 'tools', emuBin), emuArgs, stdio)); }); } @@ -271,13 +274,14 @@ function killAndroid() { // Manage appium process let appiumProcess: ChildProcess; -function startAppium(outputDir: string, binary: Binary, androidSDK: Binary, port: string) { +function startAppium( + outputDir: string, binary: Binary, androidSDK: Binary, port: string, stdio: string) { logger.info('Starting appium server'); if (androidSDK) { process.env.ANDROID_HOME = path.resolve(outputDir, androidSDK.executableFilename(os.type())); } appiumProcess = spawn( - 'npm', ['run', 'appium'].concat(port ? ['--', '--port', port] : []), null, + 'npm', ['run', 'appium'].concat(port ? ['--', '--port', port] : []), stdio, {cwd: path.resolve(outputDir, binary.filename())}); } diff --git a/lib/cmds/update.ts b/lib/cmds/update.ts index 82331898..b86e8a01 100644 --- a/lib/cmds/update.ts +++ b/lib/cmds/update.ts @@ -22,6 +22,7 @@ let prog = new Program() .command('update', 'install or update selected binaries') .action(update) .addOption(Opts[Opt.OUT_DIR]) + .addOption(Opts[Opt.VERBOSE]) .addOption(Opts[Opt.IGNORE_SSL]) .addOption(Opts[Opt.PROXY]) .addOption(Opts[Opt.ALTERNATE_CDN]) @@ -98,6 +99,7 @@ function update(options: Options): void { } let ignoreSSL = options[Opt.IGNORE_SSL].getBoolean(); let proxy = options[Opt.PROXY].getString(); + let verbose = options[Opt.VERBOSE].getBoolean(); // setup versions for binaries let binaries = FileManager.setupBinaries(options[Opt.ALTERNATE_CDN].getString()); @@ -166,7 +168,7 @@ function update(options: Options): void { initializeAndroid( path.resolve(outputDir, binary.executableFilename(os.type())), android_api_levels, android_architectures, android_platforms, android_accept_licenses, - binaries[AndroidSDK.id].versionCustom, JSON.parse(oldAVDList), logger); + binaries[AndroidSDK.id].versionCustom, JSON.parse(oldAVDList), logger, verbose); }) .done(); }