all files / common/ config.js

80% Statements 12/15
37.5% Branches 3/8
100% Functions 1/1
80% Lines 12/15
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                                                          
const fs = require('fs');
const path = require('path');
const version = require('../package.json').version;
 
const config = {
  version,
  authFile: path.join(process.env.HOME, '.polyglot.auth.json'),
  projectFile: path.join(process.cwd(), '.polyglot.json'),
  hostname: 'https://polyglot.infinum.co',
  apiPath: '/api/v2',
  debug: process.env.NODE_ENV === 'development',
  reloadProjectData(projectFile, requireFn = require) {
    this.projectFile = path.resolve(projectFile);
    this.project = requireFn(this.projectFile);
  }
};
 
Eif (fs.existsSync(config.authFile)) {
  config.auth = require(config.authFile);
} else if (process.env.POLYGLOT_AUTH_TOKEN) {
  config.auth = {
    token: process.env.POLYGLOT_AUTH_TOKEN
  };
}
 
Iif (fs.existsSync(config.projectFile)) {
  config.project = require(config.projectFile);
}
 
Eif (process.env.NODE_ENV === 'test') {
  Object.assign(config, {
    authFile: '/.polyglot.auth.json',
    projectFile: '/.polyglot.json',
    silent: true,
    auth: null,
    project: null
  });
}
 
module.exports = config;