MCPcopy
hub / github.com/prisma/prisma / cleanLeftoversIO

Function cleanLeftoversIO

packages/migrate/src/views/handleViewsIO.ts:99–131  ·  view source on GitHub ↗

* - Delete every *.sql file in the subfolders of viewsDir * - Delete any empty subfolders * - Delete viewsDir if it is empty

(viewsDir: string, viewFilesToKeep: string[] = [])

Source from the content-addressed store, hash-verified

97 * - Delete viewsDir if it is empty
98 */
99async function cleanLeftoversIO(viewsDir: string, viewFilesToKeep: string[] = []): Promise<void> {
100 const pipeline = pipe(
101 // remove any SQL files in the views directory beyond the ones just created, concurrently, collapsing the possible errors
102 fsFunctional.getFilesInDir(viewsDir, '**/*/*.sql'),
103 T.chain((filesInViewsDir) => {
104 const viewFilesToRemove = filesInViewsDir.filter((file) => !viewFilesToKeep.includes(file))
105 return TE.traverseArray(fsFunctional.removeFile)(viewFilesToRemove)
106 }),
107
108 // remove any empty directories in the views directory, recursively
109 TE.chainW(() => fsFunctional.removeEmptyDirs(viewsDir)),
110 )
111
112 const either = await pipeline()
113
114 if (E.isRight(either)) {
115 return
116 }
117
118 // failure: check which error to throw
119 const error = match(either.left)
120 .with({ type: 'fs-remove-empty-dirs' }, (e) => {
121 throw new Error(`Error removing empty directories in: ${e.meta.dir}.\n${e.error}.`)
122 })
123 .with({ type: 'fs-remove-file' }, (e) => {
124 throw new Error(`Error removing the file: ${e.meta.filePath}.\n${e.error}.`)
125 })
126 .exhaustive()
127 // We execute the cleanup and ignore the possible errors
128 await pipeline()
129
130 throw error
131}

Callers 1

handleViewsIOFunction · 0.85

Calls 3

includesMethod · 0.80
withMethod · 0.65
pipeFunction · 0.50

Tested by

no test coverage detected