1
1
import type { Config } from '@/src/utils/get-config'
2
2
import type { RegistryItem } from '@/src/utils/registry/schema'
3
3
import { existsSync , promises as fs } from 'node:fs'
4
+ import os from 'node:os'
4
5
import { getProjectInfo } from '@/src/utils/get-project-info'
5
6
import { highlighter } from '@/src/utils/highlighter'
6
7
import { logger } from '@/src/utils/logger'
@@ -60,6 +61,23 @@ export async function updateFiles(
60
61
const folderSkipped = new Map < string , boolean > ( )
61
62
const filesSkipped = [ ]
62
63
64
+ let tempRoot = ''
65
+ if ( ! config . typescript ) {
66
+ for ( const file of files ) {
67
+ if ( ! file . content ) {
68
+ continue
69
+ }
70
+ const dirName = path . dirname ( file . path )
71
+ tempRoot = path . join ( os . tmpdir ( ) , 'shadcn-vue' )
72
+
73
+ // Create the full temp directory path with original directory structure
74
+ const tempDir = path . join ( tempRoot , dirName )
75
+
76
+ await fs . mkdir ( tempDir , { recursive : true } )
77
+ await fs . writeFile ( path . join ( tempRoot , file . path ) , file . content , 'utf-8' )
78
+ }
79
+ }
80
+
63
81
for ( const file of files ) {
64
82
if ( ! file . content ) {
65
83
continue
@@ -133,7 +151,7 @@ export async function updateFiles(
133
151
134
152
// Run our transformers.
135
153
const content = await transform ( {
136
- filename : file . path ,
154
+ filename : path . join ( tempRoot , file . path ) ,
137
155
raw : file . content ,
138
156
config,
139
157
baseColor,
@@ -145,6 +163,11 @@ export async function updateFiles(
145
163
: filesCreated . push ( path . relative ( config . resolvedPaths . cwd , filePath ) )
146
164
}
147
165
166
+ // Perform clean up if there's tempRoot generated for compiler-sfc to parse
167
+ if ( tempRoot ) {
168
+ await fs . rm ( tempRoot , { recursive : true } )
169
+ }
170
+
148
171
const hasUpdatedFiles = filesCreated . length || filesUpdated . length
149
172
if ( ! hasUpdatedFiles && ! filesSkipped . length ) {
150
173
filesCreatedSpinner ?. info ( 'No files updated.' )
0 commit comments