aoc2022/scripts/make-day

29 lines
874 B
Racket
Executable File

#!/usr/bin/env racket
#lang racket
(require racket/runtime-path
scribble/text (rename-in scribble/text/output [output scribble-output])
"aoc-lib.rkt")
(define-runtime-path template "template.rktrkt")
(define (eval-template file vars [port (current-output-port)])
(define cs (current-namespace))
(define output-exp
(parameterize ([current-namespace (make-base-namespace)])
(for ([mod (in-list '(scribble/text))])
(namespace-attach-module cs mod)
(namespace-require mod))
(hash-for-each vars namespace-set-variable-value!)
(eval `(include/text (file ,file)))))
(scribble-output output-exp port))
(command-line
#:program "make-day"
#:args (day)
;; make solution file
(call-with-output-file
(format "~a.rkt" day)
(lambda (out)
(eval-template (path->string template) (hash 'day day) out))))