Skip to content

Commit

Permalink
Update: clean code and change number color if there's updates / erros
Browse files Browse the repository at this point in the history
  • Loading branch information
themitosan committed Dec 7, 2024
1 parent ef39cdd commit ccfcf12
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 57 deletions.
6 changes: 3 additions & 3 deletions Lang/pt-br.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@

"batchStatus": "==> Atualização global:",
"batch_overallProgress": "Progresso geral: %VAR_0%% [%VAR_1% de %VAR_2%]",
"batch_updateCounter": "Atualizações: %VAR_0%%VAR_1%%VAR_2%",
"batch_errorCounter": "Erros: %VAR_0%%VAR_1%%VAR_2%",
"batch_updateCounter": "Atualizações: %VAR_0%",
"batch_errorCounter": "Erros: %VAR_0%",
"batch_elapsedTime": "Tempo decorrido: %VAR_0%%VAR_1%%VAR_2%",
"batchProcessList": "==> Processos ativos:",

"batchProcess": "%VAR_0% %VAR_1% Processo %VAR_2% - Progresso: %VAR_3%% [%VAR_4% de %VAR_5%] - Atualizações: %VAR_6%%VAR_7%%VAR_8%, Erros: %VAR_9%%VAR_10%%VAR_11%%VAR_12%",
"batchProcess": "%VAR_0% %VAR_1% Processo %VAR_2% - Progresso: %VAR_3%% [%VAR_4% de %VAR_5%] - Atualizações: %VAR_6%, Erros: %VAR_7%%VAR_8%",

"noErrorsRun": "...Nenhum erro ocorreu durante todo o processo.",
"noUpdatesRun": "...Nenhum repositório foi atualizado durante todo o processo.",
Expand Down
6 changes: 3 additions & 3 deletions src/lang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ export var langDatabase:any = {

"batchStatus": "==> Batch update:",
"batch_overallProgress": "Overall Progress: %VAR_0%% [%VAR_1% of %VAR_2%]",
"batch_updateCounter": "Update counter: %VAR_0%%VAR_1%%VAR_2%",
"batch_errorCounter": "Error counter: %VAR_0%%VAR_1%%VAR_2%",
"batch_updateCounter": "Update counter: %VAR_0%",
"batch_errorCounter": "Error counter: %VAR_0%",
"batch_elapsedTime": "Elapsed time: %VAR_0%%VAR_1%%VAR_2%",
"batchProcessList": "==> Process list:",

"batchProcess": "%VAR_0% %VAR_1% Process %VAR_2% - Progress: %VAR_3%% [%VAR_4% of %VAR_5%] - Repos updated: %VAR_6%%VAR_7%%VAR_8%, Errors: %VAR_9%%VAR_10%%VAR_11%%VAR_12%",
"batchProcess": "%VAR_0% %VAR_1% Process %VAR_2% - Progress: %VAR_3%% [%VAR_4% of %VAR_5%] - Repos updated: %VAR_6%, Errors: %VAR_7%%VAR_8%",

"noErrorsRun": "...there was no errors on this run.",
"noUpdatesRun": "...there was no updates on this run.",
Expand Down
50 changes: 49 additions & 1 deletion src/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,60 @@ export const runExternalCommand_Defaults:Pick <runExternalCommandOptions, 'chdir
enableConsoleLog: !0,
removeBlankLines: !1,
onStdData: function(){return;}
};
}

/*
Variables
*/

/*
Console text style database
Source code: https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color
*/
export const consoleTextStyle = {
reset: "\x1b[0m",
bright: "\x1b[1m",
dim: "\x1b[2m",
underline: "\x1b[4m",
blink: "\x1b[5m",
reverse: "\x1b[7m",
hidden: "\x1b[8m",
fgBlack: "\x1b[30m",
fgRed: "\x1b[31m",
fgGreen: "\x1b[32m",
fgYellow: "\x1b[33m",
fgBlue: "\x1b[34m",
fgMagenta: "\x1b[35m",
fgCyan: "\x1b[36m",
fgWhite: "\x1b[37m",
fgGray: "\x1b[90m",
bgBlack: "\x1b[40m",
bgRed: "\x1b[41m",
bgGreen: "\x1b[42m",
bgYellow: "\x1b[43m",
bgBlue: "\x1b[44m",
bgMagenta: "\x1b[45m",
bgCyan: "\x1b[46m",
bgWhite: "\x1b[47m",
bgGray: "\x1b[100m"
}

/*
Functions
*/

/**
* Change text color if determinated var is higher than zero
* @param currentValue [number] Current value
* @param newColor [string] New color style (Default: reset)
* @returns [string] String with new color
*/
export function changeTextColorNumber(currentValue:number, newColor:string = consoleTextStyle.reset):string {
var res = currentValue.toString();
if (currentValue > 0) res = `${newColor}${currentValue}${consoleTextStyle.reset}`;
return res;
}

/**
* Update console line
* @param x [number] Console X position
Expand Down
23 changes: 9 additions & 14 deletions src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
*/

import { grppRepoEntry } from './import';
import { grpp_displayMainLogo } from './utils';
import { grpp_convertLangVar, langDatabase } from './lang';
import { consoleTextStyle, grpp_getLogoString } from './utils';
import { grpp_displayMainLogo, grpp_getLogoString } from './utils';
import { APP_COMPILED_AT, APP_HASH, APP_VERSION, grpp_updateRepoData, grpp_updateDatabaseSettings, grppSettings } from './main';
import { checkConnection, converMsToHHMMSS, convertArrayToString, createLogEntry, execReasonListCheck, isValidJSON, openOnTextEditor, parsePercentage, parsePositive, runExternalCommand, runExternalCommand_Defaults, runExternalCommand_output, spliceArrayIntoChunks, trimString, updateConsoleLine } from './tools';
import { checkConnection, converMsToHHMMSS, convertArrayToString, createLogEntry, execReasonListCheck, isValidJSON, openOnTextEditor, parsePercentage, parsePositive, runExternalCommand, runExternalCommand_Defaults, runExternalCommand_output, spliceArrayIntoChunks, trimString, updateConsoleLine, consoleTextStyle, changeTextColorNumber } from './tools';

/*
Require node modules
Expand Down Expand Up @@ -343,29 +342,25 @@ function processBatchResFiles(){
entryChar = ' └';
enableLineBreak = '\n';
updateConsoleLine(0, 11, `──┬ ${grpp_convertLangVar(langDatabase.update.batch_overallProgress, [parsePercentage(reposProcessed, totalReposQueued), reposProcessed, totalReposQueued])}`);
updateConsoleLine(0, 13, ` ├ ${grpp_convertLangVar(langDatabase.update.batch_updateCounter, [consoleTextStyle.fgGreen, updateCounter, consoleTextStyle.reset])}`);
updateConsoleLine(0, 14, ` └ ${grpp_convertLangVar(langDatabase.update.batch_errorCounter, [consoleTextStyle.fgRed, errorCounter, consoleTextStyle.reset])}\n\n${langDatabase.update.batchProcessList}\n\n`);
updateConsoleLine(0, 13, ` ├ ${grpp_convertLangVar(langDatabase.update.batch_updateCounter, [changeTextColorNumber(updateCounter, consoleTextStyle.fgGreen)])}`);
updateConsoleLine(0, 14, ` └ ${grpp_convertLangVar(langDatabase.update.batch_errorCounter, [changeTextColorNumber(errorCounter, consoleTextStyle.fgGreen)])}\n\n${langDatabase.update.batchProcessList}\n\n`);
}

// Update entryChar if there is only one process and update elapsed time line
if (totalResFiles === 1) entryChar = '───';
if (totalResFiles === 1) entryChar = '-->';
updateConsoleLine(0, 12, ` ├ ${grpp_convertLangVar(langDatabase.update.batch_elapsedTime, [consoleTextStyle.fgGreen, converMsToHHMMSS(parsePositive(performance.now() - startUpdateTime)), consoleTextStyle.reset])}`);

// Check if process finished. If so, update checkbox char and update each process line
if (batchResData.currentRepo > (batchResData.totalRepos - 1)) checkboxChar = '[✓]';
// Check if process finished - if so, update checkbox char and update each process line
if (batchResData.currentRepo > (batchResData.totalRepos - 1)) checkboxChar = `[${consoleTextStyle.fgGreen}${consoleTextStyle.reset}]`;
updateConsoleLine(0, (currentFile + 18), grpp_convertLangVar(langDatabase.update.batchProcess, [
entryChar,
checkboxChar,
currentFile,
parsePercentage(batchResData.currentRepo, batchResData.totalRepos),
batchResData.currentRepo,
batchResData.totalRepos,
consoleTextStyle.fgGreen,
batchResData.updateList.length,
consoleTextStyle.reset,
consoleTextStyle.fgRed,
batchResData.errorList.length,
consoleTextStyle.reset,
changeTextColorNumber(batchResData.updateList.length, consoleTextStyle.fgGreen),
changeTextColorNumber(batchResData.errorList.length, consoleTextStyle.fgRed),
enableLineBreak
]));

Expand Down
36 changes: 0 additions & 36 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +21,6 @@ import { consoleClear, converMsToHHMMSS, convertArrayToString, createLogEntry, e
import * as module_fs from 'fs';
import * as module_os from 'os';

/*
Variables
*/

/*
Console text style database
Source code: https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color
*/
export const consoleTextStyle = {
'reset': "\x1b[0m",
'bright': "\x1b[1m",
'dim': "\x1b[2m",
'underline': "\x1b[4m",
'blink': "\x1b[5m",
'reverse': "\x1b[7m",
'hidden': "\x1b[8m",
'fgBlack': "\x1b[30m",
'fgRed': "\x1b[31m",
'fgGreen': "\x1b[32m",
'fgYellow': "\x1b[33m",
'fgBlue': "\x1b[34m",
'fgMagenta': "\x1b[35m",
'fgCyan': "\x1b[36m",
'fgWhite': "\x1b[37m",
'fgGray': "\x1b[90m",
'bgBlack': "\x1b[40m",
'bgRed': "\x1b[41m",
'bgGreen': "\x1b[42m",
'bgYellow': "\x1b[43m",
'bgBlue': "\x1b[44m",
'bgMagenta': "\x1b[45m",
'bgCyan': "\x1b[46m",
'bgWhite': "\x1b[47m",
'bgGray': "\x1b[100m"
};

/*
Functions
*/
Expand Down

0 comments on commit ccfcf12

Please sign in to comment.