forked from Mijago/D2ArmorPicker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset-env.ts
More file actions
77 lines (66 loc) · 2.68 KB
/
set-env.ts
File metadata and controls
77 lines (66 loc) · 2.68 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Copyright (c) 2023 D2ArmorPicker by Mijago.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const writeFile = require("fs").writeFile;
const production = process.env["PRODUCTION"] === "1";
const beta_branch = process.env["BETA"] === "1";
const canary_branch = process.env["CANARY"] === "1";
const version = "2.9.5";
// Configure Angular `environment.ts` file path
const targetPath = production
? "./src/environments/environment.prod.ts"
: beta_branch || canary_branch
? "./src/environments/environment.prod.ts"
: "./src/environments/environment.ts";
// Load node modules
const dotenvfile = production
? ".env"
: beta_branch
? ".env_beta"
: canary_branch
? ".env_canary"
: ".env_dev";
require("dotenv").config({ path: dotenvfile });
const revision = require("child_process").execSync("git rev-parse --short HEAD").toString().trim();
var version_tag = production ? "" : beta_branch ? "-beta-" + revision : "-dev-" + revision;
console.log(`Reading ${dotenvfile} version ${version + version_tag}`);
const data = {
version: version + version_tag,
revision: revision,
production: production,
beta: beta_branch,
canary: canary_branch,
apiKey: process.env["D2AP_BUNGIE_API_KEY"],
clientId: process.env["D2AP_BUNGIE_CLIENT_ID"],
client_secret: process.env["D2AP_BUNGIE_CLIENT_SECRET"],
nodeEnv: process.env["NODE_ENV"],
offlineMode: false,
highlight_project_id: process.env["D2AP_HIGHLIGHT_MONITORING_ID"],
featureFlags: {
enableModslotLimitation: process.env["D2AP_FEATURE_ENABLE_MODSLOT_LIMITATION"] == "1",
enableZeroWaste: process.env["D2AP_FEATURE_ENABLE_ZERO_WASTE"] == "1",
enableGuardianGamesFeatures: process.env["D2AP_FEATURE_ENABLE_GUARDIAN_GAMES_FEATURES"] == "1",
},
};
// `environment.ts` file structure
const envConfigFile = `export const environment = ${JSON.stringify(data, null, 2)};`;
writeFile(targetPath, envConfigFile, (err: NodeJS.ErrnoException | null) => {
if (err) {
throw console.error(err);
} else {
console.log(`Angular environment.ts file generated correctly at ${targetPath} \n`);
}
});