# All files / src/Site index.ts

87.8% Statements 36/41
100% Branches 2/2
70.58% Functions 12/17
87.8% Lines 36/41

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
    1222x
    2x
    2x
    2x

    2x
    2x

    2x

    2x

    1x

    5x
    5x
    5x
    5x

    12x
    12x
    12x
    12x

    12x
    12x
    12x
    12x

    12x

    3x
    3x
    3x

    6x

    1x

    1x

    2x

    1x

    1x

    2x
    2x

    1x
    1x
    1x

     import { SiteAssetsManager } from './SiteAssetsManager';
    import { SiteDeployManager } from './SiteDeployManager';
    import { SiteGenerationManager } from './SiteGenerationManager';
    import { SitePagesManager } from './SitePagesManager';
    import { SiteConfig } from './SiteConfig';
    import * as logger from '../utils/logger';
    import {
      SITE_CONFIG_NAME,
    } from './constants';

    // Change when migrated to TypeScript
    require('../patches/htmlparser2');

    export class Site {
      isDevMode: boolean;
      rootPath: string;
      outputPath: string;
      siteConfigPath: string;

      // Facade Internal Components
      assetsManager: SiteAssetsManager;
      pagesManager: SitePagesManager;
      deployManager: SiteDeployManager;
      generationManager: SiteGenerationManager;

      // Getters for compatibility
      get siteConfig() { return this.generationManager.siteConfig; }
      set siteConfig(config: SiteConfig) {
        this.generationManager.siteConfig = config;
        this.assetsManager.siteConfig = config;
        this.pagesManager.siteConfig = config;
        this.deployManager.siteConfig = config;
      }

      constructor(rootPath: string, outputPath: string, onePagePath: string, forceReload = false,
                  siteConfigPath = SITE_CONFIG_NAME, isDevMode: any, backgroundBuildMode: boolean,
                  postBackgroundBuildFunc: () => void) {
        this.isDevMode = !!isDevMode;
        this.rootPath = rootPath;
        this.outputPath = outputPath;
        this.siteConfigPath = siteConfigPath;

        this.assetsManager = new SiteAssetsManager(rootPath, outputPath);
        this.pagesManager = new SitePagesManager(rootPath, outputPath, this.isDevMode);
        this.deployManager = new SiteDeployManager(rootPath, outputPath);
        this.generationManager = new SiteGenerationManager(rootPath, outputPath, onePagePath, forceReload,
                                                           siteConfigPath, this.isDevMode, backgroundBuildMode,
                                                           postBackgroundBuildFunc);

        // Configure Generator with references
        this.generationManager.configure(this.assetsManager, this.pagesManager);
      }

      changeCurrentPage(normalizedUrl: string) {
        return this.generationManager.changeCurrentPage(normalizedUrl);
      }

      changeCurrentOpenedPages(normalizedUrls: string[]) {
        return this.generationManager.changeCurrentOpenedPages(normalizedUrls);
      }

      async readSiteConfig(baseUrl?: string) {
        const config = await this.generationManager.readSiteConfig(baseUrl);
        this.siteConfig = config;
        return config;
      }

      static printBaseUrlMessage() {
        logger.info('The default base URL of your site is set to /\n'
          + 'You can change the base URL of your site by editing site.json\n'
          + 'Check https://markbind.org/userGuide/siteConfiguration.html for more information.');
      }

      async generate(baseUrl: string | undefined): Promise<any> {
        return this.generationManager.generate(baseUrl);
      }

      async buildSourceFiles() {
        return this.generationManager.buildSourceFiles();
      }

      rebuildAffectedSourceFiles(filePaths: string | string[]) {
        return this.generationManager.rebuildAffectedSourceFiles(filePaths);
      }

      rebuildSourceFiles() {
        return this.generationManager.rebuildSourceFiles();
      }

      buildAsset(filePaths: string | string[]) {
        return this.assetsManager.buildAsset(filePaths);
      }

      removeAsset(filePaths: string | string[]) {
        return this.assetsManager.removeAsset(filePaths);
      }

      isFilepathAPage(filePath: string) {
        return this.pagesManager.isFilepathAPage(filePath);
      }

      isDependencyOfPage(filePath: string) {
        return this.pagesManager.isDependencyOfPage(filePath);
      }

      async reloadSiteConfig() {
        await this.generationManager.reloadSiteConfig();
        this.siteConfig = this.generationManager.siteConfig;
      }

      /**
       * Deploys the site to the specified deployment platform.
       * @param ciTokenVar The CI token variable to use for authentication.
       * @returns A promise that resolves when the deployment is complete.
       */
      async deploy(ciTokenVar: string | boolean) {
        const config = await this.readSiteConfig();
        this.deployManager.siteConfig = config;
        return this.deployManager.deploy(ciTokenVar);
      }
    }