From 52a7a1ba30af43a251b5eb575515beabe012ceef Mon Sep 17 00:00:00 2001 From: 9cb14c1ec0 <9cb14c1ec0@sendmeemail.xyz> Date: Sat, 9 Nov 2024 21:50:47 -0500 Subject: [PATCH] Remove spinnies for more sane logs --- package-lock.json | 117 --------------------- package.json | 1 - src/api/helpers/delete-file.ts | 19 +--- src/api/layers/host.layer.ts | 79 +++------------ src/api/layers/listener.layer.ts | 6 +- src/controllers/browser.ts | 132 +++++------------------- src/controllers/initializer.ts | 168 +++++++------------------------ src/types/spinnies.d.ts | 148 --------------------------- src/utils/spinnies.ts | 10 -- test/index.js | 1 - 10 files changed, 84 insertions(+), 597 deletions(-) delete mode 100644 src/types/spinnies.d.ts delete mode 100644 src/utils/spinnies.ts diff --git a/package-lock.json b/package-lock.json index c1ad8f187..87834a00c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,6 @@ "qrcode-terminal": "^0.12.0", "sanitize-filename": "^1.6.3", "sharp": "^0.33.1", - "spinnies": "^0.5.1", "unzipper": "^0.11.4", "ws": "^8.8.0", "yoo-hoo": "^1.2.0" @@ -17118,122 +17117,6 @@ "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.13.tgz", "integrity": "sha512-XkD+zwiqXHikFZm4AX/7JSCXA98U5Db4AFd5XUg/+9UNtnH75+Z9KxtpYiJZx36mUDVOwH83pl7yvCer6ewM3w==" }, - "node_modules/spinnies": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/spinnies/-/spinnies-0.5.1.tgz", - "integrity": "sha512-WpjSXv9NQz0nU3yCT9TFEOfpFrXADY9C5fG6eAJqixLhvTX1jP3w92Y8IE5oafIe42nlF9otjhllnXN/QCaB3A==", - "dependencies": { - "chalk": "^2.4.2", - "cli-cursor": "^3.0.0", - "strip-ansi": "^5.2.0" - } - }, - "node_modules/spinnies/node_modules/ansi-regex": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", - "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", - "engines": { - "node": ">=6" - } - }, - "node_modules/spinnies/node_modules/ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dependencies": { - "color-convert": "^1.9.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/spinnies/node_modules/chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/spinnies/node_modules/cli-cursor": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", - "integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==", - "dependencies": { - "restore-cursor": "^3.1.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/spinnies/node_modules/color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", - "dependencies": { - "color-name": "1.1.3" - } - }, - "node_modules/spinnies/node_modules/color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==" - }, - "node_modules/spinnies/node_modules/escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", - "engines": { - "node": ">=0.8.0" - } - }, - "node_modules/spinnies/node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "engines": { - "node": ">=4" - } - }, - "node_modules/spinnies/node_modules/restore-cursor": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", - "integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==", - "dependencies": { - "onetime": "^5.1.0", - "signal-exit": "^3.0.2" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/spinnies/node_modules/strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", - "dependencies": { - "ansi-regex": "^4.1.0" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/spinnies/node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/split": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/split/-/split-1.0.1.tgz", diff --git a/package.json b/package.json index 411380602..76ada4e59 100644 --- a/package.json +++ b/package.json @@ -140,7 +140,6 @@ "qrcode-terminal": "^0.12.0", "sanitize-filename": "^1.6.3", "sharp": "^0.33.1", - "spinnies": "^0.5.1", "unzipper": "^0.11.4", "ws": "^8.8.0", "yoo-hoo": "^1.2.0" diff --git a/src/api/helpers/delete-file.ts b/src/api/helpers/delete-file.ts index 26977473d..becb82bae 100644 --- a/src/api/helpers/delete-file.ts +++ b/src/api/helpers/delete-file.ts @@ -1,13 +1,7 @@ import path from 'path'; import { existsSync, unlink } from 'fs'; -import * as Spinnies from 'spinnies'; -export async function deleteFiles( - mergedOptions: any, - Session: String, - spinnies: Spinnies -) { +export async function deleteFiles(mergedOptions: any, Session: String) { try { - spinnies.add(`removeFile`, { text: '....' }); const pathTokens: string = path.join( path.resolve( process.cwd() + mergedOptions.mkdirFolderToken, @@ -18,16 +12,13 @@ export async function deleteFiles( if (existsSync(pathTokens)) { unlink(pathTokens, (err) => { if (err) { - spinnies.fail(`removeFile`, { - text: `Not removed file: ${pathTokens}` - }); + console.error(`Not removed file: ${pathTokens}`); + } else { + console.info(`Removed file: ${pathTokens}`); } - spinnies.succeed(`removeFile`, { - text: `Removed file: ${pathTokens}` - }); }); } else { - spinnies.fail(`removeFile`, { text: `Not Files: ${pathTokens}` }); + console.error(`Not Files: ${pathTokens}`); } } catch (e) {} } diff --git a/src/api/layers/host.layer.ts b/src/api/layers/host.layer.ts index 1e5028a64..bf926ea73 100644 --- a/src/api/layers/host.layer.ts +++ b/src/api/layers/host.layer.ts @@ -12,14 +12,11 @@ import { retrieveQR } from '../../controllers/auth'; import { sleep } from '../../utils/sleep'; -import { getSpinnies } from '../../utils/spinnies'; -import * as Spinnies from 'spinnies'; export class HostLayer { readonly session: string; readonly options: CreateConfig; - protected spinnies: Spinnies = getSpinnies(); protected spinStatus = { apiInject: '', autoCloseRemain: 0, @@ -39,54 +36,8 @@ export class HostLayer { ) { this.session = session; this.options = { ...defaultOptions, ...options }; - - // this.spin('Initializing...', 'spinning'); - //this._initialize(this.page); - } - - protected spin(text?: string, status?: Spinnies.SpinnerStatus) { - const name = `session-${this.session}`; - - text = text || this.spinStatus.previousText; - this.spinStatus.previousText = text; - - status = - status || (this.spinStatus.previousStatus as Spinnies.SpinnerStatus); - this.spinStatus.previousStatus = status; - - let fullText = `[instance: ${this.session}`; - // if (this.spinStatus.state) { - // fullText += `, ${this.spinStatus.state}`; - // } - fullText += `]: ${text}`; - - let prevText = ''; - - try { - prevText = this.spinnies.pick(name).text; - } catch (error) { - this.spinnies.add(name, { text: fullText, status }); - prevText = fullText; - } - if (prevText !== fullText) { - this.spinnies.update(name, { - text: fullText, - status - }); - } } - // public async _initialize(page: Page) { - // this.spinStatus.apiInject = 'injecting'; - // await injectApi(page) - // .then(() => { - // this.spinStatus.apiInject = 'injected'; - // }) - // .catch(() => { - // this.spinStatus.apiInject = 'failed'; - // }); - // } - protected tryAutoClose() { if ( this.options.autoClose > 0 && @@ -169,7 +120,7 @@ export class HostLayer { if (this.options.logQR) { console.log(qr); } else { - this.spin(`Waiting for QRCode Scan: Attempt ${attempt}`); + console.info(`Waiting for QRCode Scan: Attempt ${attempt}`); } if (catchQR) { @@ -201,13 +152,11 @@ export class HostLayer { ) { this.statusFind = statusFind; - this.spin('Waiting page load', 'spinning'); - - this.spin('Checking is logged...'); + console.info('Waiting page load'); let authenticated = await isAuthenticated(this.page).catch(() => null); if (typeof authenticated === 'object' && authenticated.type) { - this.spin(`Error http: ${authenticated.type}`, 'fail'); + console.error(`Error http: ${authenticated.type}`); this.page.close().catch(() => {}); this.browser.close().catch(() => {}); throw `Error http: ${authenticated.type}`; @@ -216,32 +165,32 @@ export class HostLayer { this.startAutoClose(); if (authenticated === false) { - this.spin('Waiting for QRCode Scan...'); + console.info('Waiting for QRCode Scan...'); statusFind && statusFind('notLogged', this.session); await this.waitForQrCodeScan(catchQR).catch(() => undefined); - this.spin('Checking QRCode status...'); + console.info('Checking QRCode status...'); // Wait for interface update await sleep(200); authenticated = await isAuthenticated(this.page).catch(() => null); if (authenticated === null || JSON.stringify(authenticated) === '{}') { - this.spin('Failed to authenticate'); + console.error('Failed to authenticate'); statusFind && statusFind('qrReadFail', this.session); } else if (authenticated) { - this.spin('QRCode Success'); + console.info('QRCode Success'); statusFind && statusFind('qrReadSuccess', this.session); } else { - this.spin('QRCode Fail', 'fail'); + console.error('QRCode Fail', 'fail'); statusFind && statusFind('qrReadFail', this.session); this.cancelAutoClose(); this.tryAutoClose(); throw 'Failed to read the QRCode'; } } else if (authenticated === true) { - this.spin('Authenticated'); + console.info('Authenticated'); statusFind && statusFind('isLogged', this.session); } @@ -251,18 +200,18 @@ export class HostLayer { this.startAutoClose(); // Wait for interface update await sleep(200); - this.spin('Checking phone is connected...'); + console.info('Checking phone is connected...'); const inChat = await this.waitForInChat(); if (!inChat) { - this.spin('Phone not connected', 'fail'); + console.error('Phone not connected'); statusFind && statusFind('phoneNotConnected', this.session); this.cancelAutoClose(); this.tryAutoClose(); throw new Error('Phone not connected'); } this.cancelAutoClose(); - this.spin('Connected', 'succeed'); + console.info('Connected'); // statusFind && statusFind('inChat', this.session); return true; } @@ -270,13 +219,13 @@ export class HostLayer { if (authenticated === false) { this.cancelAutoClose(); this.tryAutoClose(); - this.spin('Not logged', 'fail'); + console.error('Not logged'); throw new Error('Not logged'); } this.cancelAutoClose(); this.tryAutoClose(); - this.spin('Unknow error', 'fail'); + console.error('Unknown error'); } //Pro diff --git a/src/api/layers/listener.layer.ts b/src/api/layers/listener.layer.ts index 0d9b1ddc7..04c19098d 100644 --- a/src/api/layers/listener.layer.ts +++ b/src/api/layers/listener.layer.ts @@ -58,7 +58,7 @@ export class ListenerLayer extends ProfileLayer { this.page.on('close', () => { this.cancelAutoClose(); - this.spin('Page Closed', 'fail'); + console.error('Page Closed'); }); } @@ -441,9 +441,9 @@ export class ListenerLayer extends ProfileLayer { /** * @event Listens to participants changed - * @param to group id: xxxxx-yyyy@us.c - * @param to callback * @returns Stream of ParticipantEvent + * @param groupId + * @param fn */ public async onParticipantsChanged( groupId: string, diff --git a/src/controllers/browser.ts b/src/controllers/browser.ts index 3e5049be3..342919e72 100644 --- a/src/controllers/browser.ts +++ b/src/controllers/browser.ts @@ -16,12 +16,12 @@ import { puppeteerConfig } from '../config/puppeteer.config'; import StealthPlugin from 'puppeteer-extra-plugin-stealth'; import { useragentOverride } from '../config/WAuserAgente'; import { sleep } from '../utils/sleep'; -import * as Spinnies from 'spinnies'; import * as os from 'os'; import axios from 'axios'; import { defaultOptions } from '../config/create-config'; import * as unzipper from 'unzipper'; import { exec } from 'child_process'; +import { zip } from 'typedoc/dist/lib/utils/array'; type CustomLaunchOptions = LaunchOptions & { headless?: boolean | 'new' | 'old'; @@ -389,8 +389,7 @@ function downloadBash(): Promise { } export async function initBrowser( - options: CustomLaunchOptions, - spinnies: any + options: CustomLaunchOptions ): Promise { try { // Use stealth plugin to avoid being detected as a bot @@ -425,32 +424,19 @@ export async function initBrowser( puppeteer.executablePath() ?? chromePath; - spinnies.add(`executable-path-${options.session}`, { - text: `...` - }); - - spinnies.succeed(`executable-path-${options.session}`, { - text: `Executable path browser: ${executablePath}` - }); + console.info(`Executable path browser: ${executablePath}`); const extractPath = path.join(process.cwd(), 'chrome'); const checkPath = await checkPathDowload(extractPath); const platform = os.platform(); if (!executablePath || !isChromeInstalled(executablePath)) { - spinnies.add(`browser-info-${options.session}`, { - text: `...` - }); - spinnies.fail(`browser-info-${options.session}`, { - text: `Could not find the google-chrome browser on the machine!` - }); + console.error(`Could not find the google-chrome browser on the machine!`); const resultBash = await downloadBash(); if (resultBash) { executablePath = resultBash; } else if (!checkPath) { - spinnies.add(`browser-status-${options.session}`, { - text: `Downloading browser...` - }); + console.info(`Downloading browser...`); // Download the latest version of Chrome const downloadUrl = `https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Win_x64%2F1000027%2Fchrome-win.zip?generation=1651780728332948&alt=media`; @@ -466,12 +452,7 @@ export async function initBrowser( fs.chmodSync(extractPath, '777'); - spinnies.add(`browser-path-${options.session}`, { - text: `...` - }); - spinnies.succeed(`browser-path-${options.session}`, { - text: `Path download Chrome: ${zipFilePath}` - }); + console.info(`Path to downloaded chrome: ${zipFilePath}`); const response = await axios.get(downloadUrl, { responseType: 'arraybuffer' @@ -480,19 +461,13 @@ export async function initBrowser( // Verifica se o status da resposta é 200 (OK) if (response.status === 200) { await fs.promises.writeFile(zipFilePath, response.data); - spinnies.succeed(`browser-status-${options.session}`, { - text: `Download completed.` - }); - - spinnies.add(`browser-status-${options.session}`, { - text: `Extracting Chrome: ${extractPath}` - }); + console.info(`Download completed.`); + console.info(`Extracting Chrome: ${extractPath}`); const zip = await unzipper.Open.file(zipFilePath); await zip.extract({ path: extractPath }); - spinnies.succeed(`browser-status-${options.session}`, { - text: `Chrome extracted successfully.` - }); + console.info(`Chrome extracted successfully.`); + const pathChrome = path.join(extractPath, 'chrome-win', 'chrome.exe'); if (!fs.existsSync(pathChrome)) { throw new Error(`Error no Path download Chrome`); @@ -506,12 +481,7 @@ export async function initBrowser( fs.chmodSync(folderChrom, '777'); executablePath = pathChrome; - spinnies.add(`browser-path-${options.session}`, { - text: `...` - }); - spinnies.succeed(`browser-path-${options.session}`, { - text: `Execute Path Chrome: ${executablePath}` - }); + console.info(`Execute Path Chrome: ${executablePath}`); } else { throw new Error('Error download file Chrome.'); } @@ -523,13 +493,7 @@ export async function initBrowser( let chromeVersion = ''; let versionTimeout: string | number | NodeJS.Timeout; - spinnies.add(`browser-Platform-${options.session}`, { - text: `...` - }); - - spinnies.succeed(`browser-Platform-${options.session}`, { - text: `Platform: ${platform}` - }); + console.info(`Platform: ${platform}`); if (platform === 'darwin' || platform === 'linux') { chromeVersion = await getChromeVersionBash(executablePath); @@ -557,13 +521,7 @@ export async function initBrowser( } if (chromeVersion) { - spinnies.add(`browser-Version-${options.session}`, { - text: `...` - }); - - spinnies.succeed(`browser-Version-${options.session}`, { - text: `Browser Version: ${chromeVersion}` - }); + console.info(`Browser Version: ${chromeVersion}`); } const extras = { executablePath }; @@ -606,11 +564,7 @@ export async function initBrowser( if (options.browserWS && options.browserWS !== '') { return await puppeteer.connect({ browserWSEndpoint: options.browserWS }); } else { - await removeStoredSingletonLock( - options.puppeteerOptions, - spinnies, - options - ); + await removeStoredSingletonLock(options.puppeteerOptions, options); return await puppeteer.launch(launchOptions); } } catch (e) { @@ -671,16 +625,13 @@ function getWindowsChromeExecutablePath() { export async function statusLog( page: Page, - spinnies: Spinnies, session: string, callback: (infoLog: string) => void ) { while (true) { if (page.isClosed()) { try { - spinnies.fail(`whatzapp-intro-${session}`, { - text: 'Erro intro' - }); + console.error('Error in intro'); } catch {} break; } @@ -729,7 +680,6 @@ function isChromeInstalled(executablePath: string): boolean { function removeStoredSingletonLock( puppeteerOptions: PuppeteerLaunchOptions, - spinnies: any, options: options | CreateConfig ): Promise { return new Promise((resolve, reject) => { @@ -744,57 +694,29 @@ function removeStoredSingletonLock( // No need to remove the lock on Windows, so resolve with true directly. resolve(true); } else { - spinnies.add(`stored-singleton-lock-${options.session}`, { - text: `...` - }); - - spinnies.succeed(`stored-singleton-lock-${options.session}`, { - text: `Path Stored "SingletonLock": ${singletonLockPath}` - }); - - spinnies.add(`path-stored-singleton-lock-${options.session}`, { - text: `checking SingletonLock file` - }); + console.info(`Path Stored "SingletonLock": ${singletonLockPath}`); if (fs.existsSync(singletonLockPath)) { - spinnies.add(`path-stored-singleton-lock-${options.session}`, { - text: `The file was found "SingletonLock"` - }); + console.info('SingletonLock file found.'); fs.unlink(singletonLockPath, (error) => { if (error && error.code !== 'ENOENT') { - spinnies.fail(`path-stored-singleton-lock-${options.session}`, { - text: `Error removing "SingletonLock": ${error}` - }); + console.error(`Error removing "SingletonLock": ${error}`); reject(false); } else { - spinnies.succeed( - `path-stored-singleton-lock-${options.session}`, - { - text: `Removing SingletonLock path: ${singletonLockPath}` - } - ); - spinnies.add( - `path-stored-singleton-lock-write-file-${options.session}`, - { - text: `re-adding the file "SingletonLock": ${singletonLockPath}` - } + console.info( + `re-adding the file "SingletonLock": ${singletonLockPath}` ); + fs.writeFile(singletonLockPath, '', (error) => { if (error && error.code !== 'ENOENT') { - spinnies.fail( - `path-stored-singleton-lock-write-file-${options.session}`, - { - text: `could not add the file "SingletonLock": ${singletonLockPath}` - } + console.error( + `could not add the file "SingletonLock": ${singletonLockPath}` ); reject(false); } else { - spinnies.succeed( - `path-stored-singleton-lock-write-file-${options.session}`, - { - text: `file created successfully "SingletonLock": ${singletonLockPath}` - } + console.error( + `file created successfully "SingletonLock": ${singletonLockPath}` ); resolve(true); } @@ -802,9 +724,7 @@ function removeStoredSingletonLock( } }); } else { - spinnies.succeed(`path-stored-singleton-lock-${options.session}`, { - text: `The file "SingletonLock" was not found` - }); + console.info(`The file "SingletonLock" was not found`); resolve(true); } } diff --git a/src/controllers/initializer.ts b/src/controllers/initializer.ts index 531adf50d..b9b7d40a5 100644 --- a/src/controllers/initializer.ts +++ b/src/controllers/initializer.ts @@ -2,7 +2,6 @@ import { Whatsapp } from '../api/whatsapp'; import { CreateConfig, defaultOptions } from '../config/create-config'; import { initWhatsapp, initBrowser, statusLog } from './browser'; import { welcomeScreen } from './welcome'; -import { getSpinnies } from '../utils/spinnies'; import { SocketState, SocketStream, @@ -154,36 +153,18 @@ export async function create( options = sessionOrOption; } - const spinnies = getSpinnies({ - disableSpins: options ? options.disableSpins : false - }); - - spinnies.add(`donate-${session}`, { - text: `....` - }); - - spinnies.fail(`donate-${session}`, { - text: `Help Keep This Project Going! Know more: https://github.com/orkestral/venom/blob/master/docs/getting-started/donate.md` - }); - - spinnies.add(`node-version-${session}`, { - text: `check nodeJs version...` - }); - + console.info('Checking NodeJS version...'); const requiredNodeVersion = 16; const currentNodeVersion = Number(process.versions.node.split('.')[0]); if (currentNodeVersion < requiredNodeVersion) { - spinnies.fail(`node-version-${session}`, { - text: `update Node.js, the version you are using doesn't work for this system!` - }); + console.error( + `update Node.js, the version you are using doesn't work for this system!` + ); return reject( `Outdated Node.js version. Node.js ${requiredNodeVersion} or higher is required. Please update Node.js.` ); } - - spinnies.succeed(`node-version-${session}`, { - text: `Node.js version verified successfully!` - }); + console.info(`Node.js version verified successfully!`); await checkUpdates(); @@ -197,53 +178,35 @@ export async function create( // Initialize whatsapp if (mergedOptions.browserWS) { - spinnies.add(`browser-${session}`, { - text: `Waiting... checking the wss server...` - }); + console.info(`Waiting... checking the wss server...`); } else { - spinnies.add(`browser-${session}`, { - text: 'Waiting... checking the browser...' - }); + console.info('Waiting... checking the browser...'); } - const browser: Browser | boolean = await initBrowser( - mergedOptions, - spinnies - ); + const browser: Browser | boolean = await initBrowser(mergedOptions); if (typeof browser === 'boolean') { - spinnies.fail(`browser-${session}`, { - text: `Error no open browser....` - }); + console.error(`Error no open browser....`); + statusFind && statusFind('noOpenBrowser', session); return reject(`Error no open browser....`); } if (mergedOptions.browserWS) { statusFind && statusFind('connectBrowserWs', session); - spinnies.succeed(`browser-${session}`, { - text: `Has been properly connected to the wss server` - }); + console.info(`Has been properly connected to the wss server`); } else { statusFind && statusFind('openBrowser', session); - spinnies.succeed(`browser-${session}`, { - text: `Browser successfully opened` - }); + console.info(`Browser successfully opened`); } if (!mergedOptions.browserWS) { - spinnies.add(`browser-${session}`, { - text: 'checking headless...' - }); + console.info('checking headless...'); if (mergedOptions.headless) { - spinnies.succeed(`browser-${session}`, { - text: 'headless option is active, browser hidden' - }); + console.info('headless option is active, browser hidden'); } else { - spinnies.succeed(`browser-${session}`, { - text: 'headless option is disabled, browser visible' - }); + console.info('headless option is disabled, browser visible'); } } @@ -257,24 +220,18 @@ export async function create( checkingCloses(browser, mergedOptions, (result) => { statusFind && statusFind(result, session); }).catch(() => { - spinnies.fail(`whatzapp-${session}-close`, { - text: 'Closed Browser' - }); + console.error('Closed Browser'); return reject('The client has been closed'); }); - spinnies.add(`whatzapp-${session}`, { - text: 'Checking page to whatzapp...' - }); + console.info('Checking page to whatzapp...'); statusFind && statusFind('initWhatsapp', session); // Initialize whatsapp const page: false | Page = await initWhatsapp(mergedOptions, browser); if (page === false) { - spinnies.fail(`whatzapp-${session}`, { - text: 'Error accessing the page: "https://web.whatsapp.com"' - }); + console.error('Error accessing the page: "https://web.whatsapp.com"'); statusFind && statusFind('erroPageWhatsapp', session); return reject( 'Error when trying to access the page: "https://web.whatsapp.com"' @@ -283,22 +240,11 @@ export async function create( statusFind && statusFind('successPageWhatsapp', session); - spinnies.succeed(`whatzapp-${session}`, { - text: 'Page successfully accessed' - }); - - try { - spinnies.add(`whatzapp-intro-${session}`, { - text: 'waiting for introduction' - }); - } catch {} + console.info('Page successfully accessed'); + console.info('waiting for introduction'); - statusLog(page, spinnies, session, (event) => { - try { - spinnies.add(`whatzapp-intro-${session}`, { - text: event - }); - } catch {} + statusLog(page, session, (event) => { + console.info(event); statusFind && statusFind('introductionHistory', session, event); }); @@ -312,17 +258,9 @@ export async function create( try { if (interFace.mode === InterfaceMode.MAIN) { interfaceChange && interfaceChange('chatsAvailable', session); - spinnies.add(`whatzapp-mode-main-${session}`, { - text: 'opening main page...' - }); - - spinnies.succeed(`whatzapp-mode-main-${session}`, { - text: 'Successfully main page!' - }); - - spinnies.succeed(`whatzapp-mode-syncing-${session}`, { - text: 'Successfully sync!' - }); + console.info('opening main page...'); + console.info('Successfully main page!'); + console.info('Successfully sync!'); await client.initService(); await client.addChatWapi(); @@ -331,23 +269,17 @@ export async function create( if (interFace.mode === InterfaceMode.SYNCING) { if (interFace.info === InterfaceState.OPENING) { interfaceChange && interfaceChange('syncingOpening', session); - spinnies.add(`whatzapp-mode-syncing-${session}`, { - text: 'opening sync page...' - }); + console.info('opening sync page...'); } if (interFace.info === InterfaceState.PAIRING) { interfaceChange && interfaceChange('syncingLoading', session); - spinnies.add(`whatzapp-mode-syncing-${session}`, { - text: 'Loading sync...' - }); + console.info('Loading sync'); } if (interFace.info === InterfaceState.NORMAL) { interfaceChange && interfaceChange('syncingNormal', session); - spinnies.succeed(`whatzapp-mode-syncing-${session}`, { - text: 'Successfully sync!' - }); + console.info('Successfully sync!'); } } @@ -356,36 +288,24 @@ export async function create( () => window?.Store?.State?.Socket?.stream ); if (status === SocketStream.DISCONNECTED) { - spinnies.add(`whatzapp-disconnected-${session}`, { - text: 'checking...' - }); - - spinnies.fail(`whatzapp-disconnected-${session}`, { - text: 'Was disconnected!' - }); + console.info(`${session} was disconnected`); document.querySelectorAll('.MLTJU p')[0].textContent; statusFind && statusFind('desconnected', session); } if (interFace.info === InterfaceState.OPENING) { interfaceChange && interfaceChange('qrcodeOpening', session); - spinnies.add(`whatzapp-mode-qr-${session}`, { - text: 'Opening QR Code page...' - }); + console.info(`${session}: Opening QR Code...`); } if (interFace.info === InterfaceState.PAIRING) { interfaceChange && interfaceChange('qrcodeLoading', session); - spinnies.add(`whatzapp-mode-qr-${session}`, { - text: 'Loading QR Code...' - }); + console.info(`${session}: Loading QR Code...`); } if (interFace.info === InterfaceState.NORMAL) { interfaceChange && interfaceChange('qrcodeNormal', session); - spinnies.succeed(`whatzapp-mode-qr-${session}`, { - text: 'Successfully loaded QR Code!' - }); + console.info(`${session}: Successfully loaded QR Code!`); } } } catch {} @@ -394,29 +314,17 @@ export async function create( client .onStreamChange(async (stateStream: SocketStream) => { if (stateStream === SocketStream.CONNECTED) { - try { - spinnies.succeed(`whatzapp-intro-${session}`, { - text: 'Successfully connected!' - }); - } catch {} + console.info(`${session}: Successfully connected!`); } if (stateStream === SocketStream.DISCONNECTED) { const mode = await page .evaluate(() => window?.Store?.Stream?.mode) .catch(() => {}); - if ( - mode === InterfaceMode.QR - // && checkFileJson(mergedOptions, session) - ) { + if (mode === InterfaceMode.QR) { if (statusFind) { - spinnies.add(`whatzapp-qr-${session}`, { - text: 'check....' - }); statusFind('desconnectedMobile', session); - spinnies.fail(`whatzapp-qr-${session}`, { - text: 'Disconnected by cell phone!' - }); + console.error(`${session}: Disconnected by phone`); } } } @@ -494,11 +402,7 @@ export async function create( .waitForSelector('#app .two', { visible: true }) .catch(() => {}); - try { - spinnies.succeed(`whatzapp-intro-${session}`, { - text: 'Successfully connected!' - }); - } catch {} + console.info(`${session}: Successfully connected`); await client.initService(); await client.addChatWapi(); diff --git a/src/types/spinnies.d.ts b/src/types/spinnies.d.ts deleted file mode 100644 index 045853e5f..000000000 --- a/src/types/spinnies.d.ts +++ /dev/null @@ -1,148 +0,0 @@ -declare module 'spinnies' { - namespace Spinnies { - type StopAllStatus = 'succeed' | 'fail' | 'stopped'; - type SpinnerStatus = StopAllStatus | 'spinning' | 'non-spinnable'; - - interface Spinner { - interval: number; - frames: string[]; - } - - interface SpinnerOptions { - /** - * Optional text to show in the spinner. If none is provided, the name field will be shown. - */ - text?: string; - - /** - * Optional, indent the spinner with the given number of spaces. - * */ - indent?: number; - - /** - * Initial status of the spinner. Valid statuses are: succeed, fail, spinning, non-spinnable and stopped. - */ - status?: SpinnerStatus; - - /** - * Any valid chalk color. - */ - color?: string; - - /** - * Any valid chalk color. - */ - succeedColor?: string; - - /** - * Any valid chalk color. - */ - failColor?: string; - } - - interface Options { - /** - * Any valid chalk color. The default value is white. - */ - color?: string; - - /** - * Any valid chalk color. The default value is green. - */ - succeedColor?: string; - - /** - * Any valid chalk color. The default value is red. - */ - failColor?: string; - - /** - * Any valid chalk color. The default value is greenBright. - */ - spinnerColor?: string; - - /** - * The default value is ✓. - */ - succeedPrefix?: string; - - /** - * The default value is ✖. - */ - failPrefix?: string; - - /** - * Disable spins (will still print raw messages). - */ - disableSpins?: boolean; - - /** - * Spinner configuration - */ - spinner?: Spinner; - } - } - - class Spinnies { - static dots: Spinnies.Spinner; - static dashes: Spinnies.Spinner; - - constructor(options?: Spinnies.Options); - - /** - * Add a new spinner with the given name. - */ - add: ( - name: string, - options?: Spinnies.SpinnerOptions - ) => Spinnies.SpinnerOptions; - - /** - * Get spinner by name. - */ - pick: (name: string) => Spinnies.SpinnerOptions; - - /** - * Remove spinner with name. - */ - remove: (name: string) => Spinnies.SpinnerOptions; - - /** - * Updates the spinner with name name with the provided options. - */ - update: ( - name: string, - options?: Spinnies.SpinnerOptions - ) => Spinnies.SpinnerOptions; - - /** - * Sets the specified spinner status as succeed. - */ - succeed: ( - name: string, - options?: Spinnies.SpinnerOptions - ) => Spinnies.SpinnerOptions; - - /** - * Sets the specified spinner status as fail. - */ - fail: ( - name: string, - options?: Spinnies.SpinnerOptions - ) => Spinnies.SpinnerOptions; - - /** - * Stops the spinners and sets the non-succeeded and non-failed ones to the provided status. - */ - stopAll: (status?: Spinnies.StopAllStatus) => { - [name: string]: Spinnies.SpinnerOptions; - }; - - /** - * @returns false if all spinners have succeeded, failed or have been stopped - */ - hasActiveSpinners: () => boolean; - } - - export = Spinnies; -} diff --git a/src/utils/spinnies.ts b/src/utils/spinnies.ts deleted file mode 100644 index 577eaf520..000000000 --- a/src/utils/spinnies.ts +++ /dev/null @@ -1,10 +0,0 @@ -import Spinnies from 'spinnies'; - -let spinnies: Spinnies = null; - -export function getSpinnies(options?: Spinnies.Options): Spinnies { - if (!spinnies) { - spinnies = new Spinnies(options); - } - return spinnies; -} diff --git a/test/index.js b/test/index.js index c09a0635f..28f83d4d5 100644 --- a/test/index.js +++ b/test/index.js @@ -6,7 +6,6 @@ venom.create({ session: 'sessionname', //name of session headless: false, logQR: true, - webVersion: '2.3000.1012170943-alpha' }) .then((client) => { start(client);