Browse Source

Move DB to shared

ghorsington 5 years ago
parent
commit
edbd29c4f1

+ 4 - 4
Makefile

@@ -1,11 +1,11 @@
 
-build_db:
-	cd db && npm run build
+build_shared:
+	cd shared && npm run build
 
-build_bot: build_db
+build_bot: build_shared
 	cd bot && npm run build
 
-build_web: build_db
+build_web: build_shared
 	cd web && npm run build
 
 build:

+ 4 - 4
bot/Dockerfile

@@ -64,8 +64,8 @@ COPY --from=opencv-builder /usr/local/share/OpenCV /usr/local/share/OpenCV
 COPY ./bot/package.json ./
 RUN npm install
 
-WORKDIR /db/
-COPY ./db/package.json .
+WORKDIR /shared/
+COPY ./shared/package.json .
 RUN npm install
 
 FROM node:10-alpine
@@ -76,13 +76,13 @@ WORKDIR /app
 RUN apk --no-cache add make
 
 COPY --from=builder node_modules bot/node_modules
-COPY --from=builder /db/node_modules db/node_modules
+COPY --from=builder /shared/node_modules shared/node_modules
 COPY --from=opencv-builder /opencv/opencv-${OPENCV_VERSION}/build/lib/libopencv* /usr/local/lib/
 COPY --from=opencv-builder /usr/local/include/opencv2 /usr/local/include/opencv2
 COPY --from=opencv-builder /usr/local/share/OpenCV /usr/local/share/OpenCV
 
 COPY ./bot bot
-COPY ./db db
+COPY ./shared shared
 COPY ./Makefile Makefile
 
 RUN make build_bot

+ 2 - 1
bot/package.json

@@ -22,7 +22,7 @@
    "author": "Geoffrey Horsington <geoffrey.hoooooorse@gmail.com>",
    "license": "MIT",
    "_moduleAliases": {
-      "@db": "../db/lib/src",
+      "@shared": "../shared/lib/src",
       "src": "./build"
    },
    "dependencies": {
@@ -59,6 +59,7 @@
       "turndown": "^5.0.1",
       "typeorm": "0.2.18",
       "typescript": "^3.5.2",
+      "typescript-rest-rpc": "^1.0.10",
       "uws": "^99.0.0",
       "yaml": "^1.6.0"
    },

+ 1 - 1
bot/src/commands/aggregators/com3d2_updates.ts

@@ -2,7 +2,7 @@ import request from "request-promise-native";
 import { Response } from "request";
 import { IAggregator, INewsItem } from "./aggregator";
 import { getRepository } from "typeorm";
-import { AggroNewsItem } from "@db/entity/AggroNewsItem";
+import { AggroNewsItem } from "@shared/db/entity/AggroNewsItem";
 import cheerio from "cheerio";
 
 const updatePage = "http://com3d2.jp/update/";

+ 1 - 1
bot/src/commands/aggregators/com3d2_world.ts

@@ -2,7 +2,7 @@ import request from "request-promise-native";
 import { Response } from "request";
 import { INewsItem, IAggregator } from "./aggregator";
 import { getRepository } from "typeorm";
-import { AggroNewsItem } from "@db/entity/AggroNewsItem";
+import { AggroNewsItem } from "@shared/db/entity/AggroNewsItem";
 import cheerio from "cheerio";
 
 const kissDiaryRoot = "https://com3d2.world/r18/notices.php";

+ 1 - 1
bot/src/commands/aggregators/kiss_diary.ts

@@ -2,7 +2,7 @@ import request from "request-promise-native";
 import { Response } from "request";
 import { INewsItem, IAggregator } from "./aggregator";
 import { getRepository } from "typeorm";
-import { AggroNewsItem } from "@db/entity/AggroNewsItem";
+import { AggroNewsItem } from "@shared/db/entity/AggroNewsItem";
 import cheerio from "cheerio";
 
 const urlPattern = /diary\.php\?no=(\d+)/i;

+ 3 - 3
bot/src/commands/contest.ts

