-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart-config.ts
41 lines (34 loc) · 1.25 KB
/
start-config.ts
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
import fs from 'fs';
import * as dotenvflow from 'dotenv-flow';
import { ConsoleUtil } from './src/utils';
dotenvflow.config({ path: './env/' });
ConsoleUtil.log('config PORT:', process.env.PORT);
ConsoleUtil.log('config ROOT_DIR:', process.env.ROOT_DIR);
ConsoleUtil.log('config WEB_ROOT:', process.env.WEB_ROOT);
ConsoleUtil.log('config REQUEST_DELAY:', process.env.REQUEST_DELAY);
ConsoleUtil.log('config EDIT_MODE:', process.env.EDIT_MODE);
const port = process.env.PORT ?? 12021;
const root_dir = process.env.ROOT_DIR || '.';
const web_root = process.env.WEB_ROOT || '.';
const request_delay = process.env.REQUEST_DELAY || 0; // unit: seconds, 0: no delay
const edit_mode = process.env.EDIT_MODE || "true"; // true: editable, false: read-only
// path of the config file
const envConfigFile = `./src/config/env.config.ts`;
// content of the config file
const configContent = `
const config = {
port: ${port},
rootDir: '${root_dir}',
webDir: '${web_root}',
request_delay: ${request_delay},
edit_mode: ${edit_mode}
};
export default config;
`;
// write the content to config.json file now
fs.writeFile(envConfigFile, configContent, (err) => {
if (err) {
ConsoleUtil.error(err);
}
ConsoleUtil.log(`Env config file was generated at ${envConfigFile}`);
});