#!/usr/bin/env mzscheme -mtv
#lang mzscheme
(require scheme/cmdline
scheme/match
(file "base.ss")
(file "file.ss"))
(define replace? #f)
(define (read-spec path)
(let ([in (open-input-file path)])
(let loop ([data (read in)])
(if (eof-object? data)
null
(cons data (loop (read in)))))))
(define (process-spec spec)
(for-each (match-lambda
[(list (? string? des) (? list? src))
(printf "Concatenating files: ~a -> ~a...~n" src des)
(for-each (lambda (src)
(unless (file-exists? src)
(raise-exn exn:unlib
(format "File does not exist: ~a." src))))
src)
(when (file-exists? des)
(if replace?
(delete-file des)
(raise-exn exn:fail:unlib
(format "File exists: ~a (use the -R option to auto-replace)." des))))
(concatenate-files des src)]
[other
(raise-exn exn:unlib
(format "Badly formatted spec: ~a~n" other))])
spec))
(define (main . argv)
(command-line "jsmake" argv
(once-each
[("-R" "--replace")
"Replace existing files."
(set! replace? #t)])
(args (filename)
(with-handlers ([exn:unlib?
(lambda (exn)
(printf "~a~n" (exn-message exn))
(printf "Bailing.~n")
(exit 1))])
(process-spec (read-spec filename)))
(printf "Done.~n"))))