UNPKG

@hadss/hmrouter-plugin

Version:

HMRouter Compiler Plugin

54 lines (53 loc) 2.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ResourceProcessProcessor = void 0; const framework_1 = require("../../framework"); const constants_1 = require("../constants"); class ResourceProcessProcessor { constructor(context) { this.context = context; } execute() { framework_1.Logger.debug(this.context.node.getNodeName(), `Start to copy router map to raw file...`); this.copyRouterMapToRawFile(); this.processHspModuleName(); } copyRouterMapToRawFile() { let routerMapFilePath = framework_1.PluginFileUtil.pathResolve(this.context.currentTarget?.getBuildTargetOutputPath(), constants_1.FilePathConstants.TEMP_ROUTER_MAP_PATH, this.context.currentTarget?.getTargetName(), constants_1.RouterMapConstants.ROUTER_MAP_NAME); let rawFilePath = this.context.config.getRawFilePath(); framework_1.PluginFileUtil.ensureFileSync(rawFilePath); framework_1.PluginFileUtil.copyFileSync(routerMapFilePath, rawFilePath); framework_1.Logger.info(this.context.node.getNodeName(), `Copy router map to raw file successfully, filePath: ${rawFilePath}`); } processHspModuleName() { if (!(0, framework_1.isHapModule)(this.context.node)) { return; } let rawFilePath = this.context.config.getRawFilePath(); let rawFileRouterMap = JSON.parse(framework_1.PluginFileUtil.readFileSync(rawFilePath).toString()); rawFileRouterMap.hspModuleNames = [...new Set(framework_1.PluginStore.getInstance().get('hspModuleNames'))]; rawFileRouterMap.hspModuleNames.push(...this.getRemoteHspModuleNames(this.context.node.getAllPluginIds())); framework_1.PluginFileUtil.writeFileSync(rawFilePath, JSON.stringify(rawFileRouterMap)); } getRemoteHspModuleNames(pluginIds) { let remoteHspModuleNames = []; try { pluginIds.forEach((id) => { let context = this.context.node.getContext(id); let signedHspObj = context.getOhpmRemoteHspDependencyInfo(true); let remoteHspObj = context.getOhpmRemoteHspDependencyInfo(false); for (const key in signedHspObj) { remoteHspModuleNames.push(signedHspObj[key].name); } for (const key in remoteHspObj) { remoteHspModuleNames.push(remoteHspObj[key].name); } }); } catch (error) { framework_1.Logger.warn(this.context.node.getNodeName(), 'Your DevEco Studio version less than 5.0.3.800, may cause remote hsp dependencies get failed'); } return remoteHspModuleNames; } } exports.ResourceProcessProcessor = ResourceProcessProcessor;