first commit

This commit is contained in:
spiduler
2021-07-13 16:53:42 +09:00
commit db05b73e5b
14 changed files with 624 additions and 0 deletions

71
config/index.js Normal file
View File

@@ -0,0 +1,71 @@
const commandLineArgs = require('command-line-args')
, xmlParserConfig = require('./xmlParserConfig')
, godoParams = require('./params.json')
, logger = require("logops");
class Config {
constructor() {
this.options = {}
this.requires = ['env', 'gateway', 'quix24', 'mongo']
this.init()
this.validate()
this.finalize()
}
init() {
try {
this.options = commandLineArgs([
{ name: 'env', alias: 'e', type: String, defaultValue: ['production'] },
{ name: 'host', type: String },
{ name: 'port', type: Number },
{ name: 'database', alias: 'd', type: String },
{ name: 'username', alias: 'u', type: String },
{ name: 'password', alias: 'p', type: String },
{ name: 'mongo', alias: 'm', type: String },
{ name: 'redis', alias: 'r', type: String },
{ name: 'level', alias: 'l', type: String },
{ name: 'gateway', alias: 'g', type: String },
{ name: 'quix24', alias: 'q', type: String }
]);
} catch (e) {
logger.debug('Command line arguments interpret failed :', e.message)
logger.debug('expected arguments : ', JSON.stringify(this.requires))
process.exit(1)
}
}
finalize() {
if (this.options.env == 'development') {
this.options.level = this.options.level ? this.options.level : "DEBUG"
logger.formatters.dev.omit = ['pid', 'port', 'hostname', 'app'];
// logger.format = logger.formatters.dev;
} else {
this.options.level = this.options.level ? this.options.level : "WARN"
}
this.options.xmlParser = xmlParserConfig
this.options.godoParams = godoParams
logger.formatters.json.omit = ['pid', 'port', 'hostname', 'app'];
logger.setLevel(this.options.level)
logger.debug(this.options, 'Environment setting options')
}
validate() {
for (let key in this.options) {
if (this.options[key]) {
delete this.requires[this.requires.indexOf(key)]
}
}
this.requires = this.requires.filter(function (el) {
return el != null;
})
if (this.requires.length) {
logger.debug('Process terminated invalid required arguments: ', JSON.stringify(this.requires))
process.exit(1)
}
}
}
let config = new Config;
module.exports = config.options

4
config/params.json Normal file
View File

@@ -0,0 +1,4 @@
{
"partner_key": "JUFDJUIzJTAyJTVEJTk5JTE5JUYwRw==",
"key": "JTVFJTE0JUZCJUVGJUQ2SSUxNiU4RCVCMyVGOSU3RSVGRCVGNSVGNyUxNSU3RCVBM0YlRDAlMkNwJUNDJUQ2JUNDVSU5MCUzRWklN0YlOEIlQUQlRTMlQURqYSVCQiUwOSUwMCVDMCUwOCVFRiVGQyVDQk0="
}

20
config/xmlParserConfig.js Normal file
View File

@@ -0,0 +1,20 @@
const he = require('he')
module.exports = {
"attributeNamePrefix": "@_",
"attrNodeName": "attr", //default is 'false'
"textNodeName": "#text",
"ignoreAttributes": true,
"ignoreNameSpace": false,
"allowBooleanAttributes": false,
"parseNodeValue": true,
"parseAttributeValue": false,
"trimValues": true,
// "cdataTagName": "__cdata", //default is 'false'
"cdataPositionChar": "\\c",
"parseTrueNumberOnly": false,
"arrayMode": false, //"strict"
"attrValueProcessor": (val, attrName) => he.decode(val, { isAttributeValue: true }),//default is a=>a
"tagValueProcessor": (val, tagName) => he.decode(val), //default is a=>a
"stopNodes": ["parse-me-as-string"]
}