Skip to content

Commit d119727

Browse files
authored
feat: print logs in different modules (vuejs#26)
1 parent 6409cdf commit d119727

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

bin/vue-codemod.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { transform as packageTransform } from '../src/packageTransformation'
2020

2121
import type { TransformationModule } from '../src/runTransformation'
2222

23-
const debug = createDebug('vue-codemod')
23+
const debug = createDebug('vue-codemod:cli')
2424
const log = console.log.bind(console)
2525
let processFilePath: string[] = []
2626

@@ -74,25 +74,36 @@ async function main() {
7474

7575
const resolvedPaths = globby.sync(files as string[])
7676
if (transformationName != undefined) {
77+
debug(`run ${transformationName} transformation`)
7778
const transformationModule = loadTransformationModule(transformationName)
7879
processTransformation(
7980
resolvedPaths,
8081
transformationName,
8182
transformationModule
8283
)
8384
packageTransform()
85+
processFilePath.push('package.json')
8486
}
8587

8688
if (runAllTransformation) {
89+
debug(`run all transformation`)
8790
for (let key in builtInTransformations) {
8891
if (!excludedTransformations.includes(key)) {
8992
processTransformation(resolvedPaths, key, builtInTransformations[key])
93+
} else {
94+
debug(
95+
`skip ${key} transformation, Because it will run in other transformation`
96+
)
9097
}
9198
}
9299

93100
for (let key in vueTransformations) {
94101
if (!excludedVueTransformations.includes(key)) {
95102
processTransformation(resolvedPaths, key, vueTransformations[key])
103+
} else {
104+
debug(
105+
`skip ${key} transformation, Because it will run in other transformation`
106+
)
96107
}
97108
}
98109
packageTransform()
@@ -125,6 +136,7 @@ function processTransformation(
125136
}
126137
const extension = (/\.([^.]*)$/.exec(fileInfo.path) || [])[0]
127138
if (!extensions.includes(extension)) {
139+
debug(`skip ${fileInfo.path} file because not end with ${extensions}.`)
128140
continue
129141
}
130142
try {

src/packageTransformation.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import * as fs from 'fs'
22
import * as globby from 'globby'
33
import * as prettier from 'prettier'
4+
import createDebug from 'debug'
5+
6+
const debug = createDebug('vue-codemod:rule')
47

58
/**
69
* Creates a fix command that inserts text at the specified index in the source text.
@@ -12,6 +15,7 @@ import * as prettier from 'prettier'
1215
export function transform(): void {
1316
const resolvedPaths = globby.sync('package.json' as string)
1417
if (resolvedPaths.length <= 0) {
18+
debug('package.json is not exists.')
1519
return
1620
}
1721

src/runTransformation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { SFCDescriptor } from './sfcUtils'
88

99
import VueTransformation from './VueTransformation'
1010

11-
const debug = createDebug('vue-codemod')
11+
const debug = createDebug('vue-codemod:run')
1212

1313
type FileInfo = {
1414
path: string
@@ -58,8 +58,6 @@ export default function runTransformation(
5858
let descriptor: SFCDescriptor
5959

6060
if (transformation.type === 'vueTransformation') {
61-
debug('Running VueTransformation')
62-
6361
if (extension === '.vue') {
6462
descriptor = parseSFC(source, { filename: path }).descriptor
6563
} else {
@@ -69,6 +67,7 @@ export default function runTransformation(
6967

7068
// skip .vue files without template block
7169
if (!descriptor.template) {
70+
debug('skip .vue files without template block.')
7271
return source
7372
}
7473
let contentStart: number =
@@ -110,6 +109,7 @@ export default function runTransformation(
110109

111110
// skip .vue files without script block
112111
if (!descriptor.script) {
112+
debug('skip .vue files without script block.')
113113
return source
114114
}
115115

vue-transformations/transition-group-root.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import type { Node } from 'vue-eslint-parser/ast/nodes'
44
import type { Operation } from '../src/operationUtils'
55
import type { VueASTTransformation } from '../src/wrapVueTransformation'
66
import wrap from '../src/wrapVueTransformation'
7+
import createDebug from 'debug'
8+
9+
const debug = createDebug('vue-codemod:rule')
710

811
/**
912
* 每一个实际的规则,需要做以下几件事:
@@ -68,6 +71,7 @@ function fix(node: any): Operation[] {
6871
hasTagAttr = true
6972
})
7073
if (hasTagAttr) {
74+
debug('No operator, transition-group element has tag attribute.')
7175
return fixOperations
7276
}
7377

vue-transformations/v-else-if-key.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import type { Node } from 'vue-eslint-parser/ast/nodes'
44
import type { Operation } from '../src/operationUtils'
55
import type { VueASTTransformation } from '../src/wrapVueTransformation'
66
import wrap from '../src/wrapVueTransformation'
7+
import createDebug from 'debug'
8+
9+
const debug = createDebug('vue-codemod:rule')
710

811
/**
912
* 每一个实际的规则,需要做以下几件事:
@@ -71,10 +74,11 @@ function fix(node: any): Operation[] {
7174
attr.key.name.name === 'else-if' ||
7275
attr.key.name.name === 'else')
7376
)
74-
.forEach((element: any) => {
77+
.forEach(() => {
7578
hasTargetAttr = true
7679
})
7780
if (!hasTargetAttr) {
81+
debug('No operator, target element is not if/else-if/else.')
7882
return fixOperations
7983
}
8084

vue-transformations/v-for-template-key.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import type { Node } from 'vue-eslint-parser/ast/nodes'
55
import type { Operation } from '../src/operationUtils'
66
import type { VueASTTransformation } from '../src/wrapVueTransformation'
77
import wrap from '../src/wrapVueTransformation'
8+
import createDebug from 'debug'
9+
10+
const debug = createDebug('vue-codemod:rule')
811

912
let operatingParentElements: any = []
1013

@@ -78,6 +81,7 @@ function fix(node: any): Operation[] {
7881
hasForAttr = true
7982
})
8083
if (hasForAttr) {
84+
debug('No operator, target element has for attribute.')
8185
return fixOperations
8286
}
8387

@@ -125,6 +129,7 @@ function fix(node: any): Operation[] {
125129
}
126130

127131
if (!elderHasFor) {
132+
debug('No operator, elder element no for attribute.')
128133
return fixOperations
129134
}
130135

0 commit comments

Comments
 (0)