1/* 2 * Copyright (c) 2022-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 */ 15import { error } from 'console'; 16import * as path from 'path'; 17 18const UI_PLUGINS = 'ui-plugins'; 19const ARKUI_PLUGINS = 'arkui-plugins'; 20 21function findMatchingFile(currentPath: string, targetFileName1: string, targetFileName2: string): string | null { 22 let current = currentPath; 23 while (true) { 24 // 获取当前路径的文件名 25 const baseName = path.basename(current); 26 if (baseName === targetFileName1 || baseName === targetFileName2) { 27 return path.dirname(current); 28 } 29 30 const parentPath = path.dirname(current); 31 if (parentPath === current) { 32 break; 33 } 34 current = parentPath; 35 } 36 throw new Error('ui-plugins not found.'); 37} 38 39function findRootDir() { 40 const plugins = findMatchingFile(__dirname, UI_PLUGINS, ARKUI_PLUGINS); 41 if (plugins === null) { 42 throw 'error'; 43 } 44 return plugins; 45} 46 47export function getArktsPath() { 48 return path.join(findRootDir(), 'koala-wrapper', './build/lib/arkts-api/index.js'); 49} 50 51export function getInteropPath() { 52 return path.join(findRootDir(), 'koala-wrapper/koalaui/interop', './dist/lib/src/interop/index.js'); 53} 54 55export function getCommonPath() { 56 return path.join(findRootDir(), 'koala-wrapper/koalaui/common', './dist/lib/src/index.js'); 57} 58 59export function getCompatPath() { 60 return path.join(findRootDir(), 'koala-wrapper/koalaui/compat', './dist/src/index.js'); 61} 62