diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 3961d0a..e2c5b87 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,6 +1,6 @@ module.exports = { root: true, - env: { browser: true, es2023: true }, + env: { browser: true, es2021: true }, extends: [ "eslint:recommended", "plugin:@typescript-eslint/recommended", diff --git a/ci/.drone.yml b/ci/.drone.yml index 608ab78..0652133 100644 --- a/ci/.drone.yml +++ b/ci/.drone.yml @@ -3,45 +3,41 @@ type: docker name: "CI and Deploy on maxou.dev" volumes: - - name: server - temp: {} + - name: server + temp: { } trigger: - event: - - push + event: + - push steps: - - image: node:latest - name: "front CI" - commands: - - npm install - - npm run tsc -# - image: node:latest -# name: "build node" -# volumes: &outputs -# - name: server -# path: /outputs -# depends_on: -# - "front CI" -# commands: -# - curl -L moshell.dev/setup.sh > /tmp/moshell_setup.sh -# - chmod +x /tmp/moshell_setup.sh -# - echo n | /tmp/moshell_setup.sh -# - echo "VITE_API_ENDPOINT=/IQBall/$DRONE_BRANCH/public/api" >> .env.PROD -# - echo "VITE_BASE=/IQBall/$DRONE_BRANCH/public" >> .env.PROD -# - apt update && apt install jq -y -# - -# - BASE="/IQBall/$DRONE_BRANCH/public" OUTPUT=/outputs /root/.local/bin/moshell ci/build_react.msh -## -# - image: eeacms/rsync:latest -# name: Deliver on staging server branch -# depends_on: -# - "prepare php" -# - "build node" -# volumes: *outputs -# environment: -# SERVER_PRIVATE_KEY: -# from_secret: SERVER_PRIVATE_KEY -# commands: -# - chmod +x ci/deploy.sh -# - ci/deploy.sh + - image: node:latest + name: "front CI" + commands: + - npm install + - npm run tsc + + - image: node:latest + name: "build react" + volumes: &outputs + - name: server + path: /outputs + depends_on: + - "front CI" + commands: + - sed -Ei "s/VITE_BASE=/VITE_BASE=\\/${DRONE_BRANCH}/g" .env + - npm run build -- --base=/$DRONE_BRANCH + - mv dist/* /outputs + + + - image: eeacms/rsync:latest + name: Deliver on staging server branch + depends_on: + - "build react" + volumes: *outputs + environment: + SERVER_PRIVATE_KEY: + from_secret: SERVER_PRIVATE_KEY + commands: + - chmod +x ci/deploy.sh + - ci/deploy.sh \ No newline at end of file diff --git a/ci/build_and_deploy_to.sh b/ci/build_and_deploy_to.sh index b0d2924..61c5ecf 100755 --- a/ci/build_and_deploy_to.sh +++ b/ci/build_and_deploy_to.sh @@ -1,8 +1,9 @@ +set -e export OUTPUT=$1 export BASE=$2 -rm -rf $OUTPUT/* +rm -rf "$OUTPUT"/* echo "VITE_API_ENDPOINT=$BASE/api" >> .env.PROD echo "VITE_BASE=$BASE" >> .env.PROD diff --git a/ci/deploy.sh b/ci/deploy.sh index 19aa768..634f7d7 100644 --- a/ci/deploy.sh +++ b/ci/deploy.sh @@ -5,7 +5,7 @@ echo "$SERVER_PRIVATE_KEY" > ~/.ssh/id_rsa chmod 0600 ~/.ssh chmod 0500 ~/.ssh/id_rsa* -SERVER_ROOT=/srv/www/IQBall +SERVER_ROOT=/srv/www/iqball ssh -p 80 -o 'StrictHostKeyChecking=no' iqball@maxou.dev mkdir -p $SERVER_ROOT/$DRONE_BRANCH rsync -avz -e "ssh -p 80 -o 'StrictHostKeyChecking=no'" --delete /outputs/* iqball@maxou.dev:$SERVER_ROOT/$DRONE_BRANCH diff --git a/index.html b/index.html index 00e7b1f..e28377b 100644 --- a/index.html +++ b/index.html @@ -4,7 +4,7 @@ - Vite + React + TS + IQBall
diff --git a/src/App.tsx b/src/App.tsx index 4312161..f28f8a9 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -3,6 +3,7 @@ import { BrowserRouter, Outlet, Route, Routes } from "react-router-dom" import { Header } from "./pages/template/Header.tsx" import "./style/app.css" import { lazy } from "react" +import { BASE } from "./Constants.ts" const HomePage = lazy(() => import("./pages/HomePage.tsx")) const LoginPage = lazy(() => import("./pages/LoginPage.tsx")) @@ -16,7 +17,7 @@ const Editor = lazy(() => import("./pages/Editor.tsx")) export default function App() { return (
- + diff --git a/src/pages/LoginPage.tsx b/src/pages/LoginPage.tsx index d868ba2..9b12ea3 100644 --- a/src/pages/LoginPage.tsx +++ b/src/pages/LoginPage.tsx @@ -27,7 +27,7 @@ export default function LoginApp() { if (response.ok) { const session = getSession() const { token, expirationDate } = await response.json() - saveSession({ ...session, auth: { token, expirationDate } }) + saveSession({ ...session, auth: { token, expirationDate }, urlTarget: undefined }) redirect(session.urlTarget ?? "/") return } diff --git a/src/pages/RegisterPage.tsx b/src/pages/RegisterPage.tsx index 263b680..84ef9b0 100644 --- a/src/pages/RegisterPage.tsx +++ b/src/pages/RegisterPage.tsx @@ -43,7 +43,7 @@ export default function RegisterPage() { if (response.ok) { const { token, expirationDate } = await response.json() const session = getSession() - saveSession({ ...session, auth: { token, expirationDate } }) + saveSession({ ...session, auth: { token, expirationDate }, urlTarget: undefined }) redirect(session.urlTarget ?? "/") return } diff --git a/vite.config.ts b/vite.config.ts index 1408a24..8e2f5c5 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -6,7 +6,7 @@ import svgr from "vite-plugin-svgr" // https://vitejs.dev/config/ export default defineConfig({ build: { - target: "es2023", + target: "es2021", }, plugins: [ react(),