Compare View
Commits (2)
Changes
Showing 4 changed files Inline Diff
config-filler.js
File was created | 1 | "use strict"; | |
2 | |||
3 | const moment = require('moment'); | ||
4 | const config = require('./config'); | ||
5 | |||
6 | function do() { | ||
7 | moment.locale(config.moment_locale || 'id'); | ||
8 | } | ||
9 | |||
10 | exports.do = do; | ||
1 | "use strict"; | 11 |
config-reload.js
1 | "use strict"; | 1 | "use strict"; |
2 | 2 | ||
3 | const config = require('./config'); | 3 | const config = require('./config'); |
4 | const logger = require('./logger'); | 4 | const logger = require('./logger'); |
5 | const configFiller = require('./config-filler'); | ||
5 | const configFiller = require('./config-filler'); | 6 | |
6 | 7 | function replace(new_config) { | |
7 | function replace(new_config) { | 8 | for (let key in new_config) { |
8 | for (let key in new_config) { | 9 | config[key] = new_config[key]; |
9 | config[key] = new_config[key]; | 10 | } |
10 | } | 11 | |
11 | 12 | _removeIfNotExists(new_config); | |
13 | configFiller.do(); | ||
12 | _removeIfNotExists(new_config); | 14 | } |
13 | configFiller.do(); | 15 | |
14 | } | 16 | function reload() { |
15 | 17 | const configFile = process.cwd() + "/config.json"; | |
16 | function reload() { | 18 | const new_config = require(configFile); |
17 | const configFile = process.cwd() + "/config.json"; | 19 | |
18 | const new_config = require(configFile); | 20 | replace(new_config); |
19 | 21 | } | |
20 | replace(new_config); | 22 | |
21 | } | 23 | function _removeIfNotExists(new_config) { |
22 | 24 | for (let key in config) { | |
23 | function _removeIfNotExists(new_config) { | 25 | if (!new_config[key]) { |
24 | for (let key in config) { | 26 | logger.verbose('Removing old config key: ' + key); |
25 | if (!new_config[key]) { | 27 | delete config[key]; |
26 | logger.verbose('Removing old config key: ' + key); | 28 | } |
27 | delete config[key]; | 29 | } |
28 | } | 30 | } |
29 | } | 31 | |
30 | } | 32 | exports.replace = replace; |
31 | 33 | exports.reload = reload; | |
32 | exports.replace = replace; | 34 |
config.js
1 | "use strict"; | 1 | "use strict"; |
2 | 2 | ||
3 | const fs = require('fs'); | 3 | const fs = require('fs'); |
4 | const configFiller = require('./config-filler'); | 4 | const configFiller = require('./config-filler'); |
5 | 5 | ||
6 | let configFile = process.cwd() + "/config.json"; | 6 | let configFile = process.cwd() + "/config.json"; |
7 | 7 | ||
8 | if (!fs.existsSync(configFile)) { | 8 | if (!fs.existsSync(configFile)) { |
9 | console.trace('Config file not found. Terminating'); | 9 | console.trace('Config file not found. Terminating'); |
10 | //setImmediate(function() { | 10 | //setImmediate(function() { |
11 | process.exit(1); | 11 | process.exit(1); |
12 | //}); | 12 | //}); |
13 | } | 13 | } |
14 | 14 | ||
15 | const config = require(configFile); | 15 | const config = require(configFile); |
16 | configFiller.do(); | 16 | configFiller.do(); |
17 | |||
18 | module.exports = config; | 17 | |
19 | 18 | module.exports = config; |
package.json
1 | { | 1 | { |
2 | "name": "komodo-sdk", | 2 | "name": "komodo-sdk", |
3 | "version": "1.8.1", | 3 | "version": "1.8.2", |
4 | "description": "SDK for Komodo", | 4 | "description": "SDK for Komodo", |
5 | "main": "index.js", | 5 | "main": "index.js", |
6 | "scripts": { | 6 | "scripts": { |
7 | "test": "mocha", | 7 | "test": "mocha", |
8 | "postversion": "git push && git push --tags" | 8 | "postversion": "git push && git push --tags" |
9 | }, | 9 | }, |
10 | "repository": { | 10 | "repository": { |
11 | "type": "git", | 11 | "type": "git", |
12 | "url": "git@gitlab.kodesumber.com:komodo/komodo-sdk.git" | 12 | "url": "git@gitlab.kodesumber.com:komodo/komodo-sdk.git" |
13 | }, | 13 | }, |
14 | "keywords": [ | 14 | "keywords": [ |
15 | "ppob", | 15 | "ppob", |
16 | "payment", | 16 | "payment", |
17 | "komodo" | 17 | "komodo" |
18 | ], | 18 | ], |
19 | "author": "Adhidarma Hadiwinoto <gua@adhisimon.org>", | 19 | "author": "Adhidarma Hadiwinoto <gua@adhisimon.org>", |
20 | "license": "ISC", | 20 | "license": "ISC", |
21 | "dependencies": { | 21 | "dependencies": { |
22 | "basic-auth": "^2.0.0", | 22 | "basic-auth": "^2.0.0", |
23 | "lru-cache": "^4.1.1", | 23 | "lru-cache": "^4.1.1", |
24 | "moment": "^2.19.1", | 24 | "moment": "^2.19.1", |
25 | "request": "^2.81.0", | 25 | "request": "^2.81.0", |
26 | "simple-git": "^1.80.1", | 26 | "simple-git": "^1.80.1", |
27 | "strftime": "^0.10.0", | 27 | "strftime": "^0.10.0", |
28 | "winston": "^2.3.1", | 28 | "winston": "^2.3.1", |
29 | "winston-circular-buffer": "^1.0.0", | 29 | "winston-circular-buffer": "^1.0.0", |
30 | "winston-daily-rotate-file": "^1.4.6" | 30 | "winston-daily-rotate-file": "^1.4.6" |
31 | } | 31 | } |
32 | } | 32 | } |
33 | 33 |