diff --git a/examples/game-of-life/.gitignore b/examples/game-of-life/.gitignore new file mode 100644 index 00000000..40b878db --- /dev/null +++ b/examples/game-of-life/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/examples/game-of-life/README.md b/examples/game-of-life/README.md index e2cb9a06..39028337 100644 --- a/examples/game-of-life/README.md +++ b/examples/game-of-life/README.md @@ -6,6 +6,12 @@ An [AssemblyScript](http://assemblyscript.org) example. Continuously updates the Instructions ------------ +You have to install the 'opn' package to be able to run the `npm browser` command + +``` +$> npm install +``` + To build [assembly/game-of-life.ts](./assembly/game-of-life.ts) to an untouched and an optimized `.wasm` including their respective `.wat` representations, run: ``` diff --git a/examples/game-of-life/package.json b/examples/game-of-life/package.json index edeb792f..22e43d35 100644 --- a/examples/game-of-life/package.json +++ b/examples/game-of-life/package.json @@ -6,6 +6,9 @@ "build": "npm run build:untouched && npm run build:optimized", "build:untouched": "asc assembly/game-of-life.ts -b game-of-life.untouched.wasm -t game-of-life.untouched.wat --validate --sourceMap --measure", "build:optimized": "asc -O assembly/game-of-life.ts -b game-of-life.optimized.wasm -t game-of-life.optimized.wat --validate --sourceMap --measure", - "browser": "game-of-life.html" + "browser": "node server.js" + }, + "dependencies": { + "opn": "^5.3.0" } } diff --git a/examples/game-of-life/server.js b/examples/game-of-life/server.js new file mode 100644 index 00000000..2fbb7f2a --- /dev/null +++ b/examples/game-of-life/server.js @@ -0,0 +1,18 @@ +var open = require('opn'); +var http = require('http'); +var fs = require('fs'); + +const PORT = 9080; + +fs.readFile('./game-of-life.html', function (err, html) { + + if (err) throw err; + + http.createServer(function(request, response) { + response.writeHeader(200, {"Content-Type": "text/html"}); + response.write(html); + response.end(); + }).listen(PORT); +}); + +open('http://localhost:9080/game-of-life.html'); \ No newline at end of file