Skip to content

Commit 483fe41

Browse files
authored
style: new output format (#108)
1 parent 43bc6be commit 483fe41

File tree

2 files changed

+50
-56
lines changed

2 files changed

+50
-56
lines changed

bin/vue-codemod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ async function main() {
9494
// Remind user to back up files
9595
const answer = question(
9696
'Warning!!\n' +
97-
'This tool may overwrite files.\n' +
98-
'press enter or enter yes or enter Y to continue:'
97+
'This tool may overwrite files. Please use version control tools or back up your code in advance.\n' +
98+
'Press enter or enter yes or enter Y to continue:'
9999
)
100100
if (!['', 'yes', 'Y'].includes(answer.trim())) {
101101
console.log('Abort!!!')

src/report.ts

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const cliInstance = new cliProgress.SingleBar(
66
format: 'progress [{bar}] {percentage}% | {process} | {value}/{total}',
77
clearOnComplete: false,
88
linewrap: true,
9-
fps: 60
9+
fps: 144
1010
},
1111
cliProgress.Presets.shades_classic
1212
)
@@ -98,11 +98,23 @@ export function formatterOutput(
9898
: ((100 * totalChanged) / totalDetected).toFixed(2)
9999

100100
console.log(`\x1B[0m--------------------------------------------------`)
101-
console.log(`Processed file:\n${processFilePathList}`)
102-
console.log(`Processed ${processFilePath.length} files`)
101+
console.log(
102+
`Processed ${processFilePath.length} files:\n${processFilePathList}\n`
103+
)
104+
105+
if (global.manualList.length) {
106+
console.log(
107+
`The list that you need to migrate your codes manually (total: ${global.manualList.length}): `
108+
)
109+
let index = 1
110+
global.manualList.forEach(manual => {
111+
console.log('index:', index++)
112+
console.log(manual)
113+
})
114+
}
103115

104116
console.log(
105-
'\x1B[31;4m%s\x1B[0m',
117+
'\n\n\x1B[31;4m%s\x1B[0m',
106118
`${totalDetected} places`,
107119
`need to be transformed`
108120
)
@@ -113,56 +125,38 @@ export function formatterOutput(
113125
)
114126
console.log(`The transformation rate is \x1B[32;4m${transRate}%\x1B[0m`)
115127

116-
if (formatter === 'all') {
117-
console.log('The transformation stats: \n')
118-
console.log(global.outputReport)
119-
}
120-
121128
Object.keys(outputReport).forEach(item => {
122129
if (!outputReport[item]) delete outputReport[item]
123130
})
124131

125132
if (formatter === 'detail') {
126133
console.log('The transformation stats: \n')
127134
console.log(global.outputReport)
128-
}
129-
130-
let tableStr: string
131-
let tableOutput: any[][] = [['Rule Names', 'Count']]
132-
for (let i in global.outputReport) {
133-
tableOutput.push([i, global.outputReport[i]])
134-
}
135-
tableStr = table(tableOutput, {
136-
drawHorizontalLine: (lineIndex, rowCount) => {
137-
return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount
138-
},
139-
columns: [{ alignment: 'left' }, { alignment: 'center' }]
140-
})
141-
142-
if (formatter === 'table') {
143-
console.log('The transformation stats: \n')
144-
console.log(tableStr)
145-
}
146-
147-
if (formatter === 'log') {
148-
logOutput(
149-
processFilePathList,
150-
processFilePath,
151-
totalDetected,
152-
totalChanged,
153-
transRate,
154-
tableStr,
155-
logger
156-
)
157-
}
158-
159-
if (global.manualList.length) {
160-
console.log('The list that you need to migrate your codes manually: ')
161-
let index = 1
162-
global.manualList.forEach(manual => {
163-
console.log('index:', index++)
164-
console.log(manual)
135+
} else {
136+
let tableStr: string
137+
let tableOutput: any[][] = [['Rule Names', 'Count']]
138+
for (let i in global.outputReport) {
139+
tableOutput.push([i, global.outputReport[i]])
140+
}
141+
tableStr = table(tableOutput, {
142+
drawHorizontalLine: (lineIndex, rowCount) => {
143+
return lineIndex === 0 || lineIndex === 1 || lineIndex === rowCount
144+
},
145+
columns: [{ alignment: 'left' }, { alignment: 'center' }]
165146
})
147+
console.log('The transformation stats: ')
148+
console.log(tableStr)
149+
if (formatter === 'log') {
150+
logOutput(
151+
processFilePathList,
152+
processFilePath,
153+
totalDetected,
154+
totalChanged,
155+
transRate,
156+
tableStr,
157+
logger
158+
)
159+
}
166160
}
167161
}
168162

@@ -175,14 +169,9 @@ export function logOutput(
175169
tableStr: string,
176170
logger: Console
177171
) {
178-
logger.log(`--------------------------------------------------`)
179-
logger.log(`Processed file:\n${processFilePathList}\n`)
180-
logger.log(`Processed ${processFilePath.length} files`)
181-
logger.log(`${totalDetected} places`, `need to be transformed`)
182-
logger.log(`${totalChanged} places`, `was transformed`)
183-
logger.log(`The transformation rate is ${transRate}%`)
184-
logger.log('The transformation stats: \n')
185-
logger.log(tableStr)
172+
logger.log(
173+
`Processed ${processFilePath.length} files:\n${processFilePathList}\n`
174+
)
186175
if (global.manualList.length) {
187176
logger.log('The list that you need to migrate your codes manually')
188177
let index = 1
@@ -191,4 +180,9 @@ export function logOutput(
191180
logger.log(manual)
192181
})
193182
}
183+
logger.log(`\n\n${totalDetected} places`, `need to be transformed`)
184+
logger.log(`${totalChanged} places`, `was transformed`)
185+
logger.log(`The transformation rate is ${transRate}%`)
186+
logger.log('The transformation stats: ')
187+
logger.log(tableStr)
194188
}

0 commit comments

Comments
 (0)