浏览代码

implements the new env files management system

Olivier Massot 1 年之前
父节点
当前提交
838c41a8b7
共有 10 个文件被更改,包括 88 次插入0 次删除
  1. 0 0
      env/.env.docker
  2. 0 0
      env/.env.prod
  3. 0 0
      env/.env.test
  4. 6 0
      env/.env.test1
  5. 6 0
      env/.env.test2
  6. 6 0
      env/.env.test3
  7. 6 0
      env/.env.test4
  8. 6 0
      env/.env.test5
  9. 57 0
      env/setupEnv.mjs
  10. 1 0
      package.json

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


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


+ 0 - 0
.env.test → env/.env.test


+ 6 - 0
env/.env.test1

@@ -0,0 +1,6 @@
+NUXT_ENV=test
+NUXT_DEBUG=1
+DEBUG=1
+
+NUXT_API_BASE_URL=https://api.test1.opentalent.fr
+NUXT_PUBLIC_API_BASE_URL=https://api.test1.opentalent.fr

+ 6 - 0
env/.env.test2

@@ -0,0 +1,6 @@
+NUXT_ENV=test
+NUXT_DEBUG=1
+DEBUG=1
+
+NUXT_API_BASE_URL=https://api.test2.opentalent.fr
+NUXT_PUBLIC_API_BASE_URL=https://api.test2.opentalent.fr

+ 6 - 0
env/.env.test3

@@ -0,0 +1,6 @@
+NUXT_ENV=test
+NUXT_DEBUG=1
+DEBUG=1
+
+NUXT_API_BASE_URL=https://api.test3.opentalent.fr
+NUXT_PUBLIC_API_BASE_URL=https://api.test3.opentalent.fr

+ 6 - 0
env/.env.test4

@@ -0,0 +1,6 @@
+NUXT_ENV=test
+NUXT_DEBUG=1
+DEBUG=1
+
+NUXT_API_BASE_URL=https://api.test4.opentalent.fr
+NUXT_PUBLIC_API_BASE_URL=https://api.test4.opentalent.fr

+ 6 - 0
env/.env.test5

@@ -0,0 +1,6 @@
+NUXT_ENV=test
+NUXT_DEBUG=1
+DEBUG=1
+
+NUXT_API_BASE_URL=https://api.test5.opentalent.fr
+NUXT_PUBLIC_API_BASE_URL=https://api.test5.opentalent.fr

+ 57 - 0
env/setupEnv.mjs

@@ -0,0 +1,57 @@
+/**
+ * Post install script: create or replace the symlink .env
+ * to the .env file matching the current environment
+ *
+ * To force a hostname, define an env variable named HOST :
+ *
+ *     HOST=ci node ./env/setupEnv.mjs
+ *
+ */
+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 = process.env.HOST ?? os.hostname()
+
+const environments = {
+  'portail_v2': '.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',
+  'ci': '.env.ci',
+}
+
+if (!environments.hasOwnProperty(hostname)) {
+  throw Error("Critical : unknown environment [" + hostname + "]")
+}
+
+const targetEnvFile = path.join(projectDir, 'env', environments[hostname])
+const mainEnvFile = path.join(projectDir, '.env')
+
+fs.unlink(mainEnvFile, (err) => {
+  // 'ENOENT' is the error code for "no such file or directory", we ignore this one
+  if (err && err.code !== 'ENOENT') {
+    throw err
+  }
+  console.log(`${mainEnvFile} was deleted`);
+});
+
+fs.symlink(
+  targetEnvFile,
+  '.env',
+  'file',
+  (err) => {
+    if (err) {
+      throw (err);
+    }
+    console.log(`Symlink created : ${mainEnvFile} -> ${targetEnvFile}`)
+  }
+)

+ 1 - 0
package.json

@@ -3,6 +3,7 @@
   "version": "0.3.0",
   "private": true,
   "scripts": {
+    "postinstall": "node ./env/setupEnv.mjs",
     "dev": "nuxt dev",
     "generate": "nuxt generate",
     "dev:local": "yarn dev --dotenv .env.local",