@@ -2,12 +2,12 @@ import { Dict, compareNumbers, isAuthorisedAsync } from "../util";
 import { Message, TextChannel, RichEmbed, MessageReaction, User, Collector, Collection, SnowflakeUtil } from "discord.js";
 import yaml from "yaml";
 import { getRepository, getManager } from "typeorm";
-import { Contest } from "@db/entity/Contest";
+import { Contest } from "@shared/db/entity/Contest";
 import emoji_regex from "emoji-regex";
 import { client } from "../client";
 import { scheduleJob } from "node-schedule";
-import { ContestEntry } from "@db/entity/ContestEntry";
-import { ContestVote } from "@db/entity/ContestVote";
+import { ContestEntry } from "@shared/db/entity/ContestEntry";
+import { ContestVote } from "@shared/db/entity/ContestVote";
 import { CommandSet, Command, Action, ActionType } from "src/model/command";
 
 const CHANNEL_ID_PATTERN = /<#(\d+)>/;

+ 1 - 1
bot/src/commands/dead_chat.ts

@@ -1,5 +1,5 @@
 import { getRepository } from "typeorm";
-import { DeadChatReply } from "@db/entity/DeadChatReply";
+import { DeadChatReply } from "@shared/db/entity/DeadChatReply";
 import { CommandSet, Action, ActionType } from "src/model/command";
 import { Message } from "discord.js";
 

+ 2 - 2
bot/src/commands/facemorph.ts

@@ -6,8 +6,8 @@ import * as path from "path";
 import request from "request-promise-native";
 import { Message } from "discord.js";
 import { getRepository } from "typeorm";
-import { FaceCaptionMessage, FaceCaptionType } from "@db/entity/FaceCaptionMessage";
-import { KnownChannel } from "@db/entity/KnownChannel";
+import { FaceCaptionMessage, FaceCaptionType } from "@shared/db/entity/FaceCaptionMessage";
+import { KnownChannel } from "@shared/db/entity/KnownChannel";
 import { CommandSet, Action, ActionType, Command } from "src/model/command";
 
 const EMOTE_GUILD = "505333548694241281";

+ 3 - 3
bot/src/commands/forums_news_checker.ts

@@ -5,9 +5,9 @@ import sha1 from "sha1";
 import { TextChannel, Message, ReactionCollector, MessageReaction, Collector, User, Channel } from "discord.js";
 import { Dict } from "../util";
 import { getRepository, Not, IsNull } from "typeorm";
-import { PostedForumNewsItem } from "@db/entity/PostedForumsNewsItem";
-import { KnownChannel } from "@db/entity/KnownChannel";
-import { PostVerifyMessage } from "@db/entity/PostVerifyMessage";
+import { PostedForumNewsItem } from "@shared/db/entity/PostedForumsNewsItem";
+import { KnownChannel } from "@shared/db/entity/KnownChannel";
+import { PostVerifyMessage } from "@shared/db/entity/PostVerifyMessage";
 import { render } from "../bbcode-parser/bbcode-js";
 import { CommandSet, Command } from "src/model/command";
 

+ 1 - 1
bot/src/commands/guide.ts

@@ -1,7 +1,7 @@
 import { isAuthorisedAsync } from "../util";
 import { Message } from "discord.js";
 import { getRepository } from "typeorm";
-import { Guide, GuideType, GuideKeyword } from "@db/entity/Guide";
+import { Guide, GuideType, GuideKeyword } from "@shared/db/entity/Guide";
 import { CommandSet, Action, ActionType, Command } from "src/model/command";
 
 @CommandSet

+ 2 - 2
bot/src/commands/news_aggregator.ts

@@ -9,8 +9,8 @@ import { Dict } from "../util";
 import { IAggregator, NewsPostItem } from "./aggregators/aggregator";
 import { RichEmbed, TextChannel, Message, Channel, ReactionCollector, MessageReaction, User, Collector } from "discord.js";
 import { getRepository, IsNull, Not } from "typeorm";
