commit 3bf77835dda3004eb636f59c74f65ae0d9058613 Author: Corban-Lee Jones Date: Tue Apr 22 00:20:56 2025 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..372592f --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +dist/ +node_modules/ +generated/prisma +package-lock.json +.env +*.db +*.db-journal \ No newline at end of file diff --git a/devnote.txt b/devnote.txt new file mode 100644 index 0000000..ffeee27 --- /dev/null +++ b/devnote.txt @@ -0,0 +1,5 @@ +moving from knex to prisma + +read more: +https://github.com/prisma/prisma-examples/blob/latest/orm/express/src/index.ts +https://www.prisma.io/docs/getting-started \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..124df98 --- /dev/null +++ b/package.json @@ -0,0 +1,44 @@ +{ + "name": "relay", + "version": "0.0.0", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1", + "start": "node ./dist/app.js", + "dev": "npx ts-node -r tsconfig-paths/register ./src/app.ts", + "build": "sh ./scripts/build.sh", + "build:client": "npx tsc -p ./src/client/tsconfig.json", + "build:server": "npx tsc -p ./tsconfig.json", + "build:tailwind": "npx @tailwindcss/cli -i ./src/client/public/css/main.css -o ./src/client/public/css/tailwind.css", + "db:migrate": "npx prisma migrate dev --name", + "db:seed": "npx prisma db seed" + }, + "author": "", + "license": "ISC", + "description": "", + "devDependencies": { + "@tailwindcss/cli": "^4.1.4", + "@types/ejs": "^3.1.5", + "@types/express": "^5.0.1", + "@types/jquery": "^3.5.32", + "@types/node": "^22.14.1", + "@zerollup/ts-transform-paths": "^1.7.18", + "nodemon": "^3.1.9", + "prisma": "^6.6.0", + "tailwindcss": "^4.1.4", + "tsc-alias": "^1.8.15", + "typescript": "^5.8.3" + }, + "dependencies": { + "@prisma/client": "^6.6.0", + "dotenv": "^16.5.0", + "ejs": "^3.1.10", + "ejs-mate": "^4.0.0", + "express": "^5.1.0", + "sqlite3": "^5.1.7", + "tsconfig-paths": "^4.2.0" + }, + "prisma": { + "seed": "ts-node prisma/seed.ts" + } +} diff --git a/prisma/migrations/20250421224829_init/migration.sql b/prisma/migrations/20250421224829_init/migration.sql new file mode 100644 index 0000000..fddcccc --- /dev/null +++ b/prisma/migrations/20250421224829_init/migration.sql @@ -0,0 +1,5 @@ +-- CreateTable +CREATE TABLE "TestModel" ( + "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + "name" TEXT +); diff --git a/prisma/migrations/20250421230249_init/migration.sql b/prisma/migrations/20250421230249_init/migration.sql new file mode 100644 index 0000000..466c8e9 --- /dev/null +++ b/prisma/migrations/20250421230249_init/migration.sql @@ -0,0 +1,10 @@ +/* + Warnings: + + - You are about to drop the `TestModel` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropTable +PRAGMA foreign_keys=off; +DROP TABLE "TestModel"; +PRAGMA foreign_keys=on; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..2a5a444 --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (e.g., Git) +provider = "sqlite" diff --git a/prisma/schema.prisma b/prisma/schema.prisma new file mode 100644 index 0000000..29d3187 --- /dev/null +++ b/prisma/schema.prisma @@ -0,0 +1,13 @@ +// This is your Prisma schema file, +// learn more about it in the docs: https://pris.ly/d/prisma-schema + +generator client { + provider = "prisma-client-js" + output = "../generated/prisma" +} + +datasource db { + provider = "sqlite" + url = env("DATABASE_URL") +} + diff --git a/scripts/build.sh b/scripts/build.sh new file mode 100644 index 0000000..7297289 --- /dev/null +++ b/scripts/build.sh @@ -0,0 +1,18 @@ +echo "Building project..." + +rm -rf ./dist +cd "$(dirname "$0")/../" + +echo "Compiling backend..." +npm run build:server + +echo "Compiling frontend..." +npm run build:tailwind +npm run build:client + +echo "Copying client files..." +mkdir -p ./dist/client +cp -r ./src/client/public ./dist/client/public +cp -r ./src/client/views ./dist/client/views + +echo "Build complete!" \ No newline at end of file diff --git a/src/app.ts b/src/app.ts new file mode 100644 index 0000000..330a719 --- /dev/null +++ b/src/app.ts @@ -0,0 +1,26 @@ +import dotenv from "dotenv"; +dotenv.config(); + +import path from "path"; +import express from "express"; +import engine from "ejs-mate"; + +import homeRouter from "@server/routers/home.router"; + +const app = express(); + +app.engine("ejs", engine); +app.set("view engine", "ejs"); +app.set("views", path.resolve(__dirname, "client/views")); +app.use(express.urlencoded({ extended: true })); + +app.use("/static", express.static(path.resolve(__dirname, "client/public"))); + +app.use("/", homeRouter); + +const HOST = process.env.HOST || "localhost"; +const PORT = process.env.PORT || 3000; + +app.listen(PORT, () => { + console.log(`Server is listening on port http://${HOST}:${PORT}`); +}); \ No newline at end of file diff --git a/src/client/public/css/main.css b/src/client/public/css/main.css new file mode 100644 index 0000000..e69de29 diff --git a/src/client/public/css/tailwind.css b/src/client/public/css/tailwind.css new file mode 100644 index 0000000..e69de29 diff --git a/src/client/public/js/placeholder.js b/src/client/public/js/placeholder.js new file mode 100644 index 0000000..e69de29 diff --git a/src/client/tsconfig.json b/src/client/tsconfig.json new file mode 100644 index 0000000..25b816d --- /dev/null +++ b/src/client/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "ES5", + "outDir": "./public/js", + "rootDir": "./typescript", + "sourceMap": false + }, + "include": [ + "./typescript/**/*" + ] +} \ No newline at end of file diff --git a/src/client/typescript/placeholder.ts b/src/client/typescript/placeholder.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/client/views/home.ejs b/src/client/views/home.ejs new file mode 100644 index 0000000..c6ffbba --- /dev/null +++ b/src/client/views/home.ejs @@ -0,0 +1,3 @@ +<% layout("layout/base") -%> + +home page \ No newline at end of file diff --git a/src/client/views/layout/base.ejs b/src/client/views/layout/base.ejs new file mode 100644 index 0000000..2bf93da --- /dev/null +++ b/src/client/views/layout/base.ejs @@ -0,0 +1,18 @@ + + + + + + <%= title %> + + + + <%- include("sidebar") -%> + +
+ <%- body -%> +
+ + <%- block("scripts").toString() %> + + \ No newline at end of file diff --git a/src/client/views/layout/sidebar.ejs b/src/client/views/layout/sidebar.ejs new file mode 100644 index 0000000..f49821e --- /dev/null +++ b/src/client/views/layout/sidebar.ejs @@ -0,0 +1 @@ +sidebar \ No newline at end of file diff --git a/src/server/controllers/home.controller.ts b/src/server/controllers/home.controller.ts new file mode 100644 index 0000000..6368167 --- /dev/null +++ b/src/server/controllers/home.controller.ts @@ -0,0 +1,7 @@ +import { Request, Response } from "express"; + +const get = async (_request: Request, response: Response) => { + response.render("home", { title: "home page" }); +}; + +export default { get } \ No newline at end of file diff --git a/src/server/routers/home.router.ts b/src/server/routers/home.router.ts new file mode 100644 index 0000000..b5a8304 --- /dev/null +++ b/src/server/routers/home.router.ts @@ -0,0 +1,8 @@ +import { Router } from "express"; +import controller from "@server/controllers/home.controller"; + +const router = Router(); + +router.get("/", controller.get); + +export default router; \ No newline at end of file diff --git a/src/types/ejs-mate.d.ts b/src/types/ejs-mate.d.ts new file mode 100644 index 0000000..f5f3861 --- /dev/null +++ b/src/types/ejs-mate.d.ts @@ -0,0 +1 @@ +declare module "ejs-mate"; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..989c0e7 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,31 @@ +{ + "compilerOptions": { + "target": "ES6", + "module": "CommonJS", + "rootDir": "./", + "baseUrl": "./", + "outDir": "./dist", + "lib": [ + "ES6", + "DOM" + ], + "paths": { + "@server/*": ["./src/server/*"] + }, + "plugins": [ + {"transform": "@zerollup/ts-transform-paths"} + ], + "typeRoots": [ + "./node_modules/@types", + "./src/types" + ], + "sourceMap": false, + "strict": true, + "skipLibCheck": true, + "esModuleInterop": true + }, + "include": [ + "./src/*", + "./src/server/**/*" + ] +} \ No newline at end of file