1+ /* jscpd:ignore-start */
12import type { PlatformError } from "@effect/platform/Error"
23import type * as FileSystem from "@effect/platform/FileSystem"
34import type * as Path from "@effect/platform/Path"
@@ -7,6 +8,55 @@ import { readFileStringIfPresent, statIfPresent, writeFileStringEnsuringParent }
78
89const shouldSkipCopiedDir = ( entry : string ) : boolean => entry === "tmp"
910
11+ const copyDirEntryRecursive = (
12+ fs : FileSystem . FileSystem ,
13+ path : Path . Path ,
14+ sourceEntry : string ,
15+ targetEntry : string
16+ ) : Effect . Effect < void , PlatformError > =>
17+ Effect . gen ( function * ( _ ) {
18+ const entryInfo = yield * _ ( statIfPresent ( fs , sourceEntry ) )
19+ if ( entryInfo === null ) {
20+ return
21+ }
22+ if ( entryInfo . type === "Directory" ) {
23+ yield * _ ( copyDirRecursive ( fs , path , sourceEntry , targetEntry ) )
24+ return
25+ }
26+ if ( entryInfo . type !== "File" ) {
27+ return
28+ }
29+
30+ const sourceText = yield * _ ( readFileStringIfPresent ( fs , sourceEntry ) )
31+ if ( sourceText === null ) {
32+ return
33+ }
34+ yield * _ ( writeFileStringEnsuringParent ( fs , path , targetEntry , sourceText ) )
35+ } )
36+
37+ const copyDirContentsRecursive = (
38+ fs : FileSystem . FileSystem ,
39+ path : Path . Path ,
40+ sourcePath : string ,
41+ targetPath : string
42+ ) : Effect . Effect < void , PlatformError > =>
43+ Effect . gen ( function * ( _ ) {
44+ const entries = yield * _ ( fs . readDirectory ( sourcePath ) )
45+ for ( const entry of entries ) {
46+ if ( shouldSkipCopiedDir ( entry ) ) {
47+ continue
48+ }
49+ yield * _ (
50+ copyDirEntryRecursive (
51+ fs ,
52+ path ,
53+ path . join ( sourcePath , entry ) ,
54+ path . join ( targetPath , entry )
55+ )
56+ )
57+ }
58+ } )
59+
1060const copyDirRecursive = (
1161 fs : FileSystem . FileSystem ,
1262 path : Path . Path ,
@@ -22,27 +72,7 @@ const copyDirRecursive = (
2272 return
2373 }
2474 yield * _ ( fs . makeDirectory ( targetPath , { recursive : true } ) )
25- const entries = yield * _ ( fs . readDirectory ( sourcePath ) )
26- for ( const entry of entries ) {
27- const sourceEntry = path . join ( sourcePath , entry )
28- const targetEntry = path . join ( targetPath , entry )
29- if ( shouldSkipCopiedDir ( entry ) ) {
30- continue
31- }
32- const entryInfo = yield * _ ( statIfPresent ( fs , sourceEntry ) )
33- if ( entryInfo === null ) {
34- continue
35- }
36- if ( entryInfo . type === "Directory" ) {
37- yield * _ ( copyDirRecursive ( fs , path , sourceEntry , targetEntry ) )
38- } else if ( entryInfo . type === "File" ) {
39- const sourceText = yield * _ ( readFileStringIfPresent ( fs , sourceEntry ) )
40- if ( sourceText === null ) {
41- continue
42- }
43- yield * _ ( writeFileStringEnsuringParent ( fs , path , targetEntry , sourceText ) )
44- }
45- }
75+ yield * _ ( copyDirContentsRecursive ( fs , path , sourcePath , targetPath ) )
4676 } )
4777
4878type CodexFileCopySpec = {
@@ -170,3 +200,4 @@ export const copyDirMissingEntries = (
170200 yield * _ ( copyMissingRecursive ( fs , path , sourceDir , targetDir ) )
171201 yield * _ ( Effect . log ( `Seeded missing ${ label } entries from ${ sourceDir } to ${ targetDir } ` ) )
172202 } )
203+ /* jscpd:ignore-end */
0 commit comments