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