Browse Source

wtf

master
Daniel Hübleitner 4 years ago
parent
commit
7ff0d1e67e
12 changed files with 52 additions and 287 deletions
  1. 6
    4
      .gitignore
  2. 0
    167
      lib/Backend.js
  3. 0
    19
      lib/Frontend.js
  4. 2
    2
      package-lock.json
  5. 8
    7
      package.json
  6. 10
    2
      src/Backend.ts
  7. 7
    2
      src/Frontend.ts
  8. 0
    66
      src/webpack.prod.js
  9. 11
    0
      test/TestBackend.ts
  10. 7
    0
      test/TestFrontend.ts
  11. 0
    18
      test/test.ts
  12. 1
    0
      tsconfig.json

+ 6
- 4
.gitignore View File

@@ -1,7 +1,9 @@
1 1
 node_modules
2 2
 
3
-*/**/*.js
4
-*/**/*.d.ts
3
+src/**/*.js
4
+src/**/*.d.ts
5 5
 
6
-!lib/Backend.js
7
-!lib/Frontend.js
6
+test/**/*.js
7
+test/**/*.d.ts
8
+
9
+lib

+ 0
- 167
lib/Backend.js
File diff suppressed because it is too large
View File


+ 0
- 19
lib/Frontend.js
File diff suppressed because it is too large
View File


+ 2
- 2
package-lock.json View File

