def compile(build_folder, check: false, write: false, release: false, verbose: false, use_cache: true)
      @file_resolver = FileResolver.new(Config.instance.project_path, build_folder)
      compilation_context.file_resolver = @file_resolver
      compilation_context.should_check = check
      compilation_context.should_write = write
      compilation_context.release_build = release
      compilation_context.verbose = verbose
      compilation_context.use_cache = use_cache

      self.class.globals_catcher.catch do
        @build_folder = build_folder

        FileUtils.mkdir_p(build_folder)

        puts "  handling target #{@target.name.inspect} in build dir `#{Config.instance.pretty_path_from_project(build_folder)}`"

        file_resolver.add_file(FileTypes::SourceFile.new(Config.instance.pretty_path_from_project(@book.file_path).to_s))
        compilation_context.plugins

        parse_toc_item(@target.root_toc)
        parse_target_file_requests

        process_all_target_files
        generate_other_files

        # build folder cleanup
        remove_unnecessary_files
        remove_empty_folders

        source_paths = file_resolver.files.select { |a| a.is_a?(FileTypes::SourceFile) }.map { |a| a.source_path }
        compilation_context.source_file_database.cleanup(source_paths)
        compilation_context.source_file_database.update_all_metadata
        compilation_context.source_file_database.save_to_file

        compilation_context.target_file_database.cleanup(source_paths)
        compilation_context.target_file_database.update_all_metadata
        compilation_context.target_file_database.save_to_file
      end
    ensure
      self.class.globals_catcher.clear_all
    end
def compile(build_folder, check: false, write: false, release: false, verbose: false, use_cache: true)
      @file_resolver = FileResolver.new(Config.instance.project_path, build_folder)
      compilation_context.file_resolver = @file_resolver
      compilation_context.should_check = check
      compilation_context.should_write = write
      compilation_context.release_build = release
      compilation_context.verbose = verbose
      compilation_context.use_cache = use_cache

      self.class.globals_catcher.catch do
        @build_folder = build_folder

        FileUtils.mkdir_p(build_folder)

        puts "  handling target #{@target.name.inspect} in build dir `#{Config.instance.pretty_path_from_project(build_folder)}`"

        file_resolver.add_file(FileTypes::SourceFile.new(Config.instance.pretty_path_from_project(@book.file_path).to_s))
        compilation_context.plugins

        parse_toc_item(@target.root_toc)
        parse_target_file_requests

        process_all_target_files
        generate_other_files

        # build folder cleanup
        remove_unnecessary_files
        remove_empty_folders

        source_paths = file_resolver.files.select { |a| a.is_a?(FileTypes::SourceFile) }.map { |a| a.source_path }
        compilation_context.source_file_database.cleanup(source_paths)
        compilation_context.source_file_database.update_all_metadata
        compilation_context.source_file_database.save_to_file

        compilation_context.target_file_database.cleanup(source_paths)
        compilation_context.target_file_database.update_all_metadata
        compilation_context.target_file_database.save_to_file
      end
    ensure
      self.class.globals_catcher.clear_all
    end
@param book [Epuber::Book::Book]
 @param target [Epuber::Book::Target]

 Compile target to build folder

 @param build_folder [String] path to folder, where will be stored all compiled files
 @param [Bool] check should run non-release checkers
 @param [Bool] write should perform transformations of source files and write them back
 @param [Bool] release this is release build

 @return [void]