{-| Module : IRTS.CodegenJavaScript Description : The JavaScript code generator. Copyright : License : BSD3 Maintainer : The Idris Community. -} {-# LANGUAGE OverloadedStrings, PatternGuards #-} module IRTS.CodegenJavaScript (codegenJavaScript , codegenNode , JSTarget(..) ) where import Data.Char import Data.Text (Text) import qualified Data.Text as T import IRTS.CodegenCommon import IRTS.JavaScript.Codegen import System.Directory import System.FilePath data JSTarget = Node | JavaScript deriving Eq htmlHeader :: Text htmlHeader = T.concat [ "\n" , "
\n" , " \n" , " \n" , " \n" , " \n" , " \n" , "" ] codegenJavaScript :: CodeGenerator codegenJavaScript ci = let (h, f) = if (map toLower $ takeExtension $ outputFile ci) == ".html" then (htmlHeader, htmlFooter) else ("","") in codegenJs (CGConf { header = h , footer = f , jsbnPath = "jsbn/jsbn-browser.js" , extraRunTime = "Runtime-javascript.js" } ) ci codegenNode :: CodeGenerator codegenNode ci = do codegenJs (CGConf { header = "#!/usr/bin/env node\n" , footer = "" , jsbnPath = "jsbn/jsbn-browser.js" , extraRunTime = "Runtime-node.js" } ) ci setPermissions (outputFile ci) (emptyPermissions { readable = True , executable = True , writable = True })