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.prisma

  • npx 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)

npm install -g nx

Install docker (if not already installed)

Follow instructions at (e.g. on Mac)

Docker Website

Clone the WePublish Repository

git clone https://github.com/wepublish/wepublish.git FOLDER_NAME
cd FOLDER_NAME

Set Node Version

If you use asdf, this will create a local .tool-versions file. Or use nvm as needed.

asdf set nodejs v18.18.0

Install Dependencies

npm install

Tip: If you have issues with sharp, try:

SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm i

If installation still fails, try:

rm -Rf node_modules
# maybe also
rm package-lock.json

Start Database & Storage

In a terminal, run:

docker compose up -d storage database pgadmin

Apply Migrations

npx prisma migrate deploy

Seed the Database

nx seed api-example --prod

Start Projects

Start API, Editor, and Media

nx run-many --target=serve --projects=api-example,editor,media

Start a Website App

In a separate terminal, replace APP_NAME with your app (e.g. website-example, bajour, bka, etc.):

nx serve APP_NAME

pgAdmin

  • pgAdmin runs at http://localhost:8000

  • To connect to the local Postgres database:

    • Object Explorer → Servers → Create → Server

      • General: Name: wepublish

      • Connection: Host name/address: host.docker.internal

      • Save

    • Navigate: Servers → wepublish → Databases → wepublish → Schemas → public → Tables

    • Right-click Tables → View/Edit Data → All Rows


URLs & Credentials


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:4100

Resetting the Database

Step-by-step

  1. Drop and recreate schema (in psql or pgAdmin):

    drop schema public cascade;
    create schema public;
  2. Re-run migrations:

    npx prisma migrate deploy
  3. Stop running applications: Press Ctrl+C in the terminal where you started nx run-many ...

  4. Re-seed the database:

    nx seed api-example --prod
  5. Restart the applications:

    nx run-many --target=serve --projects=api-example,editor,media

Or: Delete Docker Volumes and Start Fresh

  1. Stop applications: Ctrl+C

  2. Remove Docker volumes and restart:

    docker compose down -v
    docker compose up -d storage database pgadmin
  3. Re-run migrations: npx prisma migrate deploy

  4. Re-seed the database: nx seed api-example --prod

  5. Restart 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 ~/.zshrc

Connect to the database

psql -h 127.0.0.1 -p 5432 -U postgres wepublish

Useful 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.dump

Binary format:

pg_restore -h 127.0.0.1 -p 5432 -U postgres -d wepublish -1 /PATH_TO_DUMP_FILE/dump.dump

Convert binary to text:

pg_restore -f /PATH_TO_DUMP_FILE/dump_out.dump /PATH_TO_DUMP_FILE/dump.dump

Manually 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_NAME

Slack 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/XXXXXXXXXXXXXXXXXXXXXXXX

Changing Prisma Models

  1. Create a new migration:

    npx prisma migrate dev --create-only --name SOME_NAME
  2. Apply the migration:

    npx prisma migrate deploy
  3. Re-seed the database if needed:

    nx seed api-example --prod
  4. Restart the applications: Ctrl+C and then:

    nx run-many --target=serve --projects=api-example,editor,media
  5. If you changed a model used in the API, re-generate the API:

    nx generate-api

Production Build

nx run website-example:build:production

Zuletzt aktualisiert