From e7b8c0d64d8d2dd4227a53e43ace56b663c82080 Mon Sep 17 00:00:00 2001 From: Dragory Date: Fri, 14 Dec 2018 06:47:58 +0200 Subject: [PATCH] Add build process for prod --- .gitignore | 3 +++ ormconfig.js | 16 +++++++++++++--- package-lock.json | 45 ++++++++++++++++++++++++++++++++++++++++----- package.json | 8 ++++++-- tsconfig.json | 14 ++++++++------ 5 files changed, 70 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index d31e8019..ee16b707 100644 --- a/.gitignore +++ b/.gitignore @@ -69,6 +69,9 @@ desktop.ini # PHPStorm .idea/ +# Compiled files +/dist + # Misc /convert.js /startscript.js diff --git a/ormconfig.js b/ormconfig.js index 688d8216..64420297 100644 --- a/ormconfig.js +++ b/ormconfig.js @@ -1,8 +1,18 @@ require('dotenv').config(); +const path = require('path'); + const moment = require('moment-timezone'); moment.tz.setDefault('UTC'); +const entities = process.env.NODE_ENV === 'production' + ? path.resolve(__dirname, 'dist/data/entities/*.js') + : path.resolve(__dirname, 'src/data/entities/*.ts'); + +const migrations = process.env.NODE_ENV === 'production' + ? path.resolve(__dirname, 'dist/migrations/*.js') + : path.resolve(__dirname, 'src/migrations/*.ts'); + module.exports = { type: "mysql", host: process.env.DB_HOST, @@ -16,7 +26,7 @@ module.exports = { synchronize: false, // Entities - entities: [`${__dirname}/src/data/entities/*.ts`], + entities: [entities], // Pool options extra: { @@ -31,8 +41,8 @@ module.exports = { }, // Migrations - migrations: ["src/migrations/*.ts"], + migrations: [migrations], cli: { - migrationsDir: "src/migrations" + migrationsDir: path.dirname(migrations) }, }; diff --git a/package-lock.json b/package-lock.json index 52a71834..b643a9aa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "newmodbot", + "name": "zeppelin", "version": "0.0.1", "lockfileVersion": 1, "requires": true, @@ -676,6 +676,29 @@ "capture-stack-trace": "^1.0.0" } }, + "cross-env": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-5.2.0.tgz", + "integrity": "sha512-jtdNFfFW1hB7sMhr/H6rW1Z45LFqyI431m3qU6bFXcQ3Eh7LtBuG3h74o7ohHZ3crrRkkqHlo4jYHFPcjroANg==", + "requires": { + "cross-spawn": "^6.0.5", + "is-windows": "^1.0.0" + }, + "dependencies": { + "cross-spawn": { + "version": "6.0.5", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-6.0.5.tgz", + "integrity": "sha512-eTVLrBSt7fjbDygz805pMnstIs2VTBNkRm0qxZd+M7A5XDdxVRWO5MxGBXZhjY4cqLYLdtrGqRf8mBPmzwSpWQ==", + "requires": { + "nice-try": "^1.0.4", + "path-key": "^2.0.1", + "semver": "^5.5.0", + "shebang-command": "^1.2.0", + "which": "^1.2.9" + } + } + } + }, "cross-spawn": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-5.1.0.tgz", @@ -2068,8 +2091,7 @@ "is-windows": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/is-windows/-/is-windows-1.0.2.tgz", - "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==", - "dev": true + "integrity": "sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA==" }, "isarray": { "version": "1.0.0", @@ -2685,6 +2707,11 @@ "to-regex": "^3.0.1" } }, + "nice-try": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/nice-try/-/nice-try-1.0.5.tgz", + "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==" + }, "nodemon": { "version": "1.17.5", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-1.17.5.tgz", @@ -3236,6 +3263,15 @@ "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", "dev": true }, + "rimraf": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.2.tgz", + "integrity": "sha512-lreewLK/BlghmxtfH36YYVg1i8IAce4TI7oao75I1g245+6BctqTVQiBP3YUJ9C6DQOXJmkYR9X9fCLtCOJc5w==", + "dev": true, + "requires": { + "glob": "^7.0.5" + } + }, "rxjs": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.2.1.tgz", @@ -3267,8 +3303,7 @@ "semver": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/semver/-/semver-5.5.0.tgz", - "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==", - "dev": true + "integrity": "sha512-4SJ3dm0WAwWy/NVeioZh5AntkdJoWKxHxcmyP622fOkgHa4z3R0TdBJICINyaSDE6uNwVc8gZr+ZinwZAH4xIA==" }, "semver-compare": { "version": "1.0.0", diff --git a/package.json b/package.json index 4e318165..f61a5765 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,14 @@ "private": true, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "ts-node src/index.ts", + "start-dev": "ts-node src/index.ts", "start-watch": "nodemon", "precommit": "lint-staged", "postcommit": "git update-index --again", "format": "prettier --write \"./**/*.ts\"", - "typeorm": "ts-node ./node_modules/typeorm/cli.js" + "typeorm": "ts-node ./node_modules/typeorm/cli.js", + "build": "rimraf dist && tsc", + "start-prod": "cross-env NODE_ENV=production node dist/index.js" }, "lint-staged": { "*.ts": [ @@ -24,6 +26,7 @@ "dependencies": { "@types/lodash.at": "^4.6.3", "@types/moment-timezone": "^0.5.6", + "cross-env": "^5.2.0", "dotenv": "^4.0.0", "emoji-regex": "^7.0.0", "eris": "^0.8.6", @@ -51,6 +54,7 @@ "lint-staged": "^7.2.0", "nodemon": "^1.17.5", "prettier": "^1.8.2", + "rimraf": "^2.6.2", "tslint": "^5.8.0", "tslint-config-prettier": "^1.6.0" } diff --git a/tsconfig.json b/tsconfig.json index b6fa8ed1..372f9fcd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,14 +6,16 @@ "allowSyntheticDefaultImports": true, "experimentalDecorators": true, "emitDecoratorMetadata": true, - "target": "ES6", + "target": "es2017", "lib": [ - "es6", - "es7", - "ES2017" + "es2017" ], "baseUrl": "./", "resolveJsonModule": true, - "esModuleInterop": true - } + "esModuleInterop": true, + "outDir": "./dist" + }, + "include": [ + "src/**/*.ts" + ] }