All files / core/repositories config.repository.ts

61.29% Statements 38/62
42.86% Branches 18/42
83.33% Functions 5/6
60% Lines 36/60

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 1291x   1x   1x 1x 1x     1x             1x 1x     1x 1x 1x   1x     1x             6x 6x 276x           276x 198x               6x             6x               6x             6x               6x     6x 6x       6x       6x 6x 6x     6x           6x             6x             6x     6x       1x   1x  
import Logger from '../../infrastructure/logging/logger';
 
import { COMPODOC_DEFAULTS } from '../defaults';
 
import { InternalConfiguration } from '../entities/internal-configuration';
import { PublicConfiguration } from '../entities/public-configuration';
import { Flag, PUBLIC_FLAGS } from '../entities/public-flags';
import { CLIProgram } from '../entities/cli-program';
 
export class ConfigurationRepository {
    private static instance: ConfigurationRepository;
 
    public publicConfiguration: PublicConfiguration;
    public internalConfiguration: InternalConfiguration;
 
    constructor() {
        this.publicConfiguration = new PublicConfiguration();
        this.internalConfiguration = new InternalConfiguration();
    }
 
    public static getInstance() {
        Eif (!ConfigurationRepository.instance) {
            ConfigurationRepository.instance = new ConfigurationRepository();
        }
        return ConfigurationRepository.instance;
    }
 
    public update(configExplorerResult) {
        this.publicConfiguration = Object.assign(
            this.publicConfiguration,
            configExplorerResult.config
        );
    }
 
    public init(currentProgram: CLIProgram) {
        PUBLIC_FLAGS.forEach((publicFlag: Flag) => {
            Iif (this.publicConfiguration[publicFlag.label]) {
                this.internalConfiguration[publicFlag.label] = this.publicConfiguration[
                    publicFlag.label
                ];
            }
 
            if (currentProgram.hasOwnProperty(publicFlag.label)) {
                this.internalConfiguration[publicFlag.label] = currentProgram[publicFlag.label];
            }
        });
 
        /**
         * Specific use-cases flags
         */
 
        Iif (this.publicConfiguration.coverageTest) {
            this.internalConfiguration.coverageTest = 0;
            this.internalConfiguration.coverageTestThreshold =
                typeof this.publicConfiguration.coverageTest === 'string'
                    ? parseInt(this.publicConfiguration.coverageTest, 10)
                    : COMPODOC_DEFAULTS.defaultCoverageThreshold;
        }
        Iif (currentProgram.coverageTest) {
            this.internalConfiguration.coverageTest = 0;
            this.internalConfiguration.coverageTestThreshold =
                typeof currentProgram.coverageTest === 'string'
                    ? parseInt(currentProgram.coverageTest, 10)
                    : COMPODOC_DEFAULTS.defaultCoverageThreshold;
        }
 
        Iif (this.publicConfiguration.coverageMinimumPerFile) {
            this.internalConfiguration.coverageTestPerFile = true;
            this.internalConfiguration.coverageMinimumPerFile =
                typeof this.publicConfiguration.coverageMinimumPerFile === 'string'
                    ? parseInt(this.publicConfiguration.coverageMinimumPerFile, 10)
                    : COMPODOC_DEFAULTS.defaultCoverageMinimumPerFile;
        }
        Iif (currentProgram.coverageMinimumPerFile) {
            this.internalConfiguration.coverageTestPerFile = true;
            this.internalConfiguration.coverageMinimumPerFile =
                typeof currentProgram.coverageMinimumPerFile === 'string'
                    ? parseInt(currentProgram.coverageMinimumPerFile, 10)
                    : COMPODOC_DEFAULTS.defaultCoverageMinimumPerFile;
        }
 
        Iif (this.publicConfiguration.coverageTestThresholdFail) {
            this.internalConfiguration.coverageTestThresholdFail = this.publicConfiguration.coverageTestThresholdFail;
        }
        Eif (currentProgram.coverageTestThresholdFail) {
            this.internalConfiguration.coverageTestThresholdFail =
                currentProgram.coverageTestThresholdFail;
        }
 
        Iif (this.publicConfiguration.host) {
            this.internalConfiguration.host = this.publicConfiguration.host;
            this.internalConfiguration.hostname = this.publicConfiguration.host;
        }
        Eif (currentProgram.host) {
            this.internalConfiguration.host = currentProgram.host;
            this.internalConfiguration.hostname = currentProgram.host;
        }
 
        Iif (this.publicConfiguration.minimal) {
            this.internalConfiguration.disableSearch = true;
            this.internalConfiguration.disableRoutesGraph = true;
            this.internalConfiguration.disableGraph = true;
            this.internalConfiguration.disableCoverage = true;
        }
        Iif (currentProgram.minimal) {
            this.internalConfiguration.disableSearch = true;
            this.internalConfiguration.disableRoutesGraph = true;
            this.internalConfiguration.disableGraph = true;
            this.internalConfiguration.disableCoverage = true;
        }
 
        Iif (
            currentProgram.navTabConfig &&
            JSON.parse(currentProgram.navTabConfig).length !== COMPODOC_DEFAULTS.navTabConfig.length
        ) {
            this.internalConfiguration.navTabConfig = JSON.parse(currentProgram.navTabConfig);
        }
 
        Iif (this.publicConfiguration.silent) {
            Logger.silent = true;
        }
        Iif (currentProgram.silent) {
            Logger.silent = true;
        }
    }
}
 
export default ConfigurationRepository.getInstance();