diff --git a/packages/fiori-elements-writer/package.json b/packages/fiori-elements-writer/package.json index c148095d8c..0494ea75f6 100644 --- a/packages/fiori-elements-writer/package.json +++ b/packages/fiori-elements-writer/package.json @@ -43,7 +43,8 @@ "mem-fs": "2.1.0", "mem-fs-editor": "9.4.0", "read-pkg-up": "7.0.1", - "semver": "7.5.4" + "semver": "7.5.4", + "yaml": "2.5.1" }, "devDependencies": { "@sap-ux/eslint-plugin-fiori-tools": "workspace:*", diff --git a/packages/fiori-elements-writer/src/index.ts b/packages/fiori-elements-writer/src/index.ts index a1a5c307dd..49eed90230 100644 --- a/packages/fiori-elements-writer/src/index.ts +++ b/packages/fiori-elements-writer/src/index.ts @@ -22,6 +22,7 @@ import semVer from 'semver'; import { initI18n } from './i18n'; import { getBootstrapResourceUrls } from '@sap-ux/fiori-generator-shared'; import { generateFpmConfig } from './fpmConfig'; +import yaml from 'yaml'; export const V2_FE_TYPES_AVAILABLE = '1.108.0'; /** @@ -32,11 +33,9 @@ export const V2_FE_TYPES_AVAILABLE = '1.108.0'; * @returns ignore pattern */ function getTypeScriptIgnoreGlob(feApp: FioriElementsApp, coercedUI5Version: semVer.SemVer): string[] { - let ignore = []; // isV2FETypesAvailable - Boolean to indicate if V2 Fiori Element types were available in the UI5 version const isV2FETypesAvailable = feApp.ui5?.version ? semVer.gte(coercedUI5Version, V2_FE_TYPES_AVAILABLE) : false; - const tsIgnoreGlob = ['**/*.js']; - ignore = tsIgnoreGlob; + const ignore = ['**/*.js']; // Add local ui5.d.ts if types are missing in UI5 version for V2 Odata services // OR template is OVP if (feApp.service.version === OdataVersion.v2) { @@ -83,9 +82,8 @@ async function generate(basePath: string, data: FioriElementsApp(basePath: string, data: FioriElementsApp { + if (!fs?.exists(ui5YamlPath)) { + return; + } + const ui5Yaml = yaml.parse(fs!.read(ui5YamlPath).toString()); + ui5Yaml.server = ui5Yaml.server || {}; + ui5Yaml.server.customMiddleware = ui5Yaml.server.customMiddleware || []; + ui5Yaml.server.customMiddleware.push({ + name: 'preview-middleware', + afterMiddleware: 'compression' + }); + fs!.write(ui5YamlPath, yaml.stringify(ui5Yaml)); + }); + if (addTest) { generateOPAFiles( basePath, diff --git a/packages/fiori-elements-writer/templates/common/add/webapp/test/flpSandbox.html b/packages/fiori-elements-writer/templates/common/add/webapp/test/flpSandbox.html deleted file mode 100644 index 683c27d72e..0000000000 --- a/packages/fiori-elements-writer/templates/common/add/webapp/test/flpSandbox.html +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - {{appTitle}} - - - - - - - <% if (appOptions.loadReuseLibs) { %> - <% } else { %> - <% } %><% if (templateOptions.changesPreview) { %> - - <% } %> - - - - - - - - diff --git a/packages/fiori-freestyle-writer/package.json b/packages/fiori-freestyle-writer/package.json index f2e01c007a..bb282ff1c4 100644 --- a/packages/fiori-freestyle-writer/package.json +++ b/packages/fiori-freestyle-writer/package.json @@ -41,7 +41,8 @@ "lodash": "4.17.21", "mem-fs": "2.1.0", "mem-fs-editor": "9.4.0", - "read-pkg-up": "7.0.1" + "read-pkg-up": "7.0.1", + "yaml": "2.5.1" }, "devDependencies": { "@sap-ux/eslint-plugin-fiori-tools": "workspace:*", diff --git a/packages/fiori-freestyle-writer/src/index.ts b/packages/fiori-freestyle-writer/src/index.ts index 5c3b08fa05..ba4a51f840 100644 --- a/packages/fiori-freestyle-writer/src/index.ts +++ b/packages/fiori-freestyle-writer/src/index.ts @@ -12,6 +12,7 @@ import { setDefaults, escapeFLPText } from './defaults'; import { UI5Config } from '@sap-ux/ui5-config'; import { initI18n } from './i18n'; import { getBootstrapResourceUrls } from '@sap-ux/fiori-generator-shared'; +import yaml from 'yaml'; /** * Generate a UI5 application based on the specified Fiori Freestyle floorplan template. @@ -114,8 +115,35 @@ async function generate(basePath: string, data: FreestyleApp, fs?: Editor) 'deploy-config': 'npx -p @sap/ux-ui5-tooling fiori add deploy-config cf' }; } + + // Add preview middleware + packageJson.devDependencies = { + ...packageJson.devDependencies, + '@sap/ux-preview-middleware': 'latest' + }; + fs.writeJSON(packagePath, packageJson); + // add preview middleware config to ui5*.yaml + const ui5YamlPaths = []; + // todo: where to get all the ui5*.yaml paths from? + ui5YamlPaths.push(join(basePath, 'ui5.yaml')); + ui5YamlPaths.push(join(basePath, 'ui5-mock.yaml')); + ui5YamlPaths.push(join(basePath, 'ui5-local.yaml')); + ui5YamlPaths.forEach((ui5YamlPath) => { + if (!fs?.exists(ui5YamlPath)) { + return; + } + const ui5Yaml = yaml.parse(fs!.read(ui5YamlPath).toString()); + ui5Yaml.server = ui5Yaml.server || {}; + ui5Yaml.server.customMiddleware = ui5Yaml.server.customMiddleware || []; + ui5Yaml.server.customMiddleware.push({ + name: 'preview-middleware', + afterMiddleware: 'compression' + }); + fs!.write(ui5YamlPath, yaml.stringify(ui5Yaml)); + }); + // Add service to the project if provided if (ffApp.service) { await addOdataService(basePath, ffApp.service, fs); diff --git a/packages/fiori-freestyle-writer/templates/common/add/webapp/test/flpSandbox.html b/packages/fiori-freestyle-writer/templates/common/add/webapp/test/flpSandbox.html deleted file mode 100644 index 25db35618e..0000000000 --- a/packages/fiori-freestyle-writer/templates/common/add/webapp/test/flpSandbox.html +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - - - {{appTitle}} - - - - - - - <% if (appOptions.loadReuseLibs) { %> - <% } else { %> - <% } %> - - - - - - - - diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6b18891833..4c61ba8160 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1416,6 +1416,9 @@ importers: semver: specifier: 7.5.4 version: 7.5.4 + yaml: + specifier: 2.5.1 + version: 2.5.1 devDependencies: '@sap-ux/eslint-plugin-fiori-tools': specifier: workspace:* @@ -1474,6 +1477,9 @@ importers: read-pkg-up: specifier: 7.0.1 version: 7.0.1 + yaml: + specifier: 2.5.1 + version: 2.5.1 devDependencies: '@sap-ux/eslint-plugin-fiori-tools': specifier: workspace:* @@ -23200,6 +23206,12 @@ packages: engines: {node: '>= 14'} dev: false + /yaml@2.5.1: + resolution: {integrity: sha512-bLQOjaX/ADgQ20isPJRvF0iRUHIxVhYvr53Of7wGcWlO2jvtUlH5m87DsmulFVxRpNLOnI4tB6p/oh8D7kpn9Q==} + engines: {node: '>= 14'} + hasBin: true + dev: false + /yamljs@0.3.0: resolution: {integrity: sha512-C/FsVVhht4iPQYXOInoxUM/1ELSf9EsgKH34FofQOp6hwCPrW4vG4w5++TED3xRUo8gD7l0P1J1dLlDYzODsTQ==} dependencies: