-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchangeConfig.js
66 lines (47 loc) · 1.46 KB
/
changeConfig.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* changeConfig
* Author: ahmedwab
* June 2021
*/
const config = require('../config/config.js');
const fs = require('fs');
var myArgs = process.argv.slice(2);
var change = myArgs[0]
var moduleName =myArgs[1];
/**
*
* Adds Module to the top right corner
*/
function addModule(){
moduleContainer= {module: moduleName,
position: 'top_right'}
moduleIndex = config.modules.findIndex(element => element.module == moduleName);
if( moduleIndex==-1)
config.modules.push(moduleContainer);
}
/**
*
* Removes Module
*/
function removeModule(){
moduleIndex = config.modules.findIndex(element => element.module == moduleName);
if( moduleIndex!=-1)
config.modules.splice(moduleIndex,1)
}
if (change=='add'){
addModule()
}
else if (change=='remove'){
removeModule()
}
fs.readFile('../config/config.js', 'utf8', function(err, data){
var s = data;
str = s.split("modules:");
var end = " /*************** DO NOT EDIT THE LINE BELOW ***************\/ \n if (typeof module !== \"undefined\") {module.exports = config;}";
configModules = JSON.stringify(config.modules, null, '\t');
configModules = configModules.replace(/"([^"]+)":/g, '$1:');
newconfigFile =str[0]+"modules: \n \t \t" + configModules +" \n }; \n" +end;
fs.writeFile('../config/config.js', newconfigFile, function (err) {
if (err) return console.log(err);
console.log('Configuration file has been changed');
});
});