• 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
16const fs = require('fs');
17const path = require('path');
18
19// 获取当前目录
20const currentDirectory = process.cwd();
21let workSpace = currentDirectory;
22for (let i = 0; i < 4; i++) {
23  workSpace = path.dirname(workSpace);
24}
25// JSON 文件路径
26const jsonFilePath = path.join(__dirname, 'demo/localtest/build_config_template.json');
27const outJsonFilePath = path.join(__dirname, 'demo/localtest/build_config.json');
28
29try {
30    // 读取 JSON 文件内容
31    const data = fs.readFileSync(jsonFilePath, 'utf8');
32    const jsonData = JSON.parse(data);
33    console.log(jsonData)
34    // 处理 baseUrl 字段
35    if (jsonData.buildSdkPath) {
36        jsonData.buildSdkPath = jsonData.buildSdkPath.replace(/workspace/g, workSpace);
37    }
38
39    // 处理 plugins 字段
40    if (jsonData.plugins.ui_plugin) {
41      jsonData.plugins.ui_plugin = jsonData.plugins.ui_plugin.replace(/workspace/g, workSpace);
42    }
43    if (jsonData.plugins.memo_plugin) {
44      jsonData.plugins.memo_plugin = jsonData.plugins.memo_plugin.replace(/workspace/g, workSpace);
45    }
46
47    // 将修改后的内容写回 JSON 文件
48    fs.writeFileSync(outJsonFilePath, JSON.stringify(jsonData, null, 2), 'utf8');
49} catch (error) {
50    console.error('处理 JSON 文件时出错:', error);
51}