|
|
@@ -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`);
|
|
|
+ }
|
|
|
+ }
|
|
|
+)
|