• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 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 * as fs from 'fs';
17import * as path from 'path';
18
19import { processBuildConfig } from './init/process_build_config';
20import { BuildMode } from './build/build_mode';
21import { BUILD_TYPE_BUILD } from './pre_define';
22import { Logger } from './logger';
23import { ArkTSConfigGenerator } from './build/generate_arktsconfig';
24import { PluginDriver } from './plugins/plugins_driver';
25import { BuildConfig } from './types';
26import { BuildFrameworkMode } from './build/build_framework_mode';
27
28export async function build(projectConfig: BuildConfig): Promise<void> {
29  let logger: Logger = Logger.getInstance(projectConfig);
30  let buildConfig: BuildConfig = processBuildConfig(projectConfig);
31
32  if (projectConfig.frameworkMode === true) {
33    let buildframeworkMode: BuildFrameworkMode = new BuildFrameworkMode(buildConfig);
34    await buildframeworkMode.run();
35    if (logger.hasErrors()) {
36      clean();
37      process.exit(1);
38    }
39  } else if (projectConfig.enableDeclgenEts2Ts === true) {
40    let buildMode: BuildMode = new BuildMode(buildConfig);
41    await buildMode.generateDeclaration();
42  } else if (projectConfig.buildType === BUILD_TYPE_BUILD) {
43    let buildMode: BuildMode = new BuildMode(buildConfig);
44    await buildMode.run();
45  }
46
47  clean();
48}
49
50function clean(): void {
51  Logger.destroyInstance();
52  ArkTSConfigGenerator.destroyInstance();
53  PluginDriver.destroyInstance();
54}
55
56function main(): void {
57  console.log(process.argv);
58
59  const buildConfigPath: string = path.resolve(process.argv[2]);
60  const projectConfig: BuildConfig = JSON.parse(fs.readFileSync(buildConfigPath, 'utf-8'));
61
62  build(projectConfig);
63}
64
65if (require.main === module) {
66  main();
67}
68