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

feat: opt-out of initial service call for fpm project #87

Merged
merged 1 commit into from
Oct 7, 2024
Merged
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
9 changes: 8 additions & 1 deletion generators/fpmpage/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ export default async function prompts() {
const manifestPath = `${this.options.config.uimoduleName}/webapp/manifest.json`
const manifestJSON = JSON.parse(fs.readFileSync(this.destinationPath(manifestPath)))

if (!manifestJSON["sap.ui5"]["models"][""]) {
this.options.config.serviceIsReady = (await this.prompt({
type: "confirm",
name: "serviceIsReady",
message: "Does your main service already exist, so we can fetch its metadata?",
default: true
})).serviceIsReady

if (this.options.config.serviceIsReady && !manifestJSON["sap.ui5"]["models"][""]) {
this.options.config.serviceUrl = (await this.prompt({
type: "input",
name: "serviceUrl",
Expand Down
28 changes: 16 additions & 12 deletions generators/uimodule/ui5Libs.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,23 @@ export default class extends Generator {
name: "sap.fe.templates"
})
ui5Yaml.server.customMiddleware = ui5Yaml.server.customMiddleware.filter(middleware => middleware.name !== "sap-fe-mockserver")
const ui5YamlMock = yaml.parse(fs.readFileSync(this.destinationPath("ui5-mock.yaml")).toString())
ui5YamlMock.framework = {
name: "SAPUI5",
version: dependencies["SAPUI5"],
libraries: [
{ name: "sap.m" },
{ name: "sap.ui.core" },
{ name: "themelib_sap_horizon" },
{ name: "sap.fe.templates" }
]
const ui5YamlMockPath = this.destinationPath("ui5-mock.yaml")
let ui5YamlMock
if (fs.existsSync(ui5YamlMockPath)) {
ui5YamlMock = yaml.parse(fs.readFileSync(this.destinationPath("ui5-mock.yaml")).toString())
ui5YamlMock.framework = {
name: "SAPUI5",
version: dependencies["SAPUI5"],
libraries: [
{ name: "sap.m" },
{ name: "sap.ui.core" },
{ name: "themelib_sap_horizon" },
{ name: "sap.fe.templates" }
]
}
deleteProxyToUI5(ui5YamlMock)
fs.writeFileSync(this.destinationPath("ui5-mock.yaml"), yaml.stringify(ui5YamlMock))
}
deleteProxyToUI5(ui5YamlMock)
fs.writeFileSync(this.destinationPath("ui5-mock.yaml"), yaml.stringify(ui5YamlMock))
}

fs.writeFileSync(this.destinationPath("ui5.yaml"), yaml.stringify(ui5Yaml))
Expand Down
130 changes: 71 additions & 59 deletions test/fpm-projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,39 @@ import assert from "yeoman-assert"
import path from "path"

export const testCases = [
{
platform: "Static webserver",
enableFPM: true,
serviceUrl: "http://localhost:4004/travel",
mainEntity: "BookedFlights",
enableTypescript: false
},
{
platform: "Application Router",
enableFPM: true,
serviceUrl: "http://localhost:4004/travel",
mainEntity: "BookedFlights",
enableTypescript: true,
newDir: false
},
{
platform: "SAP HTML5 Application Repository Service",
enableFPM: true,
serviceUrl: "http://localhost:4004/travel",
mainEntity: "BookedFlights",
enableTypescript: true
},
// {
// platform: "Static webserver",
// enableFPM: true,
// serviceUrl: "http://localhost:4004/travel",
// mainEntity: "BookedFlights",
// enableTypescript: false
// },
// {
// platform: "Application Router",
// enableFPM: true,
// serviceUrl: "http://localhost:4004/travel",
// mainEntity: "BookedFlights",
// enableTypescript: true,
// newDir: false
// },
// {
// platform: "SAP HTML5 Application Repository Service",
// enableFPM: true,
// serviceUrl: "http://localhost:4004/travel",
// mainEntity: "BookedFlights",
// enableTypescript: true
// },
// {
// platform: "SAP Build Work Zone, standard edition",
// enableFPM: true,
// serviceUrl: "http://localhost:4004/travel",
// mainEntity: "BookedFlights",
// enableTypescript: true
// },
{
platform: "SAP Build Work Zone, standard edition",
enableFPM: true,
serviceUrl: "http://localhost:4004/travel",
serviceIsReady: false,
mainEntity: "BookedFlights",
enableTypescript: true
},
Expand Down Expand Up @@ -65,54 +72,59 @@ export const tests = (testCase, uimodulePath) => {
path.join(uimodulePath, "ui5.yaml"),
"SAPUI5"
)
assert.fileContent(
path.join(uimodulePath, "ui5-mock.yaml"),
"SAPUI5"
)
if (testCase.serviceIsReady) {
assert.fileContent(
path.join(uimodulePath, "ui5-mock.yaml"),
"SAPUI5"
)
}

// don't proxy resources/ to CDN unless its needed for flpSandbox.html (via preview-middleware)
if (testCase.platform !== "SAP Build Work Zone, standard edition") {
assert.noFileContent(
path.join(uimodulePath, "ui5.yaml"),
"https://ui5.sap.com"
)
assert.noFileContent(
path.join(uimodulePath, "ui5-mock.yaml"),
"https://ui5.sap.com"
)

if (testCase.serviceIsReady) {
assert.noFileContent(
path.join(uimodulePath, "ui5-mock.yaml"),
"https://ui5.sap.com"
)
}
}
})

it("should use sap-fe-mockserver properly", async function() {
assert.noFileContent(
path.join(uimodulePath, "ui5.yaml"),
"sap-fe-mockserver"
)
assert.fileContent(
path.join(uimodulePath, "ui5-mock.yaml"),
"sap-fe-mockserver"
)
})
if (testCase.serviceIsReady) {
it("should use sap-fe-mockserver properly", async function() {
assert.noFileContent(
path.join(uimodulePath, "ui5.yaml"),
"sap-fe-mockserver"
)
assert.fileContent(
path.join(uimodulePath, "ui5-mock.yaml"),
"sap-fe-mockserver"
)
})

it("should set up a proxy to service url", async function() {
assert.fileContent(
path.join(uimodulePath, "ui5.yaml"),
"fiori-tools-proxy"
)
assert.fileContent(
path.join(uimodulePath, "ui5.yaml"),
new URL(testCase.serviceUrl).origin
)
assert.fileContent(
path.join(uimodulePath, "ui5-mock.yaml"),
new URL(testCase.serviceUrl).origin
)
})
it("should generate annotation file", async function() {
assert.file(path.join(uimodulePath, "webapp/annotations/annotation.xml"))
})

it("should generate annotation file", async function() {
assert.file(path.join(uimodulePath, "webapp/annotations/annotation.xml"))
})
it("should set up a proxy to service url", async function() {
assert.fileContent(
path.join(uimodulePath, "ui5.yaml"),
"fiori-tools-proxy"
)
assert.fileContent(
path.join(uimodulePath, "ui5.yaml"),
new URL(testCase.serviceUrl).origin
)
assert.fileContent(
path.join(uimodulePath, "ui5-mock.yaml"),
new URL(testCase.serviceUrl).origin
)
})
}

it("should use Fiori elements components", async function() {
assert.fileContent(
Expand Down
Loading