1/* 2 * Copyright (c) 2023 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 fs from 'fs'; 16import path from 'path'; 17 18const { 19 projectConfig, 20 loadEntryObj, 21 abilityConfig, 22 initBuildInfo, 23 readWorkerFile, 24 loadWorker, 25 readPatchConfig, 26 loadModuleInfo 27} = require('../../../main.js'); 28 29export let workerFile = null; 30export function getEntryObj() { 31 loadEntryObj(projectConfig); 32 initBuildInfo(); 33 readPatchConfig(); 34 loadModuleInfo(projectConfig); 35 workerFile = readWorkerFile(); 36 if (!projectConfig.isPreview) { 37 loadWorker(projectConfig, workerFile); 38 } 39 projectConfig.entryObj = Object.keys(projectConfig.entryObj).reduce((newEntry, key) => { 40 const newKey: string = key.replace(/^\.\//, ''); 41 newEntry[newKey] = projectConfig.entryObj[key].replace('?entry', ''); 42 return newEntry; 43 }, {}); 44} 45 46export function setCopyPluginConfig(projectConfig: any, appResource: string) { 47 const copyPluginPattrens: object[] = []; 48 const BUILD_SHARE_PATH: string = '../share'; 49 copyPluginPattrens.push({ 50 src: [ 51 path.resolve(projectConfig.projectPath, '**/*'), 52 '!**/*.ets', 53 '!**/*.ts', 54 '!**/*.js', 55 `!${projectConfig.buildPath}` 56 ], 57 dest: projectConfig.buildPath 58 }); 59 const sharePath: string = path.resolve(projectConfig.projectPath, BUILD_SHARE_PATH); 60 if (fs.existsSync(sharePath)) { 61 copyPluginPattrens.push({ 62 src: [ 63 path.resolve(projectConfig.projectPath, BUILD_SHARE_PATH, '**/*'), 64 '!**/*.ets', 65 '!**/*.ts', 66 '!**/*.js' 67 ], 68 dest: path.resolve(projectConfig.buildPath, BUILD_SHARE_PATH), 69 }); 70 } 71 if (abilityConfig.abilityType === 'page') { 72 if (fs.existsSync(projectConfig.manifestFilePath)) { 73 copyPluginPattrens.push({ 74 src: projectConfig.manifestFilePath, 75 dest: projectConfig.buildPath 76 }); 77 } else if (fs.existsSync(projectConfig.aceConfigPath)) { 78 copyPluginPattrens.push({ 79 src: projectConfig.aceConfigPath, 80 dest: projectConfig.buildPath 81 }); 82 } 83 } 84 if (appResource && fs.existsSync(appResource) && !projectConfig.xtsMode && 85 projectConfig.isPreview) { 86 copyPluginPattrens.push({ 87 src: path.resolve(__dirname, appResource), 88 dest: path.resolve(__dirname, projectConfig.cachePath) 89 }); 90 } 91 return copyPluginPattrens; 92} 93