Skip to content

Commit 6fc2a6d

Browse files
author
Adolph-WSY
authored
chore: avoid repetitive counting of modified files (#71)
1 parent c106d87 commit 6fc2a6d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

bin/vue-codemod.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import Module from 'module'
66

77
import * as yargs from 'yargs'
88
import * as globby from 'globby'
9-
import * as util from 'util'
109

1110
import createDebug from 'debug'
1211
import { question } from 'readline-sync'
@@ -147,9 +146,14 @@ function processTransformation(
147146
const extensions = ['.js', '.ts', '.vue', '.jsx', '.tsx']
148147
for (const p of resolvedPaths) {
149148
debug(`Processing ${p}…`)
149+
let retainedSource: string = fs
150+
.readFileSync(p)
151+
.toString()
152+
.split('\r\n')
153+
.join('\n')
150154
const fileInfo = {
151155
path: p,
152-
source: fs.readFileSync(p).toString().split('\r\n').join('\n')
156+
source: retainedSource
153157
}
154158
const extension = (/\.([^.]*)$/.exec(fileInfo.path) || [])[0]
155159
if (!extensions.includes(extension)) {
@@ -164,10 +168,12 @@ function processTransformation(
164168
params as object
165169
)
166170

167-
if (fileInfo.source != result) {
171+
if (retainedSource != result) {
168172
fs.writeFileSync(p, result)
169-
if (util.inspect(processFilePath).indexOf(util.inspect(p)) == -1) {
173+
if (processFilePath.indexOf(p) == -1) {
170174
processFilePath.push(p)
175+
} else {
176+
debug(`Skip this file ${p} because of duplicate statistics`)
171177
}
172178
}
173179
} catch (e) {

0 commit comments

Comments
 (0)