cmux 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const commander_1 = require("commander");
8
+ const index_js_1 = require("./index.js");
9
+ const path_1 = __importDefault(require("path"));
10
+ const program = new commander_1.Command();
11
+ program
12
+ .name('cmux')
13
+ .description('Socket.IO and static file server')
14
+ .version('0.1.1')
15
+ .option('-p, --port <port>', 'port to listen on', '2689')
16
+ .option('-d, --dir <directory>', 'static files directory', './public')
17
+ .option('-c, --cors <origin>', 'CORS origin configuration', 'true')
18
+ .action((options) => {
19
+ const port = parseInt(options.port);
20
+ const staticDir = path_1.default.resolve(options.dir);
21
+ const corsOrigin = options.cors === 'true' ? true : options.cors === 'false' ? false : options.cors;
22
+ (0, index_js_1.startServer)({
23
+ port,
24
+ staticDir,
25
+ corsOrigin
26
+ });
27
+ process.on('SIGINT', () => {
28
+ console.log('\nShutting down server...');
29
+ process.exit(0);
30
+ });
31
+ process.on('SIGTERM', () => {
32
+ console.log('\nShutting down server...');
33
+ process.exit(0);
34
+ });
35
+ });
36
+ program.parse();
37
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";;;;;;AAEA,yCAAoC;AACpC,yCAAyC;AACzC,gDAAwB;AAExB,MA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'socket.io';
2
+ export interface CmuxOptions {
3
+ port?: number;
4
+ staticDir?: string;
5
+ corsOrigin?: string | string[] | boolean;
6
+ }
7
+ export declare function createCmuxServer(options?: CmuxOptions): {
8
+ app: import("express-serve-static-core").Express;
9
+ io: Server<import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, any>;
10
+ httpServer: import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
11
+ start: () => Promise<void>;
12
+ stop: () => Promise<void>;
13
+ };
14
+ export declare function startServer(options?: CmuxOptions): {
15
+ app: import("express-serve-static-core").Express;
16
+ io: Server<import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, import("socket.io").DefaultEventsMap, any>;
17
+ httpServer: import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>;
18
+ start: () => Promise<void>;
19
+ stop: () => Promise<void>;
20
+ };
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAKnC,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC;CAC1C;AAED,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,WAAgB;;;;;;EAiEzD;AAED,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,WAAW;;;;;;EAIhD"}
package/dist/index.js ADDED
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createCmuxServer = createCmuxServer;
7
+ exports.startServer = startServer;
8
+ const express_1 = __importDefault(require("express"));
9
+ const http_1 = require("http");
10
+ const socket_io_1 = require("socket.io");
11
+ const cors_1 = __importDefault(require("cors"));
12
+ const path_1 = __importDefault(require("path"));
13
+ function createCmuxServer(options = {}) {
14
+ const { port = 2689, staticDir = path_1.default.join(process.cwd(), 'public'), corsOrigin = true } = options;
15
+ const app = (0, express_1.default)();
16
+ const httpServer = (0, http_1.createServer)(app);
17
+ const io = new socket_io_1.Server(httpServer, {
18
+ cors: {
19
+ origin: corsOrigin,
20
+ methods: ['GET', 'POST']
21
+ }
22
+ });
23
+ app.use((0, cors_1.default)({
24
+ origin: corsOrigin
25
+ }));
26
+ app.use(express_1.default.static(staticDir));
27
+ app.get('*', (req, res) => {
28
+ res.sendFile(path_1.default.join(staticDir, 'index.html'));
29
+ });
30
+ io.on('connection', (socket) => {
31
+ console.log('Client connected:', socket.id);
32
+ socket.on('disconnect', () => {
33
+ console.log('Client disconnected:', socket.id);
34
+ });
35
+ socket.on('message', (data) => {
36
+ console.log('Message received:', data);
37
+ socket.emit('message', { echo: data });
38
+ });
39
+ });
40
+ const start = () => {
41
+ return new Promise((resolve) => {
42
+ httpServer.listen(port, () => {
43
+ console.log(`Cmux server running on port ${port}`);
44
+ console.log(`Serving static files from: ${staticDir}`);
45
+ resolve();
46
+ });
47
+ });
48
+ };
49
+ const stop = () => {
50
+ return new Promise((resolve) => {
51
+ httpServer.close(() => {
52
+ console.log('Cmux server stopped');
53
+ resolve();
54
+ });
55
+ });
56
+ };
57
+ return {
58
+ app,
59
+ io,
60
+ httpServer,
61
+ start,
62
+ stop
63
+ };
64
+ }
65
+ function startServer(options) {
66
+ const server = createCmuxServer(options);
67
+ server.start();
68
+ return server;
69
+ }
70
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAaA,4CAiEC;AAED,kCAIC;AApFD,sDAA8B;AAC9B,+BAAoC;AACp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S,EAAE,CAAC,IAAI,EAAE,EAAE;YAC5B,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,IAAI,CAAC,CAAC;YACvC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,MAAM,KAAK,GAAG,GAAG,EAAE;QACjB,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YACnC,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;gBAC3B,OAAO,CAAC,GAAG,CAAC,+BAA+B,IAAI,EAAE,CAAC,CAAC;gBACnD,OAAO,CAAC,GAAG,CAAC,8BAA8B,SAAS,EAAE,CAAC,CAAC;gBACvD,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,IAAI,GAAG,GAAG,EAAE;QAChB,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YACnC,UAAU,CAAC,KAAK,CAAC,GAAG,EAAE;gBACpB,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;gBACnC,OAAO,EAAE,CAAC;YACZ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,OAAO;QACL,GAAG;QACH,EAAE;QACF,UAAU;QACV,KAAK;QACL,IAAI;KACL,CAAC;AACJ,CAAC;AAED,SAAgB,WAAW,CAAC,OAAqB;IAC/C,MAAM,MAAM,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACzC,MAAM,CAAC,KAAK,EAAE,CAAC;IACf,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,16 +1,36 @@
1
1
  {
2
2
  "name": "cmux",
3
- "version": "0.1.0",
4
- "description": "A multiplexer tool",
5
- "main": "index.js",
3
+ "version": "0.1.1",
4
+ "description": "Socket.IO and static file server",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "cmux": "./dist/cli.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "public"
13
+ ],
6
14
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
15
+ "start": "node dist/index.js"
8
16
  },
