Skip to content

Commit

Permalink
chore: add demo to share code between frontend-usagers and backend
Browse files Browse the repository at this point in the history
  • Loading branch information
achauve committed Jul 24, 2024
1 parent 89e4fc9 commit c0a2a78
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"@sentry/node": "~8.17.0",
"@vao/common": "^1.0.0",
"axios": "^1.6.8",
"body-parser": "~1.20.2",
"cookie-parser": "^1.4.6",
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const routes = require("./routes");
const logger = require("./utils/logger");
const AppError = require("./utils/error");
const ValidationAppError = require("./utils/validation-error");
const { hello } = require("@vao/common");

const log = logger(module.filename);

Expand Down Expand Up @@ -70,7 +71,7 @@ app.use(
app.use(cookieParser());

app.get("", (req, res) => {
res.send("Bienvenue sur le server du portail Front");
res.send("Bienvenue sur le server du portail Front: " + hello());
});

app.use(`/bo-authentication`, routes.BOAuthentication);
Expand Down
23 changes: 23 additions & 0 deletions packages/common/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"root": true,
"env": {
"browser": true,
"node": true,
"es2021": true
},
"extends": [
"plugin:vue/vue3-recommended",
"@nuxt/eslint-config",
"plugin:prettier/recommended"
],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": "latest"
},
"rules": {
"prettier/prettier": [
"error"
],
"vue/multi-word-component-names": "off"
}
}
21 changes: 21 additions & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@vao/common",
"version": "1.0.0",
"main": "src/index.js",
"type": "commonjs",
"scripts": {
"lint": "eslint --fix ./src",
"test": "echo \"Error: no test specified\" && exit 1"
},
"sourceType": "module",
"author": "",
"license": "ISC",
"description": "",
"dependencies": {},
"devDependencies": {
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"prettier": "^3.3.3"
}
}
8 changes: 8 additions & 0 deletions packages/common/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
function hello() {
console.log("Hello from shared package!");
return "hello world from common!";
}

module.exports = {
hello: hello,
};
2 changes: 2 additions & 0 deletions packages/frontend-usagers/nuxt.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// https://nuxt.com/docs/api/configuration/nuxt-config

import { sentryVitePlugin } from "@sentry/vite-plugin";
import commonjs from "vite-plugin-commonjs";

