feat: move to pnpm

This commit is contained in:
Nevo David 2025-05-06 20:16:50 +07:00
parent 4ba5156502
commit fab3ebd35c
21 changed files with 88 additions and 207 deletions

View File

@ -2,12 +2,22 @@
# any half-built stuff in the build context as a pre-caution (also saves copying
# 180k files in node_modules that isn't used!).
**/node_modules
node_modules/*
node_modules
docker-data/*
dist
.nx
/apps/frontend/.next
/apps/backend/dist
/apps/workers/dist
/apps/cron/dist
/apps/commands/dist
.devcontainer
**/.git
**/dist
**/*.md
**/LICENSE
**/npm-debug.log
**/*.vscode
.git
.github
reports

View File

@ -1,78 +1,19 @@
# This Dockerfile is used for producing 3 container images.
#
# base - which is thrown away, that contains node and the basic infrastructure.
# devcontainer - which is used for development, and contains the source code and the node_modules.
# dist - which is used for production, and contains the built source code and the node_modules.
ARG NODE_VERSION="20.17"
# Base image
FROM docker.io/node:${NODE_VERSION}-alpine3.19 AS base
## Just reduce unccessary noise in the logs.
ENV NPM_CONFIG_UPDATE_NOTIFIER=false
ENV NEXT_TELEMETRY_DISABLED=1
RUN apk add --no-cache \
caddy \
bash=5.2.21-r0 \
supervisor=4.2.5-r4
FROM node:20-alpine3.19
RUN apk add --no-cache g++ make py3-pip supervisor bash caddy
RUN npm --no-update-notifier --no-fund --global install pnpm@10.6.1 pm2
WORKDIR /app
EXPOSE 3000
EXPOSE 4200
EXPOSE 5000
COPY var/docker/entrypoint.sh /app/entrypoint.sh
COPY . /app
COPY var/docker/supervisord.conf /etc/supervisord.conf
COPY var/docker/supervisord /app/supervisord_available_configs/
COPY var/docker/Caddyfile /app/Caddyfile
COPY .env.example /config/postiz.env
COPY var/docker/entrypoint.sh /app/entrypoint.sh
COPY var/docker/supervisord/caddy.conf /etc/supervisor.d/caddy.conf
RUN chmod +x /app/entrypoint.sh
VOLUME /config
VOLUME /uploads
RUN pnpm install
RUN pnpm run build
LABEL org.opencontainers.image.source=https://github.com/gitroomhq/postiz-app
EXPOSE 4200
ENTRYPOINT ["/app/entrypoint.sh"]
# Builder image
FROM base AS devcontainer
RUN apk add --no-cache \
pkgconfig \
gcc \
pixman-dev \
cairo-dev \
pango-dev \
make \
build-base
COPY nx.json tsconfig.base.json package.json package-lock.json build.plugins.js /app/
COPY apps /app/apps/
COPY libraries /app/libraries/
RUN npm ci --no-fund && npx nx run-many --target=build --projects=frontend,backend,workers,cron
VOLUME /config
VOLUME /uploads
LABEL org.opencontainers.image.title="Postiz App (DevContainer)"
# Output image
FROM base AS dist
COPY --from=devcontainer /app/node_modules/ /app/node_modules/
COPY --from=devcontainer /app/dist/ /app/dist/
# Required for prisma
COPY --from=devcontainer /app/libraries/ /app/libraries/
COPY package.json nx.json /app/
VOLUME /config
VOLUME /uploads
## Labels at the bottom, because CI will eventually add dates, commit hashes, etc.
LABEL org.opencontainers.image.title="Postiz App (Production)"
CMD ["pnpm", "run", "pm2"]

View File

@ -5,7 +5,7 @@
"scripts": {
"dev": "dotenv -e ../../.env -- nest start --watch --entryFile=./apps/backend/src/main",
"build": "NODE_ENV=production nest build",
"start": "node ./dist/apps/backend/src/main.js",
"start": "dotenv -e ../../.env -- node ./dist/apps/backend/src/main.js",
"pm2": "pm2 start pnpm --name backend -- start"
},
"keywords": [],

View File

@ -5,8 +5,7 @@
"scripts": {
"dev": "dotenv -e ../../.env -- nest start --watch --entryFile=./apps/command/src/main",
"build": "NODE_ENV=production nest build",
"start": "node ./dist/apps/command/src/main.js",
"pm2": "pm2 start pnpm --name command -- start"
"start": "node ./dist/apps/command/src/main.js"
},
"keywords": [],
"author": "",

View File

@ -5,7 +5,8 @@
"scripts": {
"dev": "dotenv -e ../../.env -- nest start --watch --entryFile=./apps/cron/src/main",
"build": "NODE_ENV=production nest build",
"start": "node ./dist/apps/cron/src/main.js"
"start": "dotenv -e ../../.env -- node ./dist/apps/cron/src/main.js",
"pm2": "pm2 start pnpm --name cron -- start"
},
"keywords": [],
"author": "",

View File

@ -1,3 +1,6 @@
// @ts-check
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
proxyTimeout: 90_000,

View File

@ -2,11 +2,12 @@
"name": "postiz-frontend",
"version": "1.0.0",
"description": "",
"type": "module",
"scripts": {
"dev": "dotenv -e ../../.env -- next dev -p 4200",
"build": "next build",
"start": "PORT=4200 next start",
"pm2": "PORT=4200 pm2 start pnpm --name frontend -- start"
"start": "dotenv -e ../../.env -- next start -p 4200",
"pm2": "pm2 start pnpm --name frontend -- start"
},
"keywords": [],
"author": "",

View File

@ -1,8 +1,8 @@
'use client';
import { useSearchParams } from 'next/navigation';
import { useCallback, useEffect } from 'react';
import { FC, useCallback, useEffect } from 'react';
const ReturnUrlComponent = () => {
const ReturnUrlComponent: FC = () => {
const params = useSearchParams();
const url = params.get('returnUrl');
useEffect(() => {

View File

@ -17,16 +17,12 @@ export const Editor = forwardRef<
RefMDEditor,
MDEditorProps & {
order: number;
currentWatching: string;
isGlobal: boolean;
totalPosts: number;
}
>(
(
props: MDEditorProps & {
order: number;
currentWatching: string;
isGlobal: boolean;
totalPosts: number;
},
ref: React.ForwardedRef<RefMDEditor>

View File

@ -44,6 +44,7 @@ export const useValues = (
return () => ({ ...form.getValues(), __type: identifier });
}, [form, integration]);
// @ts-ignore
finalInformation[integration] = finalInformation[integration] || {};
finalInformation[integration].posts = value;
finalInformation[integration].isValid = form.formState.isValid;

View File

@ -3,12 +3,12 @@ import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import timezone from 'dayjs/plugin/timezone';
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
import { useEffect } from 'react';
import { FC, useEffect } from 'react';
dayjs.extend(utc);
dayjs.extend(timezone);
export const IntegrationRedirectComponent = () => {
export const IntegrationRedirectComponent: FC = () => {
const offset = dayjs.tz().utcOffset();
const pathname = usePathname();
const searchParams = useSearchParams();

View File

@ -2,8 +2,8 @@
import React, { useCallback } from 'react';
import { observer } from 'mobx-react-lite';
// import { InputGroup } from '@blueprintjs/core';
// import { Clean } from '@blueprintjs/icons';
import { InputGroup } from '@blueprintjs/core';
import { Clean } from '@blueprintjs/icons';
import { SectionTab } from 'polotno/side-panel';
import { getImageSize } from 'polotno/utils/image';
@ -71,18 +71,18 @@ const GenerateTab = observer(({ store }: any) => {
<div style={{ height: '40px', paddingTop: '5px' }}>
Generate image with AI {data?.credits ? `(${data?.credits} left)` : ``}
</div>
{/*<InputGroup*/}
{/* placeholder="Type your image generation prompt here..."*/}
{/* onKeyDown={(e) => {*/}
{/* if (e.key === 'Enter') {*/}
{/* handleGenerate();*/}
{/* }*/}
{/* }}*/}
{/* style={{*/}
{/* marginBottom: '20px',*/}
{/* }}*/}
{/* inputRef={inputRef}*/}
{/*/>*/}
<InputGroup
placeholder="Type your image generation prompt here..."
onKeyDown={(e) => {
if (e.key === 'Enter') {
handleGenerate();
}
}}
style={{
marginBottom: '20px',
}}
inputRef={inputRef}
/>
<Button
onClick={handleGenerate}
loading={loading} innerClassName="invert"
@ -150,7 +150,7 @@ export const PictureGeneratorSection = {
name: 'picture-generator-ai',
Tab: (props: any) => (
<SectionTab name="AI Img" {...props}>
{/*<Clean />*/}
<Clean />
</SectionTab>
),
// we need observer to update component automatically on any store changes

View File

@ -1,8 +1,8 @@
import { useSearchParams } from 'next/navigation';
import { useEffect } from 'react';
import { FC, useEffect } from 'react';
import { useFireEvents } from '@gitroom/helpers/utils/use.fire.events';
export const NewSubscription = () =>{
export const NewSubscription: FC = () =>{
const query = useSearchParams();
const fireEvents = useFireEvents();

View File

@ -2,16 +2,8 @@ const { join } = require('path');
module.exports = {
content: [
'@gitroom/react',
join(
'@gitroom/react',
'{src,pages,components,app}/**/*!(*.stories|*.spec).{ts,tsx,html}'
),
join(
__dirname,
'{src,pages,components,app}/**/*!(*.stories|*.spec).{ts,tsx,html}'
),
'./src/**/*.{ts,tsx,html}',
'../../libraries/**/*.{ts,tsx,html}',
],
theme: {
extend: {

View File

@ -5,7 +5,8 @@
"scripts": {
"dev": "dotenv -e ../../.env -- nest start --watch --entryFile=./apps/workers/src/main",
"build": "NODE_ENV=production nest build",
"start": "node ./dist/apps/workers/src/main.js"
"start": "dotenv -e ../../.env -- node ./dist/apps/workers/src/main.js",
"pm2": "pm2 start pnpm --name workers -- start"
},
"keywords": [],
"author": "",

View File

@ -12,26 +12,28 @@
"packageManager": "pnpm@10.6.1",
"scripts": {
"dev": "pnpm run --filter ./apps/workers --filter ./apps/backend --filter ./apps/frontend --parallel dev",
"dev:stripe": "npx concurrently \"stripe listen --forward-to localhost:3000/stripe\" \"npm run dev\"",
"build": "npx nx run-many --target=build --projects=frontend,backend,workers,cron",
"build:frontend": "npx nx run frontend:build:production",
"dev:frontend": "npx nx run frontend:serve:development",
"dev:backend": "npx nx run backend:serve:development",
"pm2": "pnpx concurrently \"pnpm run pm2-run\" \"pnpm run entryfile\"",
"entryfile": "./entrypoint.sh",
"pm2-run": "pm2 delete all || true && pnpm run prisma-db-push && pnpm run --parallel pm2 && pm2 logs",
"dev:stripe": "pnpx concurrently \"stripe listen --forward-to localhost:3000/stripe\" \"pnpm run dev\"",
"build": "pnpm -r --workspace-concurrency=1 --filter ./apps/frontend --filter ./apps/backend --filter ./apps/workers --filter ./apps/cron run build",
"build:frontend": "rm -rf dist/frontend && pnpm --filter ./apps/frontend run build",
"dev:frontend": "rm -rf dist/frontend && pnpm --filter ./apps/frontend run dev",
"dev:backend": "rm -rf dist/backend && pnpm --filter ./apps/backend run dev",
"update-plugins": "node build.plugins.js",
"dev:workers": "npx nx run workers:serve:development",
"dev:cron": "npx nx run cron:serve:development",
"dev:workers": "rm -rf dist/workers && pnpm --filter ./apps/workers run dev",
"dev:cron": "rm -rf dist/cron && pnpm --filter ./apps/cron run dev",
"dev:docker": "docker compose -f ./docker-compose.dev.yaml up -d",
"start:prod": "node dist/apps/backend/main.js",
"commands:build:development": "npx nx run commands:build:development",
"start:prod:frontend": "nx run frontend:serve:production",
"start:prod:workers": "node dist/apps/workers/main.js",
"start:prod:cron": "node dist/apps/cron/main.js",
"workers": "npx nx run workers:serve:development",
"cron": "npx nx run cron:serve:development",
"command": "rm -rf dist/apps/commands && npx nx run commands:build && npx nx run commands:command",
"prisma-generate": "cd ./libraries/nestjs-libraries/src/database/prisma && npx prisma generate",
"prisma-db-push": "cd ./libraries/nestjs-libraries/src/database/prisma && npx prisma db push",
"prisma-reset": "cd ./libraries/nestjs-libraries/src/database/prisma && npx prisma db push --force-reset && npx prisma db push",
"start:prod": "pnpm --filter ./apps/backend run start",
"commands:build:development": "pnpm --filter ./apps/commands run build",
"start:prod:frontend": "pnpm --filter ./apps/backend run start",
"start:prod:workers": "pnpm --filter ./apps/workers run start",
"start:prod:cron": "pnpm --filter ./apps/cron run start",
"workers": "rm -rf dist/backend && pnpm --filter ./apps/workers run dev",
"cron": "rm -rf dist/cron && pnpm --filter ./apps/cron run dev",
"prisma-generate": "pnpx prisma generate --schema ./libraries/nestjs-libraries/src/database/prisma/schema.prisma",
"prisma-db-push": "pnpx prisma db push --schema ./libraries/nestjs-libraries/src/database/prisma/schema.prisma",
"prisma-reset": "cd ./libraries/nestjs-libraries/src/database/prisma && pnpx prisma db push --force-reset && npx prisma db push",
"docker-build": "./var/docker/docker-build.sh",
"docker-create": "./var/docker/docker-create.sh",
"postinstall": "npm run update-plugins && npm run prisma-generate",

View File

@ -2,45 +2,16 @@
set -o xtrace
if [[ "$SKIP_CONFIG_CHECK" != "true" ]]; then
echo "Entrypoint: Copying /config/postiz.env into /app/.env"
# Wait for port 4200 to be open
while ! nc -z localhost 4200; do
echo "Waiting for port 4200..."
sleep 1
done
if [ ! -f /config/postiz.env ]; then
echo "Entrypoint: WARNING: No postiz.env file found in /config/postiz.env"
fi
# Wait for port 3000 to be open
while ! nc -z localhost 3000; do
echo "Waiting for port 3000..."
sleep 1
done
cp -vf /config/postiz.env /app/.env
fi
if [[ "$POSTIZ_APPS" -eq "" ]]; then
echo "Entrypoint: POSTIZ_APPS is not set, starting everything!"
POSTIZ_APPS="frontend workers cron backend"
fi
echo "Entrypoint: Running database migrations"
npm run prisma-db-push
mkdir -p /etc/supervisor.d/
if [[ "$INTERNAL_PROXY_ENABLED" != "false" ]]; then
echo "Entrypoint: Starting internal proxy"
cp -vf /app/supervisord_available_configs/caddy.conf /etc/supervisor.d/
fi
if [[ "$POSTIZ_APPS" == *"frontend"* ]]; then
ln -sf /app/supervisord_available_configs/frontend.conf /etc/supervisor.d/
fi
if [[ $POSTIZ_APPS == *"workers"* ]]; then
ln -sf /app/supervisord_available_configs/workers.conf /etc/supervisor.d/
fi
if [[ $POSTIZ_APPS == *"cron"* ]]; then
ln -sf /app/supervisord_available_configs/cron.conf /etc/supervisor.d/
fi
if [[ $POSTIZ_APPS == *"backend"* ]]; then
ln -sf /app/supervisord_available_configs/backend.conf /etc/supervisor.d/
fi
/usr/bin/supervisord -c /etc/supervisord.conf
caddy run --config /app/Caddyfile

View File

@ -1,9 +0,0 @@
[program:backend]
directory=/app
command=npm run start:prod
autostart=true
autorestart=false
redirect_stderr=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
startsecs=10

View File

@ -1,9 +0,0 @@
[program:cron]
directory=/app
command=npm run start:prod:cron
autostart=true
autorestart=false
redirect_stderr=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
startsecs=3

View File

@ -1,10 +0,0 @@
[program:frontend]
directory=/app/dist/apps/frontend
command=npx next start
autostart=true
autorestart=false
redirect_stderr=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
environment=PORT=4200
startsecs=3

View File

@ -1,9 +0,0 @@
[program:workers]
directory=/app
command=npm run start:prod:workers
autostart=true
autorestart=false
redirect_stderr=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
startsecs=3