forked from osmforcities/osmforcities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-env.js
43 lines (37 loc) · 1.15 KB
/
setup-env.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// check if .env file exists, if not, create it
// and set default values
const fs = require("fs");
const path = require("path");
const envPath = path.join(__dirname, "./.env");
if (!fs.existsSync(envPath)) {
fs.writeFileSync(
envPath,
`POSTGRES_PRISMA_URL=\"postgres://postgres:docker@localhost:5433/postgres\"\n`
);
}
function removeSymlinkIfItExists(filePath) {
try {
const stats = fs.lstatSync(filePath);
if (stats.isSymbolicLink()) {
console.log(`Removing existing .env symlink at ${filePath}`);
fs.unlinkSync(filePath);
}
} catch (error) {
if (error.code !== "ENOENT") {
throw error; // Rethrow if the error is not related to the absence of the file
}
}
}
// Create symlinks to .env file in all apps
const apps = ["cli", "web"];
apps.forEach((app) => {
const appDir = path.join(__dirname, `./apps/${app}/`);
if (!fs.existsSync(appDir)) {
console.log(`Creating ${app} app directory`);
fs.mkdirSync(appDir);
}
const appEnvPath = path.join(appDir, `.env`);
removeSymlinkIfItExists(appEnvPath);
console.log(`Creating .env symlink for ${app} app.`);
fs.symlinkSync(envPath, appEnvPath);
});