UNPKG

@ui5/task-adaptation

Version:

Custom task for ui5-builder which allows building UI5 Flexibility Adaptation Projects for SAP BTP, Cloud Foundry environment

79 lines 3.61 kB
import BaseAppManager from "./baseAppManager.js"; import DataSourceManager from "./annotations/dataSource/dataSourceManager.js"; import I18nManager from "./i18nManager.js"; import ServiceRequestor from "./annotations/serviceRequestor.js"; import { posix as path } from "path"; const I18N_DEFAULT_PATH = "i18n/annotations"; const I18N_DEFAULT_MODEL_NAME = "@i18n"; const SAPUI5 = "sap.ui5"; export default class AnnotationManager { abapRepoManager; configuration; constructor(configuration, abapRepoManager) { this.configuration = configuration; this.abapRepoManager = abapRepoManager; } ANNOTATIONS_FOLDER = "annotations"; async process(renamedBaseAppManifest, languages) { const { id } = BaseAppManager.getIdVersion(renamedBaseAppManifest); BaseAppManager.validateProperty(id, "sap.app/id"); const normalisedId = this.normalizeAppVariantId(id); //TODO: switch to this after resolving @i18n custom model const modelName = I18N_DEFAULT_MODEL_NAME; //`i18n_a9n_${normalisedId}`; const i18nPathName = path.join(I18N_DEFAULT_PATH, normalisedId); const i18nManager = new I18nManager(modelName, id, languages); const serviceRequestor = new ServiceRequestor(this.configuration, this.abapRepoManager); const dataSourceManager = new DataSourceManager(); dataSourceManager.addDataSources(renamedBaseAppManifest["sap.app"]?.dataSources); const annotationFiles = await dataSourceManager.createAnnotationFiles(languages, i18nManager, serviceRequestor); const i18nFiles = i18nManager.createFiles(i18nPathName); if (i18nManager.hasTranslations()) { this.updateManifestModel(renamedBaseAppManifest, modelName, i18nPathName); } return new Map([...annotationFiles, ...i18nFiles]); } normalizeAppVariantId(id, replaceWith = "") { return id.replace(/[.\W]+/gi, replaceWith); } updateManifestModel(renamedBaseAppManifest, modelName, i18nPathName) { const uri = `${i18nPathName}/i18n.properties`; this.enhanceManifestModel(renamedBaseAppManifest, modelName, uri); //TODO: switch to this after resolving @i18n custom model //this.createManifestModel(renamedBaseAppManifest, modelName, uri); } createManifestModel(manifest, modelName, uri) { let sapui5 = manifest[SAPUI5] == null ? manifest[SAPUI5] = {} : manifest[SAPUI5]; if (sapui5.models == null) { sapui5.models = {}; } if (sapui5.models[modelName] == null) { sapui5.models[modelName] = {}; } sapui5.models[modelName].type = "sap.ui.model.resource.ResourceModel"; if (uri) { sapui5.models[modelName].uri = uri; } return sapui5.models[modelName]; } enhanceManifestModel(manifest, modelToEnhance, bundleUrl) { let model = manifest[SAPUI5]?.models[modelToEnhance]; if (model) { if (model.settings == null) { model.settings = {}; } if (model.settings.enhanceWith == null) { model.settings.enhanceWith = []; } if (model.settings.enhanceWith.every((bundle) => bundle.bundleUrl !== bundleUrl)) { model.settings.enhanceWith.push({ bundleUrl, bundleUrlRelativeTo: "component" }); } } else { this.createManifestModel(manifest, modelToEnhance, bundleUrl); } } } //# sourceMappingURL=annotationManager.js.map