From 7859110d97d076d40337de2a4aca077914d81805 Mon Sep 17 00:00:00 2001 From: Kfir Dayan Date: Mon, 3 Apr 2023 19:52:41 +0300 Subject: [PATCH] dockerfile add tsc command --- .dockerignore | 1 - Dockerfile | 11 ++++++++++- package-lock.json | 16 +++++++++++++++- package.json | 5 +++-- src/index.ts | 10 +++------- tsconfig.json | 7 +++++-- 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/.dockerignore b/.dockerignore index 92a116f..5cb6bfd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,4 +1,3 @@ node_modules npm-debug.log -src tmp \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 7d0eb91..1d09dc4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,9 @@ WORKDIR /usr/src/app COPY package*.json ./ RUN npm install + +RUN npm install -g typescript + # If you are building your code for production # RUN npm ci --omit=dev @@ -16,4 +19,10 @@ RUN npm install COPY . . EXPOSE ${PORT} -CMD [ "node", "dist/index.js" ] \ No newline at end of file + +# run npm build to create the dist folder + +RUN tsc +# run npm start to start the server +CMD [ "npm", "start" ] + diff --git a/package-lock.json b/package-lock.json index 9a6ab7d..5f3c910 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,8 @@ }, "devDependencies": { "@types/express": "^4.17.17", - "@types/node": "^18.15.5" + "@types/node": "^18.15.5", + "typescript": "^5.0.3" } }, "node_modules/@babel/runtime": { @@ -1293,6 +1294,19 @@ "node": ">= 0.6" } }, + "node_modules/typescript": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.3.tgz", + "integrity": "sha512-xv8mOEDnigb/tN9PSMTwSEqAnUvkoXMQlicOb0IUVDBSQCgBSaAAROUZYy2IcUy5qU6XajK5jjjO7TMWqBTKZA==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=12.20" + } + }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", diff --git a/package.json b/package.json index e56d53e..f5ac154 100644 --- a/package.json +++ b/package.json @@ -11,11 +11,12 @@ }, "scripts": { "dev": "nodemon dist/index.js", - "build": "tsc", + "build": "npx tsc", "start": "node dist/index.js" }, "devDependencies": { "@types/express": "^4.17.17", - "@types/node": "^18.15.5" + "@types/node": "^18.15.5", + "typescript": "^5.0.3" } } diff --git a/src/index.ts b/src/index.ts index 5f58443..56e6903 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,11 +7,6 @@ import env from 'dotenv'; env.config(); - - -const CronJob = require('cron').CronJob; - - class App { googleCalendar: GoogleCalendar; gameSource: GameSource; @@ -40,6 +35,8 @@ class App { const app = new App(); console.log("Declaring Cron Job every day at 10:00") +const CronJob = require('cron').CronJob; + const job = new CronJob( "0 10 * * *", // every day at 10:00, async () => { @@ -62,10 +59,9 @@ const webServer = express(); webServer.use(express.static('public')) webServer.listen(process.env.PORT, () => { - console.log('Example app listening on port '+process.env.PORT+'!') + console.log(`Calender app listening on port ${process.env.PORT}!`) }) -// when client try to access 404 file webServer.use(function (req, res, next) { res.status(404).send("Sorry can't find that!") }) \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index 9326bb1..8c55c8c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,5 +7,8 @@ "moduleResolution": "node", "outDir": "./dist", "rootDir": "./src" - } -} \ No newline at end of file + }, + "include": [ + "src/**/*" + ] +}