diff --git a/.versionrc b/.versionrc new file mode 100644 index 0000000..5f4bcf3 --- /dev/null +++ b/.versionrc @@ -0,0 +1,20 @@ +{ + "bumpFiles": [ + "package.json" + ], + "types": [ + { + "type": "feat", + "section": "Features" + }, + { + "type": "fix", + "section": "Bug Fixes" + }, + { + "type": "chore", + "section": "Maintenance", + "hidden": false + } + ] +} diff --git a/package.json b/package.json index 5731565..ab0313e 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,8 @@ "express": "^4.21.0", "prettier": "^3.3.3", "puppeteer": "^23.4.1", - "readline": "^1.3.0" + "readline": "^1.3.0", + "zolt": "^1.0.0" }, "husky": { "hooks": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e0f0176..91b3f8d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,9 @@ importers: readline: specifier: ^1.3.0 version: 1.3.0 + zolt: + specifier: ^1.0.0 + version: 1.0.0 devDependencies: '@commitlint/cli': specifier: ^19.5.0 @@ -3781,6 +3784,9 @@ packages: zod@3.23.8: resolution: {integrity: sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==} + zolt@1.0.0: + resolution: {integrity: sha512-00Oa9sgBAaEAjNkOjdTwoQK/fzWWosLzDxFjctVikZzyS1T1AF8cNWTwlyBod7WhUAmdZkFiEibI6yK8Rf+8ag==} + snapshots: '@ampproject/remapping@2.3.0': @@ -8022,3 +8028,5 @@ snapshots: yocto-queue@1.1.1: {} zod@3.23.8: {} + + zolt@1.0.0: {} diff --git a/src/utils/cli.ts b/src/utils/cli.ts index 4cf9813..5352a9c 100644 --- a/src/utils/cli.ts +++ b/src/utils/cli.ts @@ -1,13 +1,10 @@ import chalk from 'chalk'; -import readline from 'readline'; +import { Zolt } from 'zolt'; type MessageType = 'error' | 'success' | 'info'; type RouteInfo = { route: string; size: number }; -let spinnerInterval: NodeJS.Timeout | null = null; -let spinnerFrameIndex = 0; let spinnerStartTime: number | null = null; // To store the time when spinner starts -const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']; /** * @param {any} msg Message or array of routes with size to print. @@ -18,13 +15,17 @@ export const printMessage = (msg: any, type: MessageType, errorSummary?: any): v switch (type) { case 'error': stopSpinner(false); - console.error(`${chalk.red.bold('\u{10102}')} ${msg}\n${errorSummary?.stack || errorSummary}\n`); + console.error( + `${chalk.red.bold('\u{10102}')} ${msg}\n${errorSummary?.stack || errorSummary}\n`, + ); break; case 'success': { const routes: RouteInfo[] = msg; if (routes && routes.length) { - routes.forEach((routeInfo) => { - console.log(`${chalk.green.bold('\u{1F5F8}')} generated ${routeInfo.route} (${routeInfo.size}kb)`); + routes.forEach(routeInfo => { + console.log( + `${chalk.green.bold('\u{1F5F8}')} generated ${routeInfo.route} (${routeInfo.size}kb)`, + ); }); } else { console.log('No pages were generated.'); @@ -32,16 +33,8 @@ export const printMessage = (msg: any, type: MessageType, errorSummary?: any): v break; } case 'info': { - spinnerFrameIndex = 0; - if (!spinnerInterval) { - spinnerStartTime = Date.now(); // Capture the time when spinner starts - spinnerInterval = setInterval(() => { - const frame = spinnerFrames[spinnerFrameIndex]; - readline.cursorTo(process.stdout, 0); - process.stdout.write(`${frame} Processing pages...`); - spinnerFrameIndex = (spinnerFrameIndex + 1) % spinnerFrames.length; - }, 80); - } + Zolt.start('dots', 'green', 'Processing pages...'); + spinnerStartTime = Date.now(); break; } default: @@ -54,22 +47,15 @@ export const printMessage = (msg: any, type: MessageType, errorSummary?: any): v * @param {boolean} success Whether the processing was successful. */ export const stopSpinner = (success: boolean = true): void => { - if (spinnerInterval) { - clearInterval(spinnerInterval); - spinnerInterval = null; - - const endTime = Date.now(); // Capture the time when the spinner stops - const elapsedTime = ((endTime - (spinnerStartTime || 0)) / 1000).toFixed(2); - - readline.cursorTo(process.stdout, 0); // Move cursor to start of line - readline.clearLine(process.stdout, 0); // Clear the current line - - if (success) { - console.log(chalk.green.bold(`All pages are processed. Took ${elapsedTime} seconds.`)); - } else { - console.log(chalk.red.bold(`Error processing routes.`)); - } - - spinnerStartTime = null; + const endTime = Date.now(); // Capture the time when the spinner stops + const elapsedTime = ((endTime - (spinnerStartTime || 0)) / 1000).toFixed(2); + let finishText: string = ''; + + if (success) { + finishText = chalk.green.bold(`All pages are processed. Took ${elapsedTime} seconds.`); + } else { + finishText = chalk.red.bold(`Error processing routes.`); } + + Zolt.stop(() => console.log(finishText)); };