@ui5/task-adaptation
Version:
Custom task for ui5-builder which allows building UI5 Flexibility Adaptation Projects for SAP BTP, Cloud Foundry environment
72 lines • 3.24 kB
JavaScript
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(baseAppManifest, languages, appVariantId, prefix) {
//TODO: switch to this after resolving @i18n custom model
const modelName = I18N_DEFAULT_MODEL_NAME; //`i18n_a9n_${normalisedId}`;
const i18nPathName = path.join(prefix, I18N_DEFAULT_PATH);
const i18nManager = new I18nManager(modelName, appVariantId, languages);
const serviceRequestor = new ServiceRequestor(this.configuration, this.abapRepoManager);
const dataSourceManager = new DataSourceManager();
dataSourceManager.addDataSources(baseAppManifest["sap.app"]?.dataSources);
const annotationFiles = await dataSourceManager.createAnnotationFiles(languages, i18nManager, serviceRequestor);
const i18nFiles = i18nManager.createFiles(i18nPathName);
if (i18nManager.hasTranslations()) {
this.updateManifestModel(baseAppManifest, modelName, i18nPathName);
}
return new Map([...annotationFiles, ...i18nFiles]);
}
updateManifestModel(baseAppManifest, modelName, i18nPathName) {
const uri = `${i18nPathName}/i18n.properties`;
this.enhanceManifestModel(baseAppManifest, modelName, uri);
//TODO: switch to this after resolving @i18n custom model
//this.createManifestModel(baseAppManifest, 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