Skip to content

Commit

Permalink
fix: Optimize the experience of report
Browse files Browse the repository at this point in the history
  • Loading branch information
yosion-p committed Jul 21, 2021
1 parent 0a3cafc commit 8b389ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export async function start (config : Config): Promise<void> {

// generate index.html must be after generate vite.config.js
geneIndexHtml(rootDir, config, astParsingResult)
printReport(config.reportType, config.rootDir, beginTime) // output conversion
printReport(config.rootDir, beginTime) // output conversion

// generate patches
const patchesDir = path.resolve(rootDir, 'patches')
Expand Down
36 changes: 16 additions & 20 deletions src/utils/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,27 @@ function recordConver (args: ConverObj) {
})
}

function printReport (reportType: string, dir: string, beginTime: number) {
function printReport (dir: string, beginTime: number) {
console.log('features of successful conversion:')
reportList.forEach(item => {
tabDt.push([item.num, item.feat, item.times?.toString()])
})
console.log(table(tabDt, tabFormat));
console.log(chalk.green(`Conversion in ${Date.now() - beginTime}ms.`))
if (reportType === 'log') {
const options = {
flags: 'w', //
encoding: 'utf8' // utf8编码
}
console.log(chalk.yellow(`output ${dir}conversion.log`));
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)
} else {
console.log(chalk.yellow('If you want to output the report file, add "-r log" after the command'));
console.log(chalk.green(`Conversion finished in ${Date.now() - beginTime}ms.`))
const options = {
flags: 'w', //
encoding: 'utf8' // utf8编码
}
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)
console.log(chalk.green(`The report output path is ${dir}conversion.log`));
}
export { recordConver, printReport }

0 comments on commit 8b389ec

Please sign in to comment.