• 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 this 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 { ESMODULE } from './common/ark_define';
17import { ModuleBuildMode } from './module/module_build_mode';
18import { ModuleHotfixMode } from './module/module_hotfix_mode';
19import { ModuleHotreloadMode } from './module/module_hotreload_mode';
20import { ModulePreviewMode } from './module/module_preview_mode';
21import { ModuleSourceFile } from './module/module_source_file';
22
23export async function generateModuleAbc(error) {
24  if (error) {
25    // When error thrown in previous plugins, rollup will catch and call buildEnd plugin.
26    // Stop generate abc if error exists
27    return;
28  }
29  if (this.share.projectConfig.compileMode === ESMODULE) {
30    await ModuleSourceFile.processModuleSourceFiles(this);
31    if (this.share.projectConfig.compileHar) {
32      // compileHar: compile closed source har of project, which convert .ets to .d.ts and js, doesn't emit abc.
33      return;
34    }
35    generateAbc(this);
36  }
37}
38
39function generateAbc(rollupObject: any) {
40  if (rollupObject.share.projectConfig.watchMode !== 'true') {
41    const moduleBuildMode: ModuleBuildMode = new ModuleBuildMode(rollupObject);
42    moduleBuildMode.generateAbc(rollupObject);
43  } else if (rollupObject.share.arkProjectConfig.hotReload) {
44    const moduleHotreloadMode: ModuleHotreloadMode = new ModuleHotreloadMode(rollupObject);
45    moduleHotreloadMode.generateAbc(rollupObject);
46  } else if (rollupObject.share.arkProjectConfig.hotFix) {
47    const moduleHotfixMode: ModuleHotfixMode = new ModuleHotfixMode(rollupObject);
48    moduleHotfixMode.generateAbc(rollupObject);
49  } else {
50    const modulePreviewMode: ModulePreviewMode = new ModulePreviewMode(rollupObject);
51    modulePreviewMode.generateAbc(rollupObject);
52  }
53}
54