# All files / core/use-cases display-environment-versions.ts

100% Statements 41/41
71.43% Branches 10/14
100% Functions 4/4
100% Lines 40/40

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
    691x
    1x

    1x

    1x
    1x

    1x
    1x
    1x

    1x

    1x
    1x
    1x

    1x

    1x
    3x
    3x
    1x

    2x

    2x
    2x

    2x
    2x
    2x
    2x
    2x

    2x
    2x
    2x
    2x
    2x
    2x
    1x

    1x
    1x

    2x
    2x
    2x
    2x

    1x

    1x
     import * as fs from 'fs-extra';
    import * as path from 'path';

    import { ts } from 'ts-morph';

    const os = require('os');
    const osName = require('os-name');

    import AngularVersionUtil from '../../infrastructure/angular/angular-version.util';
    import FileEngine from '../../infrastructure/files/file.engine';
    import Logger from '../../infrastructure/logging/logger';

    export class DisplayEnvironmentVersions {
        private static instance: DisplayEnvironmentVersions;

        constructor() {}

        public static getInstance() {
            Eif (!DisplayEnvironmentVersions.instance) {
                DisplayEnvironmentVersions.instance = new DisplayEnvironmentVersions();
            }
            return DisplayEnvironmentVersions.instance;
        }

        public display(compodocPackageJsonFile) {
            const cwd = process.cwd();
            if (Logger.silent) {
                console.log(`Compodoc v${compodocPackageJsonFile.version}`);
            } else {
                let bannerPath = '../src/banner';

                /**
                 * Switch between CLI and Unit testing environment
                 */
                Eif (__dirname.substr(-4) !== 'dist') {
                    bannerPath = '../../../src/banner';
                }

                console.log(fs.readFileSync(path.join(__dirname, bannerPath)).toString());
                console.log(compodocPackageJsonFile.version);
                console.log('');
                console.log(`TypeScript version used by Compodoc : ${ts.version}`);
                console.log('');

                Eif (FileEngine.existsSync(cwd + path.sep + 'package.json')) {
                    const packageData = FileEngine.getSync(cwd + path.sep + 'package.json');
                    Eif (packageData) {
                        const parsedData = JSON.parse(packageData);
                        const projectDevDependencies = parsedData.devDependencies;
                        if (projectDevDependencies && projectDevDependencies.typescript) {
                            const tsProjectVersion = AngularVersionUtil.cleanVersion(
                                projectDevDependencies.typescript
                            );
                            console.log(`TypeScript version of current project : ${tsProjectVersion}`);
                            console.log('');
                        }
                    }
                }

                console.log(`Node.js version : ${process.version}`);
                console.log('');
                console.log(`Operating system : ${osName(os.platform(), os.release())}`);
                console.log('');
            }
        }
    }

    export default DisplayEnvironmentVersions.getInstance();