Skip to content

Commit 0ddd68e

Browse files
committed
Merge branch 'gren-0.2.0'
2 parents 4114e9f + 4569b29 commit 0ddd68e

File tree

25 files changed

+27026
-31260
lines changed

25 files changed

+27026
-31260
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.gren
2+
app
23
node_modules
34

45
.idea

Makefile

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
common_examples := counter\
2-
files\
3-
flight_booker\
4-
hello_world\
5-
temperature_converter\
6-
timer\
7-
local_storage
1+
browser_examples := \
2+
counter\
3+
files\
4+
flight_booker\
5+
hello_world\
6+
temperature_converter\
7+
timer\
8+
local_storage\
9+
todo_mvc
810

9-
all_examples := $(common_examples) todo_mvc
11+
node_examples := cat
12+
13+
all_examples := $(browser_examples) $(node_examples)
1014

1115
project_caches := $(foreach project, $(all_examples), $(project)/.gren)
1216

@@ -21,12 +25,12 @@ clean:
2125
rm -r $(project_caches)
2226
@echo "Done"
2327

24-
$(common_examples):
28+
$(browser_examples):
2529
@echo "Compiling $@"
2630
@cd "./$@/";\
2731
gren make ./src/Main.gren --output=./Example.html
2832

29-
todo_mvc:
33+
$(node_examples):
3034
@echo "Compiling $@"
3135
@cd "./$@/";\
32-
gren make ./src/Main.gren --output=./Example.js
36+
gren make ./src/Main.gren --optimize --output=./app

cat/gren.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "application",
3+
"platform": "node",
4+
"source-directories": [
5+
"src"
6+
],
7+
"gren-version": "0.2.0",
8+
"dependencies": {
9+
"direct": {
10+
"gren-lang/core": "3.0.0",
11+
"gren-lang/node": "1.0.0"
12+
},
13+
"indirect": {}
14+
}
15+
}

cat/src/Main.gren

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
module Main exposing (main)
2+
3+
import Node
4+
import Bytes exposing (Bytes)
5+
import Bytes.Encode as BE
6+
import Stream exposing (Stream)
7+
import Node.Program as Program exposing (Program)
8+
import FileSystem
9+
import Task
10+
11+
12+
main : Program Model Msg
13+
main =
14+
Program.define
15+
{ init = init
16+
, update = update
17+
, subscriptions = \_ -> Sub.none
18+
}
19+
20+
21+
type alias Model =
22+
{ stdout : Stream }
23+
24+
25+
type Msg
26+
= OpenResult (Result FileSystem.AccessError (FileSystem.ReadableFileHandle Never))
27+
| ReadResult (Result FileSystem.UnknownFileSystemError Bytes)
28+
29+
30+
init : Program.AppInitTask { model : Model, command : Cmd Msg }
31+
init =
32+
Program.await Node.initialize <| \nodeConfig ->
33+
Program.await FileSystem.initialize <| \fsPermission ->
34+
Program.startProgram
35+
{ model =
36+
{ stdout = nodeConfig.stdout
37+
}
38+
, command =
39+
case nodeConfig.args of
40+
[ _, _, file ] ->
41+
FileSystem.openForRead fsPermission file
42+
|> Task.attempt OpenResult
43+
44+
_ ->
45+
Stream.send nodeConfig.stderr <|
46+
BE.encode <|
47+
BE.string "Exactly one argument is required: the file name to read\n"
48+
}
49+
50+
51+
update : Msg -> Model -> { model : Model, command : Cmd Msg }
52+
update msg model =
53+
case msg of
54+
OpenResult (Ok fh) ->
55+
{ model = model
56+
, command =
57+
FileSystem.read fh
58+
|> Task.attempt ReadResult
59+
}
60+
61+
OpenResult (Err error) ->
62+
{ model = model
63+
, command = Cmd.none
64+
}
65+
66+
ReadResult (Ok bytes) ->
67+
{ model = model
68+
, command = Stream.send model.stdout bytes
69+
}
70+
71+
ReadResult (Err error) ->
72+
{ model = model
73+
, command = Cmd.none
74+
}
75+

0 commit comments

Comments
 (0)