Skip to content

racketscript/racketscript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

308 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RacketScript

A lightweight Racket to JavaScript compiler

Installation

Following system packages are required -

  • Racket 6.4 or higher
  • NodeJS and NPM
  • Make

NPM and Racket package installation steps could be done by directly by executing make setup at RacketScript root directory. Or follow following steps to install NodeJS and Racket modules -

## If you install locally, make sure they are in PATH
$ npm install -g gulp

RacketScript will generate Gulpfiles to compile ES6 to ES5 using Traceur or Babel. If you wish to run ES6 modules directly, install Traceur using NPM. Babel is recommended for writing NodeJS programs.

If you do not wish to pollute your root NPM directory, you can set a custom global location by changing your npmrc (eg. echo "prefix = $HOME/.npm-packages" >> ~/.npmrc. Then add /prefix/path/above/bin to your PATH.

## Racket dependencies
$ raco pkg install threading graph

If you wish to hack on RacketScript code or run tests, lints and coverage tool, run make setup-extra form RacketScript root directory. See Makefile for more information.

Build

The compiler is written in Typed Racket. To avoid long startups, it is advised to pre-compile Racket sources to bytecode.

# From source root
$ make build

Basic Usage

$ racks -h

racketscript [ <option> ... ] [<filename>]
  Compile Racket to JavaScript
 where <option> is one of
  -d <dir>, --build-dir <dir> : Output directory
  -n, --skip-npm-install : Skip NPM install phase
  -g, --skip-gulp-build : Skip Gulp build phase
  -b, --js-beautify : Beautify JS output
  --dump-debug-info : Dumps some debug information in output directory
  --stdin : Reads module from standard input, with file name argument being pseudo name
  --enable-self-tail : Translate self tail calls to loops
* -t <target>, --target <target> : ES6 to ES5 compiler [traceur|babel]
/ --expand : Fully expand Racket source
| --ast : Expand and print AST
| --rename : Expand and print AST after α-renaming
| --il : Compile to intermediate langauge (IL)
| --js : Compile and print JS module to stdout
\ --complete : Compile module and its dependencies to JS
  --help, -h : Show this help
  -- : Do not treat any remaining argument as a switch (at this level)
 * Asterisks indicate options allowed multiple times.
 /|\ Brackets indicate mutually exclusive options.
 Multiple single-letter switches can be combined after one `-'; for
  example: `-h-' is the same as `-h --'

Default output directory is named js-build. To compile a Racket file named foobar.rkt, run -

    # Installs all NPM dependencies and compile foobar.rkt
    $ racks foobar.rkt

	# To avoid re-installing NPM packages use `-n`
	$ racks -n foobar.rkt

    # Override default output directory
    $ racks -d /path/to/output/dir foobar.rkt

	# To beautify assembled modules use `-b`
	$ racks -b foobar.rkt

The compiled ES6 modules typically goto one of following three folders:

  • "modules": The normal Racket files.
  • "collects": Racket collects source files.
  • "links": Other third party packages.

If you use skip-gulp-build option, run gulp in output directory to produce final output. To speed up later builds, you may want to skip NPM install phase by using skip-npm-install flag.

Traceur

By default RacketScript will use Traceur and produce dist/compiled.js. To execute inside NodeJS, execute bootstrap.js in output directory. For running in browser, include the Traceur runtime along with dist/compiled.js.

A more robust (and less portable) way, is to run the ES6 modules generated in modules directly from Traceur. Goto modules output directory and execute $ traceur foobar.js.

Babel

RacketScript could also use Babel. It will compile each assembled ES6 module to ES5, and put it in dist directory, persevering original directory structure. Replace above command with following -

    $ racks --es6 babel foobar.rkt

This will compile each ES6 module generated by RacketScript, and put in dist with same directory structure.

About

Racket to JavaScript Compiler

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors