├── .gitignore ├── README.md ├── benchmarks ├── .gitignore ├── clio.toml └── src │ ├── main.clio │ └── tests │ ├── fib │ ├── fib.clio │ └── fib.js │ ├── jimp │ ├── grey.clio │ ├── grey.js │ └── images │ │ ├── img1.jpg │ │ ├── img10.jpg │ │ ├── img11.jpg │ │ ├── img12.jpg │ │ ├── img13.jpg │ │ ├── img14.jpg │ │ ├── img15.jpg │ │ ├── img16.jpg │ │ ├── img2.jpg │ │ ├── img3.jpg │ │ ├── img4.jpg │ │ ├── img5.jpg │ │ ├── img6.jpg │ │ ├── img7.jpg │ │ ├── img8.jpg │ │ ├── img9.jpg │ │ └── low │ │ ├── img1.jpg │ │ ├── img10.jpg │ │ ├── img11.jpg │ │ ├── img12.jpg │ │ ├── img13.jpg │ │ ├── img14.jpg │ │ ├── img15.jpg │ │ ├── img16.jpg │ │ ├── img2.jpg │ │ ├── img3.jpg │ │ ├── img4.jpg │ │ ├── img5.jpg │ │ ├── img6.jpg │ │ ├── img7.jpg │ │ ├── img8.jpg │ │ └── img9.jpg │ └── primes │ ├── primes.clio │ └── primes.js ├── channel-client ├── .gitignore ├── clio.toml └── src │ └── main.clio ├── channel ├── .gitignore ├── clio.toml └── src │ └── main.clio ├── express ├── .gitignore ├── clio.toml └── src │ └── main.clio ├── fib-parallel ├── .DS_Store ├── .gitignore ├── clio.toml └── src │ └── main.clio ├── fib ├── .gitignore ├── clio.toml └── src │ └── main.clio ├── game ├── .gitignore ├── clio.toml └── src │ ├── main.clio │ ├── public │ └── index.html │ └── rollup.config.js ├── hello ├── .gitignore ├── clio.toml └── src │ └── main.clio ├── mandelbrot ├── .gitignore ├── clio.toml └── src │ ├── main.clio │ ├── public │ └── index.html │ └── rollup.config.js ├── todo ├── client │ ├── .gitignore │ ├── clio.toml │ └── src │ │ ├── main.clio │ │ ├── public │ │ ├── index.html │ │ └── style.css │ │ └── rollup.config.js └── server │ ├── .gitignore │ ├── clio.toml │ └── src │ └── main.clio └── web ├── .gitignore ├── clio.toml └── src ├── main.clio ├── public └── index.html └── rollup.config.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Clio examples 2 | 3 | To run each of the examples, `cd` into the example directory and run `clio run`. 4 | -------------------------------------------------------------------------------- /benchmarks/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Make sure this directory matches what you defined as 7 | # build.directory in clio.toml file (default is build) 8 | build/ 9 | 10 | # Clio specific cache directories 11 | .clio-cache 12 | clio_env 13 | 14 | # Dependency directories 15 | node_modules/ 16 | 17 | .npm 18 | 19 | # Output of 'npm pack' 20 | *.tgz 21 | 22 | # dotenv environment variables file 23 | .env 24 | .env.test 25 | 26 | # parcel-bundler cache (https://parceljs.org/) 27 | .cache 28 | -------------------------------------------------------------------------------- /benchmarks/clio.toml: -------------------------------------------------------------------------------- 1 | title = "template-node" 2 | description = "" 3 | version = "0.1.0" 4 | license = "MIT" 5 | authors = [ "Your Name " ] 6 | keywords = "" 7 | 8 | [build] 9 | source = "src" 10 | destination = "build" 11 | target = "js" 12 | 13 | [scripts] 14 | test = "No tests specified" 15 | 16 | [[servers]] 17 | proto = "wt" 18 | name = "default" 19 | 20 | [[workers]] 21 | proto = "wt" 22 | count = "cpu" 23 | server = "default" 24 | 25 | [executor] 26 | proto = "wt" 27 | wait_for = "cpu" 28 | server = "default" 29 | 30 | [npm.dependencies] 31 | benny = "3.6.15" 32 | node-fetch = "2.6.1" 33 | jimp = "0.16.1" 34 | 35 | [npm.scripts] 36 | start = "node .clio/index.js" 37 | host = "node .clio/host.js" -------------------------------------------------------------------------------- /benchmarks/src/main.clio: -------------------------------------------------------------------------------- 1 | import "cjs:benny" 2 | from "./tests/fib/fib.clio" import fib 3 | from "cjs:./tests/fib/fib.js" import fib as jsFib 4 | from "./tests/primes/primes.clio" import isPrime 5 | from "cjs:./tests/primes/primes.js" import isPrime as jsIsPrime 6 | from "./tests/jimp/grey.clio" import grey 7 | from "cjs:./tests/jimp/grey.js" import grey as jsGrey 8 | 9 | all30 = [30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30] 10 | fibdata = 20..36 -> .toArray 11 | 12 | fn clioFib30Test: 13 | all30 -> * fib 14 | 15 | fn clioParallelFib30Test: 16 | all30 -> * [await] |fib| 17 | 18 | fn jsFib30Test: 19 | all30 -> * jsFib 20 | 21 | fn clioFibTest: 22 | fibdata -> * fib 23 | 24 | fn clioParallelFibTest: 25 | fibdata -> * [await] |fib| 26 | 27 | fn jsFibTest: 28 | fibdata -> * jsFib 29 | 30 | fn clioJimpTest: 31 | 1..16 -> .toArray -> * [await] grey 32 | 33 | fn clioParallelJimpTest: 34 | 1..16 -> .toArray -> * [await] |grey| 35 | 36 | fn jsJimpTest: 37 | 1..16 -> .toArray -> * [await] jsGrey 38 | 39 | fn clioPrimesTest: 40 | 1..16000 -> .toArray -> * isPrime -> .filter Boolean 41 | 42 | fn parallelIsPrime start: 43 | (start * 1000 + 1)..((start + 1) * 1000) -> .toArray -> * isPrime -> .filter Boolean 44 | 45 | fn clioParallelPrimesTest: 46 | 0..16 -> .toArray -> * [await] |parallelIsPrime| -> .flat 47 | 48 | fn jsPrimesTest: 49 | 1..16000 -> .toArray -> * isPrime -> .filter Boolean 50 | 51 | export fn main argv: 52 | await benny.suite.apply null [ 53 | "Clio benchmark (Jimp)" 54 | (benny.add "Clio - Jimp" clioJimpTest) 55 | (benny.add "Clio - Jimp (Parallel)" clioParallelJimpTest) 56 | (benny.add "JS - Jimp" jsJimpTest) 57 | (benny -> .cycle) 58 | (benny -> .complete) 59 | (benny -> .save # format: "chart.html" file: "jimp") 60 | ] 61 | await benny.suite.apply null [ 62 | "Clio benchmark (Primes)" 63 | (benny.add "Clio - Primes" clioPrimesTest) 64 | (benny.add "Clio - Primes (Parallel)" clioParallelPrimesTest) 65 | (benny.add "JS - Primes" jsPrimesTest) 66 | (benny -> .cycle) 67 | (benny -> .complete) 68 | (benny -> .save # format: "chart.html" file: "primes") 69 | ] 70 | await benny.suite.apply null [ 71 | "Clio benchmark (Fib 30)" 72 | (benny.add "Clio - Fib" clioFib30Test) 73 | (benny.add "Clio - Fib (Parallel)" clioParallelFib30Test) 74 | (benny.add "JS - Fib" jsFib30Test) 75 | (benny -> .cycle) 76 | (benny -> .complete) 77 | (benny -> .save # format: "chart.html" file: "fib.30") 78 | ] 79 | await benny.suite.apply null [ 80 | "Clio benchmark (Fib 30..46)" 81 | (benny.add "Clio - Fib" clioFibTest) 82 | (benny.add "Clio - Fib (Parallel)" clioParallelFibTest) 83 | (benny.add "JS - Fib" jsFibTest) 84 | (benny -> .cycle) 85 | (benny -> .complete) 86 | (benny -> .save # format: "chart.html" file: "fib.range") 87 | ] 88 | process -> .exit 0 -------------------------------------------------------------------------------- /benchmarks/src/tests/fib/fib.clio: -------------------------------------------------------------------------------- 1 | export fn fib n: 2 | if n < 2: n 3 | else: (fib n - 1) 4 | + (fib n - 2) -------------------------------------------------------------------------------- /benchmarks/src/tests/fib/fib.js: -------------------------------------------------------------------------------- 1 | const fib = (n) => { 2 | if (n < 2) return n; 3 | else return fib(n - 1) + fib(n - 2); 4 | }; 5 | module.exports.fib = fib; 6 | -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/grey.clio: -------------------------------------------------------------------------------- 1 | import "cjs:jimp" 2 | 3 | export fn grey index: 4 | img = await jimp.read f"tests/jimp/images/low/img{index}.jpg" -> .greyscale 5 | img.bitmap.width * img.bitmap.height 6 | -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/grey.js: -------------------------------------------------------------------------------- 1 | const Jimp = require("jimp"); 2 | 3 | module.exports.grey = async (index) => { 4 | const img = await Jimp.read(`tests/jimp/images/low/img${index}.jpg`); 5 | img.greyscale(); 6 | return img.bitmap.width * img.bitmap.height; 7 | }; 8 | -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img1.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img10.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img11.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img12.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img13.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img14.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img15.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img16.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img2.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img3.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img4.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img5.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img6.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img7.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img8.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/img9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/img9.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img1.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img10.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img11.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img12.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img12.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img13.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img13.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img14.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img14.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img15.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img15.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img16.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img16.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img2.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img3.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img4.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img5.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img6.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img7.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img8.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/jimp/images/low/img9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/benchmarks/src/tests/jimp/images/low/img9.jpg -------------------------------------------------------------------------------- /benchmarks/src/tests/primes/primes.clio: -------------------------------------------------------------------------------- 1 | export fn isPrime n: 2 | if n == 2 or n == 3 or n == 5 or n == 7: true 3 | else if n < 2 or n % 2 == 0: false 4 | else: 5 | 1..(n ** 0.5) 6 | -> .toArray 7 | -> .every (@i % n > 0) 8 | -------------------------------------------------------------------------------- /benchmarks/src/tests/primes/primes.js: -------------------------------------------------------------------------------- 1 | module.exports.isPrime = (n) => { 2 | if (n == 2 || n == 3 || n == 5 || n == 7) { 3 | return true; 4 | } else if (n < 2 || n % 2 == 0) { 5 | return false; 6 | } else { 7 | return new Array(Math.ceil(n ** (1 / 2)) - 1) 8 | .fill() 9 | .map((_, i) => i + 1) 10 | .every((i) => i % n > 0); 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /channel-client/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Make sure this directory matches what you defined as 7 | # build.directory in clio.toml file (default is build) 8 | build/ 9 | 10 | # Clio specific cache directories 11 | .clio-cache 12 | clio_env 13 | 14 | # Dependency directories 15 | node_modules/ 16 | 17 | .npm 18 | 19 | # Output of 'npm pack' 20 | *.tgz 21 | 22 | # dotenv environment variables file 23 | .env 24 | .env.test 25 | 26 | # parcel-bundler cache (https://parceljs.org/) 27 | .cache 28 | -------------------------------------------------------------------------------- /channel-client/clio.toml: -------------------------------------------------------------------------------- 1 | title = "template-node" 2 | description = "" 3 | version = "0.1.0" 4 | license = "MIT" 5 | authors = [ "Your Name " ] 6 | keywords = "" 7 | 8 | [build] 9 | source = "src" 10 | destination = "build" 11 | target = "js" 12 | 13 | [scripts] 14 | test = "No tests specified" 15 | 16 | [npm_dependencies] 17 | #express = "^4.17.1" 18 | 19 | [[servers]] 20 | proto = "wt" 21 | name = "default" 22 | 23 | [[workers]] 24 | proto = "wt" 25 | count = "cpu" 26 | server = "default" 27 | 28 | [executor] 29 | proto = "wt" 30 | wait_for = "cpu" 31 | server = "default" 32 | 33 | [npm.scripts] 34 | start = "node .clio/index.js" 35 | host = "node .clio/host.js" -------------------------------------------------------------------------------- /channel-client/src/main.clio: -------------------------------------------------------------------------------- 1 | from "ws:localhost:1337/ping@0.1.0/main.clio" import pingPong 2 | 3 | fn onPong: 4 | console.log "Pong received" 5 | 6 | export fn main: 7 | await pingPong () 8 | => ch 9 | -> .on "pong" onPong 10 | 11 | fn ping: 12 | ch -> .emit "ping" 13 | 14 | setInterval ping 1000 -------------------------------------------------------------------------------- /channel/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Make sure this directory matches what you defined as 7 | # build.directory in clio.toml file (default is build) 8 | build/ 9 | 10 | # Clio specific cache directories 11 | .clio-cache 12 | clio_env 13 | 14 | # Dependency directories 15 | node_modules/ 16 | 17 | .npm 18 | 19 | # Output of 'npm pack' 20 | *.tgz 21 | 22 | # dotenv environment variables file 23 | .env 24 | .env.test 25 | 26 | # parcel-bundler cache (https://parceljs.org/) 27 | .cache 28 | -------------------------------------------------------------------------------- /channel/clio.toml: -------------------------------------------------------------------------------- 1 | title = "ping" 2 | description = "" 3 | version = "0.1.0" 4 | license = "MIT" 5 | authors = [ "Your Name " ] 6 | keywords = "" 7 | 8 | [build] 9 | source = "src" 10 | destination = "build" 11 | target = "js" 12 | 13 | [scripts] 14 | test = "No tests specified" 15 | 16 | [[servers]] 17 | proto = "ws" 18 | port = 1337 19 | host = "0.0.0.0" 20 | name = "default" 21 | 22 | [[workers]] 23 | proto = "ws" 24 | url = "ws://localhost:1337" 25 | count = "cpu" 26 | server = "default" 27 | 28 | [executor] 29 | proto = "ws" 30 | url = "ws://localhost:1337" 31 | wait_for = "cpu" 32 | server = "default" 33 | 34 | [npm.scripts] 35 | start = "node .clio/index.js" 36 | host = "node .clio/host.js" -------------------------------------------------------------------------------- /channel/src/main.clio: -------------------------------------------------------------------------------- 1 | fn onPing ch: 2 | fn onPingInner: 3 | console.log "Ping received" 4 | ch -> .emit "pong" 5 | 6 | export fn pingPong: 7 | emitter () 8 | => ch 9 | -> .on "ping" (onPing ch) 10 | -------------------------------------------------------------------------------- /express/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Make sure this directory matches what you defined as 7 | # build.directory in clio.toml file (default is build) 8 | build/ 9 | 10 | # Clio specific cache directories 11 | .clio-cache 12 | clio_env 13 | 14 | # Dependency directories 15 | node_modules/ 16 | 17 | .npm 18 | 19 | # Output of 'npm pack' 20 | *.tgz 21 | 22 | # dotenv environment variables file 23 | .env 24 | .env.test 25 | 26 | # parcel-bundler cache (https://parceljs.org/) 27 | .cache 28 | -------------------------------------------------------------------------------- /express/clio.toml: -------------------------------------------------------------------------------- 1 | title = "template-node" 2 | description = "" 3 | version = "0.1.0" 4 | license = "MIT" 5 | authors = [ "Your Name " ] 6 | keywords = "" 7 | 8 | [build] 9 | source = "src" 10 | destination = "build" 11 | target = "js" 12 | 13 | [scripts] 14 | test = "No tests specified" 15 | 16 | [[servers]] 17 | proto = "wt" 18 | name = "default" 19 | 20 | [[workers]] 21 | proto = "wt" 22 | count = "cpu" 23 | server = "default" 24 | 25 | [executor] 26 | proto = "wt" 27 | wait_for = "cpu" 28 | server = "default" 29 | 30 | [npm.dependencies] 31 | express = "4.17.1" 32 | 33 | [npm.scripts] 34 | start = "node .clio/index.js" 35 | host = "node .clio/host.js" -------------------------------------------------------------------------------- /express/src/main.clio: -------------------------------------------------------------------------------- 1 | import "esm:express" 2 | 3 | fn hello req res: 4 | "Hello world" -> res.send 5 | 6 | export fn main argv: 7 | express () => app 8 | app.get "/" hello 9 | app.listen 3000 -------------------------------------------------------------------------------- /fib-parallel/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/clio-lang/examples/a4f151187c1c7fe7a142cf72dc32d6845502bb6a/fib-parallel/.DS_Store -------------------------------------------------------------------------------- /fib-parallel/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Make sure this directory matches what you defined as 7 | # build.directory in clio.toml file (default is build) 8 | build/ 9 | 10 | # Clio specific cache directories 11 | .clio-cache 12 | clio_env 13 | 14 | # Dependency directories 15 | node_modules/ 16 | 17 | .npm 18 | 19 | # Output of 'npm pack' 20 | *.tgz 21 | 22 | # dotenv environment variables file 23 | .env 24 | .env.test 25 | 26 | # parcel-bundler cache (https://parceljs.org/) 27 | .cache 28 | -------------------------------------------------------------------------------- /fib-parallel/clio.toml: -------------------------------------------------------------------------------- 1 | title = "template-node" 2 | description = "" 3 | version = "0.1.0" 4 | license = "MIT" 5 | authors = [ "Your Name " ] 6 | keywords = "" 7 | 8 | [build] 9 | source = "src" 10 | destination = "build" 11 | target = "js" 12 | 13 | [scripts] 14 | test = "No tests specified" 15 | 16 | [[servers]] 17 | proto = "tcp" 18 | name = "default" 19 | 20 | [[workers]] 21 | proto = "tcp" 22 | count = "cpu" 23 | server = "default" 24 | 25 | [executor] 26 | proto = "tcp" 27 | wait_for = "cpu" 28 | server = "default" 29 | 30 | [npm.scripts] 31 | start = "node .clio/index.js" 32 | host = "node .clio/host.js" -------------------------------------------------------------------------------- /fib-parallel/src/main.clio: -------------------------------------------------------------------------------- 1 | fn fib n: 2 | if n < 2: n 3 | else: (fib n - 1) 4 | + (fib n - 2) 5 | 6 | export fn main argv: 7 | [39 40 41 42] 8 | -> * [await] |fib| 9 | -> * (console.log @item) -------------------------------------------------------------------------------- /fib/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Make sure this directory matches what you defined as 7 | # build.directory in clio.toml file (default is build) 8 | build/ 9 | 10 | # Clio specific cache directories 11 | .clio-cache 12 | clio_env 13 | 14 | # Dependency directories 15 | node_modules/ 16 | 17 | .npm 18 | 19 | # Output of 'npm pack' 20 | *.tgz 21 | 22 | # dotenv environment variables file 23 | .env 24 | .env.test 25 | 26 | # parcel-bundler cache (https://parceljs.org/) 27 | .cache 28 | -------------------------------------------------------------------------------- /fib/clio.toml: -------------------------------------------------------------------------------- 1 | title = "template-node" 2 | description = "" 3 | version = "0.1.0" 4 | license = "MIT" 5 | authors = [ "Your Name " ] 6 | keywords = "" 7 | 8 | [build] 9 | source = "src" 10 | destination = "build" 11 | target = "js" 12 | 13 | [scripts] 14 | test = "No tests specified" 15 | 16 | [[servers]] 17 | proto = "wt" 18 | name = "default" 19 | 20 | [[workers]] 21 | proto = "wt" 22 | count = "cpu" 23 | server = "default" 24 | 25 | [executor] 26 | proto = "wt" 27 | wait_for = "cpu" 28 | server = "default" 29 | 30 | [npm.scripts] 31 | start = "node .clio/index.js" 32 | host = "node .clio/host.js" -------------------------------------------------------------------------------- /fib/src/main.clio: -------------------------------------------------------------------------------- 1 | fn fib n: 2 | if n < 2: n 3 | else: (fib n - 1) 4 | + (fib n - 2) 5 | 6 | export fn main argv: 7 | [37 38 39 40] 8 | -> * [await] |fib| 9 | -> console.log -------------------------------------------------------------------------------- /game/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Make sure this directory matches what you defined as 7 | # build.directory in clio.toml file (default is build) 8 | build/ 9 | 10 | # Clio specific cache directories 11 | .clio-cache 12 | clio_env 13 | 14 | # Dependency directories 15 | node_modules/ 16 | 17 | .npm 18 | 19 | # Output of 'npm pack' 20 | *.tgz 21 | 22 | # dotenv environment variables file 23 | .env 24 | .env.test 25 | 26 | # parcel-bundler cache (https://parceljs.org/) 27 | .cache 28 | -------------------------------------------------------------------------------- /game/clio.toml: -------------------------------------------------------------------------------- 1 | title = "template-web" 2 | description = "" 3 | version = "0.1.0" 4 | license = "MIT" 5 | authors = [ "Your Name " ] 6 | keywords = "" 7 | 8 | [build] 9 | source = "src" 10 | destination = "build" 11 | target = "js" 12 | 13 | [scripts] 14 | test = "No tests specified" 15 | 16 | [[servers]] 17 | proto = "ww" 18 | name = "default" 19 | 20 | [[workers]] 21 | proto = "ww" 22 | count = "cpu" 23 | server = "default" 24 | 25 | [executor] 26 | proto = "ww" 27 | wait_for = "cpu" 28 | server = "default" 29 | 30 | # Npm specific configs 31 | 32 | [npm] 33 | browserslist = ["defaults", "not IE 11"] 34 | 35 | [npm.devDependencies] 36 | rollup = "^2.56.2" 37 | sirv-cli = "^1.0.12" 38 | clio-rollup = "latest" 39 | "@babel/preset-env" = "^7.15.0" 40 | 41 | [npm.scripts] 42 | host = "node .clio/host.js" 43 | build = "rollup -c" 44 | dev = "rollup -c -w" 45 | start = "npm run build && sirv public" 46 | -------------------------------------------------------------------------------- /game/src/main.clio: -------------------------------------------------------------------------------- 1 | fn random: Math.random () -> Math.round 2 | fn row _ width: 0..width -> * random -> .toArray 3 | fn slicer x: (x - 1) .. (x + 2) -> .toArray -> .filter (@it >= 0) 4 | 5 | fn tickCol cell board y x row: 6 | score = [board[y - 1] row board[y + 1]] 7 | -> .filter Boolean 8 | -> * slice (slicer x) 9 | -> .flat 10 | -> .reduce (@left + @right) (0 - cell) 11 | 12 | if score == 3: 1 else if score == 2: cell else: 0 13 | 14 | fn tickRow row y board: row -> * tickCol board y 15 | 16 | fn drawCol col ctx y x: 17 | ctx.fillStyle = col and "#282a36" or "#dfe4eb" 18 | ctx.fillRect (x * 5) (y * 5) 4 4 19 | 20 | fn drawRow row ctx y: row -> * drawCol ctx y 21 | fn draw board ctx: board -> * drawRow ctx 22 | 23 | fn tick width height board ctx time fps: 24 | now = performance.now () 25 | fps.innerText = Math.round (6000 / (now - time)) 26 | draw board ctx 27 | next = board -> * [await] |tickRow| 28 | fn nextTick: tick width height next ctx now fps 29 | requestAnimationFrame nextTick 30 | 31 | fn gameOfLife width height ctx fps: 32 | board = 0..height -> * row width -> .toArray 33 | now = performance.now () 34 | tick width height board ctx now fps 35 | 36 | export fn main argv: 37 | fps = document.getElementById "fps" 38 | canvas = document.getElementById "game" 39 | canvas.width = 128 * 5 -- let each cell be 4x4 pixels 40 | canvas.height = 128 * 5 -- with 1 pixel empty in between 41 | ctx = canvas.getContext "2d" 42 | gameOfLife 128 128 ctx fps -------------------------------------------------------------------------------- /game/src/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Game of Life 8 | 46 | 47 | 48 |
49 |

Clio - Game of Life

50 | 51 |
fps - 16384 cells
52 |
53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /game/src/rollup.config.js: -------------------------------------------------------------------------------- 1 | export { default } from "clio-rollup"; 2 | -------------------------------------------------------------------------------- /hello/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Make sure this directory matches what you defined as 7 | # build.directory in clio.toml file (default is build) 8 | build/ 9 | 10 | # Clio specific cache directories 11 | .clio-cache 12 | clio_env 13 | 14 | # Dependency directories 15 | node_modules/ 16 | 17 | .npm 18 | 19 | # Output of 'npm pack' 20 | *.tgz 21 | 22 | # dotenv environment variables file 23 | .env 24 | .env.test 25 | 26 | # parcel-bundler cache (https://parceljs.org/) 27 | .cache 28 | -------------------------------------------------------------------------------- /hello/clio.toml: -------------------------------------------------------------------------------- 1 | title = "template-node" 2 | description = "" 3 | version = "0.1.0" 4 | license = "MIT" 5 | authors = [ "Your Name " ] 6 | keywords = "" 7 | 8 | [build] 9 | source = "src" 10 | destination = "build" 11 | target = "js" 12 | 13 | [scripts] 14 | test = "No tests specified" 15 | 16 | [[servers]] 17 | proto = "wt" 18 | name = "default" 19 | 20 | [[workers]] 21 | proto = "wt" 22 | count = "cpu" 23 | server = "default" 24 | 25 | [executor] 26 | proto = "wt" 27 | wait_for = "cpu" 28 | server = "default" 29 | 30 | [npm.scripts] 31 | start = "node .clio/index.js" 32 | host = "node .clio/host.js" -------------------------------------------------------------------------------- /hello/src/main.clio: -------------------------------------------------------------------------------- 1 | export fn main argv: 2 | "Hello World" -> console.log 3 | -------------------------------------------------------------------------------- /mandelbrot/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Make sure this directory matches what you defined as 7 | # build.directory in clio.toml file (default is build) 8 | build/ 9 | 10 | # Clio specific cache directories 11 | .clio-cache 12 | clio_env 13 | 14 | # Dependency directories 15 | node_modules/ 16 | 17 | .npm 18 | 19 | # Output of 'npm pack' 20 | *.tgz 21 | 22 | # dotenv environment variables file 23 | .env 24 | .env.test 25 | 26 | # parcel-bundler cache (https://parceljs.org/) 27 | .cache 28 | -------------------------------------------------------------------------------- /mandelbrot/clio.toml: -------------------------------------------------------------------------------- 1 | title = "template-web" 2 | description = "" 3 | version = "0.1.0" 4 | license = "MIT" 5 | authors = [ "Your Name " ] 6 | keywords = "" 7 | 8 | [build] 9 | source = "src" 10 | destination = "build" 11 | target = "js" 12 | 13 | [scripts] 14 | test = "No tests specified" 15 | 16 | [[servers]] 17 | proto = "ww" 18 | name = "default" 19 | 20 | [[workers]] 21 | proto = "ww" 22 | count = "cpu" 23 | server = "default" 24 | 25 | [executor] 26 | proto = "ww" 27 | wait_for = "cpu" 28 | server = "default" 29 | 30 | # Npm specific configs 31 | 32 | [npm] 33 | browserslist = ["defaults", "not IE 11"] 34 | 35 | [npm.devDependencies] 36 | rollup = "^2.56.2" 37 | sirv-cli = "^1.0.12" 38 | clio-rollup = "latest" 39 | "@babel/preset-env" = "^7.15.0" 40 | 41 | [npm.scripts] 42 | host = "node .clio/host.js" 43 | build = "rollup -c" 44 | dev = "rollup -c -w" 45 | start = "npm run build && sirv public" 46 | -------------------------------------------------------------------------------- /mandelbrot/src/main.clio: -------------------------------------------------------------------------------- 1 | fn complex real imag: 2 | # real: real imag: imag 3 | 4 | fn complexAdd lhs rhs: 5 | # real: (lhs.real + rhs.real) 6 | imag: (lhs.imag + rhs.imag) 7 | 8 | fn complexMul lhs rhs: 9 | # real: (lhs.real * rhs.real - lhs.imag * rhs.imag) 10 | imag: (lhs.real * rhs.imag + rhs.real * lhs.imag) 11 | 12 | fn complexAbs number: 13 | (number.real ** 2 + number.imag ** 2) ** 0.5 14 | 15 | fn mandelbrot initial number iter: 16 | result = complexMul number number -> complexAdd initial 17 | if iter and (complexAbs result) < 2: mandelbrot initial result (iter - 1) 18 | else: iter 19 | 20 | fn calculateCell x y width height: 21 | number = complex (3.675 * (x / width) - 2.325) (4 * (y / height) - 2) 22 | result = mandelbrot number number 1000 23 | # x: x y: y m: result 24 | 25 | fn calculateRow y width height: 26 | 0..width -> .toArray -> * calculateCell y width height 27 | 28 | fn drawCell cell ctx: 29 | ctx.fillStyle = f"hsl({cell.m/1000*569},66%,50%)" 30 | ctx.fillRect cell.x cell.y 1 1 31 | 32 | fn drawRow promise ctx: 33 | await promise -> * drawCell ctx 34 | 35 | fn draw width height ctx: 36 | 0..height -> .toArray -> * |calculateRow| width height -> * drawRow ctx 37 | 38 | export fn main argv: 39 | canvas = document.getElementById "mandelbrot" 40 | canvas.width = 1024 41 | canvas.height = 1024 42 | ctx = canvas.getContext "2d" 43 | draw 1024 1024 ctx -------------------------------------------------------------------------------- /mandelbrot/src/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Mandelbrot 8 | 47 | 48 | 49 |
50 |

