feat: Upgraded to Yarn modern, improved the docker image size and added a contribution guide (#770)

* ci: update yarn & build to yarn modern

* refactor: removed node-prune, breaks build

* docs: added a contribution guide & improved the docker build

* feat: Upgraded to Yarn modern and improved the docker image size

* refactor: removed node-prune, breaks build

* docs: added a contribution guide & improved the docker build

* refactor: update yarn.lock

* ci: update pipeplines after yarn migration

* chore: move required dependencies to prod build

* chore: Add monaco-editor as dev peer dependency

* chore: add yarn.lock

* chore: remove old supertest dep

* chore: add updated yarn.lock
This commit is contained in:
Joren V
2024-01-19 13:30:04 +01:00
committed by GitHub
parent 76d29ef252
commit 6233b71f33
19 changed files with 15707 additions and 11853 deletions

View File

@@ -1 +1,2 @@
node_modules
.yarn

View File

@@ -26,8 +26,12 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Activate corepack
run: |
corepack install
corepack enable
- name: Install dependencies
run: yarn --frozen-lockfile
run: yarn --immutable
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -22,8 +22,13 @@ jobs:
with:
node-version: "20.x"
- name: Activate corepack
run: |
corepack install
corepack enable
- name: Install dependencies
run: yarn --frozen-lockfile
run: yarn --immutable
- name: Run tests
run: yarn test

1
.gitignore vendored
View File

@@ -1,3 +1,4 @@
data/maintainerr.sqlite
docs-output/
node_modules
.yarn

13
.vscode/extensions.json vendored Normal file
View File

@@ -0,0 +1,13 @@
{
// see
// - https://code.visualstudio.com/docs/editor/extension-gallery#_workspace-recommended-extensions
"recommendations": [
// https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint
"dbaeumer.vscode-eslint",
// https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
"esbenp.prettier-vscode",
"bradlc.vscode-tailwindcss"
]
}

23
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,23 @@
{
"eslint.enable": true,
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
],
"typescript.tsdk": "node_modules/typescript/lib",
"sqltools.connections": [
{
"previewLimit": 50,
"driver": "SQLite",
"name": "Local SQLite",
"database": "./data/maintainerr.sqlite"
}
],
"editor.formatOnSave": true,
"typescript.preferences.importModuleSpecifier": "non-relative",
"files.associations": {
"globals.css": "tailwindcss"
}
}

3
.yarnrc.yml Normal file
View File

@@ -0,0 +1,3 @@
nodeLinker: node-modules
# yarnPath: .yarn/releases/yarn-4.0.2.cjs
enableGlobalCache: false

