Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 140 lines (121 sloc) 5.187 kb
#!/usr/bin/env racket
#lang racket/base
(require "private/command.rkt"
"parameters.rkt"
"whalesong-helpers.rkt"
profile profile/render-text
(for-syntax racket/base))
;; Command line for running Whalesong.
;; TODO: we may want to adopt this as a raco command, as described in:
;;
;; http://docs.racket-lang.org/raco/command.html
;; Usage:
;;
;; * Build standalone .xhtml application.
;;
;; $ whalesong build main-module-name.rkt
;;
;;
;; * Print out the runtime library to standard output.
;;
;; $ whalesong get-runtime
;;
;;
;; * Print out the JavaScript for the program.
;;
;; $ whalesong get-javascript main-module-name.rkt
(define as-standalone-html? (make-parameter #f))
(define with-profiling? (make-parameter #f))
(define-syntax (maybe-with-profiling stx)
(syntax-case stx ()
[(_ expr)
(syntax/loc stx
(if (with-profiling?)
(profile expr
#:threads #t
#:delay 0.0001
#:render (lambda (profile)
(render profile
#:truncate-source 500)))
expr))]))
(define (at-toplevel)
(svn-style-command-line
#:program "whalesong"
#:argv (current-command-line-arguments)
"The Whalesong command-line tool for compiling Racket to JavaScript"
["build" "build a standalone html and javascript package"
"Builds a Racket program and its required dependencies into a .html and .js file."
#:once-each
[("-v" "--verbose")
("Display verbose messages.")
(current-verbose? #t)]
[("--debug-show-timings")
("Display debug messages about compilation time.")
(current-timing-port (current-output-port))]
[("--enable-profiling")
("Enable profiling to standard output")
(with-profiling? #t)]
[("--without-cache")
("Turn off the internal compilation cache")
(current-with-cache? #f)]
[("--compress-javascript")
("Compress JavaScript with Google Closure (requires Java)")
(current-compress-javascript? #t)]
[("--split-modules")
("Write one file per module")
(current-one-module-per-file? #t)]
[("--dest-dir")
dest-dir
("Set destination directory (default: current-directory)")
(current-output-dir dest-dir)]
[("--as-standalone-xhtml")
("Write single standalone xhtml file")
(as-standalone-html? #t)]
#:args (path)
(maybe-with-profiling
(if (as-standalone-html?)
(build-standalone-xhtml path)
(build-html-and-javascript path)))]
["get-runtime" "print the runtime library to standard output"
"Prints the runtime JavaScript library that's used by Whalesong programs."
#:once-each
[("-v" "--verbose")
("Display verbose messages.")
(current-verbose? #t)]
[("--debug-show-timings")
("Display debug messages about compilation time.")
(current-timing-port (current-output-port))]
[("--enable-profiling")
("Enable profiling to standard output")
(with-profiling? #t)]
[("--without-cache")
("Turn off the internal compilation cache")
(current-with-cache? #f)]
[("--compress-javascript")
("Compress JavaScript with Google Closure (requires Java)")
(current-compress-javascript? #t)]
#:args ()
(maybe-with-profiling
(print-the-runtime))]
["get-javascript" "Gets just the JavaScript code and prints it to standard output"
"Builds a racket program into JavaScript. The outputted file depends on the runtime."
#:once-each
[("-v" "--verbose")
("Display verbose messages.")
(current-verbose? #t)]
[("--debug-show-timings")
("Display debug messages about compilation time.")
(current-timing-port (current-output-port))]
[("--enable-profiling")
("Enable profiling to standard output")
(with-profiling? #t)]
[("--without-cache")
("Turn off the internal compilation cache")
(current-with-cache? #f)]
[("--compress-javascript")
("Compress JavaScript with Google Closure (requires Java)")
(current-compress-javascript? #t)]
#:args (file)
(maybe-with-profiling
(get-javascript-code file))]))
(at-toplevel)
Jump to Line
Something went wrong with that request. Please try again.