Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Simplify project setup (#3)
Thomase5d7df3e7b6c
diff --git a/.env.sample b/.envsimilarity index 95%rename from .env.samplerename to .envindex 13c6f5e5d3..9c4f9789a3 100644--- a/.env.sample+++ b/.env@@ -3,7 +3,7 @@ COMPOSE_PROJECT_NAME=ghostfolio-development# CACHECACHE_TTL=1MAX_ITEM_IN_CACHE=9999-REDIS_HOST=redis+REDIS_HOST=localhostREDIS_PORT=6379# POSTGRESdiff --git a/.gitignore b/.gitignoreindex b19ecb9c9d..301ed078d4 100644--- a/.gitignore+++ b/.gitignore@@ -40,8 +40,3 @@ testem.log# System Files.DS_StoreThumbs.db--# Local-/backups-.env-ec2-nano-ssh.pemdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6cfec22d3f..56154676b8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Changed- Changed the routing to `routerLink` for an improved navigation experience+- Simplified the initial project setup## 0.85.0 - 12.04.2021diff --git a/Dockerfile b/Dockerfiledeleted file mode 100644index af9ed9ac78..0000000000--- a/Dockerfile+++ /dev/null@@ -1,9 +0,0 @@-FROM node:14--# Create app directory-WORKDIR /app--COPY . .--EXPOSE 3333-CMD [ "npm", "run", "start:prod" ]diff --git a/README.md b/README.mdindex a49cad0dde..c389af9125 100644--- a/README.md+++ b/README.md@@ -23,18 +23,19 @@### Setup1. Run `yarn install`-2. Run `yarn docker:dockerize`-3. Copy `.env.sample` to `docker/.env`-4. Run `cd docker/<version>`-5. Run `docker-compose build`-6. Run `docker-compose up -d`+2. Run `cd docker`+3. Run `docker compose build`+4. Run `docker compose up -d`+5. Run `yarn setup:database`+6. Start server and client (see _Development_)+7. Login as _Admin_ with the `Security Token`: `ae76872ae8f3419c6d6f64bf51888ecbcc703927a342d815fafe486acdb938da07d0cf44fca211a0be74a423238f535362d390a41e81e633a9ce668a6e31cdf9`## Development### Start server-- Serve: Run `yarn start:server`- Debug: Run `yarn watch:server` and click "Launch Program" in _Visual Studio Code_+- Serve: Run `yarn start:server`### Start clientdiff --git a/docker-compose.yml b/docker/docker-compose.ymlsimilarity index 53%rename from docker-compose.ymlrename to docker/docker-compose.ymlindex 1530c0da05..8e5a8ec07e 100644--- a/docker-compose.yml+++ b/docker/docker-compose.yml@@ -1,20 +1,5 @@version: '3.7'services:- ghostfolio:- container_name: ghostfolio- image: ghostfolio:{{VERSION}}- restart: unless-stopped- build:- context: .- dockerfile: Dockerfile- depends_on:- - postgres- - redis- env_file:- - ../.env- environment:- - NODE_ENV=production-postgres:image: postgres:12container_name: postgres@@ -34,6 +19,4 @@ services:- 6379:6379volumes:- portainer_data:postgres:- name: ghostfolio-dbdiff --git a/package.json b/package.jsonindex 0aa1403ba7..6d0fa2a240 100644--- a/package.json+++ b/package.json@@ -13,6 +13,8 @@"angular": "node --max_old_space_size=32768 ./node_modules/@angular/cli/bin/ng","build:all": "ng build --prod api && ng build --prod client && yarn run replace-placeholders-in-build","clean": "rimraf dist",+ "database:push": "yarn prisma db push --preview-feature",+ "database:seed": "prisma db seed --preview-feature","dep-graph": "nx dep-graph","docker:build": "cd docker/1.0.1 && docker-compose build","docker:dockerize": "./node_modules/.bin/ts-node ./scripts/dockerize.ts",@@ -29,11 +31,13 @@"nx": "nx","postinstall": "yarn prisma generate","replace-placeholders-in-build": "node ./replace.build.js",+ "setup:database": "yarn database:push && yarn database:seed","start": "node dist/apps/api/main","start:client": "ng serve client --hmr -o","start:prod": "node apps/api/main","start:server": "yarn run nx serve api","test": "ng test",+ "ts-node": "ts-node --compiler-options '{\"module\":\"CommonJS\"}'","update": "nx migrate latest","watch:server": "yarn run nx build api --watch","workspace-generator": "nx workspace-generator"diff --git a/prisma/seed.ts b/prisma/seed.tsnew file mode 100644index 0000000000..b63df349d9--- /dev/null+++ b/prisma/seed.ts@@ -0,0 +1,53 @@+import { Currency, PrismaClient, Role, Type } from '@prisma/client';+const prisma = new PrismaClient();++async function main() {+ const admin = await prisma.user.upsert({+ create: {+ accessToken:+ 'c689bcc894e4a420cb609ee34271f3e07f200594f7d199c50d75add7102889eb60061a04cd2792ebc853c54e37308271271e7bf588657c9e0c37faacbc28c3c6',+ alias: 'Admin',+ id: '4e1af723-95f6-44f8-92a7-464df17f6ec3',+ role: Role.ADMIN+ },+ update: {},+ where: { id: '4e1af723-95f6-44f8-92a7-464df17f6ec3' }+ });++ const demo = await prisma.user.upsert({+ create: {+ accessToken:+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjliMTEyYjRkLTNiN2QtNGJhZC05YmRkLTNiMGY3YjRkYWMyZiIsImlhdCI6MTYxODUxMjAxNCwiZXhwIjoxNjIxMTA0MDE0fQ.l3WUxpI0hxuQtdPrD0kd7sem6S2kx_7CrdNvkmlKuWw',+ alias: 'Demo',+ id: '9b112b4d-3b7d-4bad-9bdd-3b0f7b4dac2f',+ role: Role.DEMO,+ Order: {+ create: [+ {+ currency: Currency.USD,+ date: new Date(Date.UTC(2017, 0, 3, 0, 0, 0)),+ fee: 30,+ id: 'cf7c0418-8535-4089-ae3d-5dbfa0aec2e1',+ quantity: 50,+ symbol: 'TSLA',+ type: Type.BUY,+ unitPrice: 42.97+ }+ ]+ }+ },+ update: {},+ where: { id: '9b112b4d-3b7d-4bad-9bdd-3b0f7b4dac2f' }+ });++ console.log({ admin, demo });+}++main()+ .catch((e) => {+ console.error(e);+ process.exit(1);+ })+ .finally(async () => {+ await prisma.$disconnect();+ });diff --git a/scripts/dockerize.ts b/scripts/dockerize.tsdeleted file mode 100644index 4931cfd575..0000000000--- a/scripts/dockerize.ts+++ /dev/null@@ -1,89 +0,0 @@-import * as dotenv from 'dotenv';-import * as path from 'path';--const replace = require('replace-in-file');-const version = require(path.resolve(__dirname, '..', 'package.json')).version;--/**- * Creates a docker image- */-class Dockerizer {- /**- * @constructor- */- constructor() {- dotenv.config({- path: path.resolve(__dirname, '..', '.env')- });- }-- public async dockerize(aVersion: string) {- console.log('Dockerizing...');-- console.log('Version:', aVersion);-- await this.executeShellCommand('rm -rf ./dist');-- console.log(`Building source...`);-- await this.executeShellCommand('ng build --prod api');-- await this.executeShellCommand('ng build --prod client');-- await this.executeShellCommand('yarn run replace-placeholders-in-build');-- console.log(`Copying files...`);-- await this.executeShellCommand(`mkdir -p ./docker/${aVersion}`);- await this.executeShellCommand(`cp -r ./dist/ ./docker/${aVersion}`);-- await this.executeShellCommand(`mkdir ./docker/${aVersion}/prisma`);- await this.executeShellCommand(- `cp -r ./prisma/schema.prisma ./docker/${aVersion}/prisma/schema.prisma`- );-- await this.executeShellCommand(- `cp ./docker-compose.yml ./docker/${aVersion}`- );-- try {- replace.sync({- allowEmptyPaths: false,- files: `./docker/${aVersion}/docker-compose.yml`,- from: /{{VERSION}}/g,- to: aVersion- });- } catch (error) {- console.error('Error while replacing docker-compose.yml:', error);- }-- await this.executeShellCommand(`cp ./Dockerfile ./docker/${aVersion}`);- await this.executeShellCommand(`cp ./package.json ./docker/${aVersion}`);- await this.executeShellCommand(`cp ./yarn.lock ./docker/${aVersion}`);-- await this.executeShellCommand(- `cd docker/${aVersion} && yarn install --production`- );-- console.log('Dockerizing has been completed successfully.');- }-- /**- * Executes a shell command and return it as a promise- */- private executeShellCommand(cmd: string) {- const exec = require('child_process').exec;- return new Promise((resolve, reject) => {- // Maximum buffer size increased to 1000 * 1000KB- exec(cmd, { maxBuffer: 1000 * 1024 * 1000 }, (error, stdout, stderr) => {- if (error) {- console.warn(error);- }- resolve(stdout ? stdout : stderr);- });- });- }-}--const dockerizer = new Dockerizer();-dockerizer.dockerize(version);