|
|
@ -17,12 +17,17 @@ export const ANALYTIC_UNIT_CACHES_DATABASE_PATCH = path.join(DATA_PATH, 'analyti |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const HASTIC_PORT = getConfigField('HASTIC_PORT', '8000'); |
|
|
|
export const HASTIC_PORT = getConfigField('HASTIC_PORT', '8000'); |
|
|
|
export const ZMQ_CONNECTION_STRING = getConfigField('ZMQ_CONNECTION_STRING', null); |
|
|
|
|
|
|
|
export const ZMQ_IPC_PATH = getConfigField('ZMQ_IPC_PATH', path.join(os.tmpdir(), 'hastic')); |
|
|
|
export const ZMQ_IPC_PATH = getConfigField('ZMQ_IPC_PATH', path.join(os.tmpdir(), 'hastic')); |
|
|
|
export const ZMQ_DEV_PORT = getConfigField('ZMQ_DEV_PORT', '8002'); |
|
|
|
export const ZMQ_DEV_PORT = getConfigField('ZMQ_DEV_PORT', '8002'); |
|
|
|
export const ZMQ_HOST = getConfigField('ZMQ_HOST', '127.0.0.1'); |
|
|
|
export const ZMQ_HOST = getConfigField('ZMQ_HOST', '127.0.0.1'); |
|
|
|
export const HASTIC_API_KEY = getConfigField('HASTIC_API_KEY'); |
|
|
|
export const HASTIC_API_KEY = getConfigField('HASTIC_API_KEY'); |
|
|
|
export const ANLYTICS_PING_INTERVAL = 500; // ms
|
|
|
|
export const ANLYTICS_PING_INTERVAL = 500; // ms
|
|
|
|
|
|
|
|
export const PACKAGE_VERSION = getPackageVersion(); |
|
|
|
|
|
|
|
export const GIT_INFO = getGitInfo(); |
|
|
|
|
|
|
|
export const INSIDE_DOCKER = process.env.INSIDE_DOCKER !== undefined; |
|
|
|
|
|
|
|
export const PRODUCTION_MODE = process.env.NODE_ENV !== 'development'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export const ZMQ_CONNECTION_STRING = createZMQConnectionString(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getConfigField(field: string, defaultVal?: any) { |
|
|
|
function getConfigField(field: string, defaultVal?: any) { |
|
|
@ -43,3 +48,45 @@ function getConfigField(field: string, defaultVal?: any) { |
|
|
|
} |
|
|
|
} |
|
|
|
return val; |
|
|
|
return val; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getPackageVersion() { |
|
|
|
|
|
|
|
if(process.env.npm_package_version !== undefined) { |
|
|
|
|
|
|
|
return process.env.npm_package_version; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
let packageFile = path.join(__dirname, '../package.json'); |
|
|
|
|
|
|
|
if(fs.existsSync(packageFile)) { |
|
|
|
|
|
|
|
let packageJson: any = getJsonDataSync(packageFile); |
|
|
|
|
|
|
|
return packageJson.version; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
console.debug(`Can't find package file ${packageFile}`); |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getGitInfo() { |
|
|
|
|
|
|
|
let gitRoot = path.join(__dirname, '../../.git'); |
|
|
|
|
|
|
|
let gitHeadFile = path.join(gitRoot, 'HEAD'); |
|
|
|
|
|
|
|
if(!fs.existsSync(gitHeadFile)) { |
|
|
|
|
|
|
|
console.debug(`Can't find git HEAD file ${gitHeadFile}`); |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const rev = fs.readFileSync(gitHeadFile).toString(); |
|
|
|
|
|
|
|
let branchPath = rev.indexOf(':') === -1 ? rev : rev.slice(5, -1); |
|
|
|
|
|
|
|
let branch = branchPath.split('/').pop(); |
|
|
|
|
|
|
|
let commitHash = fs.readFileSync(`${gitRoot}/${branchPath}`).toString().slice(0, -1); |
|
|
|
|
|
|
|
return { branch, commitHash }; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createZMQConnectionString() { |
|
|
|
|
|
|
|
let zmq =`tcp://${ZMQ_HOST}:${ZMQ_DEV_PORT}`; //debug mode
|
|
|
|
|
|
|
|
let zmqConf = getConfigField('ZMQ_CONNECTION_STRING', null); |
|
|
|
|
|
|
|
if(INSIDE_DOCKER) { |
|
|
|
|
|
|
|
return zmqConf; |
|
|
|
|
|
|
|
} else if(PRODUCTION_MODE) { |
|
|
|
|
|
|
|
if(zmqConf === null) { |
|
|
|
|
|
|
|
return 'ipc://' + `${path.join(ZMQ_IPC_PATH, process.pid.toString())}.ipc`; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return zmq; |
|
|
|
|
|
|
|
} |
|
|
|