Clio - Mandelbrot

51 | 52 |
1024x1024 points - 1000 recursions / point
53 |
54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /mandelbrot/src/rollup.config.js: -------------------------------------------------------------------------------- 1 | export { default } from "clio-rollup"; 2 | -------------------------------------------------------------------------------- /todo/client/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Make sure this directory matches what you defined as 7 | # build.directory in clio.toml file (default is build) 8 | build/ 9 | 10 | # Clio specific cache directories 11 | .clio-cache 12 | clio_env 13 | 14 | # Dependency directories 15 | node_modules/ 16 | 17 | .npm 18 | 19 | # Output of 'npm pack' 20 | *.tgz 21 | 22 | # dotenv environment variables file 23 | .env 24 | .env.test 25 | 26 | # parcel-bundler cache (https://parceljs.org/) 27 | .cache 28 | -------------------------------------------------------------------------------- /todo/client/clio.toml: -------------------------------------------------------------------------------- 1 | title = "todo-client" 2 | description = "" 3 | version = "0.1.0" 4 | license = "MIT" 5 | authors = [ "Your Name " ] 6 | keywords = "" 7 | 8 | [build] 9 | source = "src" 10 | destination = "build" 11 | target = "js" 12 | 13 | [scripts] 14 | test = "No tests specified" 15 | 16 | [[servers]] 17 | proto = "ww" 18 | name = "default" 19 | 20 | [[workers]] 21 | proto = "ww" 22 | count = "cpu" 23 | server = "default" 24 | 25 | [executor] 26 | proto = "ww" 27 | wait_for = "cpu" 28 | server = "default" 29 | 30 | # Npm specific configs 31 | 32 | [npm] 33 | browserslist = ["defaults", "not IE 11"] 34 | 35 | [npm.devDependencies] 36 | rollup = "^2.56.2" 37 | sirv-cli = "^1.0.12" 38 | clio-rollup = "latest" 39 | "@babel/preset-env" = "^7.15.0" 40 | 41 | [npm.scripts] 42 | host = "node .clio/host.js" 43 | build = "rollup -c" 44 | dev = "rollup -c -w" 45 | start = "npm run build && sirv public" 46 | -------------------------------------------------------------------------------- /todo/client/src/main.clio: -------------------------------------------------------------------------------- 1 | from "ws:127.0.0.1:1337/todo-server@0.1.0/main.clio" import set del sub update 2 | 3 | fn template todo: 4 | f" 8 | " 9 | 10 | fn onDelBtnClicked id: 11 | fn onEvent: del id 12 | 13 | fn onCheck id: 14 | fn onEvent event: 15 | update id # checked: event.target.checked 16 | 17 | fn onAdded data: 18 | el = document.createElement "div" 19 | document.getElementById "todos" -> .appendChild el 20 | el.innerHTML = template data 21 | el.dataset.id = data.id 22 | el.querySelector ".delete" -> .addEventListener "click" (onDelBtnClicked data.id) 23 | el.querySelector ".check" -> .addEventListener "change" (onCheck data.id) 24 | 25 | fn onRemoved data: 26 | document.querySelector f"[data-id='{data.id}']" -> .remove 27 | 28 | fn onModified data: 29 | checkbox = document.querySelector f"[data-id='{data.id}'] .check" 30 | checkbox.checked = data.checked 31 | 32 | fn onAddBtnClicked: 33 | el = document.querySelector "[name=body]" 34 | if el.value: 35 | id = Math.random () -> (@number * 1000000000) -> Math.round -> .toString 36 | set id # body: el.value id: id checked: false 37 | el.value = "" 38 | 39 | export fn main argv: 40 | await sub () 41 | -> .on "added" onAdded 42 | -> .on "modified" onModified 43 | -> .on "removed" onRemoved 44 | document.getElementById "add" -> .addEventListener "click" onAddBtnClicked -------------------------------------------------------------------------------- /todo/client/src/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Clio Todos 9 | 10 | 11 |