export default defineNuxtConfig({
app: {
Expand Down Expand Up @@ -67,6 +68,7 @@ export default defineNuxtConfig({
project: process.env.SENTRY_PROJECT,
url: process.env.SENTRY_URL,
}),
commonjs(),
],
},
});
4 changes: 3 additions & 1 deletion packages/frontend-usagers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@sentry/vue": "~8.17.0",
"@socialgouv/dsfr-toaster-nuxt-module": "~1.2.1",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@vao/common": "^1.0.0",
"@vao/shared": "^1.0.0",
"@vee-validate/i18n": "~4.13.0",
"@vee-validate/rules": "~4.13.0",
Expand Down Expand Up @@ -46,7 +47,8 @@
"prettier": "^3.2.5",
"sass": "~1.77.0",
"sass-loader": "~14.2.0",
"typescript": "~5.4.3"
"typescript": "~5.4.3",
"vite-plugin-commonjs": "^0.10.1"
},
"lint-staged": {
"src/**/*.{js,vue,ts}": "npx eslint --cache --fix"
Expand Down
7 changes: 6 additions & 1 deletion packages/frontend-usagers/src/pages/index.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<template>
<div class="fr-container">
<div class="fr-grid-row fr-py-5w">
<h3>Bienvenue {{ userStore.user.prenom }} {{ userStore.user.nom }}</h3>
<h3>
Bienvenue {{ userStore.user.prenom }} {{ userStore.user.nom }}
{{ hello() }}
</h3>
</div>
<div
v-if="!organismeCourant || !organismeCourant.complet"
Expand Down Expand Up @@ -37,6 +40,8 @@ useHead({
meta: [{ name: "description", content: "Page d'accueil." }],
});
const { hello } = require("@vao/common");
const userStore = useUserStore();
const organismeStore = useOrganismeStore();
Expand Down
26 changes: 23 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4998,7 +4998,7 @@ es-errors@^1.2.1, es-errors@^1.3.0:
resolved "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz"
integrity sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==

es-module-lexer@^1.5.3:
es-module-lexer@^1.2.1, es-module-lexer@^1.5.3:
version "1.5.4"
resolved "https://registry.yarnpkg.com/es-module-lexer/-/es-module-lexer-1.5.4.tgz#a8efec3a3da991e60efa6b633a7cad6ab8d26b78"
integrity sha512-MVNK56NiMrOwitFB7cqDwq0CQutbw+0BvLshJSse0MUNU+y1FC3bUS/AQg7oUng+/wKrrki7JfmwtVHkVfPLlw==
Expand Down Expand Up @@ -5653,7 +5653,7 @@ fast-fifo@^1.2.0, fast-fifo@^1.3.2:
resolved "https://registry.yarnpkg.com/fast-fifo/-/fast-fifo-1.3.2.tgz#286e31de96eb96d38a97899815740ba2a4f3640c"
integrity sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ==

fast-glob@^3.2.7, fast-glob@^3.2.9, fast-glob@^3.3.2:
fast-glob@^3.2.12, fast-glob@^3.2.7, fast-glob@^3.2.9, fast-glob@^3.3.2:
version "3.3.2"
resolved "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz"
integrity sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==
Expand Down Expand Up @@ -7705,7 +7705,7 @@ [email protected]:
dependencies:
"@jridgewell/sourcemap-codec" "^1.4.15"

magic-string@^0.30.0, magic-string@^0.30.10, magic-string@^0.30.3, magic-string@^0.30.4, magic-string@^0.30.8:
magic-string@^0.30.0, magic-string@^0.30.1, magic-string@^0.30.10, magic-string@^0.30.3, magic-string@^0.30.4, magic-string@^0.30.8:
version "0.30.10"
resolved "https://registry.npmjs.org/magic-string/-/magic-string-0.30.10.tgz"
integrity sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==
Expand Down Expand Up @@ -10935,6 +10935,26 @@ vite-plugin-checker@^0.7.2:
vscode-languageserver-textdocument "^1.0.1"
vscode-uri "^3.0.2"

vite-plugin-commonjs@^0.10.1:
version "0.10.1"
resolved "https://registry.yarnpkg.com/vite-plugin-commonjs/-/vite-plugin-commonjs-0.10.1.tgz#18585abc6020adaee733150847972f55a1f88c55"
integrity sha512-taP8R9kYGlCW5OzkVR0UIWRCnG6rSxeWWuA7tnU5b9t5MniibOnDY219NhisTeDhJAeGT8cEnrhVWZ9A5yD+vg==
dependencies:
acorn "^8.8.2"
fast-glob "^3.2.12"
magic-string "^0.30.1"
vite-plugin-dynamic-import "^1.5.0"

vite-plugin-dynamic-import@^1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/vite-plugin-dynamic-import/-/vite-plugin-dynamic-import-1.5.0.tgz#a28f4768da977f0e448009489617aec259180b63"
integrity sha512-Qp85c+AVJmLa8MLni74U4BDiWpUeFNx7NJqbGZyR2XJOU7mgW0cb7nwlAMucFyM4arEd92Nfxp4j44xPi6Fu7g==
dependencies:
acorn "^8.8.2"
es-module-lexer "^1.2.1"
fast-glob "^3.2.12"
magic-string "^0.30.1"

vite-plugin-inspect@^0.8.4:
version "0.8.4"
resolved "https://registry.yarnpkg.com/vite-plugin-inspect/-/vite-plugin-inspect-0.8.4.tgz#1fcdf6703164d651db3f13c8c6610e1ced5108e1"
Expand Down

0 comments on commit c0a2a78

Please sign in to comment.