1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use rollupObject 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 */ 15 16import { 17 ProjectConfig, 18 IArkProjectConfig 19} from "./project_config"; 20import { 21 OH_MODULES_OHPM_HYPIUM, 22 OH_MODULES_OHOS_HYPIUM, 23 MOCK_CONFIG_PATH 24} from "./path_config"; 25 26class Logger { 27 private prefix: string; 28 private messsage: string; 29 static instances = []; 30 31 constructor(prefix: string) { 32 this.prefix = prefix; 33 } 34 35 public debug(color: string, msg: string, reset: string) { 36 console.debug(`${color}${this.prefix}: ${JSON.stringify(msg)}${reset}`); 37 } 38 39 public error(color: string, errormsg: string, reset: string) { 40 this.messsage = color.toString(); 41 } 42 43 public getPrefix() { 44 return this.prefix; 45 } 46 47 48 public static getLogger(prefix): object { 49 for (const instance of Logger.instances) { 50 if (instance.getPrefix() == prefix) { 51 return instance; 52 } 53 } 54 } 55 public static createLogger(prefix) { 56 const logger = new Logger(prefix); 57 Logger.instances.push(logger); 58 return logger; 59 } 60} 61 62class Share { 63 projectConfig: ProjectConfig; 64 arkProjectConfig: IArkProjectConfig; 65 symlinkMap = {}; 66 currentModuleMetaMap = {}; 67 68 allComponents?: Map<string, Array<string>>; 69 allFiles?: Set<string>; 70 71 constructor(buildMode: string) { 72 this.projectConfig = new ProjectConfig(buildMode); 73 } 74 75 public throwArkTsCompilerError(error: object) { 76 console.error(JSON.stringify(error)); 77 } 78 79 public getLogger(prefix: string): Logger { 80 const logger = Logger.getLogger(prefix); 81 if (!logger || logger == undefined) { 82 return Logger.createLogger(prefix); 83 } 84 return logger; 85 } 86 87 public scan(testcase: string) { 88 if (!testcase) { 89 return; 90 } 91 this.projectConfig.scan(testcase); 92 this.symlinkMap[`${this.projectConfig.projectTopDir}/${OH_MODULES_OHPM_HYPIUM}`] = [ 93 `${this.projectConfig.projectTopDir}/${OH_MODULES_OHOS_HYPIUM}` 94 ]; 95 } 96 97 public setMockParams() { 98 this.projectConfig.setMockParams({ mockConfigPath: MOCK_CONFIG_PATH }); 99 } 100} 101 102export default Share; 103