-
Notifications
You must be signed in to change notification settings - Fork 0
/
prebuild.mjs
38 lines (32 loc) · 1.27 KB
/
prebuild.mjs
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
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// =====================
// Environment variables
// =====================
/*
* Needed for client compilations with docker compose, where the 'APP_VERSION' property isn't injected by gradle.
*
* Returns the inferred APP_VERSION from 'build.gradle', or 'DEV' if this couldn't be retrieved
*/
function inferVersion() {
let version = 'DEV';
try {
let data = fs.readFileSync('build.gradle', 'UTF-8');
version = data.match(/\nversion\s=\s"(.*)"/);
version = version[1] ?? 'DEV';
} catch (error) {
console.log("Error while retrieving 'APP_VERSION' property");
}
return version;
}
// --develop flag is used to enable debug mode
const args = process.argv.slice(2);
const developFlag = args.includes('--develop');
const environmentConfig = `// Don't change this file manually, it will be overwritten by the build process!
export const __DEBUG_INFO_ENABLED__ = ${developFlag};
export const __VERSION__ = '${process.env.APP_VERSION || inferVersion()}';
`;
fs.writeFileSync(path.resolve(__dirname, 'src', 'main', 'webapp', 'app', 'environments', 'environment.override.ts'), environmentConfig);