mirror of
https://github.com/gren-lang/compiler.git
synced 2024-09-11 08:45:42 +03:00
Add NodeJS wrapper, which executes the main function when run under Node.
This commit is contained in:
parent
71f4fd97f3
commit
71af2c99b9
33
compiler/src/Generate/Node.hs
Normal file
33
compiler/src/Generate/Node.hs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
|
|
||||||
|
module Generate.Node
|
||||||
|
( sandwich,
|
||||||
|
)
|
||||||
|
where
|
||||||
|
|
||||||
|
import Data.ByteString.Builder qualified as B
|
||||||
|
import Data.Name qualified as Name
|
||||||
|
import Text.RawString.QQ (r)
|
||||||
|
|
||||||
|
-- SANDWICH
|
||||||
|
|
||||||
|
sandwich :: Name.Name -> B.Builder -> B.Builder
|
||||||
|
sandwich moduleName javascript =
|
||||||
|
let name = Name.toBuilder moduleName
|
||||||
|
in [r|#!/usr/bin/env node
|
||||||
|
|
||||||
|
try {
|
||||||
|
|]
|
||||||
|
<> javascript
|
||||||
|
<> [r|
|
||||||
|
|]
|
||||||
|
<> [r|this.Gren.|]
|
||||||
|
<> name
|
||||||
|
<> [r|.init({});
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
|]
|
@ -134,6 +134,7 @@ Common gren-common
|
|||||||
Canonicalize.Type
|
Canonicalize.Type
|
||||||
Compile
|
Compile
|
||||||
Generate.Html
|
Generate.Html
|
||||||
|
Generate.Node
|
||||||
Generate.JavaScript
|
Generate.JavaScript
|
||||||
Generate.JavaScript.Builder
|
Generate.JavaScript.Builder
|
||||||
Generate.JavaScript.Expression
|
Generate.JavaScript.Expression
|
||||||
|
@ -21,6 +21,7 @@ import Directories qualified as Dirs
|
|||||||
import File qualified
|
import File qualified
|
||||||
import Generate qualified
|
import Generate qualified
|
||||||
import Generate.Html qualified as Html
|
import Generate.Html qualified as Html
|
||||||
|
import Generate.Node qualified as Node
|
||||||
import Gren.Details qualified as Details
|
import Gren.Details qualified as Details
|
||||||
import Gren.ModuleName qualified as ModuleName
|
import Gren.ModuleName qualified as ModuleName
|
||||||
import Gren.Outline qualified as Outline
|
import Gren.Outline qualified as Outline
|
||||||
@ -92,6 +93,10 @@ runHelp root paths style (Flags debug optimize maybeOutput _ maybeDocs) =
|
|||||||
do
|
do
|
||||||
builder <- toBuilder root details desiredMode artifacts
|
builder <- toBuilder root details desiredMode artifacts
|
||||||
generate style "index.html" (Html.sandwich name builder) (NE.List name [])
|
generate style "index.html" (Html.sandwich name builder) (NE.List name [])
|
||||||
|
(Platform.Node, [name]) ->
|
||||||
|
do
|
||||||
|
builder <- toBuilder root details desiredMode artifacts
|
||||||
|
generate style "gren.js" (Node.sandwich name builder) (NE.List name [])
|
||||||
(_, name : names) ->
|
(_, name : names) ->
|
||||||
do
|
do
|
||||||
builder <- toBuilder root details desiredMode artifacts
|
builder <- toBuilder root details desiredMode artifacts
|
||||||
|
Loading…
Reference in New Issue
Block a user