Forráskód Böngészése

automatize symlink creation to .env

Olivier Massot 2 éve
szülő
commit
e7b54a6149
13 módosított fájl, 239 hozzáadás és 14 törlés
  1. 2 2
      .gitignore
  2. 1 5
      README.md
  3. 0 0
      env/.env.docker
  4. 0 0
      env/.env.prod
  5. 36 0
      env/.env.test
  6. 1 1
      env/.env.test1
  7. 36 0
      env/.env.test2
  8. 36 0
      env/.env.test3
  9. 36 0
      env/.env.test4
  10. 36 0
      env/.env.test5
  11. 51 0
      env/setupEnv.mjs
  12. 3 2
      nuxt.config.ts
  13. 1 4
      package.json

+ 2 - 2
.gitignore

@@ -16,8 +16,8 @@ dist
 # macOS
 .DS_Store
 
-local.app.opentalent.fr.crt
-local.app.opentalent.fr.key
+env/local.app.opentalent.fr.crt
+env/local.app.opentalent.fr.key
 /.project
 yarn.lock
 coverage/

+ 1 - 5
README.md

@@ -33,12 +33,8 @@ Installer les dépendances :
 
     yarn install
 
-Créer le symlink vers le bon fichier env (remplacer `<environnement>` par l'env courant):
 
-    ln -s .env.<environnement> .env
-
-
-Copier les certificats à la racine de ce projet :
+Copier les certificats dans le répertoire `env/` de ce projet :
 
 * local.app.opentalent.fr.crt
 * local.app.opentalent.fr.key

+ 0 - 0
.env.docker → env/.env.docker


+ 0 - 0
.env.prod → env/.env.prod


+ 36 - 0
env/.env.test

@@ -0,0 +1,36 @@
+## TEST ENVIRONMENT FILE
+
+DEBUG=1
+
+HOST=0
+PORT=3002
+
+# Current env
+NUXT_ENV=test
+NUXT_PUBLIC_ENV=test
+
+## API Base Url
+NUXT_BASE_URL=https://ap2i.test.opentalent.fr
+NUXT_PUBLIC_BASE_URL=https://ap2i.test.opentalent.fr
+
+# Legacy API Base Url
+NUXT_BASE_URL_LEGACY=https://api.test.opentalent.fr
+NUXT_PUBLIC_BASE_URL_LEGACY=https://api.test.opentalent.fr
+
+# Legacy Admin Base Url
+NUXT_BASE_URL_ADMIN_LEGACY=https://admin.test.opentalent.fr/#
+NUXT_PUBLIC_BASE_URL_ADMIN_LEGACY=https://admin.test.opentalent.fr/#
+
+# Typo3 Base Url
+NUXT_BASE_URL_TYPO3=https://test.opentalent.fr/###subDomain###
+NUXT_PUBLIC_BASE_URL_TYPO3=https://test.opentalent.fr/###subDomain###
+
+# Mercure push events
+NUXT_BASE_URL_MERCURE=https://mercure.test.opentalent.fr/.well-known/mercure
+NUXT_PUBLIC_BASE_URL_MERCURE=https://mercure.test.opentalent.fr/.well-known/mercure
+MERCURE_SUBSCRIBER_JWT_KEY=NQEupdREijrfYvCmF2mnvZQFL9zLKDH9RCYter6tUWzjemPqzicffhc2fSf0yEmM
+
+# Other links
+NUXT_SUPPORT_URL=https://support.opentalent.fr/
+NUXT_PUBLIC_SUPPORT_URL=https://support.opentalent.fr/
+

+ 1 - 1
.env.test → env/.env.test1

@@ -1,4 +1,4 @@
-## TEST ENVIRONMENT FILE
+.env.test## TEST ENVIRONMENT FILE
 
 DEBUG=1
 

+ 36 - 0
env/.env.test2

@@ -0,0 +1,36 @@
+## TEST ENVIRONMENT FILE
+
+DEBUG=1
+
+HOST=0
+PORT=3002
+
+# Current env
+NUXT_ENV=test
+NUXT_PUBLIC_ENV=test
+
+## API Base Url
+NUXT_BASE_URL=https://ap2i.test2.opentalent.fr
+NUXT_PUBLIC_BASE_URL=https://ap2i.test2.opentalent.fr
+
+# Legacy API Base Url
+NUXT_BASE_URL_LEGACY=https://api.test2.opentalent.fr
+NUXT_PUBLIC_BASE_URL_LEGACY=https://api.test2.opentalent.fr
+
+# Legacy Admin Base Url
+NUXT_BASE_URL_ADMIN_LEGACY=https://admin.test2.opentalent.fr/#
+NUXT_PUBLIC_BASE_URL_ADMIN_LEGACY=https://admin.test2.opentalent.fr/#
+
+# Typo3 Base Url
+NUXT_BASE_URL_TYPO3=https://test2.opentalent.fr/###subDomain###
+NUXT_PUBLIC_BASE_URL_TYPO3=https://test2.opentalent.fr/###subDomain###
+
+# Mercure push events
+NUXT_BASE_URL_MERCURE=https://mercure.test.opentalent.fr/.well-known/mercure
+NUXT_PUBLIC_BASE_URL_MERCURE=https://mercure.test.opentalent.fr/.well-known/mercure
+MERCURE_SUBSCRIBER_JWT_KEY=NQEupdREijrfYvCmF2mnvZQFL9zLKDH9RCYter6tUWzjemPqzicffhc2fSf0yEmM
+
+# Other links
+NUXT_SUPPORT_URL=https://support.opentalent.fr/
+NUXT_PUBLIC_SUPPORT_URL=https://support.opentalent.fr/
+

+ 36 - 0
env/.env.test3

@@ -0,0 +1,36 @@
+## TEST ENVIRONMENT FILE
+
+DEBUG=1
+
+HOST=0
+PORT=3002
+
+# Current env
+NUXT_ENV=test
+NUXT_PUBLIC_ENV=test
+
+## API Base Url
+NUXT_BASE_URL=https://ap2i.test3.opentalent.fr
+NUXT_PUBLIC_BASE_URL=https://ap2i.test3.opentalent.fr
+
+# Legacy API Base Url
+NUXT_BASE_URL_LEGACY=https://api.test3.opentalent.fr
+NUXT_PUBLIC_BASE_URL_LEGACY=https://api.test3.opentalent.fr
+
+# Legacy Admin Base Url
+NUXT_BASE_URL_ADMIN_LEGACY=https://admin.test3.opentalent.fr/#
+NUXT_PUBLIC_BASE_URL_ADMIN_LEGACY=https://admin.test3.opentalent.fr/#
+
+# Typo3 Base Url
+NUXT_BASE_URL_TYPO3=https://test3.opentalent.fr/###subDomain###
+NUXT_PUBLIC_BASE_URL_TYPO3=https://test3.opentalent.fr/###subDomain###
+
+# Mercure push events
+NUXT_BASE_URL_MERCURE=https://mercure.test.opentalent.fr/.well-known/mercure
+NUXT_PUBLIC_BASE_URL_MERCURE=https://mercure.test.opentalent.fr/.well-known/mercure
+MERCURE_SUBSCRIBER_JWT_KEY=NQEupdREijrfYvCmF2mnvZQFL9zLKDH9RCYter6tUWzjemPqzicffhc2fSf0yEmM
+
+# Other links
+NUXT_SUPPORT_URL=https://support.opentalent.fr/
+NUXT_PUBLIC_SUPPORT_URL=https://support.opentalent.fr/
+

+ 36 - 0
env/.env.test4

@@ -0,0 +1,36 @@
+## TEST ENVIRONMENT FILE
+
+DEBUG=1
+
+HOST=0
+PORT=3002
+
+# Current env
+NUXT_ENV=test
+NUXT_PUBLIC_ENV=test
+
+## API Base Url
+NUXT_BASE_URL=https://ap2i.test4.opentalent.fr
+NUXT_PUBLIC_BASE_URL=https://ap2i.test4.opentalent.fr
+
+# Legacy API Base Url
+NUXT_BASE_URL_LEGACY=https://api.test4.opentalent.fr
+NUXT_PUBLIC_BASE_URL_LEGACY=https://api.test4.opentalent.fr
+
+# Legacy Admin Base Url
+NUXT_BASE_URL_ADMIN_LEGACY=https://admin.test4.opentalent.fr/#
+NUXT_PUBLIC_BASE_URL_ADMIN_LEGACY=https://admin.test4.opentalent.fr/#
+
+# Typo3 Base Url
+NUXT_BASE_URL_TYPO3=https://test4.opentalent.fr/###subDomain###
+NUXT_PUBLIC_BASE_URL_TYPO3=https://test4.opentalent.fr/###subDomain###
+
+# Mercure push events
+NUXT_BASE_URL_MERCURE=https://mercure.test.opentalent.fr/.well-known/mercure
+NUXT_PUBLIC_BASE_URL_MERCURE=https://mercure.test.opentalent.fr/.well-known/mercure
+MERCURE_SUBSCRIBER_JWT_KEY=NQEupdREijrfYvCmF2mnvZQFL9zLKDH9RCYter6tUWzjemPqzicffhc2fSf0yEmM
+
+# Other links
+NUXT_SUPPORT_URL=https://support.opentalent.fr/
+NUXT_PUBLIC_SUPPORT_URL=https://support.opentalent.fr/
+

+ 36 - 0
env/.env.test5

@@ -0,0 +1,36 @@
+## TEST ENVIRONMENT FILE
+
+DEBUG=1
+
+HOST=0
+PORT=3002
+
+# Current env
+NUXT_ENV=test
+NUXT_PUBLIC_ENV=test
+
+## API Base Url
+NUXT_BASE_URL=https://ap2i.test5.opentalent.fr
+NUXT_PUBLIC_BASE_URL=https://ap2i.test5.opentalent.fr
+
+# Legacy API Base Url
+NUXT_BASE_URL_LEGACY=https://api.test5.opentalent.fr
+NUXT_PUBLIC_BASE_URL_LEGACY=https://api.test5.opentalent.fr
+
+# Legacy Admin Base Url
+NUXT_BASE_URL_ADMIN_LEGACY=https://admin.test5.opentalent.fr/#
+NUXT_PUBLIC_BASE_URL_ADMIN_LEGACY=https://admin.test5.opentalent.fr/#
+
+# Typo3 Base Url
+NUXT_BASE_URL_TYPO3=https://test5.opentalent.fr/###subDomain###
+NUXT_PUBLIC_BASE_URL_TYPO3=https://test5.opentalent.fr/###subDomain###
+
+# Mercure push events
+NUXT_BASE_URL_MERCURE=https://mercure.test.opentalent.fr/.well-known/mercure
+NUXT_PUBLIC_BASE_URL_MERCURE=https://mercure.test.opentalent.fr/.well-known/mercure
+MERCURE_SUBSCRIBER_JWT_KEY=NQEupdREijrfYvCmF2mnvZQFL9zLKDH9RCYter6tUWzjemPqzicffhc2fSf0yEmM
+
+# Other links
+NUXT_SUPPORT_URL=https://support.opentalent.fr/
+NUXT_PUBLIC_SUPPORT_URL=https://support.opentalent.fr/
+

+ 51 - 0
env/setupEnv.mjs

@@ -0,0 +1,51 @@
+/**
+ * Post install script: create or replace the symlink .env
+ * to the .env file matching the current environment
+ */
+import os from "os";
+import fs from "fs";
+import {fileURLToPath} from "node:url";
+import path from 'path';
+
+
+const projectDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..')
+
+const hostname = os.hostname()
+
+const environments = {
+    'app': '.env.docker',
+    'prod-v2': '.env.prod',
+    'test-v2': '.env.test',
+    'test1': '.env.test1',
+    'test2': '.env.test2',
+    'test3': '.env.test3',
+    'test4': '.env.test4',
+    'test5': '.env.test5',
+}
+
+if (!environments.hasOwnProperty(hostname)) {
+    throw Error("Critical : unknown environment")
+}
+
+const targetEnvFile = path.join(projectDir, 'env', environments[hostname])
+const mainEnvFile = path.join(projectDir, '.env')
+
+if (fs.existsSync(mainEnvFile)) {
+    fs.unlink(mainEnvFile, (err) => {
+        if (err) throw err;
+        console.log(`${mainEnvFile} was deleted`);
+    });
+}
+
+fs.symlink(
+    targetEnvFile,
+    '.env',
+    'file',
+    (err) => {
+        if (err)
+            console.error(err);
+        else {
+            console.log(`Symlink to ${targetEnvFile} file created`);
+        }
+    }
+)

+ 3 - 2
nuxt.config.ts

@@ -1,12 +1,13 @@
 import fs from 'fs';
 import vuetify from 'vite-plugin-vuetify'
+import * as os from "os";
 
 let https = {}
 
 if (process.env.NUXT_ENV === 'dev') {
     https = {
-        key: fs.readFileSync('local.app.opentalent.fr.key'),
-        cert: fs.readFileSync('local.app.opentalent.fr.crt'),
+        key: fs.readFileSync('env/local.app.opentalent.fr.key'),
+        cert: fs.readFileSync('env/local.app.opentalent.fr.crt'),
     }
 }
 

+ 1 - 4
package.json

@@ -3,12 +3,9 @@
   "private": true,
   "version": "2.3.0",
   "scripts": {
+    "postinstall": "node ./env/setupEnv.mjs",
     "dev": "rm -rf /tmp/nitro && nuxt dev",
-    "dev:local": "yarn dev --dotenv .env.docker",
-    "dev:prod": "yarn dev --dotenv .env.prod",
     "build": "nuxt build && cp -r config/ .output/config",
-    "build:local": "yarn build --dotenv .env.docker",
-    "build:prod": "yarn build --dotenv .env.prod",
     "prepare": "nuxt prepare",
     "start": "nuxt start",
     "deploy": "git pull && yarn install & yarn build",