Get Started
Requirements
npm version 18
Installation
tbd
Implement a new feature in We.Publish
Let's implment a new easy feature for We.Publish which requires changes in database, api, editor and Websitebuilder.
Changes on the database
Change database schema:
schema.prismanpx prisma migrate dev
Change in the API
Changes in the editor
Update documentation
WePublish Development Cheatsheet
Welcome! Here you'll find useful commands and information to get started with WePublish development.
Prerequisites
Install nx (if not already installed)
nx (if not already installed)npm install -g nxInstall docker (if not already installed)
docker (if not already installed)Follow instructions at (e.g. on Mac)
Clone the WePublish Repository
git clone https://github.com/wepublish/wepublish.git FOLDER_NAME
cd FOLDER_NAMESet Node Version
If you use asdf, this will create a local .tool-versions file. Or use nvm as needed.
asdf set nodejs v18.18.0Install Dependencies
npm installTip: If you have issues with sharp, try:
SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm iIf installation still fails, try:
rm -Rf node_modules
# maybe also
rm package-lock.jsonStart Database & Storage
In a terminal, run:
docker compose up -d storage database pgadminApply Migrations
npx prisma migrate deploySeed the Database
nx seed api-example --prodStart Projects
Start API, Editor, and Media
nx run-many --target=serve --projects=api-example,editor,mediaStart a Website App
In a separate terminal, replace APP_NAME with your app (e.g. website-example, bajour, bka, etc.):
nx serve APP_NAMEpgAdmin
pgAdmin runs at http://localhost:8000
To connect to the local Postgres database:
Object Explorer → Servers → Create → Server
General: Name:
wepublishConnection: Host name/address:
host.docker.internalSave
Navigate: Servers → wepublish → Databases → wepublish → Schemas → public → Tables
Right-click Tables → View/Edit Data → All Rows
URLs & Credentials
Editor: http://localhost:3000 Login:
dev@wepublish.ch/123Frontend (website-example): http://localhost:4200
Using a Different API
To use a different API than the local one on localhost:4000, create a .env.local file in the apps/website-example folder (or any other website app folder):
# Staging
API_URL=https://api-onlinereports.wepublish.dev
MEDIA_SERVER_URL=https://media-onlinereports.wepublish.dev
# Production
API_URL=https://api-onlinereports.wepublish.media
MEDIA_SERVER_URL=https://media-onlinereports.wepublish.media
# Local
API_URL=http://localhost:4000
MEDIA_SERVER_URL=http://localhost:4100Resetting the Database
Step-by-step
Drop and recreate schema (in psql or pgAdmin):
drop schema public cascade; create schema public;Re-run migrations:
npx prisma migrate deployStop running applications: Press
Ctrl+Cin the terminal where you startednx run-many ...Re-seed the database:
nx seed api-example --prodRestart the applications:
nx run-many --target=serve --projects=api-example,editor,media
Or: Delete Docker Volumes and Start Fresh
Stop applications:
Ctrl+CRemove Docker volumes and restart:
docker compose down -v docker compose up -d storage database pgadminRe-run migrations:
npx prisma migrate deployRe-seed the database:
nx seed api-example --prodRestart the applications:
nx run-many --target=serve --projects=api-example,editor,media
Connecting to PostgreSQL
(If not already done) Install psql client (macOS)
brew install libpq
echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcConnect to the database
psql -h 127.0.0.1 -p 5432 -U postgres wepublishUseful psql commands
\l– List all databases\c wepublish– Connect to database\dt public.*– Show tables\q– Quit
Importing a Database Dump
Text format:
psql -h 127.0.0.1 -p 5432 --username=postgres wepublish < /PATH_TO_DUMP_FILE/dump.dumpBinary format:
pg_restore -h 127.0.0.1 -p 5432 -U postgres -d wepublish -1 /PATH_TO_DUMP_FILE/dump.dumpConvert binary to text:
pg_restore -f /PATH_TO_DUMP_FILE/dump_out.dump /PATH_TO_DUMP_FILE/dump.dumpManually create users before import (if needed):
CREATE USER "USER_NAME" WITH PASSWORD '123';Monorepo Structure
apps/
api-example/
editor/
media/
babanews/
bajour/
...
libs/
api/
prisma/
migrations/
article/
api/
article.resolver/
website/
...Useful Documentation
Deploying an App to Production
The currently checked-out branch will be tagged on GitHub with a deploy_APPNAME_YYYYMMDDHHMM tag.
This triggers the deployment GitHub action, which builds and deploys the app based on the checked-out branch.
git checkout BRANCH_NAME
git pull --all
npm run deploy:production APP_NAMESlack Dev Mail Webhook
To forward mails to the Slack #dev channel, add this to your .env (get an API-Key from Slack first...):
SLACK_DEV_MAIL_WEBHOOK_URL=https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXXChanging Prisma Models
Create a new migration:
npx prisma migrate dev --create-only --name SOME_NAMEApply the migration:
npx prisma migrate deployRe-seed the database if needed:
nx seed api-example --prodRestart the applications:
Ctrl+Cand then:nx run-many --target=serve --projects=api-example,editor,mediaIf you changed a model used in the API, re-generate the API:
nx generate-api
Production Build
nx run website-example:build:productionZuletzt aktualisiert