diff --git a/package-lock.json b/package-lock.json index be1ebeb..ebaf486 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "ansi-colors": "^4.1.3", "appium-adb": "^9.10.11", "axios": "^1.1.2", + "boxen": "5.1.2", "cli-progress": "^3.11.2", "dotenv": "^16.0.3", "download": "^8.0.0", diff --git a/package.json b/package.json index cbbce76..0faa37a 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "ansi-colors": "^4.1.3", "appium-adb": "^9.10.11", "axios": "^1.1.2", + "boxen": "5.1.2", "cli-progress": "^3.11.2", "dotenv": "^16.0.3", "download": "^8.0.0", diff --git a/src/commands/ios/index.ts b/src/commands/ios/index.ts index 8903a23..bf31582 100644 --- a/src/commands/ios/index.ts +++ b/src/commands/ios/index.ts @@ -4,6 +4,8 @@ import { getPlatformName, iosRealDeviceUUID, symbols } from '../../utils'; import { AVAILABLE_OPTIONS, SETUP_CONFIG_QUES } from './constants'; import colors from 'ansi-colors'; import { execSync } from 'child_process'; +import boxen from 'boxen'; +import Logger from '../../logger'; export class IosSetup { options: Options; @@ -29,7 +31,7 @@ export class IosSetup { } if (this.platform !== 'mac') { - console.log('Only macOS is supported'); + Logger.log('Only macOS is supported'); return false; } @@ -75,26 +77,26 @@ export class IosSetup { const missingRequirements: string[] = []; if (setupConfigs.mode === 'simulator' || setupConfigs.mode === 'both') { - console.log('\nVerifying the setup requirements for simulators ...'); + Logger.log('\nVerifying the setup requirements for simulators ...'); try { execSync("/usr/bin/xcodebuild -version", { stdio: 'pipe' }); - console.log(` ${colors.red(symbols().ok)} Xcode is installed in your machine\n`); + Logger.log(` ${colors.red(symbols().ok)} Xcode is installed in your machine\n`); - console.log(`Run the following command to get the list of siulators\n` + + Logger.log(boxen(`Run the following command to get the list of simulators\n` + colors.cyan.italic('xcrun simctl list devices') + '\n' + `\nAnd then update ${colors.cyan('safari:deviceName')} (eg: 'iphone 13') and ${colors.cyan('safari:platformVersion')} (eg: '15.0') in nightwatch configuration for ${colors.gray.italic('ios.simulator.safari')} environment accordingly.` - ); + , {padding: 1})); } catch (error) { - console.log(` ${colors.red(symbols().fail)} Xcode is not installed.`); + Logger.log(` ${colors.red(symbols().fail)} Xcode is not installed.`); missingRequirements.push('Xcode is not installed') } } if (setupConfigs.mode === 'real' || setupConfigs.mode === 'both') { - console.log('\nVerifying the setup requirements for real devices...'); + Logger.log('\nVerifying the setup requirements for real devices...'); try { const stdout = execSync("system_profiler SPUSBDataType | sed -n '/iPhone/,/Serial/p' | grep 'Serial Number:' | awk -F ': ' '{print $2}'", { @@ -102,32 +104,32 @@ export class IosSetup { }); if (stdout.toString() !== '') { - console.log( + Logger.log(boxen( colors.white(`Update ${colors.cyan('UUID')} in nightwatch configuration for ${colors.gray.italic('ios.real.safari')} environment.`) + - colors.cyan("\nUUID: " + iosRealDeviceUUID(stdout.toString()) + "\n")); + colors.cyan("\nUUID: " + iosRealDeviceUUID(stdout.toString())), {padding: 1})); } else { throw "Device is not connected"; } } catch (error) { - console.log(` ${colors.red(symbols().fail)} Device is either not connected or turned off.`); + Logger.log(` ${colors.red(symbols().fail)} Device is either not connected or turned off.`); missingRequirements.push('Device is not connected') } } if (missingRequirements.length === 0) { - console.log('\nGreat! All the requirements are being met.'); + Logger.log('\nGreat! All the requirements are being met.'); if (setupConfigs.mode === 'real') { - console.log('You can go ahead and run your tests now on your iOS device.'); + Logger.log('You can go ahead and run your tests now on your iOS device.'); } else if (setupConfigs.mode === 'simulator') { - console.log('You can go ahead and run your tests now on an iOS simulator.'); + Logger.log('You can go ahead and run your tests now on an iOS simulator.'); } else { - console.log('You can go ahead and run your tests now on an iOS device/simulator.'); + Logger.log('You can go ahead and run your tests now on an iOS device/simulator.'); } } else if (!this.options.setup) { - console.log(`\nSome requirements are missing: ${missingRequirements.join(', ')}`); - console.log(`Please use ${colors.magenta('--setup')} flag with the command to install all the missing requirements.`); + Logger.log(`\nSome requirements are missing: ${missingRequirements.join(', ')}`); + Logger.log(`Please use ${colors.magenta('--setup')} flag with the command to install all the missing requirements.`); } return missingRequirements; @@ -142,41 +144,41 @@ export class IosSetup { if (setupConfigs.mode === 'simulator' || setupConfigs.mode === 'both') { if (missingRequirements.includes('Xcode is not installed')) { - console.log('\nSetting up missing requirements for iOS simulator...\n'); - - console.log(`${colors.cyan(" If Xcode is already installed : ")}` + - `${colors.white("\n 1. Run the following after changing the Xcode app name in the command ")}` + - `\n ${colors.grey.italic("sudo xcode-select -switch /Applications/Xcode_x_x.app")}\n` + - - `${colors.cyan("\n If Xcode is not installed : ")}` + - `${colors.green("\n [Easiest Option] : Download via the App Store for the latest version")}` + - `${colors.white("\n 1. Open the App Store on your mac and Sign in with your Apple credentials")}` + - `${colors.white("\n 2. Search for Xcode & click install or update. That's it!!")}\n` + - `${colors.green("\n [Preferred Option] : Download via the Developer site for a specific version")}` + - `${colors.white(`\n 1. Navigate to this URL ${colors.grey.italic("https://developer.apple.com/download/more/")}`)}` + - `${colors.white("\n 2. Sign in with your Apple credentials")}` + - `${colors.white("\n 3. Type in the version that you like, and download the Xcode_x_x.xip file")}` + - `${colors.white("\n 4. Once the file is downloaded, click on .xip to extract it.")}` + - `${colors.white("\n 5. Now click on that Xcode file complete all the installation process")}` + - `${colors.white("\n 6. After completion drag the Xcode to Applications folder")}`); - - console.log(`${colors.magenta("\n Follow the guide for more detailed info https://www.freecodecamp.org/news/how-to-download-and-install-xcode/")}\n`); + Logger.log('\nSetting up missing requirements for iOS simulator...'); + + Logger.log(boxen(`${colors.cyan("If Xcode is already installed : ")}` + + `${colors.white("\n 1. Run the following after changing the Xcode app name in the command ")}` + + `\n ${colors.grey.italic("sudo xcode-select -switch /Applications/Xcode_x_x.app")}\n` + + + `${colors.cyan("\nIf Xcode is not installed : ")}` + + `${colors.green("\n [Easiest Option] : Download via the App Store for the latest version")}` + + `${colors.white("\n 1. Open the App Store on your mac and Sign in with your Apple credentials")}` + + `${colors.white("\n 2. Search for Xcode & click install or update. That's it!!")}\n` + + `${colors.green("\n [Preferred Option] : Download via the Developer site for a specific version")}` + + `${colors.white(`\n 1. Navigate to this URL ${colors.grey.italic("https://developer.apple.com/download/more/")}`)}` + + `${colors.white("\n 2. Sign in with your Apple credentials")}` + + `${colors.white("\n 3. Type in the version that you like, and download the Xcode_x_x.xip file")}` + + `${colors.white("\n 4. Once the file is downloaded, click on .xip to extract it.")}` + + `${colors.white("\n 5. Now click on that Xcode file complete all the installation process")}` + + `${colors.white("\n 6. After completion drag the Xcode to Applications folder")}`, {padding: 1})); + + Logger.log(`\nFollow the guide for more detailed info ${colors.magenta("https://www.freecodecamp.org/news/how-to-download-and-install-xcode/")}\n`); result = false; } } if (setupConfigs.mode === 'real' || setupConfigs.mode === 'both') { - console.log('\nSetting up missing requirements for real devices...'); + Logger.log("\nSetting up missing requirements for real devices...") - console.log(colors.cyan("\n Remote Automation should be turned on (necessary) ") + - colors.grey.italic("\n (turn it on via Settings → Safari → Advanced → Remote Automation.)")); + let msg = colors.cyan("Remote Automation should be turned on (necessary) ") + + colors.grey.italic("\n(turn it on via Settings → Safari → Advanced → Remote Automation.)"); if (missingRequirements.includes('Device is not connected')) { - console.log(colors.cyan(`\n Make sure your device is connected and turned on properly`)); - + msg += colors.cyan(`\n\nAlso make sure your device is connected and turned on properly`); result = false; } + Logger.log(boxen(msg, {padding: 1})); } return result; @@ -184,13 +186,13 @@ export class IosSetup { showHelp(unknownOptions: string[]) { if (unknownOptions.length) { - console.log(colors.red(`unknown option(s) passed: ${unknownOptions.join(', ')}\n`)); + Logger.log(colors.red(`unknown option(s) passed: ${unknownOptions.join(', ')}\n`)); } - console.log(`Usage: ${colors.cyan('npx @nightwatch/mobile-helper ios [options]')}`); - console.log(' Verify if all the requirements are met to run tests on an iOS device/simulator.\n'); + Logger.log(`Usage: ${colors.cyan('npx @nightwatch/mobile-helper ios [options]')}`); + Logger.log(' Verify if all the requirements are met to run tests on an iOS device/simulator.\n'); - console.log(`${colors.yellow('Options:')}`); + Logger.log(`${colors.yellow('Options:')}`); const switches = Object.keys(AVAILABLE_OPTIONS).reduce((acc: {[T: string]: string}, key) => { acc[key] = [key].concat(AVAILABLE_OPTIONS[key].alias || []) @@ -224,7 +226,7 @@ export class IosSetup { const prelude = ' ' + (kswitch) + ' ' + colors.grey(spadding); - console.log(prelude + ' ' + colors.grey(desc)); + Logger.log(prelude + ' ' + colors.grey(desc)); }); }