From e01400058dd85a268054437c9d798f4768d53a41 Mon Sep 17 00:00:00 2001 From: schmelczerandras Date: Wed, 7 Oct 2020 18:35:32 +0200 Subject: [PATCH] Fix ide support --- .devcontainer/Dockerfile | 2 -- .devcontainer/devcontainer.json | 10 +++++----- backend/package.json | 4 ++-- backend/webpack.config.js | 2 ++ declared.code-workspace | 21 +++++++++++++++++++++ frontend/package.json | 4 ++-- frontend/webpack.config.js | 2 ++ package.json | 1 + shared/package.json | 7 +++---- shared/src/commands/command-executors.ts | 3 +++ shared/src/commands/command-receiver.ts | 5 +---- shared/src/helper/circle.ts | 4 ++++ shared/src/main.ts | 1 + tsconfig.json | 4 +++- 14 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 declared.code-workspace create mode 100644 shared/src/commands/command-executors.ts diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 6e9cd3e..83a24ff 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,5 +1,3 @@ -# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.140.1/containers/typescript-node/.devcontainer/base.Dockerfile - ARG VARIANT="14-buster" FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT} diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 627d477..44e6c5d 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -42,11 +42,11 @@ "workspaceMount": "source=${localWorkspaceFolder},target=/workspace,type=bind,consistency=cached", "workspaceFolder": "/workspace", "mounts": [ - "source=decla-red-root-node_modules2,target=/workspace/node_modules,type=volume", - "source=decla-red-frontend-node_modules2,target=/workspace/frontend/node_modules,type=volume", - "source=decla-red-backend-node_modules2,target=/workspace/backend/node_modules,type=volume", - "source=decla-red-shared-node_modules2,target=/workspace/shared/node_modules,type=volume" + "source=decla-red-root-node_modules-static,target=/workspace/node_modules,type=volume", + "source=decla-red-frontend-node_modules-static,target=/workspace/frontend/node_modules,type=volume", + "source=decla-red-backend-node_modules-static,target=/workspace/backend/node_modules,type=volume", + "source=decla-red-shared-node_modules-static,target=/workspace/shared/node_modules,type=volume" ], "forwardPorts": [3000, 8080], - "postCreateCommand": "sudo npm install && sudo npm run initialize && npm run build" + "postCreateCommand": "chown node:node ./**/node_modules && sudo npm install && npm run initialize && npm run build" } diff --git a/backend/package.json b/backend/package.json index ad36970..dc4016b 100644 --- a/backend/package.json +++ b/backend/package.json @@ -6,9 +6,9 @@ "author": "AndrĂ¡s Schmelczer (https://schmelczer.dev/)", "main": "index.js", "scripts": { - "build": "webpack --mode production", + "build": "npx webpack --mode production", "initialize": "npm install", - "start": "concurrently --kill-others \"webpack --mode development -w\" \"nodemon --legacy-watch dist/main.js\"", + "start": "concurrently --kill-others \"npx webpack --mode development -w\" \"nodemon --legacy-watch dist/main.js\"", "try-build": "npm run build && node dist/main.js" }, "dependencies": { diff --git a/backend/webpack.config.js b/backend/webpack.config.js index 34c4fc5..b0586e3 100644 --- a/backend/webpack.config.js +++ b/backend/webpack.config.js @@ -33,6 +33,7 @@ module.exports = (env, argv) => ({ new TerserJSPlugin({ sourceMap: false, test: /\.js$/, + exclude: /node_modules/, terserOptions: { keep_classnames: true, }, @@ -65,6 +66,7 @@ module.exports = (env, argv) => ({ loader: 'ts', target: 'es2015', }, + exclude: /node_modules/, }, ], }, diff --git a/declared.code-workspace b/declared.code-workspace new file mode 100644 index 0000000..3288688 --- /dev/null +++ b/declared.code-workspace @@ -0,0 +1,21 @@ +{ + "folders": [ + { + "name": "Root", + "path": "." + }, + { + "name": "Frontend", + "path": "./frontend" + }, + { + "name": "Backend", + "path": "./backend" + }, + { + "name": "Shared", + "path": "./shared" + } + ], + "settings": {} +} diff --git a/frontend/package.json b/frontend/package.json index a13af73..4dfb715 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -9,9 +9,9 @@ ], "main": "index.js", "scripts": { - "build": "webpack --mode production", + "build": "npx webpack --mode production", "initialize": "npm install", - "start": "webpack-dev-server --mode development", + "start": "npx webpack-dev-server --mode development", "try-build": "npm run build && cd dist && python3 -m http.server 8080" }, "browserslist": [ diff --git a/frontend/webpack.config.js b/frontend/webpack.config.js index fa96363..f2a7f66 100644 --- a/frontend/webpack.config.js +++ b/frontend/webpack.config.js @@ -37,6 +37,7 @@ module.exports = (env, argv) => ({ new TerserJSPlugin({ sourceMap: false, test: /\.js$/, + exclude: /node_modules/, terserOptions: { keep_classnames: true, }, @@ -109,6 +110,7 @@ module.exports = (env, argv) => ({ loader: 'ts', target: 'es2015', }, + exclude: /node_modules/, }, ], }, diff --git a/package.json b/package.json index 36a6e67..d5544fe 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "prettier": "^2.0.5", "sdf-2d": "^0.4.0", "socket.io-client": "^2.3.1", + "typescript": "^3.9.7", "uuid": "^8.2.0" } } diff --git a/shared/package.json b/shared/package.json index 1ebaa18..547b1ff 100644 --- a/shared/package.json +++ b/shared/package.json @@ -8,11 +8,10 @@ "lib" ], "scripts": { - "build": "webpack --mode production", - "build-before": "npm run build", + "build-before": "npx webpack --mode production", "initialize": "npm install", - "start": "webpack --mode development --watch", - "try-build-before": "npm run build-before" + "start": "npx webpack --mode development --watch", + "try-build-before": "npx webpack --mode production" }, "devDependencies": { "clean-webpack-plugin": "^3.0.0", diff --git a/shared/src/commands/command-executors.ts b/shared/src/commands/command-executors.ts new file mode 100644 index 0000000..a5271f5 --- /dev/null +++ b/shared/src/commands/command-executors.ts @@ -0,0 +1,3 @@ +export type CommandExecutors = { + [type: string]: (command: any) => unknown; +}; diff --git a/shared/src/commands/command-receiver.ts b/shared/src/commands/command-receiver.ts index 385874f..6495573 100644 --- a/shared/src/commands/command-receiver.ts +++ b/shared/src/commands/command-receiver.ts @@ -1,9 +1,6 @@ +import { CommandExecutors } from './command-executors'; import { Command } from './command'; -export type CommandExecutors = { - [type: string]: (command: any) => unknown; -}; - export abstract class CommandReceiver { protected commandExecutors: CommandExecutors = {}; diff --git a/shared/src/helper/circle.ts b/shared/src/helper/circle.ts index 5710478..4fe9632 100644 --- a/shared/src/helper/circle.ts +++ b/shared/src/helper/circle.ts @@ -5,6 +5,10 @@ import { serializable } from '../transport/serialization/serializable'; export class Circle { constructor(public center: vec2, public radius: number) {} + public distance(target: vec2): number { + return vec2.distance(this.center, target) - this.radius; + } + public toArray(): Array { return [this.center, this.radius]; } diff --git a/shared/src/main.ts b/shared/src/main.ts index 9e02766..7ff5cd3 100644 --- a/shared/src/main.ts +++ b/shared/src/main.ts @@ -10,6 +10,7 @@ export * from './commands/types/set-view-area-action'; export * from './commands/types/primary-action'; export * from './commands/types/secondary-action'; export * from './commands/command-receiver'; +export * from './commands/command-executors'; export * from './commands/command-generator'; export * from './commands/broadcast-commands'; export * from './helper/array'; diff --git a/tsconfig.json b/tsconfig.json index fa9d96f..0a9eb5b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "outDir": "lib", "sourceMap": true, "declaration": true, "declarationMap": true, @@ -12,5 +13,6 @@ "module": "es6", "composite": true, "lib": ["dom", "es2017"] - } + }, + "include": ["**/src/**/*", "package.json"] }