#lang racket/base
;;; SPDX-License-Identifier: LGPL-3.0-or-later
;;; SPDX-FileCopyrightText: Copyright © 2021 Tony Garnock-Jones <tonyg@leastfixedpoint.com>

(provide pre-installer)

(require racket/runtime-path)
(require preserves-schema/bin/preserves-schema-rkt)
(require (only-in racket/file delete-directory/files))

(require (only-in "../schema-compiler.rkt"
                  schema-compiler-plugin
                  schema-compiler-plugin-mode))

(define (pre-installer _collects-path syndicate-path)
  (define output-directory (build-path syndicate-path "schemas/gen"))
  (delete-directory/files output-directory #:must-exist? #f)
  (parameterize ((schema-compiler-plugin-mode 'meta))
    (batch-compile #:inputs (list (build-path syndicate-path "schemas/**.prs"))
                   #:additional-modules (hash '(Actor) 'syndicate/actor)
                   #:output-directory output-directory
                   #:plugins (list schema-compiler-plugin))))

(define-runtime-path syndicate-path "..")
(define (regenerate!)
  (void (pre-installer 'not-bothering-to-figure-this-out-since-we-do-not-need-it
                       syndicate-path)))

(module+ main
  (regenerate!))