-import { KnownChannel } from "@db/entity/KnownChannel";
-import { AggroNewsItem } from "@db/entity/AggroNewsItem";
+import { KnownChannel } from "@shared/db/entity/KnownChannel";
+import { AggroNewsItem } from "@shared/db/entity/AggroNewsItem";
 import { v3beta1 } from "@google-cloud/translate";
 import { CommandSet } from "src/model/command";
 const { TranslationServiceClient } = v3beta1;

+ 1 - 1
bot/src/commands/quote.ts

@@ -1,6 +1,6 @@
 import { isAuthorisedAsync } from "../util";
 import { getRepository } from "typeorm";
-import { Quote } from "@db/entity/Quote";
+import { Quote } from "@shared/db/entity/Quote";
 import { CommandSet, Command } from "src/model/command";
 import { Message } from "discord.js";
 

+ 3 - 3
bot/src/commands/react.ts

@@ -1,8 +1,8 @@
 import { client } from "../client";
 import { getRepository } from "typeorm";
-import { MessageReaction } from "@db/entity/MessageReaction";
-import { KnownUser } from "@db/entity/KnownUser";
-import { ReactionType, ReactionEmote } from "@db/entity/ReactionEmote";
+import { MessageReaction } from "@shared/db/entity/MessageReaction";
+import { KnownUser } from "@shared/db/entity/KnownUser";
+import { ReactionType, ReactionEmote } from "@shared/db/entity/ReactionEmote";
 import { isAuthorisedAsync } from "../util";
 import { CommandSet, Command, Action, ActionType } from "src/model/command";
 import { Message } from "discord.js";

+ 9 - 9
bot/src/lowdb_migrator.ts

@@ -1,15 +1,15 @@
 import { existsSync, readFileSync, renameSync } from "fs";
 import { getRepository, Repository } from "typeorm";
 import { Dictionary } from "lodash";
-import { KnownUser, User, UserRole } from "@db/entity/KnownUser";
-import { ReactionType, ReactionEmote } from "@db/entity/ReactionEmote";
-import { Guide, GuideKeyword, GuideType } from "@db/entity/Guide";
-import { Quote } from "@db/entity/Quote";
-import { MessageReaction } from "@db/entity/MessageReaction";
-import { FaceCaptionMessage, FaceCaptionType } from "@db/entity/FaceCaptionMessage";
-import { PostedForumNewsItem } from "@db/entity/PostedForumsNewsItem";
-import { KnownChannel } from "@db/entity/KnownChannel";
-import { DeadChatReply } from "@db/entity/DeadChatReply";
+import { KnownUser, User, UserRole } from "@shared/db/entity/KnownUser";
+import { ReactionType, ReactionEmote } from "@shared/db/entity/ReactionEmote";
+import { Guide, GuideKeyword, GuideType } from "@shared/db/entity/Guide";
+import { Quote } from "@shared/db/entity/Quote";
+import { MessageReaction } from "@shared/db/entity/MessageReaction";
+import { FaceCaptionMessage, FaceCaptionType } from "@shared/db/entity/FaceCaptionMessage";
+import { PostedForumNewsItem } from "@shared/db/entity/PostedForumsNewsItem";
+import { KnownChannel } from "@shared/db/entity/KnownChannel";
+import { DeadChatReply } from "@shared/db/entity/DeadChatReply";
 
 type EmoteTable = { [reactionType: string]: string[] };
 

+ 2 - 2
bot/src/main.ts

@@ -1,4 +1,4 @@
-// We need some kind of module resolver for @db. We use module-alias.
+// We need some kind of module resolver for @shared/db. We use module-alias.
 require("module-alias/register");
 
 import dotenv from "dotenv";
@@ -22,7 +22,7 @@ import * as mCmd from "./model/command";
 import "reflect-metadata";
 import { createConnection, getConnectionOptions } from "typeorm";
 import { getNumberEnums } from "./util";
-import { DB_ENTITIES } from "@db/entities";
+import { DB_ENTITIES } from "@shared/db/entities";
 import { BOT_COMMAND_DESCRIPTOR } from "./model/command";
 
 

+ 1 - 1
bot/src/util.ts

@@ -1,6 +1,6 @@
 import { GuildMember } from "discord.js";
 import { getRepository, In } from "typeorm";
