简体   繁体   中英

F# Project template for an F# to JavaScript compiler

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM