@@ -9,27 +9,9 @@ namespace :anchor do
9
9
puts "✅ #{ File . basename ( path ) } "
10
10
end
11
11
12
- def write_to_multi ( folder , force , generate )
13
- FileUtils . mkdir_p ( "test/files/#{ folder } " )
14
- result = generate . call
15
- result . each do |res |
16
- path = Rails . root . join ( "test/files/#{ folder } " , res [ :name ] )
17
- if force || !File . exist? ( path )
18
- File . open ( path , "w" ) { |f | f . write ( res [ :content ] ) }
19
- next
20
- end
21
-
22
- existing_content = File . read ( path )
23
- new_content =
24
- if existing_content . starts_with? ( "// START AUTOGEN\n " ) && existing_content . include? ( "// END AUTOGEN\n " )
25
- after_end = existing_content . split ( "// END AUTOGEN\n " ) . second
26
- [ res [ :content ] . split ( "\n // END AUTOGEN\n " ) . first , "// END AUTOGEN" , after_end ] . join ( "\n " )
27
- else
28
- res [ :content ]
29
- end
30
-
31
- File . open ( path , "w" ) { |f | f . write ( new_content ) }
32
- end
12
+ def write_to_multi ( folder , force , generator )
13
+ folder_path = "test/files/#{ folder } "
14
+ Anchor ::TypeScript ::MultifileSaveService . call ( generator :, folder_path :, force :)
33
15
puts "✅ #{ folder } "
34
16
end
35
17
@@ -43,15 +25,16 @@ namespace :anchor do
43
25
write_to "excluded_fields_schema.ts" , -> {
44
26
Anchor ::TypeScript ::SchemaGenerator . call ( register : Schema . register , exclude_fields : { User : [ :name , :posts ] } )
45
27
}
46
- write_to_multi "multifile" , false , -> {
47
- Anchor ::TypeScript ::MultifileSchemaGenerator . call (
28
+ write_to_multi "multifile" ,
29
+ false ,
30
+ Anchor ::TypeScript ::MultifileSchemaGenerator . new (
48
31
register : Schema . register ,
49
32
context : { } ,
50
33
include_all_fields : true ,
51
34
exclude_fields : nil ,
52
35
manually_editable : true ,
53
36
)
54
- }
37
+
55
38
write_to "json_schema.json" , -> {
56
39
Anchor ::JSONSchema ::SchemaGenerator . call ( register : Schema . register , include_all_fields : true )
57
40
}
0 commit comments