UNPKG

@hadss/hmrouter-plugin

Version:

HMRouter Compiler Plugin

62 lines (61 loc) 2.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigUpdateProcessor = void 0; const framework_1 = require("../../framework"); const constants_1 = require("../constants"); class ConfigUpdateProcessor { constructor(context) { this.context = context; this.moduleContext = context.moduleContext; this.routerMap = context.routerMap; this.nodeName = context.node.getNodeName(); } execute() { framework_1.Logger.debug(this.nodeName, `Start to update module.json and build profile...`); const isHar = (0, framework_1.isHarModule)(this.context.node); if (this.context.moduleIgnored && isHar) { framework_1.Logger.info(this.nodeName, `skip update module.json and build profile...`); return; } if (this.routerMap.length > 0 || !isHar) { this.updateModuleJson(); } this.updateBuildProfile(); } updateModuleJson() { const moduleJsonOpt = this.moduleContext.getModuleJsonOpt(); moduleJsonOpt.module.routerMap = constants_1.RouterMapConstants.MODULE_ROUTER_MAP_NAME; this.moduleContext.setModuleJsonOpt(moduleJsonOpt); framework_1.Logger.info(this.nodeName, `Update module.json5 routerMap successfully, current routerMap: ${this.moduleContext.getModuleJsonOpt().module.routerMap}`); } updateBuildProfile() { const buildProfileOpt = this.moduleContext.getBuildProfileOpt(); let sources = framework_1.ObjectUtils.ensureNestedObject(buildProfileOpt, [ 'buildOption', 'arkOptions', 'runtimeOnly', 'sources', ]); if (!Array.isArray(sources)) { buildProfileOpt.buildOption.arkOptions.runtimeOnly.sources = []; } this.pushRouterInfo(buildProfileOpt, this.routerMap); this.moduleContext.setBuildProfileOpt(buildProfileOpt); framework_1.Logger.info(this.nodeName, `Update build profile successfully, current sources: ${this.moduleContext.getBuildProfileOpt()?.buildOption?.arkOptions?.runtimeOnly?.sources}`); } pushRouterInfo(buildProfileOpt, routerMap) { let sources = buildProfileOpt.buildOption.arkOptions.runtimeOnly.sources; routerMap.forEach((item) => { const name = item.name; if (name.includes(constants_1.PrefixConstants.LIFECYCLE_PREFIX) || name.includes(constants_1.PrefixConstants.INTERCEPTOR_PREFIX) || name.includes(constants_1.PrefixConstants.ANIMATOR_PREFIX) || name.includes(constants_1.PrefixConstants.SERVICE_PREFIX) || name.includes(constants_1.PrefixConstants.SERVICE_PROVIDE_PREFIX)) { sources.push(constants_1.FilePathConstants.CURRENT_DELIMITER + item.pageSourceFile); } }); sources = [...new Set(sources)]; } } exports.ConfigUpdateProcessor = ConfigUpdateProcessor;