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