aboutsummaryrefslogtreecommitdiff
path: root/docs/Code Documentation
diff options
context:
space:
mode:
Diffstat (limited to 'docs/Code Documentation')
-rw-r--r--docs/Code Documentation/Design/index.md4
-rw-r--r--docs/Code Documentation/Modules/CompileAndRun.md58
-rw-r--r--docs/Code Documentation/Run/index.md79
-rw-r--r--docs/Code Documentation/SocketIO.md116
4 files changed, 257 insertions, 0 deletions
diff --git a/docs/Code Documentation/Design/index.md b/docs/Code Documentation/Design/index.md
new file mode 100644
index 0000000..5355af6
--- /dev/null
+++ b/docs/Code Documentation/Design/index.md
@@ -0,0 +1,4 @@
+# Design
+We are using googles material design.
+
+[Link to the components](https://material.io/components/)
diff --git a/docs/Code Documentation/Modules/CompileAndRun.md b/docs/Code Documentation/Modules/CompileAndRun.md
new file mode 100644
index 0000000..535ed5f
--- /dev/null
+++ b/docs/Code Documentation/Modules/CompileAndRun.md
@@ -0,0 +1,58 @@
+## Index
+---
+## Locals
+
+### var `pythonSupportFiles`
+
+Points to the files for our python support code. They should be in a subdir of the module itself.
+
+## Exported
+
+### class `Python`
+
+This is exported as Python, just so that we could add other languages later. Used to build and run python-scripts with our support-code.
+
+### method `Python.constructor`
+
+Takes one parameter, which is the full path to the folder where the script is located.
+
+When initializing the class, this will be called. Can be done like this:
+
+```javascript
+new compileRun.Python(global.DirSwap + "/usrData/usrCode/example");
+```
+
+### method `Python.compile`
+
+This deletes old build-folder, and makes a new one. It then moves all required files into the build-folder, making us ready for running the script.
+
+### method `Python.run`
+
+Spawns a new process, starting entry.py in our build-folder. It also attaches event-listners on our class-object. All of them is in the example below:
+
+```javascript
+let sc = new compileRun.Python(global.DirSwap + "/usrData/usrCode/example");
+​
+// When data is printed from the python-script
+sc.on("stdout::data", (_stdout) => { });
+// Last write when script closes, any exiting messages
+sc.on("stdout::end", (_stdout) => { });
+// When something is printed from the python-script to the error-out. Usually when a `throw` is called
+sc.on("stderr::out", (_stderr) => { });
+// Last words when process is dying from an error :`(
+sc.on("stderr::end", (_stderr) => { });
+// When script exits, _code is the exit-code
+sc.on("close", (_code) => { });
+```
+
+## Python
+
+This is the support-files for user-made scripts.
+
+## Entry.py
+
+The entry-point when running a script. A file called script.py, containing the user-script, should be placed next to this file. Starting it should be done like this (Where app-root is where our app.js is located):
+
+```
+python entry.py <pathToAppRoot>
+```
diff --git a/docs/Code Documentation/Run/index.md b/docs/Code Documentation/Run/index.md
new file mode 100644
index 0000000..54031d1
--- /dev/null
+++ b/docs/Code Documentation/Run/index.md
@@ -0,0 +1,79 @@
+# Run when developing
+I have made a simple script, that can be run both on a rPI and a normal computer.
+(You will obviously not get any script to do anything on you pc)
+
+I have only tested this on my mac...
+
+To start it run:
+```bash
+npm run dev
+```
+You have to run these commands beforehand:
+```bash
+npm i
+pip3 install mkdocs mkdocs-gitbook pygments pymdown-extensions
+```
+
+!!! warning "Starting"
+ It will when starting freak out a little. All the filewatchers fires an event for every file,
+ they find for some reason. But node should be killed each time, and when you end up with
+ only two processes, it should work as you'd expect.
+
+This will create a folder named `tmp` in you working directory. where all the user-files will be stored.
+
+## Build watcher.
+It starts to watch these directories:
+```
+- /build/
+```
+If a change is detected, it runs:
+```bash
+mkdocs build
+```
+
+## Node watcher
+It starts to watch these directories:
+```
+- src/ (Except /src/public/ and /src/js/)
+- app.js
+```
+
+It then shuts down node and starts it again:
+```bash
+node app.js <WORKING_DIR>/tmp/
+```
+
+## webpack
+It just starts this command, witch rebundles when anything is changed:
+```bash
+npx webpack -p -w --mode=development
+```
+
+## Inteface
+- `fsWatch`-window: logs when one of the watchers (not webpack obv.) detects a filesystem-change. `NODE` means node-watcher, and `DOCS` means docs-watcher.
+- `Actions`-window: Logs all events with processes, like starting one, when one exits, when we try to kill one etc.
+- `Node`-window: Shows the output of node.
+- `mkDocs`-window: Show the output from running mkDocs.
+- `Active Processes`-table: Shows a table of currently active processes started by the app. Use arrow keys to navigate it.
+- `Webpack`-window: Shows the output from our webpack-process.
+!!! tip
+ All the log-windows respond to holding your cursor over and scrolling.
+
+### `Exit`
+The script will exit when pressing `q`, `s`, `escape`, `Control+c`.
+It will then send a kill signal to all processes, wait 10 seconds and then exit.
+
+## Edit file-watchers.
+Each of the file-watchers have explanatory names: `watcher_node` and `watcher_docs`.
+
+To add files or paths they should watch, find the init of the variable, and modify that code:
+```javascript
+e.g.
+let; watcher_node = chokidar.watch([
+ "app.js",
+ 'src/' // Add new entrys here
+
+]).on('all', (event, path) => { // ...
+```
+
+For the node-watcher, specify paths it should ignore in the `path.includes` block.
diff --git a/docs/Code Documentation/SocketIO.md b/docs/Code Documentation/SocketIO.md
new file mode 100644
index 0000000..b605857
--- /dev/null
+++ b/docs/Code Documentation/SocketIO.md
@@ -0,0 +1,116 @@
+# SocketIO
+
+## Client
+Socketio is setup in the file `globals`.
+This means, import `globals`, and then you can use `Socket` from there.
+
+### Connect
+1. Client first needs to get an Authentication token,
+ this can be obtained by doing this:
+ ```javascript
+ import {setCookie} from "../../../cookies";
+ let CryptoJS = require("crypto-js");
+ let passwordHash = CryptoJS.SHA256(<PASSWORD>;).toString();
+
+ Socket.emit("authenticate", <USERNAME>, passwordHash, (token) => {
+ // Token will be a string if username/password combo is right,
+ // if not, it is false.
+ setCookie("session_token", token, 500);
+ };)
+ ```
+2. Then the user can authenticate like this:
+ ```javascript
+ import {getCookie} from "../../../cookies";
+ let cookieToken = getCookie("session_token");
+
+ Socket.emit("authenticateToken", cookieToken, (res) => {
+ // Res is true if we got authenticated,
+ // If not, it is false.
+ });
+ ```
+3. We are now authenticated, and all actions and events are available to the client.
+
+### "Actions"
+```javascript
+Socket.emit(Action, *Arguments, (Return) => {
+};)
+```
+
+##### NeoRuntime/status
+
+
+| Name | Type | Description |
+| ------ | ------ | ----------- |
+| status | object | |
+
+??? info "Return/status"
+
+ | Name | Type | Description |
+ | -------------- | ------- | ----------------------------- |
+ | currentScript | string | "None"/Name of current script |
+ | scriptIsExited | boolean | |
+ | uptime | number | |
+
+##### NeoRuntime/Script/Create
+
+??? info "Arguments"
+
+ | Name | Type | Description |
+ | ---------- | ------ | ------------------------------------- |
+ | scriptPath | string | Path of the new script, local/example |
+
+??? info "Return"
+
+ | Name | Type | Description |
+ | ------ | ------- | --------------------- |
+ | res | boolean | success |
+ | resMsg | string | if fail, errorMessage |
+
+
+##### NeoRuntime/Script/Delete
+
+??? info "Arguments"
+
+ | Name | Type | Description |
+ | ---------- | ------ | ------------------------------------------- |
+ | scriptPath | string | Path of the script to delete, local/example |
+
+??? info "Return"
+
+ | Name | Type | Description |
+ | ------ | ------- | --------------------- |
+ | res | boolean | success |
+ | resMsg | string | if fail, errorMessage |
+
+##### NeoRuntime/Script/Select
+
+??? info "Arguments"
+
+ | Name | Type | Description |
+ | ---------- | ------ | ------------------------------------------ |
+ | scriptPath | string | Path of the script to start, local/example |
+
+##### NeoRuntime/Scripts/get
+
+??? info "Return"
+
+ | Name | Type | Description |
+ | ------ | ------- | --------------------- |
+ | local | list | local scripts |
+ | remote | list | remote scripts |
+
+### "Events"
+```javascript
+// Listen for a event
+Socket.emit(event + "::join");
+Socket.on(event, (*Return); => {
+
+})
+```
+```javascript
+// Stop listening for an event
+Socket.emit(event + "::leave")
+```
+
+
+## Server