Reputation: 359
I developed an F# to JavaScript (and to other dynamically typed languages) compiler. The compiler by itself is powerful, in the sense it is able to translate many F# constructs, on the other hand it is not so user-friendly. You still have to use a command-line executable to translate the project into JavaScript code.
This is user-unfriendly for many reasons, one of them is debugging.
So, I would like to create a project template (with basic directory structure) that would allow a programmer to write the code as if it was a normal F# project, then when he clicks the green "run" button the compilation process should start and finally a browser should open with a web page running the resulting JavaScript code. Anyone who has ever used Websharper or Pit knows what I'm talking about.
Of course, in case the translation is done to some other language, I would like the "run" button to behave differently. Basically, another template should do the job.
So my question is: are there any alternatives to pre- and post-compilation phases? I precise that the compiler can also be used as a library instead of a binary executable.
Any reference to useful documentation is appreciated.
Upvotes: 0
Views: 174
Reputation: 6543
The FunScript project (F# to JavaScript compiler) has example projects that employ a launcher (written by Tomas Petricek) that compiles the marked modules, starts a minimal web server and opens the default web page in the browser.
FunScript Canvas sample:
[<ReflectedDefinition>]
module Program
open FunScript
let main() =
let canvas = Globals.document.getElementsByTagName_canvas().[0]
canvas.width <- 1000.
canvas.height <- 800.
let ctx = canvas.getContext_2d()
ctx.fillStyle <- "rgb(200,0,0)"
ctx.fillRect (10., 10., 55., 50.);
ctx.fillStyle <- "rgba(0, 0, 200, 0.5)"
ctx.fillRect (30., 30., 55., 50.)
do Runtime.Run(directory="Web")
Where Runtime.Run
does the work.
See: https://github.com/ZachBray/FunScript/blob/master/Examples/Shared/Launcher.fs
For info on building F# project templates Dan Mohl has built a number of web templates using SideWaffle: http://bloggemdano.blogspot.co.uk/2013/12/simpleweb-and-servicestack-templates.html
Upvotes: 4