• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { PROJECT_ROOT } from "./path_config";
17import {
18  SDK_VERSION,
19  BUNDLE_NAME_DEFAULT,
20  ETS_LOADER_VERSION,
21  ENTRY_MODULE_NAME_DEFAULT,
22  RUNTIME_OS_OPENHARMONY,
23  MODULE_NAME_HASH_DEFAULT,
24  RESOURCE_TABLE_HASH_DEFAULT,
25  DEVICE_TYPE,
26  NODE_JS_PATH,
27  PORT_DEFAULT,
28  ENTRY_MODULE_VERSION_DEFAULT
29} from "./common";
30import {
31  ESMODULE,
32  OHPM,
33  RELEASE
34} from "../../../../lib/fast_build/ark_compiler/common/ark_define";
35
36interface IArkProjectConfig {
37  projectRootPath: string,
38  modulePathMap: object,
39  isOhosTest: object,
40  oldMapFilePath?: object,
41  processTs: boolean,
42  pandaMode: string,
43  anBuildOutPut?: string,
44  anBuildMode?: object,
45  apPath?: object,
46  nodeModulesPath?: object,
47  harNameOhmMap: object,
48  minPlatformVersion: number,
49  moduleName: string,
50  bundleName: string,
51  hotReload: object,
52  patchAbcPath: object,
53  changedFileList: object,
54  compileMode: string
55}
56
57class ProjectConfig {
58  compileMode: string = ESMODULE;
59  packageManagerType: string = OHPM;
60  compileSdkVersion: number = SDK_VERSION;
61  compatibleSdkVersion: number = SDK_VERSION;
62  bundleName: string = BUNDLE_NAME_DEFAULT;
63  etsLoaderVersion: string = ETS_LOADER_VERSION;
64  etsLoaderReleaseType: string = RELEASE;
65  entryModuleName: string = ENTRY_MODULE_NAME_DEFAULT;
66  entryModuleVersion: string = ENTRY_MODULE_VERSION_DEFAULT;
67  allModuleNameHash: string = MODULE_NAME_HASH_DEFAULT;
68  resourceTableHash: string = RESOURCE_TABLE_HASH_DEFAULT;
69  runtimeOS: string = RUNTIME_OS_OPENHARMONY;
70  sdkInfo: string = `true:${SDK_VERSION}:${ETS_LOADER_VERSION}:${RELEASE}`;
71
72  watchMode: string;
73  isPreview: boolean;
74  buildMode: string;
75  localPropertiesPath: string;
76  aceProfilePath: string;
77  etsLoaderPath: string;
78  modulePath: string;
79  needCoverageInsert: boolean;
80  projectTopDir: string;
81  apPath: string;
82  aceModuleJsonPath: string;
83  appResource: string;
84  aceModuleRoot: string;
85  aceSuperVisualPath: string;
86  aceBuildJson: string;
87  cachePath: string;
88  aceModuleBuild: string;
89  patchAbcPath: string;
90  DynamicImportpath: string;
91  supportChunks: boolean;
92  projectPath: string;
93  resolveModulePaths: Array<string>;
94  compileHar: boolean;
95  compileShared: boolean;
96  moduleRootPath: object;
97  buildPath: string;
98
99  deviceType?: string;
100  checkEntry?: string;
101  Path?: string;
102  note?: string;
103  hapMode?: string;
104  img2bin?: string;
105  projectProfilePath?: string;
106  logLevel?: string;
107  stageRouterConfig?: Array<object>;
108  port?: string;
109  aceSoPath?: string;
110  mockParams?: object;
111  projectRootPath: string;
112  pkgContextInfo: object;
113  useNormalizedOHMUrl: boolean = false;
114  dependencyAliasMap: Map<string, string>;
115
116  constructor(buildMode: string) {
117    this.watchMode = 'false';
118    this.isPreview = false;
119    this.buildMode = buildMode;
120    this.needCoverageInsert = false;
121    this.supportChunks = true;
122    this.compileHar = false;
123    this.compileShared = false;
124  }
125
126  public scan(testcase: string) {
127    this.initPath(`${PROJECT_ROOT}/${testcase}`);
128  }
129
130  public setPreview(isPreview: boolean) {
131    this.isPreview = isPreview;
132    this.watchMode = String(isPreview);
133  }
134
135  public setCompilerVersion(version: number) {
136    this.compileSdkVersion = version;
137    this.compatibleSdkVersion = version;
138  }
139
140  public setMockParams(params: object) {
141    this.mockParams = params;
142  }
143
144  private initPath(proPath: string) {
145    // build and preview
146    let mode = this.isPreview ? 'preview' : 'build';
147    this.localPropertiesPath = `${proPath}/local.properties`;
148    this.aceProfilePath = `${proPath}/${this.entryModuleName}/${mode}/res/default/resources/base/profile`;
149    this.etsLoaderPath = `/${this.runtimeOS}/Sdk/${this.compileSdkVersion}/ets/build-tools/app`;
150    this.modulePath = `${proPath}/${this.entryModuleName}`;
151    this.projectTopDir = `${proPath}`;
152    this.apPath = '';
153    this.aceModuleJsonPath = `${proPath}/${this.entryModuleName}/${mode}/module.json`;
154    this.appResource = `${proPath}/${this.entryModuleName}/${mode}/res/default/ResourceTable.txt`;
155    this.aceModuleRoot = `${proPath}/${this.entryModuleName}/src`;
156    this.aceSuperVisualPath = `${proPath}/${this.entryModuleName}/src/main/supervisual`;
157    this.aceBuildJson = `${proPath}/${this.entryModuleName}/${mode}/loader.json`;
158    this.cachePath = `${proPath}/${this.entryModuleName}/${mode}`;
159    this.aceModuleBuild = `${proPath}/${this.entryModuleName}/${mode}`;
160    this.projectPath = `${proPath}/${this.entryModuleName}/src`;
161    this.moduleRootPath = undefined;
162    this.buildPath = `${proPath}/${this.entryModuleName}/${mode}`;
163    this.patchAbcPath = `${proPath}/${this.entryModuleName}/${mode}/hotReload`;
164    this.DynamicImportpath = `${this.modulePath}/DynamicImport.ets`;
165    this.projectRootPath = `${proPath}`;
166
167    if (this.isPreview) {
168      this.previewUniqueConfig();
169    }
170  }
171
172  private previewUniqueConfig() {
173    this.deviceType = DEVICE_TYPE;
174    this.checkEntry = 'true';
175    this.Path = NODE_JS_PATH;
176    this.note = 'false';
177    this.hapMode = 'false';
178    this.img2bin = 'true';
179    this.projectProfilePath = `${this.projectTopDir}/build-profile.json5`;
180    this.logLevel = '3';
181    this.stageRouterConfig = [];
182    this.port = PORT_DEFAULT;
183    this.aceSoPath = `${this.projectTopDir}/entry/preview/cache/nativeDependencies.txt`;
184  }
185}
186
187export { ProjectConfig, IArkProjectConfig }
188