Skip to content

Commit

Permalink
fix: format report
Browse files Browse the repository at this point in the history
  • Loading branch information
yosion-p committed Jul 23, 2021
1 parent 71bc5ac commit b41474c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import cliProgress from 'cli-progress'

const cliInstance = new cliProgress.SingleBar({
format: 'progress [{bar}] {percentage}% | {doSomething} | {value}/{total}',
clearOnComplete: true, // clear the progress bar on complete / stop()
clearOnComplete: false, // clear the progress bar on complete / stop()
linewrap: true,
fps: 60
}, cliProgress.Presets.shades_classic)
Expand Down
40 changes: 13 additions & 27 deletions src/utils/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,6 @@ const reportList: ConverObj[] = []
const tabDt = [
['Number', 'Features', 'Conversion count']
];
const tabFormat = {
border: {
topBody: '─',
topJoin: '┬',
topLeft: '┌',
topRight: '┐',
bottomBody: '─',
bottomJoin: '┴',
bottomLeft: '└',
bottomRight: '┘',
bodyLeft: '│',
bodyRight: '│',
bodyJoin: '│',
joinBody: '─',
joinLeft: '├',
joinRight: '┤',
joinJoin: '┼'
}
};

function recordConver (args: ConverObj) {
const { num, feat } = args
Expand All @@ -54,22 +35,27 @@ function printReport (dir: string, beginTime: number) {
reportList.forEach(item => {
tabDt.push([item.num, item.feat, item.times?.toString()])
})
console.log(table(tabDt, tabFormat));
const tableStr: string = table(tabDt, {
drawHorizontalLine: (lineIndex, rowCount) => {
return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount
},
columns: [{ alignment: 'center' }, { alignment: 'left' }, { alignment: 'center' }]
})
console.log(tableStr);
console.log(chalk.green(`Conversion finished in ${Date.now() - beginTime}ms.`))
const options = {
flags: 'w', //
encoding: 'utf8' // utf8编码
}
while (dir[dir.length - 1] === '/') {
dir = dir.slice(0, dir.length - 1)
}
dir += '/'
const stdout = fs.createWriteStream(`${dir}conversion.log`, options);
const logger = new console.Console(stdout);
logger.log('--------------------------------------------------')
// TODO features
// logger.log(`Processed file:\n${processFilePathList}\n`)
// logger.log(`Processed ${processFilePath.length} files`)
// logger.log(`${totalDetected} places`, 'need to be transformed')
// logger.log(`${totalChanged} places`, 'was transformed')
// logger.log(`The transformation rate is ${transRate}%`)
logger.log('The transformation stats: \n', tabDt)
logger.log('features of successful conversion: \n')
logger.log(tableStr)
console.log(chalk.green(`The report output path is ${dir}conversion.log`));
}
export { recordConver, printReport }

0 comments on commit b41474c

Please sign in to comment.