Skip to content

Commit

Permalink
refactor(core): Recreate project scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
Mega-JC committed Nov 30, 2024
1 parent d6d7a36 commit d38cac4
Show file tree
Hide file tree
Showing 73 changed files with 10,727 additions and 4,616 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.git
**/dist
**/node_modules
**/db-data
.vscode
docs
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
2 changes: 2 additions & 0 deletions .env.development.local.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ENABLE_ESLINT=true
ENABLE_TYPESCRIPT=true
File renamed without changes.
File renamed without changes.
60 changes: 60 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const { resolve } = require("node:path");

const project = resolve(process.cwd(), "tsconfig.json");

/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
extends: [
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended",
"prettier",
require.resolve("@vercel/style-guide/eslint/next"),
"next/core-web-vitals",
],
plugins: ["@typescript-eslint/eslint-plugin"],
parser: "@typescript-eslint/parser",
ignorePatterns: [
".*.js",
"*.setup.js",
"*.config.js",
"dist/",
"coverage/",
"node_modules/",
],
rules: {
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-non-null-asserted-optional-chain": "off",
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_",
varsIgnorePattern: "^_",
caughtErrorsIgnorePattern: "^_",
},
],
"prettier/prettier": ["error", { singleQuote: false }],
},
globals: {
React: true,
JSX: true,
},
env: {
node: true,
browser: true,
},
plugins: ["only-warn"],
settings: {
"import/resolver": {
typescript: {
project,
},
},
},
overrides: [{ files: ["*.js?(x)", "*.ts?(x)"] }],
};
3 changes: 0 additions & 3 deletions .eslintrc.json

This file was deleted.

2 changes: 2 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

pnpm exec commitlint --edit $1
1 change: 1 addition & 0 deletions .husky/post-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm run lint && pnpx lint-staged
Empty file added .lintst
Empty file.
4 changes: 4 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"*/**/*.{js,json,jsx,ts,tsx,mdx}": ["prettier --check"],
"*/**/*.css": ["prettier --check", "stylelint"]
}
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.16.0
Empty file added .prettierignore
Empty file.
18 changes: 18 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"recommendations": [
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"redhat.vscode-yaml",
"vscode-icons-team.vscode-icons",
"bradlc.vscode-tailwindcss",
"yoavbls.pretty-ts-errors",
"postman.postman-for-vscode",
"christian-kohler.path-intellisense",
"donjayamanne.githistory",
"mhutchie.git-graph",
"waderyan.gitblame",
"dotenv.dotenv-vscode",
"ms-azuretools.vscode-docker",
"supabase.vscode-supabase-extension"
]
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"eslint.workingDirectories": [
{
"mode": "auto"
}
],
"tailwindCSS.experimental.classRegex": ["cn\\(([^)]+)\\)"]
}
1 change: 0 additions & 1 deletion .yarnrc.yml

This file was deleted.

66 changes: 66 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# syntax=docker.io/docker/dockerfile:1

FROM node:20-alpine AS base

# Add Python and required packages
RUN apk add --no-cache python3 py3-pip git

ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN apk add --no-cache libc6-compat
RUN corepack enable && corepack prepare pnpm@9 --activate

# Install dependencies only when needed
FROM base AS deps
WORKDIR /app

# Copy package files
COPY package.json pnpm-lock.yaml* .npmrc* ./
RUN pnpm install --frozen-lockfile

# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Generate Python documentation
RUN python3 -m pip install --upgrade pip && \
pip install sphinx==7.1.2 && \
git clone https://github.com/pygame-community/pygame-ce.git && \
cd pygame-ce && \
python3 setup.py docs && \
cd .. && \
python3 utils/generate_docs.py

# Build Next.js app
RUN pnpm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV=production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED=1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT=3000

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]
143 changes: 143 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import type { UserConfig } from "@commitlint/types";
import { RuleConfigSeverity } from "@commitlint/types";

const types = [
"feat", // new user-facing feature (must have (or may introduce a new) scope)
"enha", // enhancement of any kind (must have a scope)
"fix", // bug fix (must have a scope)
"docs", // documentation enhancement (same as 'enha(docs)')
"style", // code style enhancement (same as 'enha(style)')

"refactor", // refactoring code enhancement (must have a scope)

"perf", // performance improvement enhancement (must have a scope)
"test", // testing enhancement (must have a scope)
"build", // build enhancement
"ci", // ci enhancement
"chore", // Relating to repository maintenance
"revert", // reverting a previous commit
"merge", // merging branches
];

const typesRequiringScope = ["feat", "enha", "fix", "refactor", "perf", "test"];

/**
* Scopes are used to describe the area of the project that the commit affects.
* They are used to group commits together and to provide context to the commit
* message.
*
* The scopes are divided into two categories: areas and topics. Areas are
* broader categories that describe the area of the project that the commit
* affects, while topics are more specific categories that describe the
* functionality or purpose of the commit.
*
* For example, commits that add a new feature to the frontend user interface
* might look like this:
*
* - `feat(ui,auth): add forgot password functionality ...`
* - `feat(ui,projects): Implement project url sharing ...`
*
* Another example might be a commit that adds a new feature to the backend API related to
* user authentication:
*
* `feat(api,auth): use new endpoint for user authentication ...`
*
*/
const scopes = {
areas: [
/* Frontend */
"ui", // UI related changes

"api", // REST API related changes
"supabase", // Supabase related changes

/* Others */
"core", // core changes neither specific to frontend nor backend
"docs", // documentation changes
"style", // code style changes
"webserver", // webserver and proxying changes
"version", // version bumping
],
topics: [
"auth",
"blog",
"analytics",
"automation",
"faq",
"projects",
"roles",
"settings",
"inbox",
],
};

const Configuration: UserConfig = {
extends: ["@commitlint/config-conventional"],
rules: {
"type-case": [RuleConfigSeverity.Error, "always", "lower-case"],
"type-empty": [RuleConfigSeverity.Error, "never"],
"type-enum": [RuleConfigSeverity.Error, "always", types],
"subject-case": [RuleConfigSeverity.Disabled, "always", "lower-case"],
"subject-empty": [RuleConfigSeverity.Error, "never"],
"subject-outer-whitespace": [RuleConfigSeverity.Error, "always"],
"scope-rich": [RuleConfigSeverity.Error, "always"],
"body-max-line-length": [RuleConfigSeverity.Warning, "always", 150],
"header-max-length": [RuleConfigSeverity.Warning, "always", 100],
},
plugins: [
{
rules: {
"scope-rich": (commit, when) => {
const errorMessages: string[] = [
"scope is required for commit of type" +
`[${typesRequiringScope.join(", ")}]`,
`scope must be one of the areas [${scopes.areas.join(", ")}], ` +
"optionally paired with one of the topics " +
`[${scopes.topics.join(", ")}], ` +
"all separated by a comma (no spaces)",
];

const scope = commit.scope ?? "";
const scopeRequired = typesRequiringScope.includes(commit.type!);

if (when !== "always" || !scopeRequired) return [true, undefined];

if (scopeRequired && !scope.length) {
return [false, errorMessages[0]];
}

if (scope.includes(",")) {
// area must be provided and valid, and if topics are provided,
// they must be valid
const [area, ...topics] = scope.split(",");
if (
!scopes.areas.includes(area) ||
topics.some((topic) => !scopes.topics.includes(topic))
) {
return [false, errorMessages[1]];
}
} else if (!scopes.areas.includes(scope)) {
return [false, errorMessages[1]];
}

return [true, undefined];
},
"subject-outer-whitespace": (commit, when) => {
const errorMessages: string[] = [
"subject must not have more than one preceding whitespace character",
];

if (when !== "always" || !commit.subject) return [true, undefined];

if ([" ", "\t", "\n", "\r"].includes(commit.subject[0])) {
return [false, errorMessages[0]];
}

return [true, undefined];
},
},
},
],
};

export default Configuration;
21 changes: 21 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": true,
"tsx": true,
"tailwind": {
"config": "tailwind.config.ts",
"css": "src/app/globals.css",
"baseColor": "neutral",
"cssVariables": true,
"prefix": ""
},
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"iconLibrary": "lucide"
}
11 changes: 11 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: pygame.community

services:
pygame-community:
container_name: pygame-community
build:
context: .
dockerfile: ./Dockerfile
restart: always
ports:
- 3000:3000
25 changes: 25 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: pygame.community

services:
frontend:
container_name: frontend
depends_on:
- backend
build:
context: .
dockerfile: ./Dockerfile
args:
- NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL}
- NEXT_PUBLIC_SUPABASE_PROJECT_URL=${NEXT_PUBLIC_SUPABASE_PROJECT_URL}
- NEXT_PUBLIC_SUPABASE_PUBLIC_ANON_KEY=${NEXT_PUBLIC_SUPABASE_PUBLIC_ANON_KEY}
- NODE_ENV=${NODE_ENV:-production}
restart: always
ports:
- 3000:3000
# networks:
# - appnet
environment:
- NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL:-https://api.pygame.community}
- NEXT_PUBLIC_SUPABASE_PROJECT_URL=${NEXT_PUBLIC_SUPABASE_PROJECT_URL:-https://kong.pygame.community}
- NEXT_PUBLIC_SUPABASE_PUBLIC_ANON_KEY=${NEXT_PUBLIC_SUPABASE_PUBLIC_ANON_KEY}
- NODE_ENV=${NODE_ENV:-production}
Loading

0 comments on commit d38cac4

Please sign in to comment.