#lang racket/base
(require "write-runtime.rkt"
"write-module-records.rkt"
"module-record.rkt"
"compile-moby-module.rkt"
racket/path
racket/contract)
(define (create-javascript-package a-path output-directory)
(let*-values ([(a-path) (normalize-path a-path)]
[(base-dir file dir?) (split-path a-path)]
[(module-records) (compile-moby-modules a-path)])
(call-with-output-file (build-path output-directory "runtime.js")
(lambda (op)
(write-runtime "browser" op))
#:exists 'replace)
(copy-support-files output-directory)
(copy-js-compatibility-libraries output-directory)
(call-with-output-file (build-path output-directory "program.js")
(lambda (op)
(write-module-records module-records op)
(for ([r module-records])
(cond
[(string=? (path->string (module-record-path r))
(path->string a-path))
(fprintf op "var programModuleName = ~s;\n\n"
(symbol->string (module-record-name r))
(path->string (find-relative-path base-dir (module-record-path r))))]
[else
(void)])))
#:exists 'replace)))
(provide/contract [create-javascript-package
(path? path? . -> . any)])