MCPcopy Create free account
hub / github.com/TanStack/cli / writeFiles

Function writeFiles

packages/create/src/add-to-app.ts:84–192  ·  view source on GitHub ↗
(
  environment: Environment,
  cwd: string,
  output: {
    files: Record<string, string>
    deletedFiles: Array<string>
  },
  forced: boolean,
)

Source from the content-addressed store, hash-verified

82}
83
84export async function writeFiles(
85 environment: Environment,
86 cwd: string,
87 output: {
88 files: Record<string, string>
89 deletedFiles: Array<string>
90 },
91 forced: boolean,
92) {
93 const toRelativePath = (filePath: string) => {
94 const normalizedFilePath = filePath.replace(/\\/g, '/')
95 const normalizedCwd = cwd.replace(/\\/g, '/')
96 const cwdWithoutDrive = normalizedCwd.replace(/^[a-zA-Z]:/, '')
97 const cwdWithoutDriveNoLeading = cwdWithoutDrive.replace(/^\/+/, '')
98
99 if (normalizedFilePath === normalizedCwd) {
100 return ''
101 }
102 if (normalizedFilePath.startsWith(`${normalizedCwd}/`)) {
103 return normalizedFilePath.slice(normalizedCwd.length + 1)
104 }
105 if (normalizedFilePath === cwdWithoutDrive) {
106 return ''
107 }
108 if (normalizedFilePath.startsWith(`${cwdWithoutDrive}/`)) {
109 return normalizedFilePath.slice(cwdWithoutDrive.length + 1)
110 }
111 if (normalizedFilePath === cwdWithoutDriveNoLeading) {
112 return ''
113 }
114 if (normalizedFilePath.startsWith(`${cwdWithoutDriveNoLeading}/`)) {
115 return normalizedFilePath.slice(cwdWithoutDriveNoLeading.length + 1)
116 }
117
118 return normalizedFilePath.replace(/^\/+/, '')
119 }
120
121 const relativeOutputFiles = Object.keys(output.files).reduce<
122 Record<string, string>
123 >((acc, filePath) => {
124 acc[toRelativePath(filePath)] = output.files[filePath]
125 return acc
126 }, {})
127
128 const currentFiles = await recursivelyGatherFilesFromEnvironment(
129 environment,
130 cwd,
131 false,
132 )
133
134 const overwrittenFiles: Array<string> = []
135 const changedFiles: Array<string> = []
136 for (const relativeFile of Object.keys(relativeOutputFiles)) {
137 if (currentFiles[relativeFile]) {
138 if (currentFiles[relativeFile] !== relativeOutputFiles[relativeFile]) {
139 overwrittenFiles.push(relativeFile)
140 }
141 } else {

Callers 2

addToAppFunction · 0.70
add-to-app.test.tsFile · 0.50

Calls 7

mergePackageJSONFunction · 0.90
toRelativePathFunction · 0.85
warnMethod · 0.80
startStepMethod · 0.80
finishStepMethod · 0.80
isBase64Function · 0.70

Tested by

no test coverage detected