diff --git a/.env.development b/.env.development index f3faced6..244e84b3 100644 --- a/.env.development +++ b/.env.development @@ -1 +1,2 @@ -NEXT_PUBLIC_API_SERVER=http://localhost:9090/v1.0 +VITE_PUBLIC_API_SERVER=http://localhost:9090/v1.0 +VITE_BASE_PATH=/ \ No newline at end of file diff --git a/.env.production b/.env.production index f3faced6..0ac1ec28 100644 --- a/.env.production +++ b/.env.production @@ -1 +1,2 @@ -NEXT_PUBLIC_API_SERVER=http://localhost:9090/v1.0 +VITE_PUBLIC_API_SERVER=http://localhost:9090/v1.0 +VITE_BASE_PATH=/ diff --git a/.eslintrc.json b/.eslintrc.json index 2cd929a8..02c2107e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,4 +1,27 @@ { - "plugins": ["react", "prettier"], - "extends": ["next/core-web-vitals", "prettier"] + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:react/recommended", + "plugin:@typescript-eslint/recommended", + "plugin:react/jsx-runtime" + ], + "overrides": [], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": ["react", "@typescript-eslint"], + "rules": { + "@typescript-eslint/no-explicit-any": "off" + }, + "settings": { + "react": { + "version": "detect" + } + } } diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ef3a8f98..6e0d4d0f 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,6 +18,7 @@ on: env: REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} + BRANCH: ${{ github.ref_name }} # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" @@ -44,7 +45,7 @@ jobs: run: yarn prettier --check . - name: Build distribution - run: yarn build-static + run: yarn build - name: Docker meta diff --git a/.gitignore b/.gitignore index 598ed0ae..dcf4b4da 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ db /specification.yml .vscode tsconfig.tsbuildinfo +dist diff --git a/.prettierignore b/.prettierignore index 18bbfe4b..745da351 100644 --- a/.prettierignore +++ b/.prettierignore @@ -3,6 +3,7 @@ .github node_modules out +dist public tmp openapi diff --git a/Dockerfile b/Dockerfile index bf9c751d..adb35304 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM nginx -COPY ./out /usr/share/nginx/html +COPY ./dist /usr/share/nginx/html COPY ./docker-entrypoint.sh /docker-entrypoint.d COPY ./nginx-spa.conf /etc/nginx/conf.d/default.conf diff --git a/Dockerfile.nextjs b/Dockerfile.nextjs deleted file mode 100644 index 9b32bb13..00000000 --- a/Dockerfile.nextjs +++ /dev/null @@ -1,32 +0,0 @@ -FROM node:16-bullseye AS deps -WORKDIR /app -COPY package.json yarn.lock ./ -RUN yarn install --frozen-lockfile --network-timeout 100000 - -FROM node:16-bullseye AS builder -WORKDIR /app -COPY --from=deps /app/node_modules ./node_modules -COPY . . - -RUN yarn build - -FROM node:16-bullseye -RUN mkdir /app - -WORKDIR /app - -COPY --from=builder /app/node_modules/ node_modules -COPY --from=builder /app/.next/ .next -COPY package.json . -COPY ./docker-entrypoint.sh / - -RUN addgroup --system user && adduser --system --group user -RUN chown -R user:user /app/.next - -USER user -EXPOSE 3000 -ENV API_URL=http://localhost:9090/v1.0 - -ENTRYPOINT ["/docker-entrypoint.sh"] - -CMD [ "yarn", "start" ] diff --git a/index.html b/index.html new file mode 100644 index 00000000..ca3ab5f2 --- /dev/null +++ b/index.html @@ -0,0 +1,14 @@ + + + + + + + Process Optimizer Frontend + + + + +
+ + diff --git a/jest.config.js b/jest.config.js deleted file mode 100644 index 19a73174..00000000 --- a/jest.config.js +++ /dev/null @@ -1,14 +0,0 @@ -module.exports = { - setupFilesAfterEnv: ['/jest.setup.ts'], - testPathIgnorePatterns: ['/.next/', '/node_modules/'], - watchPathIgnorePatterns: ['/boost-tests-', '/tmp/'], - moduleNameMapper: { - '\\.(scss|sass|css)$': 'identity-obj-proxy', - '^@/(.*)': ['/src/$1'], - '^@openapi': ['/openapi'], - }, - testEnvironment: 'jsdom', - transform: { - '^.+\\.(js|jsx|ts|tsx)$': ['babel-jest', { presets: ['next/babel'] }], - }, -} diff --git a/jest.setup.ts b/jest.setup.ts deleted file mode 100644 index c7c299e0..00000000 --- a/jest.setup.ts +++ /dev/null @@ -1,2 +0,0 @@ -import '@testing-library/jest-dom' -global.console.log = jest.fn() diff --git a/next-env.d.ts b/next-env.d.ts deleted file mode 100644 index 4f11a03d..00000000 --- a/next-env.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -/// -/// - -// NOTE: This file should not be edited -// see https://nextjs.org/docs/basic-features/typescript for more information. diff --git a/next.config.js b/next.config.js deleted file mode 100644 index 5fc16178..00000000 --- a/next.config.js +++ /dev/null @@ -1,23 +0,0 @@ -/** @type {import('next').NextConfig} */ - -const { GitRevisionPlugin } = require('git-revision-webpack-plugin') - -module.exports = { - swcMinify: true, - reactStrictMode: true, - future: {}, - webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => { - const gitRevisionPlugin = new GitRevisionPlugin({ - versionCommand: 'describe --tags --always --first-parent', - }) - config.plugins.push(gitRevisionPlugin) - config.plugins.push( - new webpack.DefinePlugin({ - VERSION: JSON.stringify(gitRevisionPlugin.version()), - COMMITHASH: JSON.stringify(gitRevisionPlugin.commithash()), - BRANCH: JSON.stringify(gitRevisionPlugin.branch()), - }) - ) - return config - }, -} diff --git a/package.json b/package.json index 462c57aa..453013a0 100644 --- a/package.json +++ b/package.json @@ -3,13 +3,13 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "next dev", - "build": "next build", - "build-static": "next build && next export", - "start": "next start", - "lint": "eslint .", + "dev": "vite", + "build": "tsc && vite build", + "start": "vite preview", + "lint": "eslint src", "formatAll": "prettier --write .", - "test": "jest", + "prettier": "prettier --check .", + "test": "vitest", "prepare": "husky install", "openapi": "openapi-generator-cli generate -i https://raw.githubusercontent.com/BoostV/process-optimizer-api/v2.1.0/optimizerapi/openapi/specification.yml -g typescript-fetch -o ./openapi --additional-properties=nullSafeAdditionalProps && prettier --write ./openapi" }, @@ -25,45 +25,46 @@ "@mui/icons-material": "^5.8.4", "@mui/lab": "^5.0.0-alpha.87", "@mui/material": "^5.8.6", - "@mui/styles": "^5.8.6", "@types/recharts": "^1.8.23", "compare-versions": "^4.1.3", - "eslint-config-prettier": "8.5.0", - "eslint-plugin-prettier": "4.1.0", "immer": "^9.0.15", - "next": "^12.1.6", - "prettier": "2.7.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-dropzone": "^14.2.1", "react-hook-form": "^7.33.0", + "react-router-dom": "^6.4.3", "recharts": "^2.1.12", - "swr": "^1.3.0", + "tss-react": "^4.4.4", "uuid": "^8.3.2" }, "devDependencies": { "@openapitools/openapi-generator-cli": "2.5.1", - "@swc/jest": "^0.2.21", "@testing-library/dom": "^8.13.0", - "@testing-library/jest-dom": "^5.16.4", + "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.3.0", "@testing-library/user-event": "^14.2.0", "@types/node": "^18.0.0", "@types/react": "^18.0.14", "@types/rimraf": "^3.0.0", "@types/uuid": "^8.3.4", + "@typescript-eslint/eslint-plugin": "^5.43.0", + "@typescript-eslint/parser": "^5.43.0", + "@vitejs/plugin-react": "^2.2.0", "eslint": "8.18.0", - "eslint-config-next": "12.1.6", - "git-revision-webpack-plugin": "^5.0.0", + "eslint-config-prettier": "8.5.0", + "eslint-plugin-jest-dom": "^4.0.3", + "eslint-plugin-prettier": "4.1.0", + "eslint-plugin-react": "^7.31.10", + "eslint-plugin-testing-library": "^5.9.1", "husky": "^8.0.1", - "identity-obj-proxy": "^3.0.0", - "jest": "^28.1.1", - "jest-dom": "^4.0.0", - "jest-environment-jsdom": "^28.1.1", + "jsdom": "^20.0.2", "lint-staged": "^13.0.3", "node-mocks-http": "^1.10.1", + "prettier": "2.7.1", "react-devtools": "^4.24.7", "rimraf": "^3.0.2", - "typescript": "^4.7.4" + "typescript": "^4.7.4", + "vite": "^3.2.4", + "vitest": "^0.25.2" } } diff --git a/pages/_app.tsx b/pages/_app.tsx deleted file mode 100644 index ef5ff927..00000000 --- a/pages/_app.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import * as React from 'react' -import Head from 'next/head' -import { AppProps } from 'next/app' -import CssBaseline from '@mui/material/CssBaseline' -import { CacheProvider, EmotionCache } from '@emotion/react' -import createEmotionCache from '@/createEmotionCache' -import { GlobalStateProvider } from '@/context/global' -import { useRouter } from 'next/router' - -// Client-side cache, shared for the whole session of the user in the browser. -const clientSideEmotionCache = createEmotionCache() - -interface MyAppProps extends AppProps { - emotionCache?: EmotionCache -} - -export default function MyApp(props: MyAppProps) { - const router = useRouter() - const [firstLoad, setFirstLoad] = React.useState(true) - React.useEffect(() => { - if (window.location.pathname !== '/' && firstLoad) { - setFirstLoad(false) - router.push(window.location.pathname + window.location.search) - } - }, [firstLoad, router]) - const { Component, emotionCache = clientSideEmotionCache, pageProps } = props - return ( - - - - - - {/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */} - - - - - ) -} diff --git a/pages/_document.tsx b/pages/_document.tsx deleted file mode 100644 index 14a35609..00000000 --- a/pages/_document.tsx +++ /dev/null @@ -1,84 +0,0 @@ -import * as React from 'react' -import Document, { Html, Head, Main, NextScript } from 'next/document' -import createEmotionServer from '@emotion/server/create-instance' -import { theme } from '../src/theme/theme' -import createEmotionCache from '../src/createEmotionCache' - -export default class MyDocument extends Document { - render() { - return ( - - - {/* PWA primary color */} - - - {/* Inject MUI styles first to match with the prepend: true configuration. */} - {(this.props as any).emotionStyleTags} - - -
- - - - ) - } -} - -// `getInitialProps` belongs to `_document` (instead of `_app`), -// it's compatible with static-site generation (SSG). -MyDocument.getInitialProps = async ctx => { - // Resolution order - // - // On the server: - // 1. app.getInitialProps - // 2. page.getInitialProps - // 3. document.getInitialProps - // 4. app.render - // 5. page.render - // 6. document.render - // - // On the server with error: - // 1. document.getInitialProps - // 2. app.render - // 3. page.render - // 4. document.render - // - // On the client - // 1. app.getInitialProps - // 2. page.getInitialProps - // 3. app.render - // 4. page.render - - const originalRenderPage = ctx.renderPage - - // You can consider sharing the same Emotion cache between all the SSR requests to speed up performance. - // However, be aware that it can have global side effects. - const cache = createEmotionCache() - const { extractCriticalToChunks } = createEmotionServer(cache) - - ctx.renderPage = () => - originalRenderPage({ - enhanceApp: (App: any) => - function EnhanceApp(props) { - return - }, - }) - - const initialProps = await Document.getInitialProps(ctx) - // This is important. It prevents Emotion to render invalid HTML. - // See https://github.com/mui/material-ui/issues/26561#issuecomment-855286153 - const emotionStyles = extractCriticalToChunks(initialProps.html) - const emotionStyleTags = emotionStyles.styles.map(style => ( -