@@ -50,19 +50,42 @@ export default function runTransformation(
50
50
transformation = transformationModule
51
51
}
52
52
53
- if ( transformation . type === 'vueTransformation' ) {
54
- debug ( 'TODO: Running VueTransformation' )
53
+ const { path, source } = fileInfo
54
+ const extension = ( / \. ( [ ^ . ] * ) $ / . exec ( path ) || [ ] ) [ 0 ]
55
+ let lang = extension . slice ( 1 )
56
+ let descriptor : SFCDescriptor
55
57
58
+ if ( transformation . type === 'vueTransformation' && extension === '.vue' ) {
59
+ debug ( 'Running VueTransformation' )
60
+
61
+ descriptor = parseSFC ( source , { filename : path } ) . descriptor
62
+
63
+ // skip .vue files without template block
64
+ if ( ! descriptor . template ) {
65
+ return source
66
+ }
67
+
68
+ fileInfo . source = `<template>${ descriptor . template . content } </template>`
56
69
const out = transformation ( fileInfo , params )
70
+
71
+ if ( ! out ) {
72
+ return source
73
+ }
74
+
75
+ // need to reconstruct the .vue file from descriptor blocks
76
+ if ( extension === '.vue' ) {
77
+ if ( out === descriptor ! . template ! . content ) {
78
+ return source // skipped, don't bother re-stringifying
79
+ }
80
+ // remove redundant <template> tag
81
+ descriptor ! . template ! . content = out . slice ( 11 , - 11 )
82
+ return stringifySFC ( descriptor ! )
83
+ }
84
+
57
85
return out
58
86
} else {
59
87
debug ( 'Running jscodeshift transform' )
60
88
61
- const { path, source } = fileInfo
62
- const extension = ( / \. ( [ ^ . ] * ) $ / . exec ( path ) || [ ] ) [ 0 ]
63
- let lang = extension . slice ( 1 )
64
-
65
- let descriptor : SFCDescriptor
66
89
if ( extension === '.vue' ) {
67
90
descriptor = parseSFC ( source , { filename : path } ) . descriptor
68
91
0 commit comments