From 900cab5e59b64ce40ae1c349ef2ca4f56043af0a Mon Sep 17 00:00:00 2001 From: Drew Short Date: Fri, 10 Jan 2020 13:57:01 -0600 Subject: [PATCH] Starting conversion to typescript --- .dockerignore | 3 +++ .gitignore | 3 +++ Dockerfile | 16 +++++++++++++--- index.js | 6 +++--- package-lock.json | 6 ++++++ package.json | 6 ++++-- {bot => src}/bot.js | 0 {bot => src}/config.js | 0 {bot => src}/engine.js | 0 {bot => src}/logging.js | 0 {bot => src}/message.js | 0 {bot => src}/module/abstract.js | 0 {bot => src}/module/admin.js | 0 {bot => src}/module/example.js | 0 {bot => src}/module/giphy.js | 0 {bot => src}/module/help.js | 0 {bot => src}/module/index.js | 0 {bot => src}/module/szurubooru/client.js | 0 {bot => src}/module/szurubooru/index.js | 0 {bot => src}/utility.js | 0 tsconfig.json | 13 +++++++++++++ 21 files changed, 45 insertions(+), 8 deletions(-) rename {bot => src}/bot.js (100%) rename {bot => src}/config.js (100%) rename {bot => src}/engine.js (100%) rename {bot => src}/logging.js (100%) rename {bot => src}/message.js (100%) rename {bot => src}/module/abstract.js (100%) rename {bot => src}/module/admin.js (100%) rename {bot => src}/module/example.js (100%) rename {bot => src}/module/giphy.js (100%) rename {bot => src}/module/help.js (100%) rename {bot => src}/module/index.js (100%) rename {bot => src}/module/szurubooru/client.js (100%) rename {bot => src}/module/szurubooru/index.js (100%) rename {bot => src}/utility.js (100%) create mode 100644 tsconfig.json diff --git a/.dockerignore b/.dockerignore index a27ca7c..c732547 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,9 @@ # Installed node files node_modules/ +# Compiled Files +dist/ + # Logging files log/ diff --git a/.gitignore b/.gitignore index fc98b80..32662d5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # Node Files node_modules/ +# Compiled Files +dist/ + # Config files data/*config.json diff --git a/Dockerfile b/Dockerfile index a1dbcdf..7c2e9fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,26 @@ -FROM node:12.14-stretch +FROM node:12.14-stretch AS builder +WORKDIR /opt/baphomet +COPY . /opt/baphomet + +RUN cd /opt/baphomet \ + && npm install \ + && npm run build +FROM node:12.14-stretch +WORKDIR /opt/baphomet COPY . /opt/baphomet ENV NODE_ENV=production ENV LOG_LEVEL=warn -RUN mkdir /opt/baphomet/log +RUN rm -rf /opt/baphomet/src \ + && mkdir /opt/baphomet/log + +COPY --from=builder /opt/baphomet/dist /opt/baphomet/dist RUN cd /opt/baphomet \ && npm install --only=prod \ && chmod +x entrypoint.sh -WORKDIR /opt/baphomet ENTRYPOINT [ "./entrypoint.sh" ] CMD [ "run" ] diff --git a/index.js b/index.js index 1e1f832..712f6ae 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ -let bot = require('./bot/bot'); -let { getConfig } = require('./bot/config'); -let engine = require('./bot/engine'); +let bot = require('./dist/bot'); +let { getConfig } = require('./dist/config'); +let engine = require('./dist/engine'); let config = getConfig(process.env.NODE_PATH + "/data/config.json", ['accessToken']) diff --git a/package-lock.json b/package-lock.json index 91170ad..3515ea2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1272,6 +1272,12 @@ "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=" }, + "typescript": { + "version": "3.7.4", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.4.tgz", + "integrity": "sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw==", + "dev": true + }, "unhomoglyph": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/unhomoglyph/-/unhomoglyph-1.0.3.tgz", diff --git a/package.json b/package.json index 59ff5da..6ff7dc0 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "description": "A Matrix bot written on top of the matrix-js-sdk", "repository": "https://git.nulloctet.com/warricksothr/baphomet-js", "scripts": { - "test": "mocha" + "test": "mocha", + "build": "tsc" }, "dependencies": { "axios": "^0.19.0", @@ -17,6 +18,7 @@ "winston": "^3.2.1" }, "devDependencies": { - "mocha": "^6.2.2" + "mocha": "^6.2.2", + "typescript": "^3.7.4" } } diff --git a/bot/bot.js b/src/bot.js similarity index 100% rename from bot/bot.js rename to src/bot.js diff --git a/bot/config.js b/src/config.js similarity index 100% rename from bot/config.js rename to src/config.js diff --git a/bot/engine.js b/src/engine.js similarity index 100% rename from bot/engine.js rename to src/engine.js diff --git a/bot/logging.js b/src/logging.js similarity index 100% rename from bot/logging.js rename to src/logging.js diff --git a/bot/message.js b/src/message.js similarity index 100% rename from bot/message.js rename to src/message.js diff --git a/bot/module/abstract.js b/src/module/abstract.js similarity index 100% rename from bot/module/abstract.js rename to src/module/abstract.js diff --git a/bot/module/admin.js b/src/module/admin.js similarity index 100% rename from bot/module/admin.js rename to src/module/admin.js diff --git a/bot/module/example.js b/src/module/example.js similarity index 100% rename from bot/module/example.js rename to src/module/example.js diff --git a/bot/module/giphy.js b/src/module/giphy.js similarity index 100% rename from bot/module/giphy.js rename to src/module/giphy.js diff --git a/bot/module/help.js b/src/module/help.js similarity index 100% rename from bot/module/help.js rename to src/module/help.js diff --git a/bot/module/index.js b/src/module/index.js similarity index 100% rename from bot/module/index.js rename to src/module/index.js diff --git a/bot/module/szurubooru/client.js b/src/module/szurubooru/client.js similarity index 100% rename from bot/module/szurubooru/client.js rename to src/module/szurubooru/client.js diff --git a/bot/module/szurubooru/index.js b/src/module/szurubooru/index.js similarity index 100% rename from bot/module/szurubooru/index.js rename to src/module/szurubooru/index.js diff --git a/bot/utility.js b/src/utility.js similarity index 100% rename from bot/utility.js rename to src/utility.js diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..3b14de4 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,13 @@ +{ + "compilerOptions": { + "outDir": "./dist", + "allowJs": true, + "target": "ES2015", + "typeRoots": [ + "node_modules/@types" + ] + }, + "include": [ + "./src/**/*" + ] +} \ No newline at end of file