Skip to content

Commit

Permalink
Combine mutiny CLI and mutiny-app #32
Browse files Browse the repository at this point in the history
  • Loading branch information
caolan committed Sep 23, 2024
1 parent 15cab83 commit eee6dd7
Show file tree
Hide file tree
Showing 23 changed files with 234 additions and 394 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# This workflow will install Deno then run `deno lint` and `deno test`.
# For more information see: https://github.com/denoland/setup-deno

name: Test mutiny-app
name: Test mutiny

on:
push:
Expand All @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: mutiny-app
working-directory: mutiny

steps:
- name: Setup repo
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ Peer-to-peer web applications runtime.

## Structure

* mutiny - user-friendly CLI interface to mutinyd
* mutiny - CLI interface to mutinyd and application server
* mutinyd - long-running process to manage networking, persistence, data sync
* mutiny-app - serves an application and provides HTTP API
* lib/ - shared code for the above applications

## Usage
Expand All @@ -21,7 +20,7 @@ cargo run
Then, run mutiny to check communication between daemon and CLI:

```
./mutiny/mutiny
./mutiny/mutiny serve chat ./examples/chat
```

## Help
Expand Down Expand Up @@ -55,14 +54,15 @@ You can then run apps on your additional instance using the `--socket`
option:

```
./mutiny-app/mutiny-app --socket ./mutinyd/mutiny2.sock chat ./examples/chat
./mutiny/mutiny serve --socket ./mutinyd/mutiny2.sock chat ./examples/chat
```

## Examples

### Ping

Demonstrates communication between frontend, mutiny-app backend, and mutinyd daemon.
Demonstrates communication between frontend, mutiny HTTP server, and
mutinyd daemon.

First, start the mutinyd daemon:

Expand All @@ -74,7 +74,7 @@ cargo run
Then, serve the app:

```
./mutiny-app/mutiny-app ping examples/ping
./mutiny/mutiny serve ping examples/ping
```

And open the displayed URL in your browser. You should see your local peer
Expand All @@ -96,7 +96,7 @@ cargo run
Then, serve the app:

```
./mutiny-app/mutiny-app chat examples/chat
./mutiny/mutiny serve chat examples/chat
```

And open the displayed URL in your browser. Repeat this process on another
Expand Down Expand Up @@ -125,12 +125,12 @@ cd mutinyd
cargo test
```

### mutiny-app
### mutiny

Unit tests for the mutiny-app server:
Unit tests for the mutiny server:

```
cd mutiny-app
cd mutiny
deno test -A
```

Expand Down
9 changes: 5 additions & 4 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ appropriate.

## Application metadata

An application is referenced canonically by it's UUID, but also locally
using a human-friendly label. If you serve the chat app using `mutiny-app chat
examples/chat`, you are serving the `examples/chat` directory with the
app label `chat`. You'll see the app's UUID printed after starting it.
An application is referenced canonically by it's UUID, but also
locally using a human-friendly label. If you serve the chat app using
`mutiny serve chat examples/chat`, you are serving the `examples/chat`
directory with the app label `chat`. You'll see the app's UUID printed
after starting it.

Use the following API to request the current app's label and UUID in
the browser:
Expand Down
4 changes: 2 additions & 2 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ We'll add a basic layout to `index.html`:

## Serving the app

You can serve this application using `mutiny-app`:
You can serve this application using `mutiny`:

```
./mutiny-app/mutiny-app mylabel ./peers-app
./mutiny/mutiny serve mylabel ./peers-app
```

This tells `mutinyd` to register a new application with label `mylabel` and
Expand Down
13 changes: 0 additions & 13 deletions mutiny-app/deno.json

This file was deleted.

269 changes: 0 additions & 269 deletions mutiny-app/deno.lock

This file was deleted.

15 changes: 0 additions & 15 deletions mutiny-app/mutiny-app

This file was deleted.

4 changes: 3 additions & 1 deletion mutiny/deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
},
"imports": {
"@std/assert": "jsr:@std/assert@^0.226.0",
"@std/http": "jsr:@std/http@^0.224.4",
"@std/io": "jsr:@std/io@^0.224.1",
"@std/msgpack": "jsr:@std/msgpack@^0.224.2",
"@std/path": "jsr:@std/path@^0.225.2"
"@std/path": "jsr:@std/path@^0.225.2",
"@std/cli": "jsr:@std/cli@^0.224.7"
}
}
73 changes: 71 additions & 2 deletions mutiny/deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions mutiny/main.ts

This file was deleted.

5 changes: 3 additions & 2 deletions mutiny/mutiny
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ DIR=`dirname $0`
deno run \
--allow-read \
--allow-write \
--allow-net="127.0.0.1" \
--allow-env="XDG_RUNTIME_DIR,HOME" \
$DIR/main.ts \
$DIR/src/main.ts \
$@

# TODO: have initial process spawn another dropping permissions and
# restricting only to environment variables relevant for platform, e.g.:
# --allow-read="$SOCKET_PATH,$XDG_RUNTIME_DIR"
# --allow-read="$SOCKET_PATH,$XDG_RUNTIME_DIR,$CWD"
# --allow-write="$SOCKET_PATH,$XDG_RUNTIME_DIR"
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions mutiny/src/commands/help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export function listCommands() {
console.error("Commands:");
console.error(" serve Serve an application");
console.error(" info Show info about mutinyd");
}

export function help(command?: string) {
switch (command) {
case "serve": {
console.error("Usage: mutiny serve [OPTIONS] LABEL PATH");
console.error("");
console.error("Options:");
console.error(" -s, --socket <SOCKET> Unix socket to bind to");
console.error(" --help Show this message");
break;
}
case "info": {
console.error("Usage: mutiny info [OPTIONS]");
console.error("");
console.error("Options:");
console.error(" -s, --socket <SOCKET> Unix socket to bind to");
console.error(" --help Show this message");
break;
}
default: {
console.error("Usage: mutiny COMMAND");
console.error("");
listCommands();
}
}
Deno.exit(1);
}
16 changes: 16 additions & 0 deletions mutiny/src/commands/info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { defaultSocketPath } from "../client.ts";
import { parseArgs } from "@std/cli/parse-args";
import { help } from "./help.ts";
import { MutinyClient } from "../client.ts";

export default async function (args: ReturnType<typeof parseArgs>) {
if (args.help) {
help('info');
}
const socket_path = args.s || args.socket || defaultSocketPath();

const client = new MutinyClient({socket_path});
const peer_id = await client.localPeerId();
console.log(`Mutinyd socket: ${socket_path}`);
console.log(`Local peer ID: ${peer_id}`);
}
Loading

0 comments on commit eee6dd7

Please sign in to comment.