-import { KnownUser } from "@db/entity/KnownUser";
+import { KnownUser } from "@shared/db/entity/KnownUser";
 
 const VALID_EXTENSIONS = new Set([
     "png",

+ 2 - 2
bot/tsconfig.json

@@ -14,12 +14,12 @@
         "experimentalDecorators": true,
         "baseUrl": ".",
         "paths": {
-            "@db/*": ["../db/src/*"]
+            "@shared/*": ["../shared/src/*"]
         }
     },
     "references": [
         {
-            "path": "../db"
+            "path": "../shared"
         }
     ],
     "include": [

+ 1 - 1
db/package.json

@@ -1,5 +1,5 @@
 {
-  "name": "db",
+  "name": "shared",
   "version": "1.0.0",
   "description": "",
   "main": "index.js",

db/src/entities.ts → shared/src/db/entities.ts


db/src/entity/AggroNewsItem.ts → shared/src/db/entity/AggroNewsItem.ts


db/src/entity/Contest.ts → shared/src/db/entity/Contest.ts


db/src/entity/ContestEntry.ts → shared/src/db/entity/ContestEntry.ts


db/src/entity/ContestVote.ts → shared/src/db/entity/ContestVote.ts


db/src/entity/DeadChatReply.ts → shared/src/db/entity/DeadChatReply.ts


db/src/entity/FaceCaptionMessage.ts → shared/src/db/entity/FaceCaptionMessage.ts


db/src/entity/Guide.ts → shared/src/db/entity/Guide.ts


db/src/entity/KnownChannel.ts → shared/src/db/entity/KnownChannel.ts


db/src/entity/KnownUser.ts → shared/src/db/entity/KnownUser.ts


db/src/entity/MessageReaction.ts → shared/src/db/entity/MessageReaction.ts


db/src/entity/PostVerifyMessage.ts → shared/src/db/entity/PostVerifyMessage.ts


db/src/entity/PostedForumsNewsItem.ts → shared/src/db/entity/PostedForumsNewsItem.ts


db/src/entity/Quote.ts → shared/src/db/entity/Quote.ts


db/src/entity/ReactionEmote.ts → shared/src/db/entity/ReactionEmote.ts


db/tsconfig.json → shared/tsconfig.json


+ 3 - 3
web/Dockerfile

@@ -4,8 +4,8 @@ RUN apk --no-cache add make
 
 WORKDIR /app
 
-COPY ./db/package.json ./db/package.json
-WORKDIR /app/db
+COPY ./shared/package.json ./shared/package.json
+WORKDIR /app/shared
 RUN npm install
 
 WORKDIR /app
@@ -16,7 +16,7 @@ RUN npm install
 
 WORKDIR /app
 
-COPY ./db ./db
+COPY ./shared ./shared
 COPY ./web ./web
 COPY ./Makefile ./Makefile
 

+ 2 - 1
web/package.json

@@ -28,7 +28,8 @@
     "request": "^2.88.0",
     "request-promise-native": "^1.0.7",
     "sirv": "^0.4.0",
-    "typeorm": "^0.2.18"
+    "typeorm": "^0.2.18",
+    "typescript-rest-rpc": "^1.0.10"
   },
   "devDependencies": {
     "@babel/core": "^7.0.0",

+ 1 - 1
web/src/server.ts

@@ -3,7 +3,7 @@ import * as sapper from '@sapper/server';
 import { createConnection, getConnectionOptions } from "typeorm";
 import express from "express";
 import dotenv from "dotenv";
-import { DB_ENTITIES } from "@db/entities";
+import { DB_ENTITIES } from "@shared/db/entities";
 
 if(process.env.NODE_ENV == "development") {
 	console.log(process.cwd());

+ 2 - 2
web/tsconfig.json

@@ -15,12 +15,12 @@
         "experimentalDecorators": true,
         "baseUrl": ".",
         "paths": {
-            "@db/*": ["../db/src/*"]
+            "@shared/*": ["../shared/src/*"]
         }
     },
     "references": [
         {
-            "path": "../db"
+            "path": "../shared"
         }
     ],
     "include": [