{"size": 1088, "ext": "scrbl", "max_stars_repo_path": "polyglot-doc/polyglot/scribblings/how-tos/before-after-builds.scrbl", "max_stars_repo_name": "pmatos/polyglot", "max_stars_repo_stars_event_min_datetime": "2019-08-25T10:41:17.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-03T19:33:04.000Z", "max_issues_repo_path": "polyglot-doc/polyglot/scribblings/how-tos/before-after-builds.scrbl", "max_issues_repo_name": "pmatos/polyglot", "max_issues_repo_issues_event_min_datetime": "2019-08-25T10:44:27.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-03T12:22:16.000Z", "max_forks_repo_path": "polyglot-doc/polyglot/scribblings/how-tos/before-after-builds.scrbl", "max_forks_repo_name": "pmatos/polyglot", "max_forks_repo_forks_event_min_datetime": "2019-12-19T06:18:49.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-13T03:20:07.000Z"}
{"max_stars_count": 89, "max_issues_count": 29, "max_forks_count": 5, "avg_line_length": 38.8571428571, "max_line_length": 71, "alphanum_fraction": 0.7619485294}
#lang scribble/manual

@require[@for-label[racket polyglot unlike-assets]]

@title[#:tag "hook-before-after"]{How-To: Hook Before and After Builds}

Under the hood, Polyglot workflows are classes. Each one is a subclass
of @racket[unlike-compiler%]. An instance of @racket[unlike-compiler%]
models relationships between files that otherwise don't fit
together. You can use it to make a PNG depend on an XML file, if you
know a way to have that make sense. Knowing the basics of the
@racketmodname[unlike-assets] collection can help you customize
Polyglot later.

The @method[unlike-compiler% compile!] method actually executes the
given workflow and the underlying build. This method is synchronous,
so if you want to add code to occur before or after a build, simply
override @method[unlike-compiler% compile!] and place code around
the superclass call.

@racketblock[
(class polyglot/functional%
  (define/override (compile! #:changed c #:removed r)
    (displayln "before build")
    (define output (super compile! #:changed c #:removed r))
    (displayln "after build")
    output))]
