JSONAPI Resources Anchor

MultifileSaveService

Anchor::TypeScript::MultifileSaveService

A utility to save files generated by Anchor::TypeScript::MultifileSchemaGenerator.

Example

generator = Anchor::TypeScript::MultifileSchemaGenerator.new(
  register: Schema.register,
  manually_editable: true,
)
Anchor::TypeScript::MultifileSaveService.call(
  generator:,
  folder_path: "test/files/multifile",
  force: false
)
puts "✅ test/files/multifile"

.call Parameters

generator

  • Type: Anchor::TypeScript::MultifileSchemaGenerator

folder_path

  • Type: String

Folder where the files will be saved.

force

When true, the contents of an existing file will be fully overwritten by the contents of the generated file.

When false:

If the existing file is detected to be manually editable (i.e. // START AUTOGEN and // END AUTOGEN generated by the generator are present) then:

  • If the corresponding file's generated content is manually editable then replace the text between // START AUTOGEN and // END AUTOGEN in the existing file with the text between those markers in the generated files.
  • If not, an error is thrown. To fix, ensure either
    • the generator was initialized with manually_editable: true
    • or use force: true if you no longer want to use a manually editable schema.

If the existing file is not manually editable then the existing will be fully overwritten regardless of force. Currently, only shared.ts will be completely overwritten.

On this page