From 4e0fcea20439740f92caf9d8482b106a6f583ba1 Mon Sep 17 00:00:00 2001 From: Harshit Agrawal Date: Fri, 28 Oct 2022 16:15:17 +0530 Subject: [PATCH 1/2] logger fixes --- package-lock.json | 122 ++++++++++++++++++++++++++++++++++++++ package.json | 1 + src/commands/ios/index.ts | 92 ++++++++++++++-------------- 3 files changed, 170 insertions(+), 45 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2d8b9ce..9241d8e 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", @@ -1666,6 +1667,14 @@ "url": "https://github.com/sponsors/epoberezkin" } }, + "node_modules/ansi-align": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz", + "integrity": "sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==", + "dependencies": { + "string-width": "^4.1.0" + } + }, "node_modules/ansi-colors": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", @@ -1974,6 +1983,38 @@ "resolved": "https://registry.npmjs.org/bmp-js/-/bmp-js-0.1.0.tgz", "integrity": "sha512-vHdS19CnY3hwiNdkaqk93DvjVLfbEcI8mys4UjuWrlX1haDmroo8o4xCzh4wD6DGV6HxRCyauwhHRqMTfERtjw==" }, + "node_modules/boxen": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/boxen/-/boxen-5.1.2.tgz", + "integrity": "sha512-9gYgQKXx+1nP8mP7CzFyaUARhg7D3n1dF/FnErWmu9l6JvGpNUN278h0aSb+QjoiKSWG+iZ3uHrcqk0qrY9RQQ==", + "dependencies": { + "ansi-align": "^3.0.0", + "camelcase": "^6.2.0", + "chalk": "^4.1.0", + "cli-boxes": "^2.2.1", + "string-width": "^4.2.2", + "type-fest": "^0.20.2", + "widest-line": "^3.1.0", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/boxen/node_modules/type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/bplist-creator": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/bplist-creator/-/bplist-creator-0.1.1.tgz", @@ -2124,6 +2165,17 @@ "node": ">=6" } }, + "node_modules/camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -2144,6 +2196,17 @@ "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==" }, + "node_modules/cli-boxes": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-2.2.1.tgz", + "integrity": "sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw==", + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/cli-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", @@ -5502,6 +5565,17 @@ "string-width": "^1.0.2 || 2 || 3 || 4" } }, + "node_modules/widest-line": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/widest-line/-/widest-line-3.1.0.tgz", + "integrity": "sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg==", + "dependencies": { + "string-width": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", @@ -6877,6 +6951,14 @@ "uri-js": "^4.2.2" } }, + "ansi-align": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.1.tgz", + "integrity": "sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==", + "requires": { + "string-width": "^4.1.0" + } + }, "ansi-colors": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", @@ -7127,6 +7209,28 @@ "resolved": "https://registry.npmjs.org/bmp-js/-/bmp-js-0.1.0.tgz", "integrity": "sha512-vHdS19CnY3hwiNdkaqk93DvjVLfbEcI8mys4UjuWrlX1haDmroo8o4xCzh4wD6DGV6HxRCyauwhHRqMTfERtjw==" }, + "boxen": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/boxen/-/boxen-5.1.2.tgz", + "integrity": "sha512-9gYgQKXx+1nP8mP7CzFyaUARhg7D3n1dF/FnErWmu9l6JvGpNUN278h0aSb+QjoiKSWG+iZ3uHrcqk0qrY9RQQ==", + "requires": { + "ansi-align": "^3.0.0", + "camelcase": "^6.2.0", + "chalk": "^4.1.0", + "cli-boxes": "^2.2.1", + "string-width": "^4.2.2", + "type-fest": "^0.20.2", + "widest-line": "^3.1.0", + "wrap-ansi": "^7.0.0" + }, + "dependencies": { + "type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==" + } + } + }, "bplist-creator": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/bplist-creator/-/bplist-creator-0.1.1.tgz", @@ -7241,6 +7345,11 @@ "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", "dev": true }, + "camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==" + }, "chalk": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", @@ -7255,6 +7364,11 @@ "resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz", "integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==" }, + "cli-boxes": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-2.2.1.tgz", + "integrity": "sha512-y4coMcylgSCdVinjiDBuR8PCC2bLjyGTwEmPb9NHR/QaNU6EUOXcTY/s6VjGMD6ENSEaeQYHCY0GNGS5jfMwPw==" + }, "cli-cursor": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", @@ -9853,6 +9967,14 @@ "string-width": "^1.0.2 || 2 || 3 || 4" } }, + "widest-line": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/widest-line/-/widest-line-3.1.0.tgz", + "integrity": "sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg==", + "requires": { + "string-width": "^4.0.0" + } + }, "word-wrap": { "version": "1.2.3", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", diff --git a/package.json b/package.json index bac7c92..563a4b2 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,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..4cf57c7 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 siulators\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)); }); } From 4eb3228fd6907d17ad81f2c675a2b8c583cec992 Mon Sep 17 00:00:00 2001 From: Harshit Agrawal Date: Fri, 28 Oct 2022 16:35:28 +0530 Subject: [PATCH 2/2] spelling fix --- src/commands/ios/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/ios/index.ts b/src/commands/ios/index.ts index 4cf57c7..bf31582 100644 --- a/src/commands/ios/index.ts +++ b/src/commands/ios/index.ts @@ -85,7 +85,7 @@ export class IosSetup { }); Logger.log(` ${colors.red(symbols().ok)} Xcode is installed in your machine\n`); - Logger.log(boxen(`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}));