• 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
19export const ARKTS_CONFIG_FILE_PATH: string = 'arktsconfig.json';
20export const PANDA_SDK_PATH: string = 'node_modules/@panda/sdk';
21export const PANDA_SDK_STDLIB_PATH: string = 'lib';
22export const STDLIB_PATH: string = 'stdlib';
23export const STDLIB_STD_PATH: string = 'stdlib/std';
24export const STDLIB_ESCOMPAT_PATH: string = 'stdlib/escompat';
25export const RUNTIME_API_PATH: string = 'demo/runtime-api';
26export const MOCK_ENTRY_DIR_PATH: string = 'demo/mock';
27export const MOCK_ENTRY_FILE_NAME: string = 'entry.ets';
28export const MOCK_OUTPUT_CACHE_PATH: string = 'generated/cache';
29export const MOCK_OUTPUT_DIR_PATH: string = 'generated/abc';
30export const MOCK_OUTPUT_FILE_NAME: string = 'entry.abc';
31export const MOCK_LOCAL_SDK_DIR_PATH: string = 'local';
32export const ETS_SUFFIX: string = '.ets';
33export const ABC_SUFFIX: string = '.abc';
34
35function getRootPath(): string {
36    return path.resolve(__dirname, '..');
37}
38
39function changeFileExtension(file: string, targetExt: string, originExt = ''): string {
40    const currentExt: string = originExt.length === 0 ? path.extname(file) : originExt;
41    const fileWithoutExt: string = file.substring(0, file.lastIndexOf(currentExt));
42    return fileWithoutExt + targetExt;
43}
44
45function getFileName(file: string): string {
46    const fileWithExt: string = path.basename(file);
47    const currentExt: string = path.extname(file);
48    return fileWithExt.substring(0, fileWithExt.lastIndexOf(currentExt));
49}
50
51function ensurePathExists(filePath: string): void {
52    try {
53        const dirPath: string = path.dirname(filePath);
54        if (!fs.existsSync(dirPath)) {
55            fs.mkdirSync(dirPath, { recursive: true });
56        }
57    } catch (error) {
58        if (error instanceof Error) {
59            console.error(`Error: ${error.message}`);
60        }
61    }
62}
63
64export { getRootPath, changeFileExtension, getFileName, ensurePathExists };
65