Skip to content

Commit

Permalink
ref: create next app 🚀 (#901)
Browse files Browse the repository at this point in the history
* ref: init next app

* chore: configure next app

* chore: wrap all modal inside legacy app

* chore: wrap all style inside legacy app

* chore: render Header conditionnaly

²
  • Loading branch information
laurentC35 authored Jan 14, 2025
1 parent f22b060 commit 6272313
Show file tree
Hide file tree
Showing 43 changed files with 3,385 additions and 562 deletions.
1 change: 1 addition & 0 deletions next/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_POGUES_LEGACY=http://localhost:5145
25 changes: 25 additions & 0 deletions next/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
.__mf__temp
22 changes: 22 additions & 0 deletions next/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

FROM nginxinc/nginx-unprivileged:1.27-alpine

# Non root user
ENV NGINX_USER_ID=101
ENV NGINX_GROUP_ID=101
ENV NGINX_USER=nginx

USER $NGINX_USER_ID

# Add build to nginx root webapp
COPY --chown=$NGINX_USER:$NGINX_USER dist /usr/share/nginx/html

# Copy nginx configuration
RUN rm etc/nginx/conf.d/default.conf
COPY --chown=$NGINX_USER:$NGINX_USER nginx.conf etc/nginx/conf.d/
RUN chmod 755 /usr/share/nginx/html/vite-envs.sh

USER $NGINX_USER_ID
EXPOSE 8080

ENTRYPOINT sh -c "/usr/share/nginx/html/vite-envs.sh && nginx -g 'daemon off;'"
50 changes: 50 additions & 0 deletions next/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default tseslint.config({
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
});
```

- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
- Optionally add `...tseslint.configs.stylisticTypeChecked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:

```js
// eslint.config.js
import react from 'eslint-plugin-react';

export default tseslint.config({
// Set the react version
settings: { react: { version: '18.3' } },
plugins: {
// Add the react plugin
react,
},
rules: {
// other rules...
// Enable its recommended rules
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules,
},
});
```
28 changes: 28 additions & 0 deletions next/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
);
13 changes: 13 additions & 0 deletions next/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pogues</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
36 changes: 36 additions & 0 deletions next/mfe/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';

import type { ImportMetaEnv } from '../src/vite-env';

const devModeConfig = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
get: (_id: string) => {
return () => ({
Main: () => {
return '=====> Pogues Legacy is not available on dev mode <=====';
},
});
},
init: () => {},
};

// @ts-ignore
const runtimePlugin: () => FederationRuntimePlugin = function () {
return {
name: 'my-runtime-plugin',
async loadEntry({ remoteInfo }) {
// @ts-ignore
const ENV = (window.__VITE_ENVS || {}) as ImportMetaEnv;
if (ENV.DEV) {
return devModeConfig;
} else {
const originalEntryFile = new URL(remoteInfo.entry).pathname;
const finalEntry = `${ENV.VITE_POGUES_LEGACY}/${originalEntryFile}`;
console.log('finalEntry', finalEntry);
return await import(/* @vite-ignore */ finalEntry);
}
},
};
};
export default runtimePlugin;
27 changes: 27 additions & 0 deletions next/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
server {
listen 8080 default_server;

root /usr/share/nginx/html;
index index.html;

location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
# access_log logs/static.log; # I don't usually include a static log
}

location ~* \.(?:css|js)$ {
try_files $uri =404;
expires 1y;
access_log off;
}

# Any route containing a file extension (e.g. /devicesfile.js)
location ~ ^.+\..+$ {
try_files $uri =404;
}

# Any route that doesn't have a file extension (e.g. /devices)
location / {
try_files $uri $uri/ /index.html;
}
}
34 changes: 34 additions & 0 deletions next/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "pogues",
"private": true,
"version": "2.0.0-rc.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-router": "^1.95.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-error-boundary": "^5.0.0",
"vite-envs": "^4.4.10"
},
"devDependencies": {
"@eslint/js": "^9.17.0",
"@module-federation/enhanced": "^0.8.8",
"@module-federation/vite": "^1.2.1",
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
"@vitejs/plugin-react": "^4.3.4",
"eslint": "^9.17.0",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-react-refresh": "^0.4.16",
"globals": "^15.14.0",
"typescript": "~5.6.2",
"typescript-eslint": "^8.18.2",
"vite": "^6.0.5"
}
}
Binary file added next/public/favicon.ico
Binary file not shown.
Binary file added next/public/pogues-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions next/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
body {
background-color: #f7f7f7;
}

#latest-pogues {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 13em;
margin: auto;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
29 changes: 29 additions & 0 deletions next/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { StrictMode } from 'react';

import { RouterProvider, createRouter } from '@tanstack/react-router';
import ReactDOM from 'react-dom/client';

import { routeTree } from './routes/root';

// Import the generated route tree

// Create a new router instance
const router = createRouter({ routeTree });

// Register the router instance for type safety
// declare module "@tanstack/react-router" {
// interface Register {
// router: typeof router;
// }
// }

// Render the app
const rootElement = document.getElementById('root')!;
if (!rootElement.innerHTML) {
const root = ReactDOM.createRoot(rootElement);
root.render(
<StrictMode>
<RouterProvider router={router} />
</StrictMode>,
);
}
22 changes: 22 additions & 0 deletions next/src/routes/home.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { createRoute } from '@tanstack/react-router';

import '../App.css';
import { RouteRoot } from './root';
import poguesLogo from '/pogues-logo.png';

export const RouteIndex = createRoute({
getParentRoute: () => RouteRoot,
path: '/',
component: App,
});

function App() {
return (
<div id="latest-pogues">
<a href="https://inseefr.github.io/Bowie/1._Pogues/" target="_blank">
<img src={poguesLogo} className="logo" alt="Pogues logo" />
</a>
<h1>Bienvenue sur la nouvelle interface de Pogues !</h1>
</div>
);
}
41 changes: 41 additions & 0 deletions next/src/routes/pogues-legacy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
import { Main } from '@pogues-legacy/App';
import { createRoute } from '@tanstack/react-router';
import { ErrorBoundary } from 'react-error-boundary';

import { RouteRoot } from './root';

export const RouteQuestionnaire = createRoute({
path: '/questionnaire/$questionnaireId',
component: RouteComponent,
getParentRoute: () => RouteRoot,
});

export const RouteQuestionnaireCompo = createRoute({
path: '/questionnaire/$questionnaireId/composition',
component: RouteComponent,
getParentRoute: () => RouteRoot,
});

export const RouteQuestionnaireTcmCompo = createRoute({
path: '/questionnaire/$questionnaireId/tcm-composition',
component: RouteComponent,
getParentRoute: () => RouteRoot,
});

export const RouteQuestionnaireMerge = createRoute({
path: '/questionnaire/$questionnaireId/merge',
component: RouteComponent,
getParentRoute: () => RouteRoot,
});

function RouteComponent() {
return (
<ErrorBoundary
fallback={<div>Le vieux Pogues n'est pas disponible en mode dev.</div>}
>
<Main />
</ErrorBoundary>
);
}
Loading

0 comments on commit 6272313

Please sign in to comment.