Clio Todo App

12 |
13 |
14 | 15 | 16 |
17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /todo/client/src/public/style.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | margin: 0; 4 | padding: 0; 5 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, 6 | Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif; 7 | background: #dfe4ea; 8 | } 9 | 10 | body { 11 | padding: 1em; 12 | } 13 | 14 | h1, 15 | #todos > div, 16 | .add-todo { 17 | max-width: 960px; 18 | margin: 0 auto; 19 | padding: 1em; 20 | box-sizing: border-box; 21 | } 22 | 23 | h1 { 24 | padding-bottom: 0.5em; 25 | } 26 | 27 | #todos > div, 28 | .add-todo { 29 | border-radius: 1em; 30 | background: #dfe4ea; 31 | box-shadow: 20px 20px 60px #bec2c7, -20px -20px 60px #ffffff; 32 | margin-top: 2em; 33 | } 34 | 35 | button { 36 | padding: 1em 2em; 37 | border: none; 38 | outline: none; 39 | border-radius: 4em; 40 | color: #fff; 41 | } 42 | 43 | .delete { 44 | background: linear-gradient(145deg, #ff3a3a, #da3131); 45 | } 46 | 47 | #add { 48 | background: linear-gradient(145deg, #3a87ff, #3171da); 49 | } 50 | 51 | .add-todo { 52 | display: flex; 53 | } 54 | 55 | [name="body"] { 56 | flex: 1; 57 | margin-right: 1em; 58 | border-radius: 1em; 59 | background: #dfe4ea; 60 | box-shadow: inset 20px 20px 60px #bec2c7, inset -20px -20px 60px #ffffff; 61 | border: none; 62 | outline: none; 63 | padding-left: 1em; 64 | } 65 | 66 | #todos > div { 67 | display: flex; 68 | align-items: center; 69 | } 70 | 71 | #todos label { 72 | flex: 1; 73 | margin-right: 1em; 74 | } 75 | 76 | .check { 77 | margin-right: 3em; 78 | } 79 | 80 | .check::after { 81 | display: flex; 82 | align-items: center; 83 | justify-content: center; 84 | content: "✖️"; 85 | background: #dfe4ea; 86 | box-shadow: 2px 2px 6px #bec2c7, -2px -2px 6px #ffffff; 87 | border: none; 88 | width: 32px; 89 | height: 32px; 90 | display: block; 91 | border-radius: 8px; 92 | margin-top: -8px; 93 | text-align: center; 94 | line-height: 35px; 95 | } 96 | 97 | .check:checked::after { 98 | content: "✔️"; 99 | box-shadow: inset 2px 2px 6px #bec2c7, inset -2px -2px 6px #ffffff; 100 | } 101 | -------------------------------------------------------------------------------- /todo/client/src/rollup.config.js: -------------------------------------------------------------------------------- 1 | export { default } from "clio-rollup"; 2 | -------------------------------------------------------------------------------- /todo/server/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Make sure this directory matches what you defined as 7 | # build.directory in clio.toml file (default is build) 8 | build/ 9 | 10 | # Clio specific cache directories 11 | .clio-cache 12 | clio_env 13 | 14 | # Dependency directories 15 | node_modules/ 16 | 17 | .npm 18 | 19 | # Output of 'npm pack' 20 | *.tgz 21 | 22 | # dotenv environment variables file 23 | .env 24 | .env.test 25 | 26 | # parcel-bundler cache (https://parceljs.org/) 27 | .cache 28 | 29 | # service account key 30 | serviceAccountKey.json -------------------------------------------------------------------------------- /todo/server/clio.toml: -------------------------------------------------------------------------------- 1 | title = "todo-server" 2 | description = "" 3 | version = "0.1.0" 4 | license = "MIT" 5 | authors = [ "Your Name " ] 6 | keywords = "" 7 | 8 | [build] 9 | source = "src" 10 | destination = "build" 11 | target = "js" 12 | 13 | [scripts] 14 | test = "No tests specified" 15 | 16 | [[servers]] 17 | proto = "ws" 18 | port = 1337 19 | host = "0.0.0.0" 20 | name = "default" 21 | 22 | [[workers]] 23 | proto = "ws" 24 | url = "ws://localhost:1337" 25 | count = "cpu" 26 | server = "default" 27 | 28 | [executor] 29 | proto = "ws" 30 | url = "ws://localhost:1337" 31 | wait_for = "cpu" 32 | server = "default" 33 | 34 | [npm.dependencies] 35 | firebase-admin = "9.8.0" 36 | 37 | [npm.scripts] 38 | start = "node .clio/index.js" 39 | host = "node .clio/host.js" -------------------------------------------------------------------------------- /todo/server/src/main.clio: -------------------------------------------------------------------------------- 1 | import "cjs:./serviceAccountKey.json" 2 | import "cjs:firebase-admin" as admin 3 | 4 | admin.initializeApp # credential: (admin.credential.cert serviceAccountKey) 5 | db = admin.firestore () 6 | collection = db.collection "todos" 7 | 8 | export fn set id todo: 9 | collection.doc id -> await .set todo 10 | 11 | export fn update id modifier: 12 | collection.doc id -> await .update modifier 13 | 14 | export fn del id: 15 | collection.doc id -> await .delete 16 | 17 | fn onChange change channel: 18 | data = change.doc.data () 19 | channel.emit change.type data 20 | 21 | fn onSnapshot channel: 22 | fn onEvent snapshot: 23 | snapshot -> .docChanges -> * onChange channel 24 | 25 | export fn sub: 26 | channel = emitter () 27 | collection.onSnapshot (onSnapshot channel) 28 | channel 29 | -------------------------------------------------------------------------------- /web/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Make sure this directory matches what you defined as 7 | # build.directory in clio.toml file (default is build) 8 | build/ 9 | 10 | # Clio specific cache directories 11 | .clio-cache 12 | clio_env 13 | 14 | # Dependency directories 15 | node_modules/ 16 | 17 | .npm 18 | 19 | # Output of 'npm pack' 20 | *.tgz 21 | 22 | # dotenv environment variables file 23 | .env 24 | .env.test 25 | 26 | # parcel-bundler cache (https://parceljs.org/) 27 | .cache 28 | -------------------------------------------------------------------------------- /web/clio.toml: -------------------------------------------------------------------------------- 1 | title = "template-web" 2 | description = "" 3 | version = "0.1.0" 4 | license = "MIT" 5 | authors = [ "Your Name " ] 6 | keywords = "" 7 | 8 | [build] 9 | source = "src" 10 | destination = "build" 11 | target = "js" 12 | 13 | [scripts] 14 | test = "No tests specified" 15 | 16 | [[servers]] 17 | proto = "ww" 18 | name = "default" 19 | 20 | [[workers]] 21 | proto = "ww" 22 | count = "cpu" 23 | server = "default" 24 | 25 | [executor] 26 | proto = "ww" 27 | wait_for = "cpu" 28 | server = "default" 29 | 30 | # Npm specific configs 31 | 32 | [npm] 33 | browserslist = ["defaults", "not IE 11"] 34 | 35 | [npm.devDependencies] 36 | rollup = "^2.56.2" 37 | sirv-cli = "^1.0.12" 38 | clio-rollup = "latest" 39 | "@babel/preset-env" = "^7.15.0" 40 | 41 | [npm.scripts] 42 | host = "node .clio/host.js" 43 | build = "rollup -c" 44 | dev = "rollup -c -w" 45 | start = "npm run build && sirv public" 46 | -------------------------------------------------------------------------------- /web/src/main.clio: -------------------------------------------------------------------------------- 1 | export fn main argv: 2 | "Hello World" => document.body.innerText 3 | -------------------------------------------------------------------------------- /web/src/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Document 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /web/src/rollup.config.js: -------------------------------------------------------------------------------- 1 | export { default } from "clio-rollup"; 2 | --------------------------------------------------------------------------------