webxdc-dev
Advanced tools
Comparing version 0.1.3 to 0.2.0
@@ -67,6 +67,2 @@ import path from "path"; | ||
webSockets.forEach((peerWebSocket) => { | ||
if (peerWebSocket === self) { | ||
// we shouldn't send to ourselves | ||
return; | ||
} | ||
console.log("gossip", update); | ||
@@ -73,0 +69,0 @@ peerWebSocket.send(JSON.stringify(update)); |
@@ -18,3 +18,3 @@ import webpackDevMiddleware from "webpack-dev-middleware"; | ||
injectSim: (app) => { | ||
// in dev mode we serve the files from the dist directory directory | ||
// in dev mode we serve the files from the dist directory | ||
app.use(express.static("./dist/webxdc")); | ||
@@ -21,0 +21,0 @@ }, |
@@ -12,7 +12,18 @@ import { Command } from "commander"; | ||
.argument("<directory>", "directory with Webxdc") | ||
.option( | ||
"-p, --port <port>", | ||
"start port for controller, instance ports are incremented by one each", | ||
"3000" | ||
) | ||
.description("Run Webxdc from directory") | ||
.action((directory) => { | ||
run(directory, inject); | ||
.action((directory, portString) => { | ||
const port = Number(portString.port); | ||
if (isNaN(port) || port < 0 || port > 65535) { | ||
throw new Error( | ||
"provided port is invalid: " + JSON.stringify(portString) | ||
); | ||
} | ||
run(directory, Number(port), inject); | ||
}); | ||
return program; | ||
} |
@@ -9,3 +9,7 @@ import { createFrontend, WebXdc, Instances, InjectExpress } from "./app"; | ||
export function run(directory: string, inject: Inject): void { | ||
export function run( | ||
directory: string, | ||
start_port: number, | ||
inject: Inject | ||
): void { | ||
console.log("Starting Webxdc project in: ", directory); | ||
@@ -19,3 +23,3 @@ const webXdc: WebXdc = { | ||
const instances = new Instances(webXdc, injectSim, 3000); | ||
const instances = new Instances(webXdc, injectSim, start_port); | ||
@@ -27,3 +31,3 @@ const peer0 = instances.add(); | ||
frontend.listen(3000, () => { | ||
frontend.listen(start_port, () => { | ||
console.log("Starting webxdc-dev frontend"); | ||
@@ -35,3 +39,3 @@ }); | ||
open("http://localhost:3000"); | ||
open("http://localhost:" + start_port); | ||
} |
@@ -50,6 +50,2 @@ "use strict"; | ||
webSockets.forEach((peerWebSocket) => { | ||
if (peerWebSocket === self) { | ||
// we shouldn't send to ourselves | ||
return; | ||
} | ||
console.log("gossip", update); | ||
@@ -56,0 +52,0 @@ peerWebSocket.send(JSON.stringify(update)); |
@@ -21,3 +21,3 @@ "use strict"; | ||
injectSim: (app) => { | ||
// in dev mode we serve the files from the dist directory directory | ||
// in dev mode we serve the files from the dist directory | ||
app.use(express_1.default.static("./dist/webxdc")); | ||
@@ -24,0 +24,0 @@ }, |
@@ -12,5 +12,10 @@ "use strict"; | ||
.argument("<directory>", "directory with Webxdc") | ||
.option("-p, --port <port>", "start port for controller, instance ports are incremented by one each", "3000") | ||
.description("Run Webxdc from directory") | ||
.action((directory) => { | ||
(0, run_1.run)(directory, inject); | ||
.action((directory, portString) => { | ||
const port = Number(portString.port); | ||
if (isNaN(port) || port < 0 || port > 65535) { | ||
throw new Error("provided port is invalid: " + JSON.stringify(portString)); | ||
} | ||
(0, run_1.run)(directory, Number(port), inject); | ||
}); | ||
@@ -17,0 +22,0 @@ return program; |
@@ -9,3 +9,3 @@ "use strict"; | ||
const open_1 = __importDefault(require("open")); | ||
function run(directory, inject) { | ||
function run(directory, start_port, inject) { | ||
console.log("Starting Webxdc project in: ", directory); | ||
@@ -17,7 +17,7 @@ const webXdc = { | ||
const { injectFrontend, injectSim } = inject; | ||
const instances = new app_1.Instances(webXdc, injectSim, 3000); | ||
const instances = new app_1.Instances(webXdc, injectSim, start_port); | ||
const peer0 = instances.add(); | ||
const peer1 = instances.add(); | ||
const frontend = (0, app_1.createFrontend)(instances, injectFrontend); | ||
frontend.listen(3000, () => { | ||
frontend.listen(start_port, () => { | ||
console.log("Starting webxdc-dev frontend"); | ||
@@ -27,4 +27,4 @@ }); | ||
peer1.start(); | ||
(0, open_1.default)("http://localhost:3000"); | ||
(0, open_1.default)("http://localhost:" + start_port); | ||
} | ||
exports.run = run; |
@@ -1,1 +0,1 @@ | ||
(()=>{"use strict";const e=`ws://${document.location.host}/webxdc`,t=new WebSocket(e);let s=null;const n={sendUpdate:(e,s)=>{t.send(JSON.stringify({update:e,descr:s}))},setUpdateListener:(e,n=0)=>{s&&t.removeEventListener("message",s);const d=t=>{const s=JSON.parse(t.data);e(s)};s=d,t.addEventListener("message",d)},selfAddr:"wat",selfName:"Something"};window.webxdc=n})(); | ||
(()=>{"use strict";const e=`ws://${document.location.host}/webxdc`,t=new WebSocket(e);let s=null;const n={sendUpdate:(e,s)=>{t.send(JSON.stringify({update:e,descr:s})),console.info("send",{update:e,descr:s})},setUpdateListener:(e,n=0)=>{s&&t.removeEventListener("message",s);const o=t=>{const s=JSON.parse(t.data);console.info("recv",s),e(s)};s=o,t.addEventListener("message",o)},selfAddr:`device@${document.location.port}`,selfName:document.location.port};window.webxdc=n})(); |
{ | ||
"name": "webxdc-dev", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"description": "A dev tool for Webxdc", | ||
@@ -29,2 +29,3 @@ "homepage": "https://github.com/webxdc/webxdc-dev#readme", | ||
"clean": "rimraf dist", | ||
"version": "auto-changelog -p && git add CHANGELOG.md", | ||
"prepublish": "npm run build" | ||
@@ -44,2 +45,3 @@ }, | ||
"@types/node": "^18.0.0", | ||
"auto-changelog": "^2.4.0", | ||
"babel-loader": "^8.2.5", | ||
@@ -46,0 +48,0 @@ "babel-preset-solid": "^1.4.4", |
@@ -35,2 +35,9 @@ # webxdc-dev | ||
By default the dev tool is opened on port 3000 and following. You can change the | ||
base port number using `--port`, so for instance: | ||
```shell | ||
webxdc-dev run --port 4000 /path/to/webxdc/project | ||
``` | ||
### With `package.json` | ||
@@ -105,4 +112,4 @@ | ||
[`npm version`](https://docs.npmjs.com/cli/v8/commands/npm-version) updates the | ||
version number automatically. You then need to push using `--follow-tags` | ||
(**NOT** `--tags``). | ||
version number automatically and also puts the latest date in `CHANGELOG.md`. | ||
You then need to push using `--follow-tags` (**NOT** `--tags``). | ||
@@ -109,0 +116,0 @@ The release process is done through a github action defined in |
@@ -11,2 +11,3 @@ import { WebXdc } from "./webxdc-types"; | ||
socket.send(JSON.stringify({ update, descr })); | ||
console.info("send", { update, descr }); | ||
}, | ||
@@ -19,2 +20,3 @@ setUpdateListener: (listener, serial = 0) => { | ||
const receivedUpdate = JSON.parse((event as any).data); | ||
console.info("recv", receivedUpdate); | ||
listener(receivedUpdate); | ||
@@ -25,6 +27,6 @@ }; | ||
}, | ||
selfAddr: "wat", | ||
selfName: "Something", | ||
selfAddr: `device@${document.location.port}`, | ||
selfName: document.location.port, | ||
}; | ||
(window as any).webxdc = webXdc; |
45486
35
619
130
23