From 7a8b4bdcad228586c460207f2c5830eeb74128b2 Mon Sep 17 00:00:00 2001 From: Sid Ferreira Date: Mon, 4 Feb 2019 09:44:06 -0200 Subject: [PATCH 1/7] refactor(logger): replaces all `console` uses --- .../copyProjectTemplateAndReplace.js | 9 ++-- .../cli/src/generator/printRunInstructions.js | 21 +++++----- packages/cli/src/generator/templates.js | 19 +++++---- packages/cli/src/init/init.js | 6 +-- packages/cli/src/logAndroid/logAndroid.js | 3 +- packages/cli/src/logIOS/logIOS.js | 3 +- packages/cli/src/runAndroid/runAndroid.js | 31 +++++++------- .../cli/src/runAndroid/runOnAllDevices.js | 16 ++++---- .../src/runAndroid/tryLaunchAppOnDevice.js | 5 ++- .../cli/src/runAndroid/tryRunAdbReverse.js | 6 +-- packages/cli/src/runIOS/runIOS.js | 41 ++++++++++--------- .../middleware/copyToClipBoardMiddleware.js | 3 +- .../middleware/getDevToolsMiddleware.js | 9 ++-- .../middleware/systraceProfileMiddleware.js | 5 ++- .../server/util/debugger-ui/debuggerWorker.js | 4 +- .../cli/src/server/util/jsPackagerClient.js | 4 +- packages/cli/src/server/util/launchChrome.js | 3 +- packages/cli/src/server/util/messageSocket.js | 15 +++---- .../cli/src/server/util/webSocketProxy.js | 4 +- packages/cli/src/upgrade/upgrade.js | 7 ++-- packages/cli/src/util/copyAndReplace.js | 2 +- packages/cli/src/util/yarn.js | 3 +- 22 files changed, 118 insertions(+), 101 deletions(-) diff --git a/packages/cli/src/generator/copyProjectTemplateAndReplace.js b/packages/cli/src/generator/copyProjectTemplateAndReplace.js index 173331f75..f49e1f313 100644 --- a/packages/cli/src/generator/copyProjectTemplateAndReplace.js +++ b/packages/cli/src/generator/copyProjectTemplateAndReplace.js @@ -12,6 +12,7 @@ const path = require('path'); const copyAndReplace = require('../util/copyAndReplace'); const prompt = require('./promptSync')(); const walk = require('../util/walk'); +const logger = require('../util/logger'); /** * Util for creating a new React Native project. @@ -135,11 +136,11 @@ function upgradeFileContentChangedCallback( contentChanged ) { if (contentChanged === 'new') { - console.log(`${chalk.bold('new')} ${relativeDestPath}`); + logger.info(`${chalk.bold('new')} ${relativeDestPath}`); return 'overwrite'; } if (contentChanged === 'changed') { - console.log( + logger.info( `${chalk.bold(relativeDestPath)} ` + `has changed in the new version.\nDo you want to keep your ${relativeDestPath} or replace it with the ` + `latest version?\nIf you ever made any changes ` + @@ -150,10 +151,10 @@ function upgradeFileContentChangedCallback( ); const answer = prompt(); if (answer === 'y') { - console.log(`Replacing ${relativeDestPath}`); + logger.info(`Replacing ${relativeDestPath}`); return 'overwrite'; } - console.log(`Keeping your ${relativeDestPath}`); + logger.info(`Keeping your ${relativeDestPath}`); return 'keep'; } if (contentChanged === 'identical') { diff --git a/packages/cli/src/generator/printRunInstructions.js b/packages/cli/src/generator/printRunInstructions.js index b011902ab..2fd09efa5 100644 --- a/packages/cli/src/generator/printRunInstructions.js +++ b/packages/cli/src/generator/printRunInstructions.js @@ -9,6 +9,7 @@ const chalk = require('chalk'); const path = require('path'); +const logger = require('../util/logger'); function printRunInstructions(projectDir, projectName) { const absoluteProjectDir = path.resolve(projectDir); @@ -22,19 +23,19 @@ function printRunInstructions(projectDir, projectName) { process.cwd(), xcodeProjectPath ); - console.log(chalk.white.bold('To run your app on iOS:')); - console.log(` cd ${absoluteProjectDir}`); - console.log(' react-native run-ios'); - console.log(' - or -'); - console.log(` Open ${relativeXcodeProjectPath} in Xcode`); - console.log(' Hit the Run button'); + logger.info(chalk.white.bold('To run your app on iOS:')); + logger.info(` cd ${absoluteProjectDir}`); + logger.info(' react-native run-ios'); + logger.info(' - or -'); + logger.info(` Open ${relativeXcodeProjectPath} in Xcode`); + logger.info(' Hit the Run button'); // Android - console.log(chalk.white.bold('To run your app on Android:')); - console.log(` cd ${absoluteProjectDir}`); - console.log( + logger.info(chalk.white.bold('To run your app on Android:')); + logger.info(` cd ${absoluteProjectDir}`); + logger.info( ' Have an Android emulator running (quickest way to get started), or a device connected' ); - console.log(' react-native run-android'); + logger.info(' react-native run-android'); } module.exports = printRunInstructions; diff --git a/packages/cli/src/generator/templates.js b/packages/cli/src/generator/templates.js index d2ec5a191..c0ce11010 100644 --- a/packages/cli/src/generator/templates.js +++ b/packages/cli/src/generator/templates.js @@ -11,6 +11,7 @@ const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); const copyProjectTemplateAndReplace = require('./copyProjectTemplateAndReplace'); +const logger = require('../util/logger'); /** * @param destPath Create the new project at this path. @@ -68,7 +69,7 @@ function createFromRemoteTemplate( } // Check if the template exists - console.log(`Fetching template ${installPackage}...`); + logger.info(`Fetching template ${installPackage}...`); try { if (yarnVersion) { execSync(`yarn add ${installPackage} --ignore-scripts`, { @@ -105,7 +106,7 @@ function createFromRemoteTemplate( } catch (err) { // Not critical but we still want people to know and report // if this the clean up fails. - console.warn( + logger.warn( `Failed to clean up template temp files in node_modules/${templateName}. ` + 'This is not a critical error, you can work on your app.' ); @@ -117,9 +118,9 @@ function installTemplateDependencies(templatePath, yarnVersion) { // dependencies.json is a special file that lists additional dependencies // that are required by this template const dependenciesJsonPath = path.resolve(templatePath, 'dependencies.json'); - console.log('Adding dependencies for the project...'); + logger.info('Adding dependencies for the project...'); if (!fs.existsSync(dependenciesJsonPath)) { - console.log('No additional dependencies.'); + logger.info('No additional dependencies.'); return; } @@ -134,7 +135,7 @@ function installTemplateDependencies(templatePath, yarnVersion) { for (const depName of Object.keys(dependencies)) { const depVersion = dependencies[depName]; const depToInstall = `${depName}@${depVersion}`; - console.log(`Adding ${depToInstall}...`); + logger.info(`Adding ${depToInstall}...`); if (yarnVersion) { execSync(`yarn add ${depToInstall}`, { stdio: 'inherit' }); } else { @@ -143,7 +144,7 @@ function installTemplateDependencies(templatePath, yarnVersion) { }); } } - console.log("Linking native dependencies into the project's build files..."); + logger.info("Linking native dependencies into the project's build files..."); execSync('react-native link', { stdio: 'inherit' }); } @@ -154,9 +155,9 @@ function installTemplateDevDependencies(templatePath, yarnVersion) { templatePath, 'devDependencies.json' ); - console.log('Adding develop dependencies for the project...'); + logger.info('Adding develop dependencies for the project...'); if (!fs.existsSync(devDependenciesJsonPath)) { - console.log('No additional develop dependencies.'); + logger.info('No additional develop dependencies.'); return; } @@ -171,7 +172,7 @@ function installTemplateDevDependencies(templatePath, yarnVersion) { for (const depName of Object.keys(dependencies)) { const depVersion = dependencies[depName]; const depToInstall = `${depName}@${depVersion}`; - console.log(`Adding ${depToInstall}...`); + logger.info(`Adding ${depToInstall}...`); if (yarnVersion) { execSync(`yarn add ${depToInstall} -D`, { stdio: 'inherit' }); } else { diff --git a/packages/cli/src/init/init.js b/packages/cli/src/init/init.js index 0a0f21530..b4233328c 100644 --- a/packages/cli/src/init/init.js +++ b/packages/cli/src/init/init.js @@ -33,7 +33,7 @@ function init(projectDir, argsOrName) { // args array is e.g. ['AwesomeApp', '--verbose', '--template', 'navigation'] if (!args || args.length === 0) { - console.error('react-native init requires a project name.'); + logger.error('react-native init requires a project name.'); return; } @@ -53,7 +53,7 @@ function generateProject(destinationRoot, newProjectName, options) { const reactNativePackageJson = require('react-native/package.json'); const { peerDependencies } = reactNativePackageJson; if (!peerDependencies) { - console.error( + logger.error( "Missing React peer dependency in React Native's package.json. Aborting." ); return; @@ -61,7 +61,7 @@ function generateProject(destinationRoot, newProjectName, options) { const reactVersion = peerDependencies.react; if (!reactVersion) { - console.error( + logger.error( "Missing React peer dependency in React Native's package.json. Aborting." ); return; diff --git a/packages/cli/src/logAndroid/logAndroid.js b/packages/cli/src/logAndroid/logAndroid.js index fc57e4e5e..9525d3911 100644 --- a/packages/cli/src/logAndroid/logAndroid.js +++ b/packages/cli/src/logAndroid/logAndroid.js @@ -7,6 +7,7 @@ const chalk = require('chalk'); const { spawnSync } = require('child_process'); +const logger = require('../util/logger'); /** * Starts adb logcat @@ -18,7 +19,7 @@ async function logAndroid() { const adbArgs = ['logcat', '*:S', 'ReactNative:V', 'ReactNativeJS:V']; - console.log( + logger.info( chalk.bold(`Starting the logger (${adbPath} ${adbArgs.join(' ')})...`) ); diff --git a/packages/cli/src/logIOS/logIOS.js b/packages/cli/src/logIOS/logIOS.js index 641dbe157..ac78b1cef 100644 --- a/packages/cli/src/logIOS/logIOS.js +++ b/packages/cli/src/logIOS/logIOS.js @@ -11,6 +11,7 @@ const chalk = require('chalk'); const { execFileSync, spawnSync } = require('child_process'); const os = require('os'); const path = require('path'); +const logger = require('../util/logger'); function findAvailableDevice(devices) { for (const key of Object.keys(devices)) { @@ -37,7 +38,7 @@ async function logIOS() { const device = findAvailableDevice(devices); if (device === undefined) { - console.log(chalk.red('No active iOS device found')); + logger.info(chalk.red('No active iOS device found')); return; } diff --git a/packages/cli/src/runAndroid/runAndroid.js b/packages/cli/src/runAndroid/runAndroid.js index 0866e418a..91c829bdd 100644 --- a/packages/cli/src/runAndroid/runAndroid.js +++ b/packages/cli/src/runAndroid/runAndroid.js @@ -17,6 +17,7 @@ const fs = require('fs'); const isString = require('lodash/isString'); const path = require('path'); const isPackagerRunning = require('../util/isPackagerRunning'); +const logger = require('../util/logger'); const adb = require('./adb'); const runOnAllDevices = require('./runOnAllDevices'); const tryRunAdbReverse = require('./tryRunAdbReverse'); @@ -33,7 +34,7 @@ function checkAndroid(root) { */ function runAndroid(argv: Array, config: ContextT, args: Object) { if (!checkAndroid(args.root)) { - console.log( + logger.info( chalk.red( 'Android project not found. Are you sure this is a React Native project?' ) @@ -47,14 +48,14 @@ function runAndroid(argv: Array, config: ContextT, args: Object) { return isPackagerRunning(args.port).then(result => { if (result === 'running') { - console.log(chalk.bold('JS server already running.')); + logger.info(chalk.bold('JS server already running.')); } else if (result === 'unrecognized') { - console.warn( + logger.warn( chalk.yellow('JS server not recognized, continuing with build...') ); } else { // result == 'not_running' - console.log(chalk.bold('Starting JS server...')); + logger.info(chalk.bold('Starting JS server...')); startServerInNewWindow(args.port, args.terminal); } return buildAndRun(args); @@ -101,7 +102,7 @@ function buildAndRun(args) { adbPath ); } - console.log(chalk.red('Argument missing for parameter --deviceId')); + logger.info(chalk.red('Argument missing for parameter --deviceId')); } else { return runOnAllDevices( args, @@ -132,25 +133,25 @@ function runOnSpecificDevice( adbPath ); } else { - console.log(`Could not find device with the id: "${args.deviceId}".`); - console.log('Choose one of the following:'); - console.log(devices); + logger.info(`Could not find device with the id: "${args.deviceId}".`); + logger.info('Choose one of the following:'); + logger.info(devices); } } else { - console.log('No Android devices connected.'); + logger.info('No Android devices connected.'); } } function buildApk(gradlew) { try { - console.log(chalk.bold('Building the app...')); + logger.info(chalk.bold('Building the app...')); // using '-x lint' in order to ignore linting errors while building the apk execFileSync(gradlew, ['build', '-x', 'lint'], { stdio: [process.stdin, process.stdout, process.stderr], }); } catch (e) { - console.log( + logger.info( chalk.red('Could not build the app, read the error above for details.\n') ); } @@ -163,7 +164,7 @@ function tryInstallAppOnDevice(args, device) { const pathToApk = `${appFolder}/build/outputs/apk/${appFolder}-debug.apk`; const adbPath = getAdbPath(); const adbArgs = ['-s', device, 'install', pathToApk]; - console.log( + logger.info( chalk.bold( `Installing the app on the device (cd android && adb -s ${device} install ${pathToApk}` ) @@ -172,8 +173,8 @@ function tryInstallAppOnDevice(args, device) { stdio: [process.stdin, process.stdout, process.stderr], }); } catch (e) { - console.log(e.message); - console.log( + logger.info(e.message); + logger.info( chalk.red( 'Could not install the app on the device, read the error above for details.\n' ) @@ -259,7 +260,7 @@ function startServerInNewWindow(port, terminal = process.env.REACT_TERMINAL) { procConfig.stdio = 'ignore'; return spawn('cmd.exe', ['/C', launchPackagerScript], procConfig); } - console.log( + logger.info( chalk.red(`Cannot start the packager. Unknown platform ${process.platform}`) ); } diff --git a/packages/cli/src/runAndroid/runOnAllDevices.js b/packages/cli/src/runAndroid/runOnAllDevices.js index 64f7e171b..a4cde69d1 100644 --- a/packages/cli/src/runAndroid/runOnAllDevices.js +++ b/packages/cli/src/runAndroid/runOnAllDevices.js @@ -11,7 +11,7 @@ const chalk = require('chalk'); const { spawnSync, execFileSync } = require('child_process'); - +const logger = require('../util/logger'); const adb = require('./adb'); const tryRunAdbReverse = require('./tryRunAdbReverse'); const tryLaunchAppOnDevice = require('./tryLaunchAppOnDevice'); @@ -40,7 +40,7 @@ function runOnAllDevices( )}${args.variant[0].toUpperCase()}${args.variant.slice(1)}` ); } else if (args.flavor) { - console.warn( + logger.warn( chalk.yellow('--flavor has been deprecated. Use --variant instead') ); gradleArgs.push( @@ -53,7 +53,7 @@ function runOnAllDevices( gradleArgs.push(getCommand(args.appFolder, 'installDebug')); } - console.log( + logger.info( chalk.bold( `Building and installing the app on the device (cd android && ${cmd} ${gradleArgs.join( ' ' @@ -65,7 +65,7 @@ function runOnAllDevices( stdio: [process.stdin, process.stdout, process.stderr], }); } catch (e) { - console.log( + logger.info( chalk.red( 'Could not install the app on the device, read the error above for details.\n' + 'Make sure you have an Android emulator running or a device connected and have\n' + @@ -75,7 +75,7 @@ function runOnAllDevices( ); // stderr is automatically piped from the gradle process, so the user // should see the error already, there is no need to do - // `console.log(e.stderr)` + // `logger.info(e.stderr)` return Promise.reject(e); } const devices = adb.getDevices(); @@ -101,19 +101,19 @@ function runOnAllDevices( '-n', `${packageNameWithSuffix}/${packageName}.MainActivity`, ]; - console.log( + logger.info( chalk.bold( `Starting the app (${adbPath} ${fallbackAdbArgs.join(' ')}...` ) ); spawnSync(adbPath, fallbackAdbArgs, { stdio: 'inherit' }); } catch (e) { - console.log( + logger.info( chalk.red('adb invocation failed. Do you have adb in your PATH?') ); // stderr is automatically piped from the gradle process, so the user // should see the error already, there is no need to do - // `console.log(e.stderr)` + // `logger.info(e.stderr)` return Promise.reject(e); } } diff --git a/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js b/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js index 1e0d86468..ae29dc87c 100644 --- a/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js +++ b/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js @@ -9,6 +9,7 @@ const chalk = require('chalk'); const { spawnSync } = require('child_process'); +const logger = require('../util/logger'); function tryLaunchAppOnDevice( device: string, @@ -27,14 +28,14 @@ function tryLaunchAppOnDevice( '-n', `${packageNameWithSuffix}/${packageName}.${mainActivity}`, ]; - console.log( + logger.info( chalk.bold( `Starting the app on ${device} (${adbPath} ${adbArgs.join(' ')})...` ) ); spawnSync(adbPath, adbArgs, { stdio: 'inherit' }); } catch (e) { - console.log( + logger.info( chalk.red('adb invocation failed. Do you have adb in your PATH?') ); } diff --git a/packages/cli/src/runAndroid/tryRunAdbReverse.js b/packages/cli/src/runAndroid/tryRunAdbReverse.js index 398ec1b13..8b9d9cdc3 100644 --- a/packages/cli/src/runAndroid/tryRunAdbReverse.js +++ b/packages/cli/src/runAndroid/tryRunAdbReverse.js @@ -9,7 +9,7 @@ const chalk = require('chalk'); const { execFileSync } = require('child_process'); - +const logger = require('../util/logger'); const getAdbPath = require('./getAdbPath'); // Runs ADB reverse tcp:8081 tcp:8081 to allow loading the jsbundle from the packager @@ -23,13 +23,13 @@ function tryRunAdbReverse(packagerPort: number | string, device: string) { adbArgs.unshift('-s', device); } - console.log(chalk.bold(`Running ${adbPath} ${adbArgs.join(' ')}`)); + logger.info(chalk.bold(`Running ${adbPath} ${adbArgs.join(' ')}`)); execFileSync(adbPath, adbArgs, { stdio: [process.stdin, process.stdout, process.stderr], }); } catch (e) { - console.log(chalk.yellow(`Could not run adb reverse: ${e.message}`)); + logger.info(chalk.yellow(`Could not run adb reverse: ${e.message}`)); } } diff --git a/packages/cli/src/runIOS/runIOS.js b/packages/cli/src/runIOS/runIOS.js index a3b42b3a1..f386c7382 100644 --- a/packages/cli/src/runIOS/runIOS.js +++ b/packages/cli/src/runIOS/runIOS.js @@ -14,6 +14,7 @@ import type { ContextT } from '../core/types.flow'; const child_process = require('child_process'); const fs = require('fs'); const path = require('path'); +const logger = require('../util/logger'); const findXcodeProject = require('./findXcodeProject'); const parseIOSDevicesList = require('./parseIOSDevicesList'); const findMatchingSimulator = require('./findMatchingSimulator'); @@ -53,7 +54,7 @@ function runIOS(_: Array, ctx: ContextT, args: FlagsT) { ); const scheme = args.scheme || inferredSchemeName; - console.log( + logger.info( `Found Xcode ${xcodeProject.isWorkspace ? 'workspace' : 'project'} ${ xcodeProject.name }` @@ -81,11 +82,11 @@ function runIOS(_: Array, ctx: ContextT, args: FlagsT) { } if (devices && devices.length > 0) { // $FlowIssue: args.device is defined in this context - console.log(`Could not find device with the name: "${args.device}".`); - console.log('Choose one of the following:'); + logger.info(`Could not find device with the name: "${args.device}".`); + logger.info('Choose one of the following:'); printFoundDevices(devices); } else { - console.log('No iOS devices connected.'); + logger.info('No iOS devices connected.'); } } else if (args.udid) { // $FlowIssue: args.udid is defined in this context @@ -118,11 +119,11 @@ function runOnDeviceByUdid( if (devices && devices.length > 0) { // $FlowIssue: args.udid is defined in this context - console.log(`Could not find device with the udid: "${args.udid}".`); - console.log('Choose one of the following:'); + logger.info(`Could not find device with the udid: "${args.udid}".`); + logger.info('Choose one of the following:'); printFoundDevices(devices); } else { - console.log('No iOS devices connected.'); + logger.info('No iOS devices connected.'); } } @@ -185,7 +186,7 @@ async function runOnSimulator(xcodeProject, args, scheme) { const appPath = getBuildPath(args.configuration, appName, false, scheme); - console.log(`Installing ${appPath}`); + logger.info(`Installing ${appPath}`); child_process.spawnSync( 'xcrun', @@ -204,7 +205,7 @@ async function runOnSimulator(xcodeProject, args, scheme) { // $FlowExpectedError https://github.com/facebook/flow/issues/5675 .trim(); - console.log(`Launching ${bundleID}`); + logger.info(`Launching ${bundleID}`); child_process.spawnSync( 'xcrun', @@ -242,7 +243,7 @@ async function runOnDevice( '--justlaunch', ]; - console.log(`installing and launching your app on ${selectedDevice.name}...`); + logger.info(`installing and launching your app on ${selectedDevice.name}...`); const iosDeployOutput = child_process.spawnSync( 'ios-deploy', @@ -251,12 +252,12 @@ async function runOnDevice( ); if (iosDeployOutput.error) { - console.log(''); - console.log('** INSTALLATION FAILED **'); - console.log('Make sure you have ios-deploy installed globally.'); - console.log('(e.g "npm install -g ios-deploy")'); + logger.info(''); + logger.info('** INSTALLATION FAILED **'); + logger.info('Make sure you have ios-deploy installed globally.'); + logger.info('(e.g "npm install -g ios-deploy")'); } else { - console.log('** INSTALLATION SUCCEEDED **'); + logger.info('** INSTALLATION SUCCEEDED **'); } } @@ -282,7 +283,7 @@ function buildProject( '-derivedDataPath', `build/${scheme}`, ]; - console.log(`Building using "xcodebuild ${xcodebuildArgs.join(' ')}"`); + logger.info(`Building using "xcodebuild ${xcodebuildArgs.join(' ')}"`); let xcpretty; if (!verbose) { xcpretty = @@ -303,7 +304,7 @@ function buildProject( if (xcpretty) { xcpretty.stdin.write(data); } else { - console.log(data.toString()); + logger.info(data.toString()); } }); buildProcess.stderr.on('data', data => { @@ -335,7 +336,7 @@ function buildProject( function bootSimulator(selectedSimulator) { const simulatorFullName = formattedDeviceName(selectedSimulator); - console.log(`Launching ${simulatorFullName}...`); + logger.info(`Launching ${simulatorFullName}...`); try { child_process.spawnSync('xcrun', [ 'instruments', @@ -382,7 +383,7 @@ function xcprettyAvailable() { function matchingDevice(devices, deviceName) { if (deviceName === true && devices.length === 1) { - console.log( + logger.info( `Using first available device ${ devices[0].name } due to lack of name supplied.` @@ -415,7 +416,7 @@ function formattedDeviceName(simulator) { function printFoundDevices(devices) { for (let i = devices.length - 1; i >= 0; i--) { - console.log(`${devices[i].name} Udid: ${devices[i].udid}`); + logger.info(`${devices[i].name} Udid: ${devices[i].udid}`); } } diff --git a/packages/cli/src/server/middleware/copyToClipBoardMiddleware.js b/packages/cli/src/server/middleware/copyToClipBoardMiddleware.js index 0d6803bb4..48083100a 100644 --- a/packages/cli/src/server/middleware/copyToClipBoardMiddleware.js +++ b/packages/cli/src/server/middleware/copyToClipBoardMiddleware.js @@ -9,6 +9,7 @@ const chalk = require('chalk'); const copyToClipBoard = require('../util/copyToClipBoard'); +const logger = require('../../util/logger'); /** * Handle the request from JS to copy contents onto host system clipboard. @@ -18,7 +19,7 @@ module.exports = function copyMiddleware(req, res, next) { if (req.url === '/copy-to-clipboard') { const ret = copyToClipBoard(req.rawBody); if (!ret) { - console.warn(chalk.red('Copy button is not supported on this platform!')); + logger.warn(chalk.red('Copy button is not supported on this platform!')); } res.end('OK'); } else { diff --git a/packages/cli/src/server/middleware/getDevToolsMiddleware.js b/packages/cli/src/server/middleware/getDevToolsMiddleware.js index dffcec451..489c30aed 100644 --- a/packages/cli/src/server/middleware/getDevToolsMiddleware.js +++ b/packages/cli/src/server/middleware/getDevToolsMiddleware.js @@ -7,10 +7,11 @@ * @format */ const launchChrome = require('../util/launchChrome'); +const logger = require('../../util/logger'); function launchChromeDevTools(host, port, args = '') { const debuggerURL = `http://${host}:${port}/debugger-ui${args}`; - console.log('Launching Dev Tools...'); + logger.info('Launching Dev Tools...'); launchChrome(debuggerURL); } @@ -28,14 +29,14 @@ function launchDevTools({ host, port, watchFolders }, isChromeConnected) { module.exports = function getDevToolsMiddleware(options, isChromeConnected) { return function devToolsMiddleware(req, res, next) { if (req.url === '/launch-safari-devtools') { - // TODO: remove `console.log` and dev tools binary - console.log( + // TODO: remove `logger.info` and dev tools binary + logger.info( 'We removed support for Safari dev-tools. ' + 'If you still need this, please let us know.' ); } else if (req.url === '/launch-chrome-devtools') { // TODO: Remove this case in the future - console.log( + logger.info( 'The method /launch-chrome-devtools is deprecated. You are ' + ' probably using an application created with an older CLI with the ' + ' packager of a newer CLI. Please upgrade your application: ' + diff --git a/packages/cli/src/server/middleware/systraceProfileMiddleware.js b/packages/cli/src/server/middleware/systraceProfileMiddleware.js index 24c54024c..5ad2a1069 100644 --- a/packages/cli/src/server/middleware/systraceProfileMiddleware.js +++ b/packages/cli/src/server/middleware/systraceProfileMiddleware.js @@ -8,6 +8,7 @@ */ const fs = require('fs'); +const logger = require('../../util/logger'); module.exports = function systraceProfileMiddleware(req, res, next) { if (req.url !== '/systrace') { @@ -15,7 +16,7 @@ module.exports = function systraceProfileMiddleware(req, res, next) { return; } - console.log('Dumping profile information...'); + logger.info('Dumping profile information...'); const dumpName = `/tmp/dump_${Date.now()}.json`; fs.writeFileSync(dumpName, req.rawBody); const response = @@ -23,6 +24,6 @@ module.exports = function systraceProfileMiddleware(req, res, next) { `On Google Chrome navigate to chrome://tracing and then click on "load" ` + `to load and visualise your profile.\n\n` + `This message is also printed to your console by the packager so you can copy it :)`; - console.log(response); + logger.info(response); res.end(response); }; diff --git a/packages/cli/src/server/util/debugger-ui/debuggerWorker.js b/packages/cli/src/server/util/debugger-ui/debuggerWorker.js index 070d753b7..1a06c3fa3 100644 --- a/packages/cli/src/server/util/debugger-ui/debuggerWorker.js +++ b/packages/cli/src/server/util/debugger-ui/debuggerWorker.js @@ -18,11 +18,11 @@ onmessage = (function() { var hasWarned = false; return function() { // Wait until `YellowBox` gets initialized before displaying the warning. - if (hasWarned || console.warn.toString().includes('[native code]')) { + if (hasWarned || logger.warn.toString().includes('[native code]')) { return; } hasWarned = true; - console.warn( + logger.warn( 'Remote debugger is in a background tab which may cause apps to ' + 'perform slowly. Fix this by foregrounding the tab (or opening it in ' + 'a separate window).', diff --git a/packages/cli/src/server/util/jsPackagerClient.js b/packages/cli/src/server/util/jsPackagerClient.js index cf36357e4..101e98f66 100644 --- a/packages/cli/src/server/util/jsPackagerClient.js +++ b/packages/cli/src/server/util/jsPackagerClient.js @@ -8,7 +8,7 @@ */ const WebSocket = require('ws'); - +const logger = require('../../util/logger'); const { parseMessage } = require('./messageSocket'); const PROTOCOL_VERSION = 2; @@ -34,7 +34,7 @@ class JsPackagerClient { if (message === undefined || message.id === undefined) { // gracefully ignore wrong messages or broadcasts } else if (msgCallback === undefined) { - console.warn(`Response with non-existing message id: '${message.id}'`); + logger.warn(`Response with non-existing message id: '${message.id}'`); } else if (message.error === undefined) { msgCallback.resolve(message.result); } else { diff --git a/packages/cli/src/server/util/launchChrome.js b/packages/cli/src/server/util/launchChrome.js index 67c449d2a..56172d6bc 100644 --- a/packages/cli/src/server/util/launchChrome.js +++ b/packages/cli/src/server/util/launchChrome.js @@ -13,6 +13,7 @@ * run Flow. */ const opn = require('opn'); const { execSync } = require('child_process'); +const logger = require('../../util/logger'); function commandExistsUnixSync(commandName) { try { @@ -49,7 +50,7 @@ function getChromeAppName(): string { function launchChrome(url: string) { opn(url, { app: [getChromeAppName()] }, err => { if (err) { - console.error('Google Chrome exited with error:', err); + logger.error('Google Chrome exited with error:', err); } }); } diff --git a/packages/cli/src/server/util/messageSocket.js b/packages/cli/src/server/util/messageSocket.js index 30b02da90..95713e46a 100644 --- a/packages/cli/src/server/util/messageSocket.js +++ b/packages/cli/src/server/util/messageSocket.js @@ -10,10 +10,11 @@ const WebSocketServer = require('ws').Server; const PROTOCOL_VERSION = 2; const notifier = require('node-notifier'); +const logger = require('../../util/logger'); function parseMessage(data, binary) { if (binary) { - console.error('Expected text message, got binary!'); + logger.error('Expected text message, got binary!'); return undefined; } try { @@ -21,11 +22,11 @@ function parseMessage(data, binary) { if (message.version === PROTOCOL_VERSION) { return message; } - console.error( + logger.error( `Received message had wrong protocol version: ${message.version}` ); } catch (e) { - console.error(`Failed to parse the message as JSON:\n${data}`); + logger.error(`Failed to parse the message as JSON:\n${data}`); } return undefined; } @@ -91,7 +92,7 @@ function attachToServer(server, path) { try { otherWs.send(JSON.stringify(forwarded)); } catch (e) { - console.error( + logger.error( `Failed to send broadcast to client: '${otherId}' ` + `due to:\n ${e.toString()}` ); @@ -114,7 +115,7 @@ function attachToServer(server, path) { }; if (message.id === undefined) { - console.error( + logger.error( `Handling message from ${clientId} failed with:\n${error}\n` + `message:\n${JSON.stringify(errorMessage)}` ); @@ -128,7 +129,7 @@ function attachToServer(server, path) { }) ); } catch (e) { - console.error( + logger.error( `Failed to reply to ${clientId} with error:\n${error}` + `\nmessage:\n${JSON.stringify(errorMessage)}` + `\ndue to error: ${e.toString()}` @@ -200,7 +201,7 @@ function attachToServer(server, path) { clientWs.onmessage = event => { const message = parseMessage(event.data, event.binary); if (message === undefined) { - console.error('Received message not matching protocol'); + logger.error('Received message not matching protocol'); return; } diff --git a/packages/cli/src/server/util/webSocketProxy.js b/packages/cli/src/server/util/webSocketProxy.js index a7d0c8a9d..908f9faee 100644 --- a/packages/cli/src/server/util/webSocketProxy.js +++ b/packages/cli/src/server/util/webSocketProxy.js @@ -7,6 +7,8 @@ * @format */ +const logger = require('../../util/logger'); + function attachToServer(server, path) { const WebSocketServer = require('ws').Server; const wss = new WebSocketServer({ @@ -25,7 +27,7 @@ function attachToServer(server, path) { try { dest.send(message); } catch (e) { - console.warn(e); + logger.warn(e); // Sometimes this call throws 'not opened' } } diff --git a/packages/cli/src/upgrade/upgrade.js b/packages/cli/src/upgrade/upgrade.js index 3b4f6d0cf..6f3de7937 100644 --- a/packages/cli/src/upgrade/upgrade.js +++ b/packages/cli/src/upgrade/upgrade.js @@ -15,6 +15,7 @@ const fs = require('fs'); const path = require('path'); const semver = require('semver'); const copyProjectTemplateAndReplace = require('../generator/copyProjectTemplateAndReplace'); +const logger = require('../util/logger'); /** * Migrate application to a new version of React Native. @@ -90,7 +91,7 @@ function validateAndUpgrade(argv: *, ctx: ContextT) { return; } - console.log( + logger.info( `Upgrading project to react-native v${installed.version}\n` + `Check out the release notes and breaking changes: ` + `https://github.com/facebook/react-native/releases/tag/v${semver.major( @@ -122,7 +123,7 @@ function validateAndUpgrade(argv: *, ctx: ContextT) { upgradeProjectFiles(projectDir, projectName); - console.log( + logger.info( `Successfully upgraded this project to react-native v${installed.version}` ); } @@ -141,7 +142,7 @@ function upgradeProjectFiles(projectDir, projectName) { } function warn(message) { - console.warn(chalk.yellow(message)); + logger.warn(chalk.yellow(message)); } const upgradeCommand = { diff --git a/packages/cli/src/util/copyAndReplace.js b/packages/cli/src/util/copyAndReplace.js index 67ade61c8..9d9ec7c33 100644 --- a/packages/cli/src/util/copyAndReplace.js +++ b/packages/cli/src/util/copyAndReplace.js @@ -82,7 +82,7 @@ function copyAndReplace( try { const origContent = fs.readFileSync(destPath, 'utf8'); if (content !== origContent) { - // console.log('Content changed: ' + destPath); + // logger.info('Content changed: ' + destPath); contentChanged = 'changed'; } } catch (err) { diff --git a/packages/cli/src/util/yarn.js b/packages/cli/src/util/yarn.js index 37ce21bbe..ca12f1297 100644 --- a/packages/cli/src/util/yarn.js +++ b/packages/cli/src/util/yarn.js @@ -11,6 +11,7 @@ const { execSync } = require('child_process'); const fs = require('fs'); const path = require('path'); const semver = require('semver'); +const logger = require('./logger'); /** * Use Yarn if available, it's much faster than the npm client. @@ -35,7 +36,7 @@ function getYarnVersionIfAvailable() { } return null; } catch (error) { - console.error(`Cannot parse yarn version: ${yarnVersion}`); + logger.error(`Cannot parse yarn version: ${yarnVersion}`); return null; } } From 5a2160e070e26c63bc903a3ee7d46911294aa33b Mon Sep 17 00:00:00 2001 From: Sid Ferreira Date: Mon, 4 Feb 2019 10:14:49 -0200 Subject: [PATCH 2/7] refactor(logger): tweaks chalk usage --- .../cli/src/generator/printRunInstructions.js | 23 +++++----- packages/cli/src/logAndroid/logAndroid.js | 4 +- packages/cli/src/logIOS/logIOS.js | 2 +- packages/cli/src/runAndroid/runAndroid.js | 44 +++++++++---------- .../cli/src/runAndroid/runOnAllDevices.js | 28 +++++------- .../src/runAndroid/tryLaunchAppOnDevice.js | 8 +--- packages/global-cli/index.js | 4 +- 7 files changed, 45 insertions(+), 68 deletions(-) diff --git a/packages/cli/src/generator/printRunInstructions.js b/packages/cli/src/generator/printRunInstructions.js index 2fd09efa5..ea816a58b 100644 --- a/packages/cli/src/generator/printRunInstructions.js +++ b/packages/cli/src/generator/printRunInstructions.js @@ -7,7 +7,6 @@ * @format */ -const chalk = require('chalk'); const path = require('path'); const logger = require('../util/logger'); @@ -23,19 +22,17 @@ function printRunInstructions(projectDir, projectName) { process.cwd(), xcodeProjectPath ); - logger.info(chalk.white.bold('To run your app on iOS:')); - logger.info(` cd ${absoluteProjectDir}`); - logger.info(' react-native run-ios'); - logger.info(' - or -'); - logger.info(` Open ${relativeXcodeProjectPath} in Xcode`); - logger.info(' Hit the Run button'); + logger.info(`To run your app on iOS: + cd ${absoluteProjectDir} + react-native run-ios'); + - or - + Open ${relativeXcodeProjectPath} in Xcode + Hit the Run button // Android - logger.info(chalk.white.bold('To run your app on Android:')); - logger.info(` cd ${absoluteProjectDir}`); - logger.info( - ' Have an Android emulator running (quickest way to get started), or a device connected' - ); - logger.info(' react-native run-android'); + To run your app on Android: + cd ${absoluteProjectDir} + Have an Android emulator running (quickest way to get started), or a device connected + react-native run-android`); } module.exports = printRunInstructions; diff --git a/packages/cli/src/logAndroid/logAndroid.js b/packages/cli/src/logAndroid/logAndroid.js index 9525d3911..ff610e118 100644 --- a/packages/cli/src/logAndroid/logAndroid.js +++ b/packages/cli/src/logAndroid/logAndroid.js @@ -19,9 +19,7 @@ async function logAndroid() { const adbArgs = ['logcat', '*:S', 'ReactNative:V', 'ReactNativeJS:V']; - logger.info( - chalk.bold(`Starting the logger (${adbPath} ${adbArgs.join(' ')})...`) - ); + logger.info(`Starting the logger (${adbPath} ${adbArgs.join(' ')})...`); const log = spawnSync(adbPath, adbArgs, { stdio: 'inherit' }); diff --git a/packages/cli/src/logIOS/logIOS.js b/packages/cli/src/logIOS/logIOS.js index ac78b1cef..8879bc487 100644 --- a/packages/cli/src/logIOS/logIOS.js +++ b/packages/cli/src/logIOS/logIOS.js @@ -38,7 +38,7 @@ async function logIOS() { const device = findAvailableDevice(devices); if (device === undefined) { - logger.info(chalk.red('No active iOS device found')); + logger.error('No active iOS device found'); return; } diff --git a/packages/cli/src/runAndroid/runAndroid.js b/packages/cli/src/runAndroid/runAndroid.js index 91c829bdd..9b6838696 100644 --- a/packages/cli/src/runAndroid/runAndroid.js +++ b/packages/cli/src/runAndroid/runAndroid.js @@ -34,10 +34,8 @@ function checkAndroid(root) { */ function runAndroid(argv: Array, config: ContextT, args: Object) { if (!checkAndroid(args.root)) { - logger.info( - chalk.red( - 'Android project not found. Are you sure this is a React Native project?' - ) + logger.error( + 'Android project not found. Are you sure this is a React Native project?' ); return; } @@ -48,14 +46,14 @@ function runAndroid(argv: Array, config: ContextT, args: Object) { return isPackagerRunning(args.port).then(result => { if (result === 'running') { - logger.info(chalk.bold('JS server already running.')); + logger.info('JS server already running.'); } else if (result === 'unrecognized') { logger.warn( chalk.yellow('JS server not recognized, continuing with build...') ); } else { // result == 'not_running' - logger.info(chalk.bold('Starting JS server...')); + logger.info('Starting JS server...'); startServerInNewWindow(args.port, args.terminal); } return buildAndRun(args); @@ -102,7 +100,7 @@ function buildAndRun(args) { adbPath ); } - logger.info(chalk.red('Argument missing for parameter --deviceId')); + logger.error('Argument missing for parameter --deviceId'); } else { return runOnAllDevices( args, @@ -133,9 +131,12 @@ function runOnSpecificDevice( adbPath ); } else { - logger.info(`Could not find device with the id: "${args.deviceId}".`); - logger.info('Choose one of the following:'); - logger.info(devices); + logger.info( + `Could not find device with the id: "${ + args.deviceId + }". Choose one of the following:`, + ...devices + ); } } else { logger.info('No Android devices connected.'); @@ -144,16 +145,14 @@ function runOnSpecificDevice( function buildApk(gradlew) { try { - logger.info(chalk.bold('Building the app...')); + logger.info('Building the app...'); // using '-x lint' in order to ignore linting errors while building the apk execFileSync(gradlew, ['build', '-x', 'lint'], { stdio: [process.stdin, process.stdout, process.stderr], }); } catch (e) { - logger.info( - chalk.red('Could not build the app, read the error above for details.\n') - ); + logger.error('Could not build the app, read the error above for details.'); } } @@ -165,19 +164,16 @@ function tryInstallAppOnDevice(args, device) { const adbPath = getAdbPath(); const adbArgs = ['-s', device, 'install', pathToApk]; logger.info( - chalk.bold( - `Installing the app on the device (cd android && adb -s ${device} install ${pathToApk}` - ) + `Installing the app on the device (cd android && adb -s ${device} install ${pathToApk}` ); execFileSync(adbPath, adbArgs, { stdio: [process.stdin, process.stdout, process.stderr], }); } catch (e) { - logger.info(e.message); - logger.info( - chalk.red( - 'Could not install the app on the device, read the error above for details.\n' - ) + logger.error( + `${ + e.message + }\nCould not install the app on the device, read the error above for details.` ); } } @@ -260,8 +256,8 @@ function startServerInNewWindow(port, terminal = process.env.REACT_TERMINAL) { procConfig.stdio = 'ignore'; return spawn('cmd.exe', ['/C', launchPackagerScript], procConfig); } - logger.info( - chalk.red(`Cannot start the packager. Unknown platform ${process.platform}`) + logger.error( + `Cannot start the packager. Unknown platform ${process.platform}` ); } diff --git a/packages/cli/src/runAndroid/runOnAllDevices.js b/packages/cli/src/runAndroid/runOnAllDevices.js index a4cde69d1..a15a6f57d 100644 --- a/packages/cli/src/runAndroid/runOnAllDevices.js +++ b/packages/cli/src/runAndroid/runOnAllDevices.js @@ -54,24 +54,20 @@ function runOnAllDevices( } logger.info( - chalk.bold( - `Building and installing the app on the device (cd android && ${cmd} ${gradleArgs.join( - ' ' - )})...` - ) + `Building and installing the app on the device (cd android && ${cmd} ${gradleArgs.join( + ' ' + )})...` ); execFileSync(cmd, gradleArgs, { stdio: [process.stdin, process.stdout, process.stderr], }); } catch (e) { - logger.info( - chalk.red( - 'Could not install the app on the device, read the error above for details.\n' + - 'Make sure you have an Android emulator running or a device connected and have\n' + - 'set up your Android development environment:\n' + - 'https://facebook.github.io/react-native/docs/getting-started.html' - ) + logger.error( + 'Could not install the app on the device, read the error above for details.\n' + + 'Make sure you have an Android emulator running or a device connected and have\n' + + 'set up your Android development environment:\n' + + 'https://facebook.github.io/react-native/docs/getting-started.html' ); // stderr is automatically piped from the gradle process, so the user // should see the error already, there is no need to do @@ -102,15 +98,11 @@ function runOnAllDevices( `${packageNameWithSuffix}/${packageName}.MainActivity`, ]; logger.info( - chalk.bold( - `Starting the app (${adbPath} ${fallbackAdbArgs.join(' ')}...` - ) + `Starting the app (${adbPath} ${fallbackAdbArgs.join(' ')}...` ); spawnSync(adbPath, fallbackAdbArgs, { stdio: 'inherit' }); } catch (e) { - logger.info( - chalk.red('adb invocation failed. Do you have adb in your PATH?') - ); + logger.error('adb invocation failed. Do you have adb in your PATH?'); // stderr is automatically piped from the gradle process, so the user // should see the error already, there is no need to do // `logger.info(e.stderr)` diff --git a/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js b/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js index ae29dc87c..ec1643e64 100644 --- a/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js +++ b/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js @@ -29,15 +29,11 @@ function tryLaunchAppOnDevice( `${packageNameWithSuffix}/${packageName}.${mainActivity}`, ]; logger.info( - chalk.bold( - `Starting the app on ${device} (${adbPath} ${adbArgs.join(' ')})...` - ) + `Starting the app on ${device} (${adbPath} ${adbArgs.join(' ')})...` ); spawnSync(adbPath, adbArgs, { stdio: 'inherit' }); } catch (e) { - logger.info( - chalk.red('adb invocation failed. Do you have adb in your PATH?') - ); + logger.error('adb invocation failed. Do you have adb in your PATH?'); } } diff --git a/packages/global-cli/index.js b/packages/global-cli/index.js index 837845746..7b12e0e7d 100755 --- a/packages/global-cli/index.js +++ b/packages/global-cli/index.js @@ -314,11 +314,9 @@ function checkNodeVersion() { } if (!semver.satisfies(process.version, packageJson.engines.node)) { console.error( - chalk.red( 'You are currently running Node %s but React Native requires %s. ' + 'Please use a supported version of Node.\n' + - 'See https://facebook.github.io/react-native/docs/getting-started.html' - ), + 'See https://facebook.github.io/react-native/docs/getting-started.html', process.version, packageJson.engines.node ); From c7df37f22dd86e869284349f103da500af253410 Mon Sep 17 00:00:00 2001 From: Sid Ferreira Date: Mon, 4 Feb 2019 10:33:38 -0200 Subject: [PATCH 3/7] fix: remove unused chalk --- packages/cli/src/logAndroid/logAndroid.js | 1 - packages/cli/src/logIOS/logIOS.js | 1 - packages/cli/src/runAndroid/tryLaunchAppOnDevice.js | 1 - 3 files changed, 3 deletions(-) diff --git a/packages/cli/src/logAndroid/logAndroid.js b/packages/cli/src/logAndroid/logAndroid.js index ff610e118..41a0f6e60 100644 --- a/packages/cli/src/logAndroid/logAndroid.js +++ b/packages/cli/src/logAndroid/logAndroid.js @@ -5,7 +5,6 @@ * LICENSE file in the root directory of this source tree. */ -const chalk = require('chalk'); const { spawnSync } = require('child_process'); const logger = require('../util/logger'); diff --git a/packages/cli/src/logIOS/logIOS.js b/packages/cli/src/logIOS/logIOS.js index 8879bc487..098815215 100644 --- a/packages/cli/src/logIOS/logIOS.js +++ b/packages/cli/src/logIOS/logIOS.js @@ -7,7 +7,6 @@ * @format */ -const chalk = require('chalk'); const { execFileSync, spawnSync } = require('child_process'); const os = require('os'); const path = require('path'); diff --git a/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js b/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js index ec1643e64..fac8f3465 100644 --- a/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js +++ b/packages/cli/src/runAndroid/tryLaunchAppOnDevice.js @@ -7,7 +7,6 @@ * @flow */ -const chalk = require('chalk'); const { spawnSync } = require('child_process'); const logger = require('../util/logger'); From 9fc3e06b98e4f14ab358b9f21aca7d23089a3a79 Mon Sep 17 00:00:00 2001 From: Sid Ferreira Date: Mon, 4 Feb 2019 10:38:45 -0200 Subject: [PATCH 4/7] fix: remove `chalk.yellow` and unused chalk --- packages/cli/src/runAndroid/runAndroid.js | 5 +---- packages/cli/src/runAndroid/runOnAllDevices.js | 5 +---- packages/cli/src/runAndroid/tryRunAdbReverse.js | 2 +- .../cli/src/server/middleware/copyToClipBoardMiddleware.js | 3 +-- packages/cli/src/upgrade/upgrade.js | 3 +-- 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/packages/cli/src/runAndroid/runAndroid.js b/packages/cli/src/runAndroid/runAndroid.js index 9b6838696..27bb7f863 100644 --- a/packages/cli/src/runAndroid/runAndroid.js +++ b/packages/cli/src/runAndroid/runAndroid.js @@ -11,7 +11,6 @@ import type { ContextT } from '../core/types.flow'; -const chalk = require('chalk'); const { spawnSync, spawn, execFileSync } = require('child_process'); const fs = require('fs'); const isString = require('lodash/isString'); @@ -48,9 +47,7 @@ function runAndroid(argv: Array, config: ContextT, args: Object) { if (result === 'running') { logger.info('JS server already running.'); } else if (result === 'unrecognized') { - logger.warn( - chalk.yellow('JS server not recognized, continuing with build...') - ); + logger.warn('JS server not recognized, continuing with build...'); } else { // result == 'not_running' logger.info('Starting JS server...'); diff --git a/packages/cli/src/runAndroid/runOnAllDevices.js b/packages/cli/src/runAndroid/runOnAllDevices.js index a15a6f57d..ecd3e2d9b 100644 --- a/packages/cli/src/runAndroid/runOnAllDevices.js +++ b/packages/cli/src/runAndroid/runOnAllDevices.js @@ -9,7 +9,6 @@ /* eslint-disable consistent-return */ -const chalk = require('chalk'); const { spawnSync, execFileSync } = require('child_process'); const logger = require('../util/logger'); const adb = require('./adb'); @@ -40,9 +39,7 @@ function runOnAllDevices( )}${args.variant[0].toUpperCase()}${args.variant.slice(1)}` ); } else if (args.flavor) { - logger.warn( - chalk.yellow('--flavor has been deprecated. Use --variant instead') - ); + logger.warn('--flavor has been deprecated. Use --variant instead'); gradleArgs.push( `${getCommand( args.appFolder, diff --git a/packages/cli/src/runAndroid/tryRunAdbReverse.js b/packages/cli/src/runAndroid/tryRunAdbReverse.js index 8b9d9cdc3..e7fd02d6f 100644 --- a/packages/cli/src/runAndroid/tryRunAdbReverse.js +++ b/packages/cli/src/runAndroid/tryRunAdbReverse.js @@ -29,7 +29,7 @@ function tryRunAdbReverse(packagerPort: number | string, device: string) { stdio: [process.stdin, process.stdout, process.stderr], }); } catch (e) { - logger.info(chalk.yellow(`Could not run adb reverse: ${e.message}`)); + logger.info(`Could not run adb reverse: ${e.message}`); } } diff --git a/packages/cli/src/server/middleware/copyToClipBoardMiddleware.js b/packages/cli/src/server/middleware/copyToClipBoardMiddleware.js index 48083100a..9346ea693 100644 --- a/packages/cli/src/server/middleware/copyToClipBoardMiddleware.js +++ b/packages/cli/src/server/middleware/copyToClipBoardMiddleware.js @@ -7,7 +7,6 @@ * @format */ -const chalk = require('chalk'); const copyToClipBoard = require('../util/copyToClipBoard'); const logger = require('../../util/logger'); @@ -19,7 +18,7 @@ module.exports = function copyMiddleware(req, res, next) { if (req.url === '/copy-to-clipboard') { const ret = copyToClipBoard(req.rawBody); if (!ret) { - logger.warn(chalk.red('Copy button is not supported on this platform!')); + logger.warn('Copy button is not supported on this platform!'); } res.end('OK'); } else { diff --git a/packages/cli/src/upgrade/upgrade.js b/packages/cli/src/upgrade/upgrade.js index 6f3de7937..ce0d15a77 100644 --- a/packages/cli/src/upgrade/upgrade.js +++ b/packages/cli/src/upgrade/upgrade.js @@ -10,7 +10,6 @@ import type { ContextT } from '../core/types.flow'; -const chalk = require('chalk'); const fs = require('fs'); const path = require('path'); const semver = require('semver'); @@ -142,7 +141,7 @@ function upgradeProjectFiles(projectDir, projectName) { } function warn(message) { - logger.warn(chalk.yellow(message)); + logger.warn(message); } const upgradeCommand = { From 01f2a2fd95a06dd2a8a07654b43860297b7fd355 Mon Sep 17 00:00:00 2001 From: Sid Ferreira Date: Mon, 4 Feb 2019 10:40:56 -0200 Subject: [PATCH 5/7] fix: changes some info to error --- packages/cli/src/runAndroid/runAndroid.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/runAndroid/runAndroid.js b/packages/cli/src/runAndroid/runAndroid.js index 27bb7f863..3ade4c247 100644 --- a/packages/cli/src/runAndroid/runAndroid.js +++ b/packages/cli/src/runAndroid/runAndroid.js @@ -128,7 +128,7 @@ function runOnSpecificDevice( adbPath ); } else { - logger.info( + logger.error( `Could not find device with the id: "${ args.deviceId }". Choose one of the following:`, @@ -136,7 +136,7 @@ function runOnSpecificDevice( ); } } else { - logger.info('No Android devices connected.'); + logger.error('No Android devices connected.'); } } From 5a2dfd0fab12c2e009b407b57c500c76f5b71987 Mon Sep 17 00:00:00 2001 From: Sid Ferreira Date: Mon, 4 Feb 2019 10:55:40 -0200 Subject: [PATCH 6/7] fix: revert Debugger changes --- packages/cli/src/server/util/debugger-ui/debuggerWorker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/server/util/debugger-ui/debuggerWorker.js b/packages/cli/src/server/util/debugger-ui/debuggerWorker.js index 1a06c3fa3..070d753b7 100644 --- a/packages/cli/src/server/util/debugger-ui/debuggerWorker.js +++ b/packages/cli/src/server/util/debugger-ui/debuggerWorker.js @@ -18,11 +18,11 @@ onmessage = (function() { var hasWarned = false; return function() { // Wait until `YellowBox` gets initialized before displaying the warning. - if (hasWarned || logger.warn.toString().includes('[native code]')) { + if (hasWarned || console.warn.toString().includes('[native code]')) { return; } hasWarned = true; - logger.warn( + console.warn( 'Remote debugger is in a background tab which may cause apps to ' + 'perform slowly. Fix this by foregrounding the tab (or opening it in ' + 'a separate window).', From 7721ffd24067dc6df7810b58f4ddaec744979e7c Mon Sep 17 00:00:00 2001 From: Sid Ferreira Date: Mon, 4 Feb 2019 11:17:31 -0200 Subject: [PATCH 7/7] fix: remove pending bold, join outputs --- .../cli/src/runAndroid/tryRunAdbReverse.js | 3 +-- packages/cli/src/runIOS/runIOS.js | 25 +++++++++---------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/cli/src/runAndroid/tryRunAdbReverse.js b/packages/cli/src/runAndroid/tryRunAdbReverse.js index e7fd02d6f..f45fb23e8 100644 --- a/packages/cli/src/runAndroid/tryRunAdbReverse.js +++ b/packages/cli/src/runAndroid/tryRunAdbReverse.js @@ -7,7 +7,6 @@ * @flow */ -const chalk = require('chalk'); const { execFileSync } = require('child_process'); const logger = require('../util/logger'); const getAdbPath = require('./getAdbPath'); @@ -23,7 +22,7 @@ function tryRunAdbReverse(packagerPort: number | string, device: string) { adbArgs.unshift('-s', device); } - logger.info(chalk.bold(`Running ${adbPath} ${adbArgs.join(' ')}`)); + logger.info(`Running ${adbPath} ${adbArgs.join(' ')}`); execFileSync(adbPath, adbArgs, { stdio: [process.stdin, process.stdout, process.stderr], diff --git a/packages/cli/src/runIOS/runIOS.js b/packages/cli/src/runIOS/runIOS.js index f386c7382..e137c97b9 100644 --- a/packages/cli/src/runIOS/runIOS.js +++ b/packages/cli/src/runIOS/runIOS.js @@ -82,11 +82,10 @@ function runIOS(_: Array, ctx: ContextT, args: FlagsT) { } if (devices && devices.length > 0) { // $FlowIssue: args.device is defined in this context - logger.info(`Could not find device with the name: "${args.device}".`); - logger.info('Choose one of the following:'); - printFoundDevices(devices); + logger.error(`Could not find device with the name: "${args.device}". +Choose one of the following:${printFoundDevices(devices)}`); } else { - logger.info('No iOS devices connected.'); + logger.error('No iOS devices connected.'); } } else if (args.udid) { // $FlowIssue: args.udid is defined in this context @@ -119,11 +118,10 @@ function runOnDeviceByUdid( if (devices && devices.length > 0) { // $FlowIssue: args.udid is defined in this context - logger.info(`Could not find device with the udid: "${args.udid}".`); - logger.info('Choose one of the following:'); - printFoundDevices(devices); + logger.error(`Could not find device with the udid: "${args.udid}". +Choose one of the following:\n${printFoundDevices(devices)}`); } else { - logger.info('No iOS devices connected.'); + logger.error('No iOS devices connected.'); } } @@ -252,10 +250,9 @@ async function runOnDevice( ); if (iosDeployOutput.error) { - logger.info(''); - logger.info('** INSTALLATION FAILED **'); - logger.info('Make sure you have ios-deploy installed globally.'); - logger.info('(e.g "npm install -g ios-deploy")'); + logger.error( + `** INSTALLATION FAILED **\nMake sure you have ios-deploy installed globally.\n(e.g "npm install -g ios-deploy")` + ); } else { logger.info('** INSTALLATION SUCCEEDED **'); } @@ -415,9 +412,11 @@ function formattedDeviceName(simulator) { } function printFoundDevices(devices) { + let output = ''; for (let i = devices.length - 1; i >= 0; i--) { - logger.info(`${devices[i].name} Udid: ${devices[i].udid}`); + output += `${devices[i].name} Udid: ${devices[i].udid}\n`; } + return output; } function getProcessOptions(launchPackager, port) {