Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: remove test/flpSandbox.html from fiori-*-writers in favor of preview middleware #2404

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/fiori-elements-writer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
35 changes: 30 additions & 5 deletions packages/fiori-elements-writer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
/**
Expand All @@ -32,11 +33,9 @@ export const V2_FE_TYPES_AVAILABLE = '1.108.0';
* @returns ignore pattern
*/
function getTypeScriptIgnoreGlob<T extends {}>(feApp: FioriElementsApp<T>, 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) {
Expand Down Expand Up @@ -83,9 +82,8 @@ async function generate<T extends {}>(basePath: string, data: FioriElementsApp<T
// Add new files from templates e.g.
const rootTemplatesPath = join(__dirname, '..', 'templates');
// Add templates common to all template types
const jsIgnoreGlob = ['**/*.ts'];

let ignore = jsIgnoreGlob;
let ignore = ['**/*.ts']; //jsIgnoreGlob
if (feApp.appOptions?.typescript === true) {
ignore = getTypeScriptIgnoreGlob(feApp, coercedUI5Version);
}
Expand Down Expand Up @@ -194,8 +192,35 @@ async function generate<T extends {}>(basePath: string, data: FioriElementsApp<T
'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));
});

if (addTest) {
generateOPAFiles(
basePath,
Expand Down

This file was deleted.

3 changes: 2 additions & 1 deletion packages/fiori-freestyle-writer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
28 changes: 28 additions & 0 deletions packages/fiori-freestyle-writer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -114,8 +115,35 @@ async function generate<T>(basePath: string, data: FreestyleApp<T>, 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);
Expand Down

This file was deleted.

12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading