diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 37 | ||||
-rw-r--r-- | src/api.js | 17 | ||||
-rwxr-xr-x | src/cli.js | 2 | ||||
-rw-r--r-- | src/ircd.js | 16 | ||||
-rw-r--r-- | src/web.js | 34 | ||||
-rw-r--r-- | tests/js/ircd.js | 7 | ||||
-rw-r--r-- | tests/js/web.js | 7 |
8 files changed, 110 insertions, 11 deletions
@@ -1,3 +1,4 @@ /doc/*.[0-9] /doc/*.3js /src/index.js +/node_modules/ @@ -50,10 +50,14 @@ manpages = $(manpages.in:.in=) sources.js = \ src/api.js \ src/cli.js \ + src/ircd.js \ src/utils.js \ + src/web.js \ tests.js = \ - tests/js/utils.js \ + tests/js/ircd.js \ + tests/js/utils.js \ + tests/js/web.js \ sources = \ @@ -61,8 +65,15 @@ sources = \ derived-assets = \ - $(manpages) \ - src/index.js \ + $(manpages) \ + src/index.js \ + node_modules/dir.sentinel \ + node_modules/ \ + node_modules/$(NAME) \ + +side-assets = \ + ircd.sock \ + web.sock \ @@ -76,6 +87,16 @@ $(manpages): Makefile src/index.js: ln -fs api.js $@ +node_modules/dir.sentinel: + mkdir $(@D) + touch $@ + +node_modules/$(NAME): node_modules/dir.sentinel + ln -s ../src $@ + touch $@ + +node_modules/: node_modules/dir.sentinel node_modules/$(NAME) + .SUFFIXES: .js .js-t @@ -106,7 +127,7 @@ check: check-t check-asserts ## Remove *all* derived artifacts produced during the build. ## A dedicated test asserts that this is always true. clean: - rm -rf $(derived-assets) + rm -rf $(derived-assets) $(side-assets) ## Installs into $(DESTDIR)$(PREFIX). Its dependency target @@ -138,13 +159,15 @@ uninstall: run-ircd: - node src/server/web.js server -l http://localhost:3000 + rm -f ircd.sock + ./src/cli.js ircd ircd.sock run-web: - node src/server/web.js server -l http://localhost:3003 + rm -f web.sock + ./src/cli.js web web.sock ## Run the web and IRC server locally. -run: +run: node_modules/$(NAME) src/index.js $(MAKE) run-ircd & $(MAKE) run-web & wait @@ -1,14 +1,25 @@ const { eq } = require("./utils.js"); +const ircd = require("./ircd.js"); +const web = require("./web.js"); -const main = async () => { - if (process.argv.length !== 2) { +const main = () => { + if (process.argv.length === 3 && process.argv[2] === "-V") { console.log("papo 1970-01-01 0.1.0"); return; } + if (process.argv[2] === "ircd") { + ircd.app(process.argv[3]); + return; + } + + if (process.argv[2] === "web") { + web.app(process.argv[3]); + return; + } + console.log({ argv: process.argv, - eq: eq({a: 1}, {a: 1}), }); }; @@ -1,4 +1,4 @@ #!/usr/bin/env node const { main } = require("papo"); -(async () => await main())(); +main(); diff --git a/src/ircd.js b/src/ircd.js new file mode 100644 index 0000000..affc986 --- /dev/null +++ b/src/ircd.js @@ -0,0 +1,16 @@ +const net = require("node:net"); + +const server = net.createServer(socket => { + socket.write("olar\r\n"); + socket.pipe(socket); +}); + +const app = udsPath => { + server.listen(udsPath, () => { + console.log("I'm ircd."); + }); +}; + +module.exports = { + app, +}; diff --git a/src/web.js b/src/web.js new file mode 100644 index 0000000..bfa1807 --- /dev/null +++ b/src/web.js @@ -0,0 +1,34 @@ +const http = require("node:http"); + +const listProducts = () => {}; +const getProduct = () => {}; + +const routes = { + GET: { + "/products": listProducts, + "/products/:id": getProduct, + }, +}; + +const server = http.createServer((req, res) => { + const { headers ,url, method } = req; + console.log({ + headers, + url, + method, + }); + res.writeHead(200, { + "Content-Type": "text/plain", + }); + res.end("Hello, web!\n"); +}); + +const app = udsPath => { + server.listen(udsPath, () => { + console.log("I'm web."); + }); +}; + +module.exports = { + app, +}; diff --git a/tests/js/ircd.js b/tests/js/ircd.js new file mode 100644 index 0000000..08bb6dc --- /dev/null +++ b/tests/js/ircd.js @@ -0,0 +1,7 @@ +const { runTests } = require("../runner.js"); +const { } = require("../../src/ircd.js"); + +const tests = [ +]; + +runTests(tests); diff --git a/tests/js/web.js b/tests/js/web.js new file mode 100644 index 0000000..6562433 --- /dev/null +++ b/tests/js/web.js @@ -0,0 +1,7 @@ +const { runTests } = require("../runner.js"); +const { } = require("../../src/web.js"); + +const tests = [ +]; + +runTests(tests); |