-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathcreate-server-properties.js
41 lines (32 loc) · 1.63 KB
/
create-server-properties.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
32
33
34
35
36
37
38
39
40
41
// Creates the server properties from config.json
const assert = require('assert');
const fs = require('fs');
const util = require('util');
const {
CONFIG_FILE_PATH,
SERVER_PROPERTIES_FILE_PATH,
SERVER_PROPERTIES_FIELDS
} = require('./utils.js')
const getServerPropertiesContentString = (serverProperties) => {
return Object.keys(serverProperties).map((property) => serverProperties[property] != null ? `${property}=${serverProperties[property]}` : null).filter(line => line != null).join('\n\n');
}
const createServerProperties = util.promisify((callback) => {
const configFile = fs.readFileSync(CONFIG_FILE_PATH, 'utf8');
const config = JSON.parse(configFile);
const configServerProperties = config['server-properties'];
assert(configServerProperties, `Expected to find server-properties in ${CONFIG_FILE_PATH}`);
actualConfigServerPropertyFields = Object.keys(configServerProperties);
// check that the fields are what we expect
actualConfigServerPropertyFields.sort();
SERVER_PROPERTIES_FIELDS.sort();
// skip the assertion for now - level-seed may not be available (TODO: reintroduce assertion with subset check?)
// assert.deepEqual(actualConfigServerPropertyFields, SERVER_PROPERTIES_FIELDS, `Expected fields in config['server-properties'] to be the same as those defined in ./utils.js`)
const content = getServerPropertiesContentString(configServerProperties);
console.log(SERVER_PROPERTIES_FILE_PATH)
fs.writeFileSync(SERVER_PROPERTIES_FILE_PATH, content);
console.log(`Overwrote ${SERVER_PROPERTIES_FILE_PATH} based on contents of ${CONFIG_FILE_PATH}`);
callback();
});
module.exports = {
createServerProperties
};