116
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,116 @@
# Contributing to Maintainerr
All help is welcome and greatly appreciated! If you would like to contribute to the project, the following instructions should get you started...
## Development
### Tools Required
- HTML/Typescript/Javascript editor
- [VSCode](https://code.visualstudio.com/) is recommended. Upon opening the project, a few extensions will be automatically recommended for install.
- [NodeJS](https://nodejs.org/en/download/) (Node 20.x or higher)
- [Git](https://git-scm.com/downloads)
### Getting Started
1. [Fork](https://help.github.com/articles/fork-a-repo/) the repository to your own GitHub account and [clone](https://help.github.com/articles/cloning-a-repository/) it to your local device:
```bash
git clone https://github.com/YOUR_USERNAME/Maintainerr.git
cd Maintainerr/
```
2. Add the remote `upstream`:
```bash
git remote add upstream https://github.com/jorenn92/Maintainerr.git
```
3. Create a new branch:
```bash
git checkout -b BRANCH_NAME main
```
- It is recommended to give your branch a meaningful name, relevant to the feature or fix you are working on.
- Good examples:
- `docs-docker-setup`
- `feat-new-system`
- `fix-title-cards`
- `ci-improve-build`
- Bad examples:
- `bug`
- `docs`
- `feature`
- `fix`
- `patch`
4. Activate the correct Yarn version
```bash
corepack install
corepack enable
```
5. Install dependencies
```bash
yarn
```
6. Initialise the database
```bash
yarn migration:run
```
7. Run the development environments:
```bash
yarn dev:server
yarn dev:ui
```
- If the build fails with Windows Powershell, try to use cmd instead.
8. Create your patch and test your changes.
- Be sure to follow both the [code](#contributing-code) and [UI text](#ui-text-style) guidelines.
- Should you need to update your fork, you can do so by rebasing from `upstream`:
```bash
git fetch upstream
git rebase upstream/develop
git push origin BRANCH_NAME -f
```
### Contributing Code
- If you are taking on an existing bug or feature ticket, please comment on the [issue](https://github.com/jorenn92/Maintainerr/issues) to avoid multiple people working on the same thing.
- All commits **must** follow [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
- Pull requests with commits not following this standard will **not** be merged.
- Please make meaningful commits, or squash them prior to opening a pull request.
- Do not squash commits once people have begun reviewing your changes.
- Always rebase your commit to the latest `main` branch. Do **not** merge `main` into your branch.
- It is your responsibility to keep your branch up-to-date. Your work will **not** be merged unless it is rebased off the latest `main` branch.
- You can create a "draft" pull request early to get feedback on your work.
- Your code **must** be formatted correctly, or the tests will fail.
- We use Prettier to format our code base. It should automatically run with a Git hook, but it is recommended to have the Prettier extension installed in your editor and format on save.
- If you have questions or need help, you can reach out via [Discussions](https://github.com/jorenn92/Maintainerr/discussions) or our [Discord server](https://discord.gg/WP4ZW2QYwk).
### UI Text Style
When adding new UI text, please try to adhere to the following guidelines:
1. Be concise and clear, and use as few words as possible to make your point.
2. Use the Oxford comma where appropriate.
3. Use the appropriate Unicode characters for ellipses, arrows, and other special characters/symbols.
4. Capitalize proper nouns, such as Plex, Radarr, Sonarr, Telegram, Slack, Pushover, etc. Be sure to also use the official capitalization for any abbreviations; e.g., IMDb has a lowercase 'b', whereas TMDB and TheTVDB have a capital 'B'.
5. Title case headings, button text, and form labels. Note that verbs such as "is" should be capitalized, whereas prepositions like "from" should be lowercase (unless as the first or last word of the string, in which case they are also capitalized).
6. Capitalize the first word in validation error messages, dropdowns, and form "tips." These strings should not end in punctuation.
7. Ensure that toast notification strings are complete sentences ending in punctuation.
8. If an additional description or "tip" is required for a form field, it should be styled using the global CSS class `label-tip`.
9. In full sentences, abbreviations like "info" or "auto" should not be used in place of full words, unless referencing the name/label of a specific setting or option which has an abbreviation in its name.
10. Do your best to check for spelling errors and grammatical mistakes.
11. Do not misspell "Maintainerr."
## Attribution
This contribution guide was inspired by the [Overseerr](https://github.com/sct/overseerr) contribution guide.

View File

@@ -1,4 +1,4 @@
FROM node:20-alpine3.19 AS BUILDER
FROM node:20-alpine3.19 as BUILDER
LABEL Description="Contains the Maintainerr Docker image"
WORKDIR /opt
@@ -8,6 +8,7 @@ ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64}
COPY server/ /opt/server/
COPY ui/ /opt/ui/
COPY tools/ /opt/tools/
COPY docs/ /opt/docs/
COPY package.json /opt/package.json
COPY yarn.lock /opt/yarn.lock
@@ -15,32 +16,58 @@ COPY datasource-config.ts /opt/datasource-config.ts
COPY ormconfig.json /opt/ormconfig.json
COPY jsdoc.json /opt/jsdoc.json
COPY start.sh /opt/start.sh
COPY .yarnrc.yml /opt/.yarnrc.yml
WORKDIR /opt/
RUN apk --update --no-cache add python3 make g++
# enable correct yarn version
RUN corepack install && \
corepack enable
RUN apk --update --no-cache add python3 make g++ curl
RUN chmod +x /opt/start.sh
RUN yarn global add @nestjs/cli --network-timeout 99999999 && \
yarn config set python /usr/bin/python3 && \
yarn --force --non-interactive --frozen-lockfile --network-timeout 99999999
RUN sed -i 's/\/server\/dist\//\/server\//g' /opt/datasource-config.ts
RUN yarn --immutable --network-timeout 99999999
RUN \
case "${TARGETPLATFORM}" in ('linux/arm64' | 'linux/amd64') \
yarn add --save --network-timeout 99999999 sharp \
;; \
esac
case "${TARGETPLATFORM}" in ('linux/arm64' | 'linux/amd64') \
yarn add sharp \
;; \
esac
RUN yarn run build:server
RUN yarn build:server
RUN yarn run build:ui
RUN yarn build:ui
RUN yarn run docs-generate && \
RUN yarn docs-generate && \
rm -rf ./docs
RUN yarn --production --non-interactive --ignore-scripts --prefer-offline --frozen-lockfile --network-timeout 99999999
# copy standalone UI
RUN mv ./ui/.next/standalone/ui/ ./standalone-ui/ && \
mv ./ui/.next/standalone/ ./standalone-ui/ && \
mv ./ui/.next/static ./standalone-ui/.next/static && \
mv ./ui/public ./standalone-ui/public && \
rm -rf ./ui && \
mv ./standalone-ui ./ui
# Copy standalone server
RUN mv ./server/dist ./standalone-server && \
rm -rf ./server && \
mv ./standalone-server ./server
RUN rm -rf node_modules .yarn
RUN yarn workspaces focus --production
RUN rm -rf .yarn && \
mkdir /opt/data && \
chown -R node:node /opt && \
chmod +x /opt/start.sh
# Final build
FROM node:20-alpine3.19
ARG TARGETPLATFORM
@@ -55,19 +82,20 @@ ENV DEBUG=${DEBUG}
# Temporary workaround for https://github.com/libuv/libuv/pull/4141
ENV UV_USE_IO_URING=0
EXPOSE 80
WORKDIR /opt
COPY --from=BUILDER /opt ./
COPY --from=builder --chown=node:node /opt /opt
COPY supervisord.conf /etc/supervisord.conf
RUN apk add supervisor && \
rm -rf /tmp/* && \
mkdir /opt/data && \
chown -R node:node /opt
# enable correct yarn version, add supervisor & chown root /opt dir
RUN corepack install && \
corepack enable && \
apk add supervisor && \
chown node:node /opt
USER node
EXPOSE 80
VOLUME [ "/opt/data" ]
ENTRYPOINT ["/opt/start.sh"]

View File

@@ -2,11 +2,15 @@
"name": "maintainerr",
"version": "1.7.1",
"private": true,
"packageManager": "yarn@4.0.2",
"repository": {
"type": "git",
"url": "https://github.com/jorenn92/Maintainerr.git"
},
"license": "MIT",
"installConfig": {
"hoistingLimits": "workspaces"
},
"scripts": {
"prebuild:server": "cd server && rimraf dist",
"dev:ui": "cd ui && next dev",
@@ -25,28 +29,29 @@
"test:e2e": "jest --config ./test/jest-e2e.json",
"docs-generate": "jsdoc -c jsdoc.json --readme ./docs/1-home/Home.md ./server/dist/",
"docs-serve": "http-server ./docs-output/ --cors",
"migration:run": "ts-node node_modules/typeorm/cli.js migration:run -d ./datasource-config.ts",
"migration:revert": "ts-node node_modules/typeorm/cli.js migration:revert -d ./datasource-config.ts",
"migration:generate": "ts-node node_modules/typeorm/cli.js migration:generate --dataSource ./datasource-config.ts -p"
"migration:run": "ts-node tools/typeOrmCli.ts migration:run -d ./datasource-config.ts",
"migration:revert": "ts-node tools/typeOrmCli.ts migration:revert -d ./datasource-config.ts",
"migration:generate": "ts-node tools/typeOrmCli.ts migration:generate --dataSource ./datasource-config.ts -p"
},
"dependencies": {
"@headlessui/react": "1.7.12",
"@headlessui/react": "1.7.18",
"@heroicons/react": "^1.0.6",
"@monaco-editor/react": "^4.6.0",
"@nestjs/cli": "^10.3.0",
"@nestjs/common": "^10.3.0",
"@nestjs/core": "^10.3.0",
"@nestjs/platform-express": "^10.3.0",
"@nestjs/schedule": "^4.0.0",
"@nestjs/typeorm": "^10.0.1",
"@types/node": "^20.10.7",
"axios": "^1.6.5",
"bowser": "^2.11.0",
"cron": "^3.1.3",
"cron": "3.1.3",
"cron-validator": "^1.3.1",
"crypto": "^1.0.1",
"fs": "^0.0.2",
"http-server": "^14.1.1",
"lodash": "^4.17.21",
"next": "14.0.3",
"next": "14.0.4",
"node-cache": "^5.1.2",
"path": "^0.12.7",
"plex-api": "^5.3.2",
@@ -56,18 +61,17 @@
"react-toast-notifications": "^2.5.1",
"react-transition-group": "^4.4.5",
"reflect-metadata": "^0.1.13",
"rimraf": "^5.0.5",
"rxjs": "^7.8.1",
"sqlite3": "^5.1.6",
"swr": "^2.2.4",
"ts-node": "^10.9.2",
"typeorm": "^0.3.19",
"typescript": "^5.3.3",
"web-push": "^3.6.6",
"xml2js": "^0.6.2",
"yaml": "^2.3.4"
},
"devDependencies": {
"@automock/jest": "^1.4.0",
"@babel/cli": "^7.23.0",
"@babel/core": "^7.23.2",
"@nestjs/cli": "^10.3.0",
"@nestjs/schematics": "^10.1.0",
@@ -83,18 +87,14 @@
"@types/express": "^4.17.20",
"@types/jest": "^29.5.6",
"@types/lodash": "^4.14.200",
"@types/node": "^20.10.7",
"@types/react": "^18.2.31",
"@types/react-dom": "^18.2.18",
"@types/react-transition-group": "^4.4.10",
"@types/supertest": "^6.0.2",
"@types/web-push": "^3.6.3",
"@types/xml2js": "^0.4.14",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"autoprefixer": "10.4.16",
"babel-plugin-react-intl": "^8.2.25",
"babel-plugin-react-intl-auto": "^3.3.0",
"clean-jsdoc-theme": "^4.2.14",
"eslint": "^8.56.0",
"eslint-config-next": "14.0.4",
@@ -102,21 +102,15 @@
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"jsdoc": "^4.0.2",
"monaco-editor": "0.45.0",
"postcss": "^8.4.33",
"prettier": "^3.1.1",
"prettier-plugin-tailwindcss": "^0.5.6",
"semantic-release": "^23.0.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"tailwindcss": "^3.4.1",
"ts-jest": "^29.1.1",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.3.3"
},
"resolutions": {
"@nestjs/cli/inquirer/wrap-ansi": "^7.0.0"
"tsconfig-paths": "^4.2.0"
},
"jest": {
"moduleFileExtensions": [

View File

@@ -1,7 +1,7 @@
import { Logger } from '@nestjs/common';
import { ExternalApiService } from '../external-api/external-api.service';
import cacheManager from './cache';
import xml2js from 'xml2js';
import { parseStringPromise } from 'xml2js';
interface PlexAccountResponse {
user: PlexUser;
@@ -167,7 +167,7 @@ export class PlexTvApi extends ExternalApiService {
responseType: 'text',
});
const parsedXml = (await xml2js.parseStringPromise(
const parsedXml = (await parseStringPromise(
response,
)) as UsersResponse;
return parsedXml;

View File

@@ -3,7 +3,7 @@ nodaemon=true
user=node
[program:server]
command=yarn start:server
command=yarn node /opt/server/main.js
autorestart=true
startretries=100
stdout_logfile=/dev/fd/1
@@ -11,7 +11,8 @@ stdout_logfile_maxbytes=0
redirect_stderr=true
[program:ui]
command=yarn start:ui
environment=PORT=80
command=yarn node /opt/ui/server.js
autorestart=true
startretries=100
stdout_logfile=/dev/fd/1

2
tools/typeOrmCli.ts Normal file
View File

@@ -0,0 +1,2 @@
import cli from 'typeorm/cli.js';
void cli;

View File

@@ -1,3 +0,0 @@
{
"presets": ["next/babel"]
}

View File

@@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'standalone',
reactStrictMode: true,
images: {
remotePatterns: [

View File

@@ -33,7 +33,7 @@ const LibrarySwitcher = (props: ILibrarySwitcher) => {
<>
<div className="mb-5 w-full">
<form >
<select className='border-zinc-600 hover:border-zinc-500 focus:border-zinc-500 focus:bg-opacity-100 focus:placeholder-zinc-400 focus:outline-none focus:ring-0' placeholder="Libraries" onChange={onSwitchLibrary}>
<select className='border-zinc-600 hover:border-zinc-500 focus:border-zinc-500 focus:bg-opacity-100 focus:placeholder-zinc-400 focus:outline-none focus:ring-0' onChange={onSwitchLibrary}>
{props.allPossible === undefined || props.allPossible ? (
<option value={9999}>All</option>
) : undefined}

View File

@@ -1,5 +1,4 @@
import axios from 'axios'
import useSWR, { SWRResponse } from 'swr'
const ApiHandler = async (
url: string,
@@ -23,7 +22,6 @@ const ApiHandler = async (
}
}
const data = await fetcher(url, payload, method)
// const { data, error } = useSWR(`http://localhost:3001/api${url}`, fetcher)
if (data) {
return data

View File

@@ -1,7 +1,5 @@
import axios from 'axios'
import Bowser from 'bowser'
import { useContext } from 'react'
import SettingsContext from '../contexts/settings-context'
import { getParser } from 'bowser'
interface PlexHeaders extends Record<string, string> {
Accept: string
@@ -36,7 +34,7 @@ class PlexOAuth {
'Window is not defined. Are you calling this in the browser?'
)
}
const browser = Bowser.getParser(window.navigator.userAgent)
const browser = getParser(window.navigator.userAgent)
this.plexHeaders = {
Accept: 'application/json',
'X-Plex-Product': 'Maintainerr',

27259
yarn.lock

File diff suppressed because it is too large Load Diff