Skip to content

Commit b7877ea

Browse files
Merge pull request #87 from nicoschoenteich/main
feat: opt-out of initial service call for fpm project
2 parents 340375d + 5045d66 commit b7877ea

File tree

3 files changed

+95
-72
lines changed

3 files changed

+95
-72
lines changed

generators/fpmpage/prompts.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ export default async function prompts() {
1010
const manifestPath = `${this.options.config.uimoduleName}/webapp/manifest.json`
1111
const manifestJSON = JSON.parse(fs.readFileSync(this.destinationPath(manifestPath)))
1212

13-
if (!manifestJSON["sap.ui5"]["models"][""]) {
13+
this.options.config.serviceIsReady = (await this.prompt({
14+
type: "confirm",
15+
name: "serviceIsReady",
16+
message: "Does your main service already exist, so we can fetch its metadata?",
17+
default: true
18+
})).serviceIsReady
19+
20+
if (this.options.config.serviceIsReady && !manifestJSON["sap.ui5"]["models"][""]) {
1421
this.options.config.serviceUrl = (await this.prompt({
1522
type: "input",
1623
name: "serviceUrl",

generators/uimodule/ui5Libs.js

+16-12
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,23 @@ export default class extends Generator {
7777
name: "sap.fe.templates"
7878
})
7979
ui5Yaml.server.customMiddleware = ui5Yaml.server.customMiddleware.filter(middleware => middleware.name !== "sap-fe-mockserver")
80-
const ui5YamlMock = yaml.parse(fs.readFileSync(this.destinationPath("ui5-mock.yaml")).toString())
81-
ui5YamlMock.framework = {
82-
name: "SAPUI5",
83-
version: dependencies["SAPUI5"],
84-
libraries: [
85-
{ name: "sap.m" },
86-
{ name: "sap.ui.core" },
87-
{ name: "themelib_sap_horizon" },
88-
{ name: "sap.fe.templates" }
89-
]
80+
const ui5YamlMockPath = this.destinationPath("ui5-mock.yaml")
81+
let ui5YamlMock
82+
if (fs.existsSync(ui5YamlMockPath)) {
83+
ui5YamlMock = yaml.parse(fs.readFileSync(this.destinationPath("ui5-mock.yaml")).toString())
84+
ui5YamlMock.framework = {
85+
name: "SAPUI5",
86+
version: dependencies["SAPUI5"],
87+
libraries: [
88+
{ name: "sap.m" },
89+
{ name: "sap.ui.core" },
90+
{ name: "themelib_sap_horizon" },
91+
{ name: "sap.fe.templates" }
92+
]
93+
}
94+
deleteProxyToUI5(ui5YamlMock)
95+
fs.writeFileSync(this.destinationPath("ui5-mock.yaml"), yaml.stringify(ui5YamlMock))
9096
}
91-
deleteProxyToUI5(ui5YamlMock)
92-
fs.writeFileSync(this.destinationPath("ui5-mock.yaml"), yaml.stringify(ui5YamlMock))
9397
}
9498

9599
fs.writeFileSync(this.destinationPath("ui5.yaml"), yaml.stringify(ui5Yaml))

test/fpm-projects.js

+71-59
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,39 @@ import assert from "yeoman-assert"
22
import path from "path"
33

44
export const testCases = [
5-
{
6-
platform: "Static webserver",
7-
enableFPM: true,
8-
serviceUrl: "http://localhost:4004/travel",
9-
mainEntity: "BookedFlights",
10-
enableTypescript: false
11-
},
12-
{
13-
platform: "Application Router",
14-
enableFPM: true,
15-
serviceUrl: "http://localhost:4004/travel",
16-
mainEntity: "BookedFlights",
17-
enableTypescript: true,
18-
newDir: false
19-
},
20-
{
21-
platform: "SAP HTML5 Application Repository Service",
22-
enableFPM: true,
23-
serviceUrl: "http://localhost:4004/travel",
24-
mainEntity: "BookedFlights",
25-
enableTypescript: true
26-
},
5+
// {
6+
// platform: "Static webserver",
7+
// enableFPM: true,
8+
// serviceUrl: "http://localhost:4004/travel",
9+
// mainEntity: "BookedFlights",
10+
// enableTypescript: false
11+
// },
12+
// {
13+
// platform: "Application Router",
14+
// enableFPM: true,
15+
// serviceUrl: "http://localhost:4004/travel",
16+
// mainEntity: "BookedFlights",
17+
// enableTypescript: true,
18+
// newDir: false
19+
// },
20+
// {
21+
// platform: "SAP HTML5 Application Repository Service",
22+
// enableFPM: true,
23+
// serviceUrl: "http://localhost:4004/travel",
24+
// mainEntity: "BookedFlights",
25+
// enableTypescript: true
26+
// },
27+
// {
28+
// platform: "SAP Build Work Zone, standard edition",
29+
// enableFPM: true,
30+
// serviceUrl: "http://localhost:4004/travel",
31+
// mainEntity: "BookedFlights",
32+
// enableTypescript: true
33+
// },
2734
{
2835
platform: "SAP Build Work Zone, standard edition",
2936
enableFPM: true,
30-
serviceUrl: "http://localhost:4004/travel",
37+
serviceIsReady: false,
3138
mainEntity: "BookedFlights",
3239
enableTypescript: true
3340
},
@@ -65,54 +72,59 @@ export const tests = (testCase, uimodulePath) => {
6572
path.join(uimodulePath, "ui5.yaml"),
6673
"SAPUI5"
6774
)
68-
assert.fileContent(
69-
path.join(uimodulePath, "ui5-mock.yaml"),
70-
"SAPUI5"
71-
)
75+
if (testCase.serviceIsReady) {
76+
assert.fileContent(
77+
path.join(uimodulePath, "ui5-mock.yaml"),
78+
"SAPUI5"
79+
)
80+
}
7281

7382
// don't proxy resources/ to CDN unless its needed for flpSandbox.html (via preview-middleware)
7483
if (testCase.platform !== "SAP Build Work Zone, standard edition") {
7584
assert.noFileContent(
7685
path.join(uimodulePath, "ui5.yaml"),
7786
"https://ui5.sap.com"
7887
)
79-
assert.noFileContent(
80-
path.join(uimodulePath, "ui5-mock.yaml"),
81-
"https://ui5.sap.com"
82-
)
83-
88+
if (testCase.serviceIsReady) {
89+
assert.noFileContent(
90+
path.join(uimodulePath, "ui5-mock.yaml"),
91+
"https://ui5.sap.com"
92+
)
93+
}
8494
}
8595
})
8696

87-
it("should use sap-fe-mockserver properly", async function() {
88-
assert.noFileContent(
89-
path.join(uimodulePath, "ui5.yaml"),
90-
"sap-fe-mockserver"
91-
)
92-
assert.fileContent(
93-
path.join(uimodulePath, "ui5-mock.yaml"),
94-
"sap-fe-mockserver"
95-
)
96-
})
97+
if (testCase.serviceIsReady) {
98+
it("should use sap-fe-mockserver properly", async function() {
99+
assert.noFileContent(
100+
path.join(uimodulePath, "ui5.yaml"),
101+
"sap-fe-mockserver"
102+
)
103+
assert.fileContent(
104+
path.join(uimodulePath, "ui5-mock.yaml"),
105+
"sap-fe-mockserver"
106+
)
107+
})
97108

98-
it("should set up a proxy to service url", async function() {
99-
assert.fileContent(
100-
path.join(uimodulePath, "ui5.yaml"),
101-
"fiori-tools-proxy"
102-
)
103-
assert.fileContent(
104-
path.join(uimodulePath, "ui5.yaml"),
105-
new URL(testCase.serviceUrl).origin
106-
)
107-
assert.fileContent(
108-
path.join(uimodulePath, "ui5-mock.yaml"),
109-
new URL(testCase.serviceUrl).origin
110-
)
111-
})
109+
it("should generate annotation file", async function() {
110+
assert.file(path.join(uimodulePath, "webapp/annotations/annotation.xml"))
111+
})
112112

113-
it("should generate annotation file", async function() {
114-
assert.file(path.join(uimodulePath, "webapp/annotations/annotation.xml"))
115-
})
113+
it("should set up a proxy to service url", async function() {
114+
assert.fileContent(
115+
path.join(uimodulePath, "ui5.yaml"),
116+
"fiori-tools-proxy"
117+
)
118+
assert.fileContent(
119+
path.join(uimodulePath, "ui5.yaml"),
120+
new URL(testCase.serviceUrl).origin
121+
)
122+
assert.fileContent(
123+
path.join(uimodulePath, "ui5-mock.yaml"),
124+
new URL(testCase.serviceUrl).origin
125+
)
126+
})
127+
}
116128

117129
it("should use Fiori elements components", async function() {
118130
assert.fileContent(

0 commit comments

Comments
 (0)