-
Notifications
You must be signed in to change notification settings - Fork 11
/
envManager.js
31 lines (26 loc) · 919 Bytes
/
envManager.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
const fs = require("fs");
const path = require("path");
const dir = "src/environments";
const file = "environment.ts";
const prodFile = "environment.prod.ts";
const content = `${process.env.API_DETAILS}`;
fs.access(dir, fs.constants.F_OK, (err) => {
if (err) {
console.log("src does not exist, creating now...", process.cwd());
fs.mkdir(dir, { recursive: true }, (err) => {
if (err) throw err;
console.log("Folder created successfully " + dir, process.cwd());
});
}
try {
fs.writeFileSync(path.join(dir, file), content);
fs.writeFileSync(path.join(dir, prodFile), content);
if (fs.existsSync(path.join(dir, file))) {
console.log("environment.ts created successfully", process.cwd());
const str = fs.readFileSync(path.join(dir, file), "utf8").toString();
}
} catch (err) {
console.log(err);
process.exit(1);
}
});