@sap-ux/fe-fpm-writer
Advanced tools
Comparing version 0.24.16 to 0.25.0
@@ -24,3 +24,7 @@ "use strict"; | ||
// clone input | ||
const config = Object.assign(Object.assign({}, data), { target: Object.assign({}, data.target), settings: Object.assign({}, data.settings) }); | ||
const config = { | ||
...data, | ||
target: { ...data.target }, | ||
settings: { ...data.settings } | ||
}; | ||
(0, defaults_1.setCommonDefaults)(config, manifestPath, manifest); | ||
@@ -56,3 +60,4 @@ // set default values for visibility and enabled | ||
page.options.settings.content[target.control] = page.options.settings.content[target.control] || {}; | ||
page.options.settings.content[target.control].sections = page.options.settings.content[target.control].sections || {}; | ||
page.options.settings.content[target.control].sections = | ||
page.options.settings.content[target.control].sections || {}; | ||
page.options.settings.content[target.control].sections[target.customSectionKey] = | ||
@@ -59,0 +64,0 @@ page.options.settings.content[target.control].sections[target.customSectionKey] || {}; |
@@ -21,3 +21,2 @@ "use strict"; | ||
function enableFPM(basePath, config = {}, fs) { | ||
var _a, _b, _c, _d, _e, _f; | ||
if (!fs) { | ||
@@ -32,3 +31,3 @@ fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)()); | ||
// add FE libs is not yet added | ||
if (!((_c = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.dependencies) === null || _b === void 0 ? void 0 : _b.libs) === null || _c === void 0 ? void 0 : _c['sap.fe.templates'])) { | ||
if (!manifest['sap.ui5']?.dependencies?.libs?.['sap.fe.templates']) { | ||
fs.extendJSON(manifestPath, { | ||
@@ -45,3 +44,3 @@ 'sap.ui5': { | ||
// if a minUI5Version is set and it is smaller than the minimum required, increase it | ||
const minUI5Version = (_e = (_d = manifest['sap.ui5']) === null || _d === void 0 ? void 0 : _d.dependencies) === null || _e === void 0 ? void 0 : _e.minUI5Version; | ||
const minUI5Version = manifest['sap.ui5']?.dependencies?.minUI5Version; | ||
if (minUI5Version && (0, semver_1.valid)(minUI5Version) && (0, semver_1.lt)(minUI5Version, exports.MIN_VERSION)) { | ||
@@ -58,3 +57,3 @@ fs.extendJSON(manifestPath, { | ||
if (config.typescript) { | ||
(0, utils_1.addExtensionTypes)(basePath, (_f = manifest['sap.ui5']) === null || _f === void 0 ? void 0 : _f.dependencies.minUI5Version, fs); | ||
(0, utils_1.addExtensionTypes)(basePath, manifest['sap.ui5']?.dependencies.minUI5Version, fs); | ||
} | ||
@@ -61,0 +60,0 @@ // enable FCL if requested |
@@ -44,3 +44,3 @@ "use strict"; | ||
// clone input and set defaults | ||
const config = Object.assign({}, data); | ||
const config = { ...data }; | ||
(0, defaults_1.setCommonDefaults)(config, manifestPath, manifest); | ||
@@ -70,3 +70,2 @@ // Apply event handler | ||
function generateCustomColumn(basePath, customColumn, fs) { | ||
var _a; | ||
(0, validate_1.validateVersion)(customColumn.minUI5Version); | ||
@@ -90,3 +89,3 @@ if (!fs) { | ||
// add fragment | ||
const viewPath = (0, path_1.join)(completeColumn.path, `${(_a = completeColumn.fragmentFile) !== null && _a !== void 0 ? _a : completeColumn.name}.fragment.xml`); | ||
const viewPath = (0, path_1.join)(completeColumn.path, `${completeColumn.fragmentFile ?? completeColumn.name}.fragment.xml`); | ||
if (completeColumn.control || !fs.exists(viewPath)) { | ||
@@ -93,0 +92,0 @@ fs.copyTpl((0, templates_1.getTemplatePath)('common/Fragment.xml'), viewPath, completeColumn); |
@@ -82,4 +82,7 @@ "use strict"; | ||
if (!fs.exists(controllerPath)) { | ||
fs.copyTpl((0, templates_1.getTemplatePath)(`${templatePath}.${ext}`), controllerPath, Object.assign({ eventHandlerFnName, | ||
parameters }, config)); | ||
fs.copyTpl((0, templates_1.getTemplatePath)(`${templatePath}.${ext}`), controllerPath, { | ||
eventHandlerFnName, | ||
parameters, | ||
...config | ||
}); | ||
} | ||
@@ -86,0 +89,0 @@ else if (insertScript) { |
@@ -68,4 +68,3 @@ "use strict"; | ||
function addExtensionTypes(basePath, minUI5Version, fs) { | ||
var _a; | ||
const version = (0, semver_1.minor)((_a = (0, semver_1.coerce)(minUI5Version)) !== null && _a !== void 0 ? _a : '1.108.0'); | ||
const version = (0, semver_1.minor)((0, semver_1.coerce)(minUI5Version) ?? '1.108.0'); | ||
const path = (0, path_1.join)(basePath, '/webapp/ext/sap.fe.d.ts'); | ||
@@ -72,0 +71,0 @@ if (version < 108 && version !== 102 && !fs.exists(path)) { |
@@ -30,3 +30,2 @@ "use strict"; | ||
function validateBasePath(basePath, fs) { | ||
var _a, _b, _c; | ||
if (!fs) { | ||
@@ -41,3 +40,3 @@ fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)()); | ||
const manifest = fs.readJSON(manifestPath); | ||
if ((((_c = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.dependencies) === null || _b === void 0 ? void 0 : _b.libs) === null || _c === void 0 ? void 0 : _c['sap.fe.templates']) !== undefined) === false) { | ||
if ((manifest['sap.ui5']?.dependencies?.libs?.['sap.fe.templates'] !== undefined) === false) { | ||
throw new Error('Dependency sap.fe.templates is missing in the manifest.json. Fiori elements FPM requires the SAP FE libraries.'); | ||
@@ -44,0 +43,0 @@ } |
@@ -42,5 +42,4 @@ "use strict"; | ||
function getExistingControllerExtension(manifest, extensionId) { | ||
var _a, _b, _c; | ||
const extensions = (_c = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.extends) === null || _b === void 0 ? void 0 : _b.extensions) === null || _c === void 0 ? void 0 : _c[UI5_CONTROLLER_EXTENSIONS]; | ||
if (extensions === null || extensions === void 0 ? void 0 : extensions.hasOwnProperty(extensionId)) { | ||
const extensions = manifest['sap.ui5']?.extends?.extensions?.[UI5_CONTROLLER_EXTENSIONS]; | ||
if (extensions?.hasOwnProperty(extensionId)) { | ||
return extensions[extensionId]; | ||
@@ -111,3 +110,5 @@ } | ||
// clone input | ||
const config = Object.assign({}, data); | ||
const config = { | ||
...data | ||
}; | ||
// Apply default data | ||
@@ -114,0 +115,0 @@ (0, defaults_1.setCommonDefaults)(config, manifestPath, manifest); |
@@ -22,3 +22,2 @@ "use strict"; | ||
function enhanceConfig(data, manifestPath, manifest) { | ||
var _a, _b; | ||
// clone input | ||
@@ -28,5 +27,5 @@ const config = data; | ||
// set default values for requirement, language, the fragment file name | ||
config.required = (_a = config.required) !== null && _a !== void 0 ? _a : false; | ||
config.required = config.required ?? false; | ||
config.typescript = !!config.typescript; | ||
config.fragmentFile = (_b = config.fragmentFile) !== null && _b !== void 0 ? _b : config.name; | ||
config.fragmentFile = config.fragmentFile ?? config.name; | ||
if (config.eventHandler === true) { | ||
@@ -83,12 +82,10 @@ config.eventHandler = {}; | ||
function enhanceManifestAndGetFiltersReference(manifest) { | ||
var _a, _b; | ||
var _c, _d, _e, _f; | ||
if ((_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.routing) === null || _b === void 0 ? void 0 : _b.targets) { | ||
if (manifest['sap.ui5']?.routing?.targets) { | ||
const pages = manifest['sap.ui5'].routing.targets; | ||
const lrPage = Object.values(pages)[0]; | ||
lrPage.options || (lrPage.options = {}); | ||
(_c = lrPage.options).settings || (_c.settings = {}); | ||
(_d = lrPage.options.settings).controlConfiguration || (_d.controlConfiguration = {}); | ||
(_e = lrPage.options.settings.controlConfiguration)['@com.sap.vocabularies.UI.v1.SelectionFields'] || (_e['@com.sap.vocabularies.UI.v1.SelectionFields'] = {}); | ||
(_f = lrPage.options.settings.controlConfiguration['@com.sap.vocabularies.UI.v1.SelectionFields']).filterFields || (_f.filterFields = {}); | ||
lrPage.options ||= {}; | ||
lrPage.options.settings ||= {}; | ||
lrPage.options.settings.controlConfiguration ||= {}; | ||
lrPage.options.settings.controlConfiguration['@com.sap.vocabularies.UI.v1.SelectionFields'] ||= {}; | ||
lrPage.options.settings.controlConfiguration['@com.sap.vocabularies.UI.v1.SelectionFields'].filterFields ||= {}; | ||
return lrPage.options.settings.controlConfiguration['@com.sap.vocabularies.UI.v1.SelectionFields'].filterFields; | ||
@@ -95,0 +92,0 @@ } |
@@ -26,7 +26,6 @@ "use strict"; | ||
function generateRoutePattern(routes, targetEntity, nav) { | ||
var _a; | ||
const parts = []; | ||
if ((nav === null || nav === void 0 ? void 0 : nav.sourcePage) && nav.navEntity) { | ||
if (nav?.sourcePage && nav.navEntity) { | ||
const sourceRoute = routes.find((route) => route.name === nav.sourcePage); | ||
if (sourceRoute === null || sourceRoute === void 0 ? void 0 : sourceRoute.pattern) { | ||
if (sourceRoute?.pattern) { | ||
const basePattern = sourceRoute.pattern.replace(exports.PATTERN_SUFFIX, ''); | ||
@@ -49,4 +48,4 @@ if (basePattern) { | ||
} | ||
if (nav === null || nav === void 0 ? void 0 : nav.navKey) { | ||
parts.push(`({${(_a = nav === null || nav === void 0 ? void 0 : nav.navEntity) !== null && _a !== void 0 ? _a : targetEntity}Key})`); | ||
if (nav?.navKey) { | ||
parts.push(`({${nav?.navEntity ?? targetEntity}Key})`); | ||
} | ||
@@ -67,7 +66,6 @@ parts.push(exports.PATTERN_SUFFIX); | ||
function generateRouteTarget(routes, name, fcl, nav) { | ||
var _a; | ||
if (nav === null || nav === void 0 ? void 0 : nav.sourcePage) { | ||
if (nav?.sourcePage) { | ||
const sourceRoute = routes.find((route) => route.name === nav.sourcePage); | ||
// FCL only supports 3 columns, therefore, show the page in fullscreen if it is the 4th level of navigation | ||
if (fcl && ((_a = sourceRoute === null || sourceRoute === void 0 ? void 0 : sourceRoute.target) === null || _a === void 0 ? void 0 : _a.constructor) === Array && sourceRoute.target.length < 3) { | ||
if (fcl && sourceRoute?.target?.constructor === Array && sourceRoute.target.length < 3) { | ||
return [...sourceRoute.target, name]; | ||
@@ -87,6 +85,5 @@ } | ||
return (key, value) => { | ||
var _a, _b, _c; | ||
switch (key) { | ||
case 'routing': | ||
value.routes = (_a = value.routes) !== null && _a !== void 0 ? _a : []; | ||
value.routes = value.routes ?? []; | ||
break; | ||
@@ -96,5 +93,5 @@ case 'routes': | ||
routes.push({ | ||
name: (_b = config.id) !== null && _b !== void 0 ? _b : `${config.entity}${config.name}`, | ||
name: config.id ?? `${config.entity}${config.name}`, | ||
pattern: generateRoutePattern(routes, config.entity, config.navigation), | ||
target: generateRouteTarget(routes, (_c = config.id) !== null && _c !== void 0 ? _c : `${config.entity}${config.name}`, config.fcl, config.navigation) | ||
target: generateRouteTarget(routes, config.id ?? `${config.entity}${config.name}`, config.fcl, config.navigation) | ||
}); | ||
@@ -117,10 +114,9 @@ break; | ||
function getFclConfig(manifest, navigation) { | ||
var _a, _b, _c, _d, _e, _f; | ||
const config = {}; | ||
if (((_c = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.routing) === null || _b === void 0 ? void 0 : _b.config) === null || _c === void 0 ? void 0 : _c.routerClass) === defaults_1.FCL_ROUTER) { | ||
if (manifest['sap.ui5']?.routing?.config?.routerClass === defaults_1.FCL_ROUTER) { | ||
config.fcl = true; | ||
if (navigation) { | ||
const sourceRoute = (((_e = (_d = manifest['sap.ui5']) === null || _d === void 0 ? void 0 : _d.routing) === null || _e === void 0 ? void 0 : _e.routes) || []).find((route) => route.name === (navigation === null || navigation === void 0 ? void 0 : navigation.sourcePage)); | ||
const sourceRoute = (manifest['sap.ui5']?.routing?.routes || []).find((route) => route.name === navigation?.sourcePage); | ||
config.controlAggregation = | ||
((_f = sourceRoute === null || sourceRoute === void 0 ? void 0 : sourceRoute.target) !== null && _f !== void 0 ? _f : []).length > 1 ? 'endColumnPages' : 'midColumnPages'; | ||
(sourceRoute?.target ?? []).length > 1 ? 'endColumnPages' : 'midColumnPages'; | ||
} | ||
@@ -142,9 +138,8 @@ else { | ||
function initializeTargetSettings(data, addSettings) { | ||
var _a, _b; | ||
const settings = addSettings ? Object.assign({}, addSettings) : {}; | ||
(_a = settings.navigation) !== null && _a !== void 0 ? _a : (settings.navigation = {}); | ||
const settings = addSettings ? { ...addSettings } : {}; | ||
settings.navigation ??= {}; | ||
// starting with UI5 v1.94.0, contextPath is the preferred setting | ||
const minVersion = (0, semver_1.coerce)(data.minUI5Version); | ||
if (!minVersion || (0, semver_1.gte)(minVersion, '1.94.0')) { | ||
settings.contextPath = (_b = data.contextPath) !== null && _b !== void 0 ? _b : `/${data.entity}`; | ||
settings.contextPath = data.contextPath ?? `/${data.entity}`; | ||
} | ||
@@ -167,12 +162,11 @@ else { | ||
// common validators | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; | ||
(0, validate_1.validateBasePath)(basePath, fs); | ||
// validate config against the manifest | ||
if ((_a = config.navigation) === null || _a === void 0 ? void 0 : _a.sourcePage) { | ||
if (config.navigation?.sourcePage) { | ||
const manifest = fs.readJSON((0, path_1.join)(basePath, 'webapp/manifest.json')); | ||
if (!((_d = (_c = (_b = manifest['sap.ui5']) === null || _b === void 0 ? void 0 : _b.routing) === null || _c === void 0 ? void 0 : _c.targets) === null || _d === void 0 ? void 0 : _d[config.navigation.sourcePage])) { | ||
if (!manifest['sap.ui5']?.routing?.targets?.[config.navigation.sourcePage]) { | ||
throw new Error(`Could not find navigation source ${config.navigation.sourcePage}!`); | ||
} | ||
const routes = {}; | ||
if (((_g = (_f = (_e = manifest['sap.ui5']) === null || _e === void 0 ? void 0 : _e.routing) === null || _f === void 0 ? void 0 : _f.routes) === null || _g === void 0 ? void 0 : _g.constructor) === Array) { | ||
if (manifest['sap.ui5']?.routing?.routes?.constructor === Array) { | ||
manifest['sap.ui5'].routing.routes.forEach((routeWithName) => { | ||
@@ -183,6 +177,6 @@ routes[routeWithName.name] = routeWithName; | ||
else { | ||
Object.assign(routes, (_k = (_j = (_h = manifest['sap.ui5']) === null || _h === void 0 ? void 0 : _h.routing) === null || _j === void 0 ? void 0 : _j.routes) !== null && _k !== void 0 ? _k : {}); | ||
Object.assign(routes, manifest['sap.ui5']?.routing?.routes ?? {}); | ||
} | ||
const route = routes[config.navigation.sourcePage]; | ||
if (!(route === null || route === void 0 ? void 0 : route.pattern) || !route.target) { | ||
if (!route?.pattern || !route.target) { | ||
throw new Error(`Invalid routing configuration for navigation source ${config.navigation.sourcePage}!`); | ||
@@ -189,0 +183,0 @@ } |
@@ -65,3 +65,2 @@ "use strict"; | ||
function generate(basePath, data, fs) { | ||
var _a, _b, _c; | ||
if (!fs) { | ||
@@ -90,4 +89,4 @@ fs = (0, mem_fs_editor_1.create)((0, mem_fs_1.create)()); | ||
const defaultI18nPath = 'i18n/i18n.properties'; | ||
const customI18nPath = (_c = (_b = (_a = manifest === null || manifest === void 0 ? void 0 : manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.models) === null || _b === void 0 ? void 0 : _b.i18n) === null || _c === void 0 ? void 0 : _c.uri; | ||
const i18nPath = (0, path_1.join)(basePath, 'webapp', customI18nPath !== null && customI18nPath !== void 0 ? customI18nPath : defaultI18nPath); | ||
const customI18nPath = manifest?.['sap.ui5']?.models?.i18n?.uri; | ||
const i18nPath = (0, path_1.join)(basePath, 'webapp', customI18nPath ?? defaultI18nPath); | ||
const i18TemplatePath = (0, path_1.join)(root, 'i18n', 'i18n.properties'); | ||
@@ -94,0 +93,0 @@ if (fs.exists(i18nPath)) { |
@@ -13,5 +13,8 @@ "use strict"; | ||
function enhanceData(data, manifest) { | ||
var _a, _b; | ||
var _c; | ||
const config = Object.assign(Object.assign(Object.assign({}, data), { settings: (0, common_1.initializeTargetSettings)(data, data.settings), name: 'ListReport' }), (0, common_1.getFclConfig)(manifest)); | ||
const config = { | ||
...data, | ||
settings: (0, common_1.initializeTargetSettings)(data, data.settings), | ||
name: 'ListReport', | ||
...(0, common_1.getFclConfig)(manifest) | ||
}; | ||
// use standard file name if i18n enhancement required | ||
@@ -23,5 +26,5 @@ if (config.settings.enhanceI18n === true) { | ||
if (config.settings.tableSettings) { | ||
(_a = (_c = config.settings).controlConfiguration) !== null && _a !== void 0 ? _a : (_c.controlConfiguration = {}); | ||
config.settings.controlConfiguration ??= {}; | ||
const controlConfig = config.settings.controlConfiguration; | ||
(_b = controlConfig['@com.sap.vocabularies.UI.v1.LineItem']) !== null && _b !== void 0 ? _b : (controlConfig['@com.sap.vocabularies.UI.v1.LineItem'] = {}); | ||
controlConfig['@com.sap.vocabularies.UI.v1.LineItem'] ??= {}; | ||
controlConfig['@com.sap.vocabularies.UI.v1.LineItem'].tableSettings = config.settings.tableSettings; | ||
@@ -28,0 +31,0 @@ delete config.settings.tableSettings; |
@@ -13,3 +13,8 @@ "use strict"; | ||
function enhanceData(data, manifest) { | ||
const config = Object.assign(Object.assign(Object.assign({}, data), { settings: (0, common_1.initializeTargetSettings)(data, data.settings), name: 'ObjectPage' }), (0, common_1.getFclConfig)(manifest)); | ||
const config = { | ||
...data, | ||
settings: (0, common_1.initializeTargetSettings)(data, data.settings), | ||
name: 'ObjectPage', | ||
...(0, common_1.getFclConfig)(manifest) | ||
}; | ||
// use standard file name if i18n enhancement required | ||
@@ -16,0 +21,0 @@ if (config.settings.enhanceI18n === true) { |
@@ -51,3 +51,3 @@ "use strict"; | ||
function enhanceConfig(fs, data, manifestPath, manifest) { | ||
const config = Object.assign({}, data); | ||
const config = { ...data }; | ||
(0, defaults_1.setCommonDefaults)(config, manifestPath, manifest); | ||
@@ -82,3 +82,2 @@ // Apply event handler | ||
function generate(basePath, customSection, manifestTemplateRoot, fs) { | ||
var _a; | ||
(0, validate_1.validateVersion)(customSection.minUI5Version); | ||
@@ -101,3 +100,3 @@ if (!fs) { | ||
// add fragment | ||
const viewPath = (0, path_1.join)(completeSection.path, `${(_a = completeSection.fragmentFile) !== null && _a !== void 0 ? _a : completeSection.name}.fragment.xml`); | ||
const viewPath = (0, path_1.join)(completeSection.path, `${completeSection.fragmentFile ?? completeSection.name}.fragment.xml`); | ||
if (!fs.exists(viewPath)) { | ||
@@ -104,0 +103,0 @@ fs.copyTpl((0, templates_1.getTemplatePath)('common/FragmentWithVBox.xml'), viewPath, completeSection); |
@@ -20,3 +20,2 @@ "use strict"; | ||
function mergeViews(config, manifest) { | ||
var _a, _b, _c, _d, _e; | ||
const newViews = { | ||
@@ -31,4 +30,4 @@ paths: [ | ||
}; | ||
const existingViews = (_e = (_d = ((_c = (_b = (_a = manifest['sap.ui5']) === null || _a === void 0 ? void 0 : _a.routing) === null || _b === void 0 ? void 0 : _b.targets) === null || _c === void 0 ? void 0 : _c[config.target]).options) === null || _d === void 0 ? void 0 : _d.settings) === null || _e === void 0 ? void 0 : _e.views; | ||
if (existingViews === null || existingViews === void 0 ? void 0 : existingViews.paths) { | ||
const existingViews = (manifest['sap.ui5']?.routing?.targets?.[config.target]).options?.settings?.views; | ||
if (existingViews?.paths) { | ||
const index = existingViews.paths.findIndex((entry) => entry.key === newViews.paths[0].key); | ||
@@ -57,3 +56,3 @@ if (index > -1) { | ||
function enhanceConfig(fs, data, manifestPath, manifest) { | ||
const config = Object.assign({}, data); | ||
const config = { ...data }; | ||
(0, defaults_1.setCommonDefaults)(config, manifestPath, manifest); | ||
@@ -60,0 +59,0 @@ // apply event handler |
{ | ||
"name": "@sap-ux/fe-fpm-writer", | ||
"description": "SAP Fiori elements flexible programming model writer", | ||
"version": "0.24.16", | ||
"version": "0.25.0", | ||
"repository": { | ||
@@ -36,3 +36,3 @@ "type": "git", | ||
"@types/semver": "7.5.2", | ||
"@sap-ux/project-access": "1.22.3" | ||
"@sap-ux/project-access": "1.23.0" | ||
}, | ||
@@ -39,0 +39,0 @@ "engines": { |
196235