• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15import {
16	ProjectConfig,
17	ArkProjectConfig
18} from './projectConfig';
19import {
20  Logger
21} from './logger';
22import {
23	CacheStoreManager
24} from './cache';
25import {
26  OH_MODULES_OHOS_HYPIUM,
27  OH_MODULES_OHPM_HYPIUM
28} from './pathConfig';
29import {
30  ARKUI_SUBSYSTEM_CODE,
31  TSC_SYSTEM_CODE
32} from './common';
33
34class Share {
35	projectConfig: ProjectConfig;
36	symlinkMap = {};
37  currentModuleMetaMap = {};
38
39	allComponents?: Map<string, Array<string>>;
40  allFiles?: Set<string>;
41	cache?: Map<string, object>;
42  cacheStoreManager?: CacheStoreManager;
43
44  private _allowedLoggerPrefix: string[] = [];
45  private _enableLogger: boolean = false;
46  private _arkProjectConfig: ArkProjectConfig;
47
48  get arkProjectConfig(): ArkProjectConfig {
49    return this._arkProjectConfig;
50  }
51
52  set arkProjectConfig(newVal: ArkProjectConfig) {
53    this.projectConfig.concat(newVal);
54    this._arkProjectConfig = newVal;
55  }
56
57	constructor() {
58		this.projectConfig = new ProjectConfig();
59	}
60
61  public setEnableLogger(newVal: boolean) {
62    this._enableLogger = newVal
63  }
64
65  public setAllowedLoggerPrefix(newVal: string[]) {
66    this._allowedLoggerPrefix = newVal;
67  }
68
69  public getHvigorConsoleLogger(key: string): object {
70    return this.getLogger(key);
71  }
72
73	public getLogger(prefix: string): object {
74    if (!this._enableLogger) {
75      return null;
76    }
77
78    if (!this._allowedLoggerPrefix.includes(prefix)) {
79      return null;
80    }
81
82    const logger = Logger.getLogger(prefix);
83    if (!logger || logger == undefined) {
84      return Logger.createLogger(prefix);
85    }
86    return logger;
87	}
88
89  public flushLogger(): void {
90		return Logger.flush();
91	}
92
93	public removeLogger(prefix: string): void {
94		return Logger.removeLogger(prefix);
95	}
96
97	public scan(projectRoot: string, testcase: string, pagePaths: string[] = []) {
98    if (!testcase) {
99      return;
100    }
101    this.projectConfig.scan(projectRoot, testcase, pagePaths);
102    this.symlinkMap[`${this.projectConfig.projectTopDir}/${OH_MODULES_OHPM_HYPIUM}`] = [
103      `${this.projectConfig.projectTopDir}/${OH_MODULES_OHOS_HYPIUM}`
104    ];
105  }
106
107	public initWithCache(): void {
108    this.cache = new Map<string, object>();
109    this.cacheStoreManager = undefined;
110  }
111
112	public initWithCacheStoreManager(): void {
113    this.cache = undefined;
114    this.cacheStoreManager = new CacheStoreManager();
115  }
116
117  public initWithoutCache(): void {
118    this.cache = undefined;
119    this.cacheStoreManager = undefined;
120  }
121}
122
123export {
124	Share
125}