Skip to content

Commit 2b8c7c3

Browse files
authored
fix: stop progress bar when countering exception (#105)
1 parent 8b73b1f commit 2b8c7c3

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

bin/vue-codemod.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ import runTransformation from '../src/runTransformation'
1818
import { transform as packageTransform } from '../src/packageTransformation'
1919

2020
import type { TransformationModule } from '../src/runTransformation'
21-
import { formatterOutput } from '../src/report'
21+
import { formatterOutput, cliInstance } from '../src/report'
2222
import { ruleDescription } from '../src/ruleDescription'
23-
import cliProgress from 'cli-progress'
2423

2524
const debug = createDebug('vue-codemod:cli')
2625
let processFilePath: string[] = []
@@ -109,16 +108,6 @@ async function main() {
109108
global.scriptLine = 0
110109
global.outputReport = {}
111110

112-
const cliInstance = new cliProgress.SingleBar(
113-
{
114-
format: 'progress [{bar}] {percentage}% | {process} | {value}/{total}',
115-
clearOnComplete: false,
116-
linewrap: true,
117-
fps: 60
118-
},
119-
cliProgress.Presets.shades_classic
120-
)
121-
122111
const resolvedPaths = globby.sync(
123112
(files as string[]).concat('!node_modules'),
124113
{ gitignore: true }
@@ -241,7 +230,6 @@ function processTransformation(
241230
// @ts-ignore
242231
ruleOutput.website = ruleDescription[transformationName].description
243232
ruleOutput.transformed_files = ruleProcessFile
244-
console.log('\x1B[0m', ruleOutput)
245233
if (formatter === 'log') logger.log(ruleOutput)
246234
}
247235
}

src/report.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import { table } from 'table'
2-
2+
import cliProgress from 'cli-progress'
3+
4+
export const cliInstance = new cliProgress.SingleBar(
5+
{
6+
format: 'progress [{bar}] {percentage}% | {process} | {value}/{total}',
7+
clearOnComplete: false,
8+
linewrap: true,
9+
fps: 60
10+
},
11+
cliProgress.Presets.shades_classic
12+
)
313
export function pushManualList(
414
path: string,
515
node: any,

src/wrapAstTransformation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { JSCodeshift, Transform, Core } from 'jscodeshift'
2+
import { cliInstance } from './report'
23

34
export type Context = {
45
root: ReturnType<Core>
@@ -21,6 +22,7 @@ export default function astTransformationToJSCodeshiftModule<Params = any>(
2122
try {
2223
root = j(file.source)
2324
} catch (err) {
25+
cliInstance.stop()
2426
console.error(
2527
`JSCodeshift failed to parse ${file.path},` +
2628
` please check whether the syntax is valid`

0 commit comments

Comments
 (0)