@@ -1,6 +1,6 @@
1 1
 {
2
-  "name": "rpclib",
3
-  "version": "1.0.0",
2
+  "name": "rpclibrary",
3
+  "version": "1.0.1",
4 4
   "lockfileVersion": 1,
5 5
   "requires": true,
6 6
   "dependencies": {

+ 8
- 7
package.json View File

@@ -1,12 +1,14 @@
1 1
 {
2
-  "name": "rpclib",
3
-  "version": "1.0.0",
2
+  "name": "rpclibrary",
3
+  "version": "1.0.1",
4 4
   "description": "",
5 5
   "scripts": {
6
-    "build": "npm run clean; npm run tsc; npm run webpack",
7 6
     "tsc": "tsc",
8
-    "webpack": "webpack  --config src/webpack.prod.js --progress --colors",
9
-    "clean": "rm -rf lib"
7
+    "webpack": "webpack",
8
+    "build-lib": "npm run webpack --config ./src/webpack.js",
9
+    "build-test": "npm run webpack --config ./test/webpack.js",
10
+    "build": "npm run clean && npm run tsc && npm run build-lib && npm run build-test",
11
+    "clean": "rm -rf lib ./*.js ./*.d.ts"
10 12
   },
11 13
   "author": "",
12 14
   "license": "ISC",
@@ -25,7 +27,6 @@
25 27
     "uuid": "^3.3.3"
26 28
   },
27 29
   "files": [
28
-    "./lib/Backend.js",
29
-    "./lib/Frontend.js"
30
+    "lib/*.js"
30 31
   ]
31 32
 }

src/Server.ts → src/Backend.ts View File

@@ -5,9 +5,17 @@ import bsock = require('bsock');
5 5
 
6 6
 import * as T from './Types'; 
7 7
 import * as U from './Utils'; 
8
-import * as I from './Interfaces'; 
8
+import * as I from './Interfaces';
9
+import * as R from './Responses';
9 10
 
10
-export class Server{
11
+export { 
12
+    T as Types, 
13
+    U as Utils, 
14
+    I as Interfaces,
15
+    R as Responses
16
+}
17
+
18
+export class Backend{
11 19
     private ws = http.createServer()
12 20
     private io = bsock.createServer()
13 21
 

src/Client.ts → src/Frontend.ts View File

@@ -2,8 +2,13 @@
2 2
 
3 3
 var bsock = require('bsock')
4 4
 
5
+import * as T from './Types'; 
5 6
 import * as I from './Interfaces';
6
-import * as T from './Types';
7
+
8
+export { 
9
+    T as Types, 
10
+    I as Interfaces,
11
+}
7 12
 
8 13
 
9 14
 //fix args with defaults like "force = true" -> "force"
@@ -11,7 +16,7 @@ function stripAfterEquals(str:string){
11 16
     return str.split("=")[0]
12 17
 }
13 18
 
14
-export class Client implements I.Socket{
19
+export class Frontend implements I.Socket{
15 20
 
16 21
     private socket: I.Socket
17 22
     constructor(public port:number, private server: string, private tls: boolean = false){

+ 0
- 66
src/webpack.prod.js View File

@@ -1,66 +0,0 @@
1
-const path = require('path');
2
-const TerserPlugin = require('terser-webpack-plugin');
3
-
4
-const frontendConf = {
5
-    mode: 'production',
6
-    target: "web",
7
-    entry: path.resolve(__dirname, 'Client.ts'),
8
-    output: {
9
-        path: path.resolve(__dirname, '../lib'),
10
-        filename: 'Frontend.js',
11
-        libraryTarget: 'commonjs',
12
-    },
13
-    module: {
14
-      rules: [
15
-        { test: /\.ts?$/, loader: "ts-loader" }
16
-      ]
17
-    },
18
-    resolve: {
19
-      extensions: [".ts", ".tsx", ".js"]
20
-    },
21
-    optimization: {
22
-      minimize: true,
23
-      minimizer: [
24
-        new TerserPlugin({
25
-          parallel: true,
26
-          exclude: [
27
-            /\.\/(.*)\/.ts/,
28
-            /\.\/(.*).ts/,
29
-          ],
30
-        }),
31
-      ],
32
-    },
33
-}
34
-
35
-const backendConf = {
36
-  mode: 'production',
37
-  target: "node",
38
-  entry: path.resolve(__dirname, 'Server.ts'),
39
-  output: {
40
-      path: path.resolve(__dirname, '../lib'),
41
-      filename: 'Backend.js',
42
-      libraryTarget: 'commonjs',
43
-  },
44
-  module: {
45
-    rules: [
46
-      { test: /\.ts?$/, loader: "ts-loader" }
47
-    ]
48
-  },
49
-  resolve: {
50
-    extensions: [".ts", ".tsx", ".js"]
51
-  },
52
-  optimization: {
53
-    minimize: true,
54
-    minimizer: [
55
-      new TerserPlugin({
56
-        parallel: true,
57
-        exclude: [
58
-          /\.\/(.*)\/.ts/,
59
-          /\.\/(.*).ts/,
60
-        ],
61
-      }),
62
-    ],
63
-  },
64
-}
65
-
66
-module.exports = [frontendConf, backendConf]

+ 11
- 0
test/TestBackend.ts View File

@@ -0,0 +1,11 @@
1
+import { Backend } from '../src/Backend'
2
+
3
+const testServer = new Backend(20000, [{
4
+    name: "HelloWorldRPCGroup",
5
+    publicRPCs: () => [],
6
+    localRPCs: () => [{
7
+        type: 'Call',
8
+        name: 'echo',
9
+        call: async (s:string) => s,
10
+    }]
11
+}])

+ 7
- 0
test/TestFrontend.ts View File

@@ -0,0 +1,7 @@
1
+import { Frontend } from '../src/Frontend'
2
+
3
+const testClient = new Frontend(20000, 'localhost')
4
+testClient.connect().then(_ => {
5
+    testClient.info().then(console.log)
6
+    testClient["HelloWorldRPCGroup"].echo("x").then(console.log)
7
+})

+ 0
- 18
test/test.ts View File

@@ -1,18 +0,0 @@
1
-import { Server } from '../src/Server'
2
-import {Client} from '../src/Client'
3
-
4
-new Server(20000, [{
5
-    name: "HelloWorldRPCGroup",
6
-    publicRPCs: () => [],
7
-    localRPCs: () => [{
8
-        type: 'Call',
9
-        name: 'echo',
10
-        call: async (s:string) => s,
11
-    }]
12
-}])
13
-
14
-const caller = new Client(20000, 'localhost')
15
-caller.connect().then(_ => {
16
-    caller.info().then(console.log)
17
-    caller["HelloWorldRPCGroup"].echo("x").then(console.log)
18
-})

+ 1
- 0
tsconfig.json View File

@@ -5,6 +5,7 @@
5 5
     "target": "ESnext",
6 6
     "module": "commonjs",
7 7
     "declaration": true,
8
+    "outDir": "./lib",
8 9
     "strict": true,
9 10
     "experimentalDecorators": true
10 11
   },

Loading…
Cancel
Save