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 DEFAULT_PROJECT, 18 PROJECT_ROOT 19} from "./path_config"; 20import { 21 SDK_VERSION, 22 BUNDLE_NAME_DEFAULT, 23 ETS_LOADER_VERSION, 24 ENTRY_MODULE_NAME_DEFAULT, 25 ENTRY_PACKAGE_NAME_DEFAULT, 26 RUNTIME_OS_OPENHARMONY, 27 MODULE_NAME_HASH_DEFAULT, 28 RESOURCE_TABLE_HASH_DEFAULT, 29 DEVICE_TYPE, 30 NODE_JS_PATH, 31 PORT_DEFAULT, 32 ENTRY_MODULE_VERSION_DEFAULT, 33 SDK_VERSION_STAGE 34} from "./common"; 35import { 36 ESMODULE, 37 OHPM, 38 RELEASE 39} from "../../../../lib/fast_build/ark_compiler/common/ark_define"; 40import EntryAbility from "../../testdata/expect/expect_EntryAbility"; 41 42interface IArkProjectConfig { 43 projectRootPath: string, 44 modulePathMap: object, 45 isOhosTest: object, 46 oldMapFilePath?: object, 47 processTs: boolean, 48 pandaMode: string, 49 anBuildOutPut?: string, 50 anBuildMode?: object, 51 apPath?: object, 52 nodeModulesPath?: object, 53 harNameOhmMap: object, 54 minPlatformVersion: number, 55 moduleName: string, 56 bundleName: string, 57 hotReload: object, 58 patchAbcPath: object, 59 changedFileList: object, 60 compileMode: string 61} 62 63class ProjectConfig { 64 compileMode: string = ESMODULE; 65 packageManagerType: string = OHPM; 66 compileSdkVersion: number = SDK_VERSION; 67 compatibleSdkVersion: number = SDK_VERSION; 68 compatibleSdkVersionStage: string = SDK_VERSION_STAGE; 69 bundleName: string = BUNDLE_NAME_DEFAULT; 70 etsLoaderVersion: string = ETS_LOADER_VERSION; 71 etsLoaderReleaseType: string = RELEASE; 72 entryModuleName: string = ENTRY_MODULE_NAME_DEFAULT; 73 entryPackageName: string = ENTRY_PACKAGE_NAME_DEFAULT; 74 entryModuleVersion: string = ENTRY_MODULE_VERSION_DEFAULT; 75 allModuleNameHash: string = MODULE_NAME_HASH_DEFAULT; 76 resourceTableHash: string = RESOURCE_TABLE_HASH_DEFAULT; 77 runtimeOS: string = RUNTIME_OS_OPENHARMONY; 78 sdkInfo: string = `true:${SDK_VERSION}:${ETS_LOADER_VERSION}:${RELEASE}`; 79 80 watchMode: string; 81 isPreview: boolean; 82 isLocalTest: boolean; 83 buildMode: string; 84 localPropertiesPath: string; 85 aceProfilePath: string; 86 etsLoaderPath: string; 87 modulePath: string; 88 needCoverageInsert: boolean; 89 projectTopDir: string; 90 apPath: string; 91 aceModuleJsonPath: string; 92 appResource: string; 93 aceModuleRoot: string; 94 aceSuperVisualPath: string; 95 aceBuildJson: string; 96 cachePath: string; 97 aceModuleBuild: string; 98 patchAbcPath: string; 99 DynamicImportpath: string; 100 supportChunks: boolean; 101 projectPath: string; 102 resolveModulePaths: Array<string>; 103 compileHar: boolean; 104 compileShared: boolean; 105 moduleRootPath: object; 106 buildPath: string; 107 rootPathSet: Object; 108 109 deviceType?: string; 110 checkEntry?: string; 111 Path?: string; 112 note?: string; 113 hapMode?: string; 114 img2bin?: string; 115 projectProfilePath?: string; 116 logLevel?: string; 117 stageRouterConfig?: Array<object>; 118 port?: string; 119 aceSoPath?: string; 120 mockParams?: object; 121 projectRootPath: string; 122 pkgContextInfo: object; 123 useNormalizedOHMUrl: boolean = false; 124 dependencyAliasMap: Map<string, string>; 125 byteCodeHarInfo: object; 126 entryObj: object; 127 harNameOhmMap: object; 128 hspNameOhmMap: object; 129 cardEntryObj: object; 130 widgetCompile: boolean; 131 arkRouterMap: Array<object>; 132 declarationEntry: Array<string>; 133 134 constructor(buildMode: string) { 135 this.watchMode = 'false'; 136 this.isPreview = false; 137 this.isLocalTest = false; 138 this.buildMode = buildMode; 139 this.needCoverageInsert = false; 140 this.supportChunks = true; 141 this.compileHar = false; 142 this.compileShared = false; 143 this.harNameOhmMap = {}; 144 this.hspNameOhmMap = {}; 145 this.arkRouterMap = []; 146 this.declarationEntry = []; 147 } 148 149 public scan(testcase: string) { 150 this.initPath(`${PROJECT_ROOT}/${testcase}`); 151 } 152 153 public setPreview(isPreview: boolean) { 154 this.isPreview = isPreview; 155 this.watchMode = String(isPreview); 156 } 157 158 public setCompilerVersion(version: number) { 159 this.compileSdkVersion = version; 160 this.compatibleSdkVersion = version; 161 } 162 163 public setMockParams(params: object) { 164 this.mockParams = params; 165 } 166 167 public mockCompileContextInfo() { 168 this.entryObj = { 169 'entryAbility/EntryAbility': `${PROJECT_ROOT}/entry/src/main/ets/entryability/EntryAbility.ets`, 170 'page/Intex': `${PROJECT_ROOT}/entry/src/main/ets/page/Index.ets`, 171 'entryformability/EntryFormAbility': `${PROJECT_ROOT}/entry/src/main/ets/entryformability/EntryFormAbility.ets`, 172 'ets/widget/page/WidgetCard': `${PROJECT_ROOT}/entry/src/main/ets/widget/page/WidgetCard.ets` 173 } 174 this.cardEntryObj = { 175 'entryformability/EntryFormAbility': `${PROJECT_ROOT}/entry/src/main/ets/entryformability/EntryFormAbility.ets`, 176 'ets/widget/page/WidgetCard': `${PROJECT_ROOT}/entry/src/main/ets/widget/page/WidgetCard.ets` 177 } 178 this.projectRootPath = PROJECT_ROOT; 179 this.pkgContextInfo = { 180 'entry': { 181 'packageName': 'entry', 182 'bundleName': '', 183 'moduleName': '', 184 'version': '', 185 'entryPath': 'Index.ets', 186 'isSO': false 187 }, 188 'har': { 189 'packageName': 'har', 190 'bundleName': '', 191 'moduleName': 'har', 192 'version': '', 193 'entryPath': 'Index.ets', 194 'isSO': false 195 }, 196 'hsp': { 197 'packageName': 'hsp', 198 'bundleName': '', 199 'moduleName': 'hsp', 200 'version': '1.0.0', 201 'entryPath': 'Index.ets', 202 'isSO': false 203 }, 204 }; 205 this.harNameOhmMap = { 206 'hspAlias': '@normalized:N&&&hsp/Index&1.0.0' 207 } 208 this.dependencyAliasMap = new Map([ 209 ['hspAlias', 'hsp'] 210 ]); 211 } 212 213 public mockBytecodeHarInfo() { 214 this.byteCodeHarInfo = { 215 "har": { 216 "abcPath": "", 217 "sourceMapsPath": `${PROJECT_ROOT}/${DEFAULT_PROJECT}/bytecodeHarSourceMap.json`, 218 } 219 } 220 } 221 222 private initPath(proPath: string) { 223 // build and preview 224 let mode = this.isPreview ? 'preview' : this.isLocalTest ? '.test' : 'build'; 225 this.localPropertiesPath = `${proPath}/local.properties`; 226 this.aceProfilePath = `${proPath}/${this.entryModuleName}/${mode}/res/default/resources/base/profile`; 227 this.etsLoaderPath = `/${this.runtimeOS}/Sdk/${this.compileSdkVersion}/ets/build-tools/app`; 228 this.modulePath = `${proPath}/${this.entryModuleName}`; 229 this.projectTopDir = `${proPath}`; 230 this.apPath = ''; 231 this.aceModuleJsonPath = `${proPath}/${this.entryModuleName}/${mode}/module.json`; 232 this.appResource = `${proPath}/${this.entryModuleName}/${mode}/res/default/ResourceTable.txt`; 233 this.aceModuleRoot = `${proPath}/${this.entryModuleName}/src`; 234 this.aceSuperVisualPath = `${proPath}/${this.entryModuleName}/src/main/supervisual`; 235 this.aceBuildJson = `${proPath}/${this.entryModuleName}/${mode}/loader.json`; 236 this.cachePath = `${proPath}/${this.entryModuleName}/${mode}`; 237 this.aceModuleBuild = `${proPath}/${this.entryModuleName}/${mode}`; 238 this.projectPath = `${proPath}/${this.entryModuleName}/src`; 239 this.moduleRootPath = undefined; 240 this.buildPath = `${proPath}/${this.entryModuleName}/${mode}`; 241 this.patchAbcPath = `${proPath}/${this.entryModuleName}/${mode}/hotReload`; 242 this.DynamicImportpath = `${this.modulePath}/DynamicImport.ets`; 243 this.projectRootPath = `${proPath}`; 244 245 if (this.isPreview) { 246 this.previewUniqueConfig(); 247 } 248 } 249 250 private previewUniqueConfig() { 251 this.deviceType = DEVICE_TYPE; 252 this.checkEntry = 'true'; 253 this.Path = NODE_JS_PATH; 254 this.note = 'false'; 255 this.hapMode = 'false'; 256 this.img2bin = 'true'; 257 this.projectProfilePath = `${this.projectTopDir}/build-profile.json5`; 258 this.logLevel = '3'; 259 this.stageRouterConfig = []; 260 this.port = PORT_DEFAULT; 261 this.aceSoPath = `${this.projectTopDir}/entry/preview/cache/nativeDependencies.txt`; 262 } 263} 264 265export { ProjectConfig, IArkProjectConfig } 266