Merge pull request #18 from HeinousTugboat/ht/typescript-ho
Add TypeScript and converts entire codebase
This commit is contained in:
commit
7e17413783
15 changed files with 498 additions and 60 deletions
|
@ -1,4 +0,0 @@
|
||||||
#!/usr/bin/env node
|
|
||||||
import {start} from "../src/index.js"
|
|
||||||
|
|
||||||
await start();
|
|
4
npx/bitburner-filesync.ts
Executable file
4
npx/bitburner-filesync.ts
Executable file
|
@ -0,0 +1,4 @@
|
||||||
|
#!/usr/bin/env ts-node
|
||||||
|
import { start } from "../src/index"
|
||||||
|
|
||||||
|
await start();
|
337
package-lock.json
generated
337
package-lock.json
generated
|
@ -1,23 +1,130 @@
|
||||||
{
|
{
|
||||||
"name": "bitburner-remote",
|
"name": "bitburner-filesync",
|
||||||
"version": "1.0.6",
|
"version": "1.1.5",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "bitburner-remote",
|
"name": "bitburner-filesync",
|
||||||
"version": "1.0.6",
|
"version": "1.1.5",
|
||||||
"license": "Unlicense",
|
"license": "Unlicense",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cheap-watch": "^1.0.4",
|
"cheap-watch": "^1.0.4",
|
||||||
"convict": "^6.2.3",
|
"convict": "^6.2.3",
|
||||||
"signal-js": "^3.0.1",
|
"signal-js": "^3.0.1",
|
||||||
|
"ts-node": "^10.9.1",
|
||||||
|
"typescript": "^4.8.4",
|
||||||
"ws": "^8.8.1"
|
"ws": "^8.8.1"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"bitburner-remote": "npx/bitburner-remote.js"
|
"bitburner-filesync": "npx/bitburner-filesync.js"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/convict": "^6.1.1",
|
||||||
|
"@types/node": "^18.7.23",
|
||||||
|
"@types/ws": "^8.5.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@cspotcode/source-map-support": {
|
||||||
|
"version": "0.8.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz",
|
||||||
|
"integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==",
|
||||||
|
"dependencies": {
|
||||||
|
"@jridgewell/trace-mapping": "0.3.9"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@jridgewell/resolve-uri": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@jridgewell/sourcemap-codec": {
|
||||||
|
"version": "1.4.14",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz",
|
||||||
|
"integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw=="
|
||||||
|
},
|
||||||
|
"node_modules/@jridgewell/trace-mapping": {
|
||||||
|
"version": "0.3.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz",
|
||||||
|
"integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"@jridgewell/resolve-uri": "^3.0.3",
|
||||||
|
"@jridgewell/sourcemap-codec": "^1.4.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@tsconfig/node10": {
|
||||||
|
"version": "1.0.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz",
|
||||||
|
"integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA=="
|
||||||
|
},
|
||||||
|
"node_modules/@tsconfig/node12": {
|
||||||
|
"version": "1.0.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz",
|
||||||
|
"integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag=="
|
||||||
|
},
|
||||||
|
"node_modules/@tsconfig/node14": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow=="
|
||||||
|
},
|
||||||
|
"node_modules/@tsconfig/node16": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ=="
|
||||||
|
},
|
||||||
|
"node_modules/@types/convict": {
|
||||||
|
"version": "6.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/convict/-/convict-6.1.1.tgz",
|
||||||
|
"integrity": "sha512-R+JLaTvhsD06p4jyjUDtbd5xMtZTRE3c0iI+lrFWZogSVEjgTWPYwvJPVf+t92E+yrlbXa4X4Eg9ro6gPdUt4w==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@types/node": {
|
||||||
|
"version": "18.7.23",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.23.tgz",
|
||||||
|
"integrity": "sha512-DWNcCHolDq0ZKGizjx2DZjR/PqsYwAcYUJmfMWqtVU2MBMG5Mo+xFZrhGId5r/O5HOuMPyQEcM6KUBp5lBZZBg=="
|
||||||
|
},
|
||||||
|
"node_modules/@types/ws": {
|
||||||
|
"version": "8.5.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.3.tgz",
|
||||||
|
"integrity": "sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/acorn": {
|
||||||
|
"version": "8.8.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz",
|
||||||
|
"integrity": "sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==",
|
||||||
|
"bin": {
|
||||||
|
"acorn": "bin/acorn"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/acorn-walk": {
|
||||||
|
"version": "8.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz",
|
||||||
|
"integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/arg": {
|
||||||
|
"version": "4.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz",
|
||||||
|
"integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA=="
|
||||||
|
},
|
||||||
"node_modules/cheap-watch": {
|
"node_modules/cheap-watch": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/cheap-watch/-/cheap-watch-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/cheap-watch/-/cheap-watch-1.0.4.tgz",
|
||||||
|
@ -38,16 +145,93 @@
|
||||||
"node": ">=6"
|
"node": ">=6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/create-require": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ=="
|
||||||
|
},
|
||||||
|
"node_modules/diff": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.3.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/lodash.clonedeep": {
|
"node_modules/lodash.clonedeep": {
|
||||||
"version": "4.5.0",
|
"version": "4.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||||
"integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ=="
|
"integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ=="
|
||||||
},
|
},
|
||||||
|
"node_modules/make-error": {
|
||||||
|
"version": "1.3.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
|
||||||
|
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw=="
|
||||||
|
},
|
||||||
"node_modules/signal-js": {
|
"node_modules/signal-js": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/signal-js/-/signal-js-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/signal-js/-/signal-js-3.0.1.tgz",
|
||||||
"integrity": "sha512-etMzOR3k2GT8I2AoBUzYHuJ3QipKARXkuM1KxbcOGjgpuGyaXVXWPn61Aezsei9FL34DdfHISMbIu2wZYlIw9w=="
|
"integrity": "sha512-etMzOR3k2GT8I2AoBUzYHuJ3QipKARXkuM1KxbcOGjgpuGyaXVXWPn61Aezsei9FL34DdfHISMbIu2wZYlIw9w=="
|
||||||
},
|
},
|
||||||
|
"node_modules/ts-node": {
|
||||||
|
"version": "10.9.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz",
|
||||||
|
"integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==",
|
||||||
|
"dependencies": {
|
||||||
|
"@cspotcode/source-map-support": "^0.8.0",
|
||||||
|
"@tsconfig/node10": "^1.0.7",
|
||||||
|
"@tsconfig/node12": "^1.0.7",
|
||||||
|
"@tsconfig/node14": "^1.0.0",
|
||||||
|
"@tsconfig/node16": "^1.0.2",
|
||||||
|
"acorn": "^8.4.1",
|
||||||
|
"acorn-walk": "^8.1.1",
|
||||||
|
"arg": "^4.1.0",
|
||||||
|
"create-require": "^1.1.0",
|
||||||
|
"diff": "^4.0.1",
|
||||||
|
"make-error": "^1.1.1",
|
||||||
|
"v8-compile-cache-lib": "^3.0.1",
|
||||||
|
"yn": "3.1.1"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"ts-node": "dist/bin.js",
|
||||||
|
"ts-node-cwd": "dist/bin-cwd.js",
|
||||||
|
"ts-node-esm": "dist/bin-esm.js",
|
||||||
|
"ts-node-script": "dist/bin-script.js",
|
||||||
|
"ts-node-transpile-only": "dist/bin-transpile.js",
|
||||||
|
"ts-script": "dist/bin-script-deprecated.js"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"@swc/core": ">=1.2.50",
|
||||||
|
"@swc/wasm": ">=1.2.50",
|
||||||
|
"@types/node": "*",
|
||||||
|
"typescript": ">=2.7"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"@swc/core": {
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
|
"@swc/wasm": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/typescript": {
|
||||||
|
"version": "4.8.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz",
|
||||||
|
"integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==",
|
||||||
|
"bin": {
|
||||||
|
"tsc": "bin/tsc",
|
||||||
|
"tsserver": "bin/tsserver"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.2.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/v8-compile-cache-lib": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg=="
|
||||||
|
},
|
||||||
"node_modules/ws": {
|
"node_modules/ws": {
|
||||||
"version": "8.8.1",
|
"version": "8.8.1",
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.8.1.tgz",
|
||||||
|
@ -75,9 +259,102 @@
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"node_modules/yn": {
|
||||||
|
"version": "3.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz",
|
||||||
|
"integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@cspotcode/source-map-support": {
|
||||||
|
"version": "0.8.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz",
|
||||||
|
"integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==",
|
||||||
|
"requires": {
|
||||||
|
"@jridgewell/trace-mapping": "0.3.9"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@jridgewell/resolve-uri": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w=="
|
||||||
|
},
|
||||||
|
"@jridgewell/sourcemap-codec": {
|
||||||
|
"version": "1.4.14",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz",
|
||||||
|
"integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw=="
|
||||||
|
},
|
||||||
|
"@jridgewell/trace-mapping": {
|
||||||
|
"version": "0.3.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz",
|
||||||
|
"integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==",
|
||||||
|
"requires": {
|
||||||
|
"@jridgewell/resolve-uri": "^3.0.3",
|
||||||
|
"@jridgewell/sourcemap-codec": "^1.4.10"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@tsconfig/node10": {
|
||||||
|
"version": "1.0.9",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.9.tgz",
|
||||||
|
"integrity": "sha512-jNsYVVxU8v5g43Erja32laIDHXeoNvFEpX33OK4d6hljo3jDhCBDhx5dhCCTMWUojscpAagGiRkBKxpdl9fxqA=="
|
||||||
|
},
|
||||||
|
"@tsconfig/node12": {
|
||||||
|
"version": "1.0.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz",
|
||||||
|
"integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag=="
|
||||||
|
},
|
||||||
|
"@tsconfig/node14": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow=="
|
||||||
|
},
|
||||||
|
"@tsconfig/node16": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.3.tgz",
|
||||||
|
"integrity": "sha512-yOlFc+7UtL/89t2ZhjPvvB/DeAr3r+Dq58IgzsFkOAvVC6NMJXmCGjbptdXdR9qsX7pKcTL+s87FtYREi2dEEQ=="
|
||||||
|
},
|
||||||
|
"@types/convict": {
|
||||||
|
"version": "6.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/convict/-/convict-6.1.1.tgz",
|
||||||
|
"integrity": "sha512-R+JLaTvhsD06p4jyjUDtbd5xMtZTRE3c0iI+lrFWZogSVEjgTWPYwvJPVf+t92E+yrlbXa4X4Eg9ro6gPdUt4w==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@types/node": {
|
||||||
|
"version": "18.7.23",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.23.tgz",
|
||||||
|
"integrity": "sha512-DWNcCHolDq0ZKGizjx2DZjR/PqsYwAcYUJmfMWqtVU2MBMG5Mo+xFZrhGId5r/O5HOuMPyQEcM6KUBp5lBZZBg=="
|
||||||
|
},
|
||||||
|
"@types/ws": {
|
||||||
|
"version": "8.5.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.3.tgz",
|
||||||
|
"integrity": "sha512-6YOoWjruKj1uLf3INHH7D3qTXwFfEsg1kf3c0uDdSBJwfa/llkwIjrAGV7j7mVgGNbzTQ3HiHKKDXl6bJPD97w==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"acorn": {
|
||||||
|
"version": "8.8.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz",
|
||||||
|
"integrity": "sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w=="
|
||||||
|
},
|
||||||
|
"acorn-walk": {
|
||||||
|
"version": "8.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz",
|
||||||
|
"integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA=="
|
||||||
|
},
|
||||||
|
"arg": {
|
||||||
|
"version": "4.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz",
|
||||||
|
"integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA=="
|
||||||
|
},
|
||||||
"cheap-watch": {
|
"cheap-watch": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/cheap-watch/-/cheap-watch-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/cheap-watch/-/cheap-watch-1.0.4.tgz",
|
||||||
|
@ -92,16 +369,61 @@
|
||||||
"yargs-parser": "^20.2.7"
|
"yargs-parser": "^20.2.7"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"create-require": {
|
||||||
|
"version": "1.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz",
|
||||||
|
"integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ=="
|
||||||
|
},
|
||||||
|
"diff": {
|
||||||
|
"version": "4.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz",
|
||||||
|
"integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A=="
|
||||||
|
},
|
||||||
"lodash.clonedeep": {
|
"lodash.clonedeep": {
|
||||||
"version": "4.5.0",
|
"version": "4.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
|
||||||
"integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ=="
|
"integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ=="
|
||||||
},
|
},
|
||||||
|
"make-error": {
|
||||||
|
"version": "1.3.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
|
||||||
|
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw=="
|
||||||
|
},
|
||||||
"signal-js": {
|
"signal-js": {
|
||||||
"version": "3.0.1",
|
"version": "3.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/signal-js/-/signal-js-3.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/signal-js/-/signal-js-3.0.1.tgz",
|
||||||
"integrity": "sha512-etMzOR3k2GT8I2AoBUzYHuJ3QipKARXkuM1KxbcOGjgpuGyaXVXWPn61Aezsei9FL34DdfHISMbIu2wZYlIw9w=="
|
"integrity": "sha512-etMzOR3k2GT8I2AoBUzYHuJ3QipKARXkuM1KxbcOGjgpuGyaXVXWPn61Aezsei9FL34DdfHISMbIu2wZYlIw9w=="
|
||||||
},
|
},
|
||||||
|
"ts-node": {
|
||||||
|
"version": "10.9.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz",
|
||||||
|
"integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==",
|
||||||
|
"requires": {
|
||||||
|
"@cspotcode/source-map-support": "^0.8.0",
|
||||||
|
"@tsconfig/node10": "^1.0.7",
|
||||||
|
"@tsconfig/node12": "^1.0.7",
|
||||||
|
"@tsconfig/node14": "^1.0.0",
|
||||||
|
"@tsconfig/node16": "^1.0.2",
|
||||||
|
"acorn": "^8.4.1",
|
||||||
|
"acorn-walk": "^8.1.1",
|
||||||
|
"arg": "^4.1.0",
|
||||||
|
"create-require": "^1.1.0",
|
||||||
|
"diff": "^4.0.1",
|
||||||
|
"make-error": "^1.1.1",
|
||||||
|
"v8-compile-cache-lib": "^3.0.1",
|
||||||
|
"yn": "3.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"typescript": {
|
||||||
|
"version": "4.8.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz",
|
||||||
|
"integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ=="
|
||||||
|
},
|
||||||
|
"v8-compile-cache-lib": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg=="
|
||||||
|
},
|
||||||
"ws": {
|
"ws": {
|
||||||
"version": "8.8.1",
|
"version": "8.8.1",
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-8.8.1.tgz",
|
"resolved": "https://registry.npmjs.org/ws/-/ws-8.8.1.tgz",
|
||||||
|
@ -112,6 +434,11 @@
|
||||||
"version": "20.2.9",
|
"version": "20.2.9",
|
||||||
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz",
|
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.9.tgz",
|
||||||
"integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w=="
|
"integrity": "sha512-y11nGElTIV+CT3Zv9t7VKl+Q3hTQoT9a1Qzezhhl6Rp21gJ/IVTW7Z3y9EWXhuUBC2Shnf+DX0antecpAwSP8w=="
|
||||||
|
},
|
||||||
|
"yn": {
|
||||||
|
"version": "3.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz",
|
||||||
|
"integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q=="
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
package.json
13
package.json
|
@ -3,11 +3,11 @@
|
||||||
"version": "1.1.5",
|
"version": "1.1.5",
|
||||||
"description": "Official implementation of the Bitburner Filesync server",
|
"description": "Official implementation of the Bitburner Filesync server",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"bin": "./npx/bitburner-filesync.js",
|
"bin": "./npx/bitburner-filesync.ts",
|
||||||
"main": "./npx/bitburner-filesync.js",
|
"main": "./npx/bitburner-filesync.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"start": "node src/index.js"
|
"start": "npx/bitburner-filesync.ts"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
@ -28,6 +28,13 @@
|
||||||
"cheap-watch": "^1.0.4",
|
"cheap-watch": "^1.0.4",
|
||||||
"convict": "^6.2.3",
|
"convict": "^6.2.3",
|
||||||
"signal-js": "^3.0.1",
|
"signal-js": "^3.0.1",
|
||||||
|
"ts-node": "^10.9.1",
|
||||||
|
"typescript": "^4.8.4",
|
||||||
"ws": "^8.8.1"
|
"ws": "^8.8.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/convict": "^6.1.1",
|
||||||
|
"@types/node": "^18.7.23",
|
||||||
|
"@types/ws": "^8.5.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import CheapWatch from "cheap-watch";
|
import CheapWatch from "cheap-watch";
|
||||||
import { config } from "./config.js";
|
import { config } from "./config";
|
||||||
import { EventType } from "./eventTypes.js";
|
import { EventType } from "./eventTypes";
|
||||||
import { resolve } from "path";
|
import { resolve } from "path";
|
||||||
|
import type { Signal } from 'signal-js';
|
||||||
|
import type { File } from './interfaces';
|
||||||
|
|
||||||
function fileFilter(file) {
|
function fileFilter(file: File) {
|
||||||
if (config.get("allowedFiletypes").some(extension => file.path.endsWith(extension)))
|
if (config.get("allowedFiletypes").some(extension => file.path.endsWith(extension)))
|
||||||
return true;
|
return true;
|
||||||
if (file.stats.isDirectory())
|
if (file.stats.isDirectory())
|
||||||
|
@ -11,7 +13,7 @@ function fileFilter(file) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setupWatch(signaller) {
|
export async function setupWatch(signaller: Signal) {
|
||||||
const watch = new CheapWatch({
|
const watch = new CheapWatch({
|
||||||
dir: config.get("scriptsFolder"),
|
dir: config.get("scriptsFolder"),
|
||||||
filter: fileFilter,
|
filter: fileFilter,
|
|
@ -1,11 +1,11 @@
|
||||||
"use strict"
|
import { setupWatch } from "./fileWatch";
|
||||||
import { setupWatch } from "./fileWatch.js";
|
import { config, loadConfig } from "./config";
|
||||||
import { config, loadConfig } from "./config.js";
|
import { setupSocket } from "./networking/webSocket";
|
||||||
import { setupSocket } from "./networking/webSocket.js";
|
|
||||||
import signal from "signal-js";
|
import signal from "signal-js";
|
||||||
import { fileChangeEventToMsg, fileRemovalEventToMsg, requestFilenames, requestDefinitionFile } from "./networking/messageGenerators.js";
|
import { fileChangeEventToMsg, fileRemovalEventToMsg, requestFilenames, requestDefinitionFile } from "./networking/messageGenerators";
|
||||||
import { EventType } from "./eventTypes.js";
|
import { EventType } from "./eventTypes";
|
||||||
import { messageHandler } from "./networking/messageHandler.js";
|
import { messageHandler } from "./networking/messageHandler";
|
||||||
|
import { FileEvent, Message } from './interfaces';
|
||||||
|
|
||||||
export async function start() {
|
export async function start() {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
@ -13,7 +13,7 @@ export async function start() {
|
||||||
const socket = setupSocket(signal);
|
const socket = setupSocket(signal);
|
||||||
|
|
||||||
// Add a handler for received messages.
|
// Add a handler for received messages.
|
||||||
signal.on(EventType.MessageReceived, msg => messageHandler(signal, msg, watch.paths));
|
signal.on(EventType.MessageReceived, (msg: Message) => messageHandler(signal, msg, watch.paths));
|
||||||
|
|
||||||
// Add a handler for when a connection to a game is made.
|
// Add a handler for when a connection to a game is made.
|
||||||
signal.on(EventType.ConnectionMade, () => {
|
signal.on(EventType.ConnectionMade, () => {
|
||||||
|
@ -27,7 +27,7 @@ export async function start() {
|
||||||
const extensions = config.get("allowedFiletypes");
|
const extensions = config.get("allowedFiletypes");
|
||||||
for (const path of watch.paths.keys()) {
|
for (const path of watch.paths.keys()) {
|
||||||
if (extensions.some(extension => path.endsWith(extension)))
|
if (extensions.some(extension => path.endsWith(extension)))
|
||||||
signal.emit(EventType.MessageSend, fileChangeEventToMsg({ path: path }))
|
signal.emit(EventType.MessageSend, fileChangeEventToMsg({ path }))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Upload missing files to the game.
|
// Upload missing files to the game.
|
||||||
|
@ -36,14 +36,14 @@ export async function start() {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Add a handler for changed files.
|
// Add a handler for changed files.
|
||||||
signal.on(EventType.FileChanged, fileEvent => {
|
signal.on(EventType.FileChanged, (fileEvent: FileEvent) => {
|
||||||
if (!config.get("quiet")) console.log(fileEvent.path + " changed");
|
if (!config.get("quiet")) console.log(fileEvent.path + " changed");
|
||||||
signal.emit(EventType.MessageSend, fileChangeEventToMsg(fileEvent))
|
signal.emit(EventType.MessageSend, fileChangeEventToMsg(fileEvent))
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add a handler for removed files, if allowed.
|
// Add a handler for removed files, if allowed.
|
||||||
if (config.get("allowDeletingFiles"))
|
if (config.get("allowDeletingFiles"))
|
||||||
signal.on(EventType.FileDeleted, fileEvent =>
|
signal.on(EventType.FileDeleted, (fileEvent: FileEvent) =>
|
||||||
signal.emit(EventType.MessageSend, fileRemovalEventToMsg(fileEvent)));
|
signal.emit(EventType.MessageSend, fileRemovalEventToMsg(fileEvent)));
|
||||||
|
|
||||||
console.log(`Server is ready, running on ${config.get("port")}!`)
|
console.log(`Server is ready, running on ${config.get("port")}!`)
|
16
src/interfaces.ts
Normal file
16
src/interfaces.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import type { Stats } from 'fs';
|
||||||
|
|
||||||
|
export interface Message {
|
||||||
|
id: string;
|
||||||
|
method?: string;
|
||||||
|
jsonrpc: string;
|
||||||
|
params?: object;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FileEvent {
|
||||||
|
path: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface File extends FileEvent {
|
||||||
|
stats: Stats
|
||||||
|
}
|
|
@ -1,10 +1,11 @@
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync } from "fs";
|
||||||
import { config } from "../config.js";
|
import { config } from "../config";
|
||||||
import { join } from "path";
|
import { join } from "path";
|
||||||
|
import type { FileEvent, Message } from '../interfaces';
|
||||||
|
|
||||||
let messageCounter = 0;
|
let messageCounter = 0;
|
||||||
|
|
||||||
export function fileChangeEventToMsg({ path }) {
|
export function fileChangeEventToMsg({ path }: FileEvent): Message {
|
||||||
return {
|
return {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"method": "pushFile",
|
"method": "pushFile",
|
||||||
|
@ -13,11 +14,11 @@ export function fileChangeEventToMsg({ path }) {
|
||||||
"filename": addLeadingSlash(path),
|
"filename": addLeadingSlash(path),
|
||||||
"content": readFileSync(join(config.get("scriptsFolder"), path)).toString()
|
"content": readFileSync(join(config.get("scriptsFolder"), path)).toString()
|
||||||
},
|
},
|
||||||
"id": messageCounter++
|
"id": (messageCounter++).toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fileRemovalEventToMsg({ path }) {
|
export function fileRemovalEventToMsg({ path }: FileEvent): Message {
|
||||||
return {
|
return {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"method": "deleteFile",
|
"method": "deleteFile",
|
||||||
|
@ -25,30 +26,30 @@ export function fileRemovalEventToMsg({ path }) {
|
||||||
"server": "home",
|
"server": "home",
|
||||||
"filename": addLeadingSlash(path),
|
"filename": addLeadingSlash(path),
|
||||||
},
|
},
|
||||||
"id": messageCounter++
|
"id": (messageCounter++).toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function requestDefinitionFile() {
|
export function requestDefinitionFile(): Message {
|
||||||
return {
|
return {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"method": "getDefinitionFile",
|
"method": "getDefinitionFile",
|
||||||
"id": messageCounter++
|
"id": (messageCounter++).toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function requestFilenames() {
|
export function requestFilenames(): Message {
|
||||||
return {
|
return {
|
||||||
"jsonrpc": "2.0",
|
"jsonrpc": "2.0",
|
||||||
"method": "getFileNames",
|
"method": "getFileNames",
|
||||||
"params": {
|
"params": {
|
||||||
"server": "home",
|
"server": "home",
|
||||||
},
|
},
|
||||||
"id": messageCounter++
|
"id": (messageCounter++).toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLeadingSlash(path){
|
function addLeadingSlash(path: string): string {
|
||||||
const slashes = path.match('/');
|
const slashes = path.match('/');
|
||||||
if (slashes)
|
if (slashes)
|
||||||
return `/${path}`
|
return `/${path}`
|
|
@ -1,10 +1,12 @@
|
||||||
import { messageTracker } from "./messageTracker.js";
|
import { messageTracker } from "./messageTracker";
|
||||||
import { writeFile } from "fs";
|
import { Stats, writeFile } from "fs";
|
||||||
import { config } from "../config.js";
|
import { config } from "../config";
|
||||||
import { EventType } from "../eventTypes.js";
|
import { EventType } from "../eventTypes";
|
||||||
import { fileChangeEventToMsg } from "./messageGenerators.js";
|
import { fileChangeEventToMsg } from "./messageGenerators";
|
||||||
|
import type { Signal } from 'signal-js';
|
||||||
|
import { Message } from '../interfaces';
|
||||||
|
|
||||||
export function messageHandler(signaller, msg, paths) {
|
export function messageHandler(signaller: Signal, msg: Message, paths: Map<string, Stats>) {
|
||||||
let incoming;
|
let incoming;
|
||||||
|
|
||||||
try { incoming = JSON.parse(msg.toString()); }
|
try { incoming = JSON.parse(msg.toString()); }
|
||||||
|
@ -25,7 +27,7 @@ export function messageHandler(signaller, msg, paths) {
|
||||||
if (request?.method &&
|
if (request?.method &&
|
||||||
request.method == "getFileNames"
|
request.method == "getFileNames"
|
||||||
&& incoming.result) {
|
&& incoming.result) {
|
||||||
const gameFiles = incoming.result.map(file => removeLeadingSlash(file));
|
const gameFiles = incoming.result.map((file: string) => removeLeadingSlash(file));
|
||||||
|
|
||||||
paths.forEach((stats, fileName) => {
|
paths.forEach((stats, fileName) => {
|
||||||
if (!stats.isDirectory() && !gameFiles.includes(fileName))
|
if (!stats.isDirectory() && !gameFiles.includes(fileName))
|
||||||
|
@ -35,7 +37,7 @@ export function messageHandler(signaller, msg, paths) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeLeadingSlash(path) {
|
function removeLeadingSlash(path: string) {
|
||||||
const reg = /^\//;
|
const reg = /^\//;
|
||||||
return path.replace(reg, "")
|
return path.replace(reg, "")
|
||||||
}
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
class MessageTracker {
|
import type { Message } from '../interfaces';
|
||||||
data = new Map()
|
|
||||||
#maxLength = 200
|
|
||||||
|
|
||||||
push(msg) {
|
class MessageTracker {
|
||||||
|
data = new Map<string, Message>();
|
||||||
|
#maxLength = 200;
|
||||||
|
|
||||||
|
push(msg: Message) {
|
||||||
this.data.set(msg.id, msg);
|
this.data.set(msg.id, msg);
|
||||||
|
|
||||||
if (this.data.size > this.#maxLength) {
|
if (this.data.size > this.#maxLength) {
|
||||||
|
@ -11,7 +13,7 @@ class MessageTracker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get(index) {
|
get(index: string) {
|
||||||
return this.data.get(index);
|
return this.data.get(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,16 +1,18 @@
|
||||||
|
import type { Signal } from 'signal-js';
|
||||||
import { WebSocketServer } from 'ws';
|
import { WebSocketServer } from 'ws';
|
||||||
import { config } from "../config.js";
|
import { config } from "../config";
|
||||||
import { EventType } from "../eventTypes.js"
|
import { EventType } from "../eventTypes"
|
||||||
import { requestDefinitionFile } from './messageGenerators.js';
|
import { Message } from '../interfaces';
|
||||||
import { messageTracker } from "./messageTracker.js"
|
import { requestDefinitionFile } from './messageGenerators';
|
||||||
|
import { messageTracker } from "./messageTracker"
|
||||||
|
|
||||||
export function setupSocket(signaller) {
|
export function setupSocket(signaller: Signal) {
|
||||||
|
|
||||||
const wss = new WebSocketServer({ port: config.get("port") });
|
const wss = new WebSocketServer({ port: config.get("port") });
|
||||||
|
|
||||||
wss.on('connection', function connection(ws) {
|
wss.on('connection', function connection(ws) {
|
||||||
|
|
||||||
function sendMessage(msg) {
|
function sendMessage(msg: Message) {
|
||||||
messageTracker.push(msg);
|
messageTracker.push(msg);
|
||||||
ws.send(JSON.stringify(msg));
|
ws.send(JSON.stringify(msg));
|
||||||
}
|
}
|
||||||
|
@ -19,7 +21,7 @@ export function setupSocket(signaller) {
|
||||||
signaller.emit(EventType.MessageReceived, msg);
|
signaller.emit(EventType.MessageReceived, msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
signaller.on(EventType.MessageSend, msg => {
|
signaller.on(EventType.MessageSend, (msg: Message) => {
|
||||||
sendMessage(msg);
|
sendMessage(msg);
|
||||||
});
|
});
|
||||||
|
|
10
src/signals.d.ts
vendored
Normal file
10
src/signals.d.ts
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
declare module 'signal-js' {
|
||||||
|
|
||||||
|
export type Signal = typeof signal;
|
||||||
|
export default class signal {
|
||||||
|
static on<T>(event: string, callback: (data: T) => void): void
|
||||||
|
static emit<T>(event: string, data: T): void
|
||||||
|
static trigger(event: string): void
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
69
tsconfig.json
Normal file
69
tsconfig.json
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
{
|
||||||
|
"ts-node": {
|
||||||
|
"files": true,
|
||||||
|
"esm": true,
|
||||||
|
"experimentalSpecifierResolution": "node"
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"src/signals.d.ts",
|
||||||
|
"src/**/*"
|
||||||
|
],
|
||||||
|
"compilerOptions": {
|
||||||
|
/* Basic Options */
|
||||||
|
// "incremental": true, /* Enable incremental compilation */
|
||||||
|
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||||
|
"module": "esnext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||||
|
// "lib": [], /* Specify library files to be included in the compilation. */
|
||||||
|
// "allowJs": true, /* Allow javascript files to be compiled. */
|
||||||
|
// "checkJs": true, /* Report errors in .js files. */
|
||||||
|
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
|
||||||
|
// "declaration": true, /* Generates corresponding '.d.ts' file. */
|
||||||
|
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
|
||||||
|
// "sourceMap": true, /* Generates corresponding '.map' file. */
|
||||||
|
// "outFile": "./", /* Concatenate and emit output to single file. */
|
||||||
|
"outDir": "./dist", /* Redirect output structure to the directory. */
|
||||||
|
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||||
|
// "composite": true, /* Enable project compilation */
|
||||||
|
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
|
||||||
|
// "removeComments": true, /* Do not emit comments to output. */
|
||||||
|
// "noEmit": true, /* Do not emit outputs. */
|
||||||
|
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
|
||||||
|
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
|
||||||
|
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
|
||||||
|
/* Strict Type-Checking Options */
|
||||||
|
"strict": true, /* Enable all strict type-checking options. */
|
||||||
|
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||||
|
// "strictNullChecks": true, /* Enable strict null checks. */
|
||||||
|
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
|
||||||
|
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
|
||||||
|
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
|
||||||
|
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
|
||||||
|
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
|
||||||
|
/* Additional Checks */
|
||||||
|
// "noUnusedLocals": true, /* Report errors on unused locals. */
|
||||||
|
// "noUnusedParameters": true, /* Report errors on unused parameters. */
|
||||||
|
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
|
||||||
|
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
|
||||||
|
/* Module Resolution Options */
|
||||||
|
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
|
||||||
|
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
|
||||||
|
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
|
||||||
|
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
|
||||||
|
// "typeRoots": [], /* List of folders to include type definitions from. */
|
||||||
|
// "types": [], /* Type declaration files to be included in compilation. */
|
||||||
|
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
|
||||||
|
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||||
|
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
|
||||||
|
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||||
|
/* Source Map Options */
|
||||||
|
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
|
||||||
|
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||||
|
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
|
||||||
|
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
|
||||||
|
/* Experimental Options */
|
||||||
|
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
|
||||||
|
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
|
||||||
|
/* Advanced Options */
|
||||||
|
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue