Skip to content

Commit

Permalink
Merge pull request #20 from valon-loshaj/bugfix/pipelines
Browse files Browse the repository at this point in the history
pipeline updates
  • Loading branch information
valon-loshaj authored Nov 11, 2024
2 parents 08c67f0 + 2fe5dda commit 334e505
Show file tree
Hide file tree
Showing 16 changed files with 1,671 additions and 167 deletions.
15 changes: 10 additions & 5 deletions .github/actions/prepare/action.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
description: Prepares the repo for a typical CI job

# .github/actions/prepare/action.yml
name: Prepare
description: Prepares the repo for a typical CI job

runs:
using: composite
steps:
- uses: pnpm/action-setup@v4
with:
version: 9

- uses: actions/setup-node@v4
with:
cache: pnpm
node-version: "20"
- run: pnpm install --frozen-lockfile
cache: "pnpm"

- name: Install dependencies
shell: bash
using: composite
run: |
pnpm install --no-frozen-lockfile
pnpm add -Dw eslint-plugin-n eslint-config-prettier @eslint/eslintrc eslint-import-resolver-typescript eslint-plugin-import knip
17 changes: 15 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,20 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- name: Update lockfile
run: |
pnpm install --no-frozen-lockfile
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git add pnpm-lock.yaml
git commit -m "chore: update pnpm-lock.yaml" || true
git push || true
- run: pnpm build
- run: node ./lib/index.js
- name: List dist directory contents
run: ls -R apps/backend/dist
- name: List all files
run: find .
- run: node apps/backend/dist/index.js
lint:
name: Lint
runs-on: ubuntu-latest
Expand Down Expand Up @@ -42,7 +54,8 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/prepare
- run: pnpm tsc
- run: pnpm tsc --project apps/frontend/tsconfig.json
- run: pnpm tsc --project apps/backend/tsconfig.json

name: CI

Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"printWidth": 80,
"overrides": [
{
"files": ".nvmrc",
"files": ["*.yaml", "*.yml", ".nvmrc"],
"options": {
"parser": "yaml"
}
Expand Down
10 changes: 7 additions & 3 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"keywords": [],
"license": "ISC",
"author": "",
"main": "index.js",
"type": "module",
"main": "src/index.ts",
"scripts": {
"build": "tsc",
"dev": "ts-node-dev --respawn --transpile-only src/server.ts",
"start": "node dist/server.js",
"dev": "ts-node-dev --respawn --transpile-only src/index.ts",
"start": "node dist/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
Expand All @@ -24,5 +25,8 @@
"prisma": "^5.22.0",
"ts-node-dev": "^2.0.0",
"typescript": "^5"
},
"engines": {
"node": ">=14.16"
}
}
11 changes: 7 additions & 4 deletions apps/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Example file to ensure ESLint has something to check
export const hello = () => {
return "Hello from backend";
};
// apps/backend/src/index.ts
import app from "./app";
import { createServer } from "./server";

const server = createServer(app);

export { server };
15 changes: 10 additions & 5 deletions apps/backend/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import app from "./app";
// apps/backend/src/server.ts
import { Server } from "http";
import express from "express";
import type { Express } from "express";

const port = process.env.PORT || 3001;
export function createServer(app: Express): Server {
return app.listen(process.env.PORT || 3001, () => {
console.log(`Server running on port ${process.env.PORT || 3001}`);
});
}

app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
export type { Express, Server };
13 changes: 10 additions & 3 deletions apps/backend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
},
"target": "ES2020",
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "dist"
"outDir": "dist",
"incremental": true,
"tsBuildInfoFile": "./.tsbuildinfo"
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist"]
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "15.0.3",
"eslint-config-prettier": "^9.0.0",
"prettier-plugin-curly": "^0.3.1",
"prettier-plugin-packagejson": "^2.5.3",
"prettier-plugin-sh": "^0.14.0",
Expand Down
10 changes: 10 additions & 0 deletions apps/frontend/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// apps/frontend/src/global.d.ts
declare module "*.module.css" {
const classes: { [key: string]: string };
export default classes;
}

declare module "*.css" {
const content: { [key: string]: string };
export default content;
}
16 changes: 0 additions & 16 deletions apps/frontend/tsconfig copy.json

This file was deleted.

22 changes: 15 additions & 7 deletions apps/frontend/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
{
"compilerOptions": {
"target": "es5",
"target": "es2020",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"noEmit": false,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
"jsx": "react-jsx",
"incremental": true,
"tsBuildInfoFile": "./.tsbuildinfo",
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./src/*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "global.d.ts"],
"exclude": ["node_modules"]
}
94 changes: 39 additions & 55 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,56 @@
import eslint from "@eslint/js";
import vitest from "@vitest/eslint-plugin";
import n from "eslint-plugin-n";
// eslint.config.js
import js from "@eslint/js";
import tseslint from "typescript-eslint";
import prettier from "eslint-config-prettier";
import eslintConfigPrettier from "eslint-config-prettier";
import eslintPluginN from "eslint-plugin-n";
import { FlatCompat } from "@eslint/eslintrc";
import path from "path";
import { fileURLToPath } from "url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const compat = new FlatCompat({
baseDirectory: __dirname,
});

export default tseslint.config(
js.configs.recommended,
...tseslint.configs.recommended,
{
ignores: [
"coverage*",
"lib",
"node_modules",
"pnpm-lock.yaml",
"**/*.snap",
],
},
{
linterOptions: {
reportUnusedDisableDirectives: "error",
plugins: {
n: eslintPluginN,
},
rules: {
"n/no-missing-import": "error",
},
},
eslint.configs.recommended,
n.configs["flat/recommended"],
...tseslint.config({
extends: tseslint.configs.recommendedTypeChecked,
files: ["**/*.js", "**/*.ts"],
languageOptions: {
parserOptions: {
projectService: {
allowDefaultProject: ["*.*s", "eslint.config.js"],
defaultProject: "./tsconfig.json",
prettier,
...compat.config({
extends: ["plugin:import/typescript"],
settings: {
"import/resolver": {
typescript: {
project: ["./apps/*/tsconfig.json"],
},
tsconfigRootDir: import.meta.dirname,
node: true,
},
},
rules: {
// These on-by-default rules don't work well for this repo and we like them off.
"no-constant-condition": "off",

// These on-by-default rules work well for this repo if configured
"@typescript-eslint/no-unused-vars": ["error", { caughtErrors: "all" }],
},
}),
eslintConfigPrettier,
{
files: ["*.jsonc"],
rules: {
"jsonc/comma-dangle": "off",
"jsonc/no-comments": "off",
"jsonc/sort-keys": "error",
},
},
{
extends: [tseslint.configs.disableTypeChecked],
files: ["**/*.md/*.ts"],
rules: {
"n/no-missing-import": ["error", { allowModules: ["side-quest"] }],
},
},
{
files: ["**/*.test.*"],
ignores: ["**/dist/**", "**/node_modules/**", "**/.next/**"],
languageOptions: {
globals: vitest.environments.env.globals,
parserOptions: {
project: ["./tsconfig.json", "./apps/*/tsconfig.json"],
tsconfigRootDir: __dirname,
},
},
plugins: { vitest },
rules: {
...vitest.configs.recommended.rules,

// These on-by-default rules aren't useful in test files.
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"n/no-missing-import": "error",
"@typescript-eslint/no-unsafe-argument": "error",
"@typescript-eslint/no-unsafe-assignment": "error",
"@typescript-eslint/no-unsafe-call": "error",
"import/no-unresolved": "error",
},
}
);
7 changes: 4 additions & 3 deletions knip.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "https://unpkg.com/knip@latest/schema.json",
"entry": ["src/index.ts!"],
"ignoreExportsUsedInFile": { "interface": true, "type": true },
"project": ["src/**/*.ts!"]
"entry": ["apps/backend/src/index.ts", "apps/frontend/src/index.ts"],
"project": ["apps/**/*.{ts,tsx}"],
"ignore": ["**/dist/**", "**/node_modules/**", "**/*.test.ts"],
"ignoreDependencies": ["typescript"]
}
20 changes: 16 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
"README.md"
],
"scripts": {
"build": "tsup",
"format": "prettier --write \"apps/**/*.{ts,tsx,js,jsx,json,md,css}\" \"*.{ts,tsx,js,jsx,json,md,css}\"",
"format:check": "prettier --check \"apps/**/*.{ts,tsx,js,jsx,json,md,css}\" \"*.{ts,tsx,js,jsx,json,md,css}\"",
"build": "pnpm build:backend && pnpm build:frontend",
"build:backend": "tsup --config tsup.config.ts",
"build:frontend": "tsup --config tsup.config.ts",
"format": "prettier --write \"apps/**/*.{ts,tsx,js,jsx,json,md,css,yaml,yml}\" \"*.{ts,tsx,js,jsx,json,md,css,yaml,yml}\"",
"format:check": "prettier --check \"apps/**/*.{ts,tsx,js,jsx,json,md,css,yaml,yml}\" \"*.{ts,tsx,js,jsx,json,md,css,yaml,yml}\"",
"lint": "eslint . --max-warnings 0",
"lint:backend": "eslint apps/backend/src/**/*.ts",
"lint:frontend": "eslint apps/frontend/src/**/*.{ts,tsx}",
"lint:knip": "knip",
"lint:knip": "knip --config knip.json",
"prepare": "husky",
"test": "vitest",
"tsc": "tsc"
Expand All @@ -34,15 +36,25 @@
"*": "prettier --ignore-unknown --write"
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "latest",
"@swc/core": "^1.9.1",
"@vitest/coverage-v8": "latest",
"@vitest/eslint-plugin": "^1.1.8",
"eslint": "^9.14.0",
"eslint-config-prettier": "latest",
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin": "^1.0.1",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-n": "^17.13.1",
"husky": "^9.1.6",
"knip": "^5.36.5",
"lint-staged": "latest",
"prettier": "^3.3.3",
"prettier-plugin-curly": "^0.3.1",
"prettier-plugin-packagejson": "^2.5.3",
"prettier-plugin-sh": "^0.14.0",
"tsup": "^8.3.5",
"typescript-eslint": "^8.13.0",
"vitest": "^2.1.3"
},
Expand Down
Loading

0 comments on commit 334e505

Please sign in to comment.