• 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 { BuildMode } from './build/buildMode';
17import { BuildConfig } from './types';
18import { ModuleDescriptor, generateBuildConfigs } from './buildConfigGenerate';
19import { PANDA_SDK_PATH_FROM_SDK } from './preDefine';
20
21import * as fs from 'fs';
22import * as path from 'path';
23import { PluginDriver } from './ui_plugins_driver';
24
25function processBuildConfig(projectConfig: BuildConfig): BuildConfig {
26  let buildConfig: BuildConfig = { ...projectConfig };
27  let buildSdkPath: string = buildConfig.buildSdkPath as string;
28  buildConfig.pandaSdkPath = buildConfig.pandaSdkPath ?? path.resolve(buildSdkPath, PANDA_SDK_PATH_FROM_SDK);
29  PluginDriver.getInstance().initPlugins(buildConfig);
30  return buildConfig;
31}
32
33export function generateArkTsConfigByModules(
34  buildSdkPath: string,
35  projectRoot: string,
36  modules?: ModuleDescriptor[]
37): void {
38  const allBuildConfig = generateBuildConfigs(buildSdkPath, projectRoot, modules);
39  let compileFileInfos: Record<string, string> = {};
40  const cacheDir = path.join(projectRoot, '.idea', '.deveco');
41  const compileFileInfosPath = path.join(cacheDir, 'lsp_compileFileInfos.json');
42  Object.keys(allBuildConfig).forEach((moduleName) => {
43    const moduleConfig = allBuildConfig[moduleName] as BuildConfig;
44    const processedConfig = processBuildConfig(moduleConfig);
45
46    const buildMode = new BuildMode(processedConfig);
47    buildMode.generateArkTSConfig(compileFileInfos);
48  });
49  try {
50    const jsonCompileFileInfos = JSON.stringify(compileFileInfos, null, 2);
51    if (!fs.existsSync(cacheDir)) {
52      fs.mkdirSync(cacheDir, { recursive: true });
53    }
54    fs.writeFileSync(compileFileInfosPath, jsonCompileFileInfos, 'utf-8');
55  } catch (err) {
56    console.error(`Failed to write compileFileInfos to ${compileFileInfosPath} with error: ${err}`);
57  }
58}
59