9
- "keywords": ["cmux", "multiplexer"],
10
- "author": "Lawrence Chen",
17
+ "keywords": [
18
+ "socket.io",
19
+ "server",
20
+ "static"
21
+ ],
22
+ "author": "",
11
23
  "license": "MIT",
12
- "repository": {
13
- "type": "git",
14
- "url": "https://github.com/lawrencechen/cmux"
24
+ "dependencies": {
25
+ "socket.io": "^4.7.2",
26
+ "express": "^4.18.2",
27
+ "cors": "^2.8.5",
28
+ "commander": "^11.1.0"
29
+ },
30
+ "engines": {
31
+ "node": ">=16.0.0"
32
+ },
33
+ "publishConfig": {
34
+ "access": "public"
15
35
  }
16
36
  }
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Cmux Server</title>
7
+ </head>
8
+ <body>
9
+ <h1>Cmux Server Running</h1>
10
+ <p>Socket.IO server is ready at port 2689</p>
11
+ <script src="/socket.io/socket.io.js"></script>
12
+ <script>
13
+ const socket = io();
14
+ socket.on('connect', () => {
15
+ console.log('Connected to server');
16
+ });
17
+ </script>
18
+ </body>
19
+ </html>
package/README.md DELETED
@@ -1,16 +0,0 @@
1
- # cmux
2
-
3
- A multiplexer tool.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install cmux
9
- ```
10
-
11
- ## Usage
12
-
13
- ```javascript
14
- const cmux = require('cmux');
15
- console.log(cmux.hello());
16
- ```
package/index.js DELETED
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- version: '0.1.0',
3
- hello: function() {
4
- return 'Hello from cmux!';
5
- }
6
- };