-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathcomb_feats.js
More file actions
40 lines (35 loc) · 994 Bytes
/
comb_feats.js
File metadata and controls
40 lines (35 loc) · 994 Bytes
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
const fs = require('fs');
const process = require('process');
const _ = require('lodash');
const argv = (key) => {
if (process.argv.includes(`--${key}`)) return true;
const value = process.argv.find((element) => element.startsWith(`--${key}=`));
if (!value) return null;
return value.replace(`--${key}=`, '');
};
const envUrl = '.env.advanced';
const feats = _.split(argv('feats'), ',');
let existingEnv = {};
if (fs.existsSync(envUrl)) {
const content = fs.readFileSync(envUrl, 'utf-8');
const lines = content.split('\n').filter((line) => line.trim() && !line.startsWith('#'));
lines.forEach((line) => {
const [key, ...valueParts] = line.split('=');
if (key) {
existingEnv[key.trim()] = valueParts.join('=').trim();
}
});
}
_.forEach(feats, (feat) => {
const key = `VITE_IS_${feat}`;
existingEnv[key] = true;
});
fs.writeFileSync(
envUrl,
_.join(
_.map(existingEnv, (value, key) => {
return `${key}=${value}`;
}),
'\n',
),
);