Skip to content

Commit 61d0865

Browse files
RandomByteKlattG
andauthored
[FEATURE] SNAPSHOT Consumption: Add cache-mode parameter (#633)
Expose cache-mode API parameter via CLI. See also: SAP/ui5-project#607 --------- Co-authored-by: Günter Klatt <[email protected]>
1 parent 1155cfc commit 61d0865

File tree

7 files changed

+175
-9
lines changed

7 files changed

+175
-9
lines changed

lib/cli/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default function(cli) {
5252
"config", "dependency-definition", "workspace-config", "workspace", "log-level",
5353

5454
// tree.js, build.js & serve.js
55-
"framework-version",
55+
"framework-version", "cache-mode",
5656

5757
// build.js
5858
"dest",

lib/cli/commands/build.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ build.builder = function(cli) {
101101
describe: "Overrides the framework version defined by the project",
102102
type: "string"
103103
})
104+
.option("cache-mode", {
105+
describe:
106+
"Cache mode to use when consuming SNAPSHOT versions of a framework: 'Default', 'Force', or 'Off'. " +
107+
"The 'Default' behavior is to invalidate the cache after 9 hours. 'Force' uses the cache only and " +
108+
"does not create any requests. 'Off' invalidates any existing cache and updates from the repository",
109+
type: "string",
110+
default: "Default",
111+
choices: ["Default", "Force", "Off"]
112+
})
104113
.option("experimental-css-variables", {
105114
describe:
106115
"Generate CSS variables (css-variables.css, css-variables.source.less)" +
@@ -129,12 +138,14 @@ async function handleBuild(argv) {
129138
graph = await graphFromStaticFile({
130139
filePath: argv.dependencyDefinition,
131140
rootConfigPath: argv.config,
132-
versionOverride: argv.frameworkVersion
141+
versionOverride: argv.frameworkVersion,
142+
cacheMode: argv.cacheMode,
133143
});
134144
} else {
135145
graph = await graphFromPackageDependencies({
136146
rootConfigPath: argv.config,
137147
versionOverride: argv.frameworkVersion,
148+
cacheMode: argv.cacheMode,
138149
workspaceConfigPath: argv.workspaceConfig,
139150
workspaceName: argv.workspace === false ? null : argv.workspace,
140151
});

lib/cli/commands/serve.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,20 @@ serve.builder = function(cli) {
6565
describe: "Overrides the framework version defined by the project",
6666
type: "string"
6767
})
68+
.option("cache-mode", {
69+
describe:
70+
"Cache mode to use when consuming SNAPSHOT versions of a framework: 'Default', 'Force', or 'Off'. " +
71+
"The 'Default' behavior is to invalidate the cache after 9 hours. 'Force' uses the cache only and " +
72+
"does not create any requests. 'Off' invalidates any existing cache and updates from the repository",
73+
type: "string",
74+
default: "Default",
75+
choices: ["Default", "Force", "Off"]
76+
})
6877
.example("ui5 serve", "Start a web server for the current project")
6978
.example("ui5 serve --h2", "Enable the HTTP/2 protocol for the web server (requires SSL certificate)")
7079
.example("ui5 serve --config /path/to/ui5.yaml", "Use the project configuration from a custom path")
71-
.example("ui5 serve --translator static:/path/to/projectDependencies.yaml",
72-
"Use a \"static\" translator with translator parameters.")
80+
.example("ui5 serve --dependency-definition /path/to/projectDependencies.yaml",
81+
"Use a static dependency definition file")
7382
.example("ui5 serve --port 1337 --open tests/QUnit.html",
7483
"Listen to port 1337 and launch default browser with http://localhost:1337/test/QUnit.html");
7584
};
@@ -83,12 +92,14 @@ serve.handler = async function(argv) {
8392
if (argv.dependencyDefinition) {
8493
graph = await graphFromStaticFile({
8594
filePath: argv.dependencyDefinition,
86-
versionOverride: argv.frameworkVersion
95+
versionOverride: argv.frameworkVersion,
96+
cacheMode: argv.cacheMode,
8797
});
8898
} else {
8999
graph = await graphFromPackageDependencies({
90100
rootConfigPath: argv.config,
91101
versionOverride: argv.frameworkVersion,
102+
cacheMode: argv.cacheMode,
92103
workspaceConfigPath: argv.workspaceConfig,
93104
workspaceName: argv.workspace === false ? null : argv.workspace,
94105
});

lib/cli/commands/tree.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ tree.builder = function(cli) {
1616
describe:
1717
"Overrides the framework version defined by the project",
1818
type: "string"
19+
})
20+
.option("cache-mode", {
21+
describe:
22+
"Cache mode to use when consuming SNAPSHOT versions of a framework: 'Default', 'Force', or 'Off'. " +
23+
"The 'Default' behavior is to invalidate the cache after 9 hours. 'Force' uses the cache only and " +
24+
"does not create any requests. 'Off' invalidates any existing cache and updates from the repository",
25+
type: "string",
26+
default: "Default",
27+
choices: ["Default", "Force", "Off"]
1928
});
2029
};
2130

@@ -30,12 +39,14 @@ tree.handler = async function(argv) {
3039
if (argv.dependencyDefinition) {
3140
graph = await graphFromStaticFile({
3241
filePath: argv.dependencyDefinition,
33-
versionOverride: argv.frameworkVersion
42+
versionOverride: argv.frameworkVersion,
43+
cacheMode: argv.cacheMode,
3444
});
3545
} else {
3646
graph = await graphFromPackageDependencies({
3747
rootConfigPath: argv.config,
3848
versionOverride: argv.frameworkVersion,
49+
cacheMode: argv.cacheMode,
3950
workspaceConfigPath: argv.workspaceConfig,
4051
workspaceName: argv.workspace === false ? null : argv.workspace,
4152
});

test/lib/cli/commands/build.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ function getDefaultArgv() {
2323
"cleanDest": false,
2424
"experimental-css-variables": false,
2525
"experimentalCssVariables": false,
26+
"cache-mode": "Default",
27+
"cacheMode": "Default",
2628
"$0": "ui5"
2729
};
2830
}
@@ -127,6 +129,26 @@ test.serial("ui5 build --framework-version", async (t) => {
127129
versionOverride: "1.99.0",
128130
workspaceConfigPath: undefined,
129131
workspaceName: undefined,
132+
cacheMode: "Default",
133+
}, "generateProjectGraph.graphFromPackageDependencies got called with expected arguments"
134+
);
135+
});
136+
137+
test.serial("ui5 build --cache-mode", async (t) => {
138+
const {build, argv, graphFromPackageDependenciesStub} = t.context;
139+
140+
argv.cacheMode = "Off";
141+
142+
await build.handler(argv);
143+
144+
t.deepEqual(
145+
graphFromPackageDependenciesStub.getCall(0).args[0],
146+
{
147+
rootConfigPath: undefined,
148+
versionOverride: undefined,
149+
workspaceConfigPath: undefined,
150+
workspaceName: undefined,
151+
cacheMode: "Off",
130152
}, "generateProjectGraph.graphFromPackageDependencies got called with expected arguments"
131153
);
132154
});
@@ -145,6 +167,7 @@ test.serial("ui5 build --config", async (t) => {
145167
versionOverride: undefined,
146168
workspaceConfigPath: undefined,
147169
workspaceName: undefined,
170+
cacheMode: "Default",
148171
}, "generateProjectGraph.graphFromPackageDependencies got called with expected arguments"
149172
);
150173
});
@@ -163,6 +186,7 @@ test.serial("ui5 build --workspace", async (t) => {
163186
versionOverride: undefined,
164187
workspaceConfigPath: undefined,
165188
workspaceName: "dolphin",
189+
cacheMode: "Default",
166190
}, "generateProjectGraph.graphFromPackageDependencies got called with expected arguments"
167191
);
168192
});
@@ -181,6 +205,7 @@ test.serial("ui5 build --no-workspace", async (t) => {
181205
versionOverride: undefined,
182206
workspaceConfigPath: undefined,
183207
workspaceName: null,
208+
cacheMode: "Default",
184209
}, "generateProjectGraph.graphFromPackageDependencies got called with expected arguments"
185210
);
186211
});
@@ -200,6 +225,7 @@ test.serial("ui5 build --workspace-config", async (t) => {
200225
versionOverride: undefined,
201226
workspaceConfigPath: fakePath,
202227
workspaceName: undefined,
228+
cacheMode: "Default",
203229
}, "generateProjectGraph.graphFromPackageDependencies got called with expected arguments"
204230
);
205231
});
@@ -217,6 +243,7 @@ test.serial("ui5 build --dependency-definition", async (t) => {
217243
filePath: "dependencies.yaml",
218244
rootConfigPath: undefined,
219245
versionOverride: undefined,
246+
cacheMode: "Default",
220247
}, "generateProjectGraph.graphFromStaticFile got called with expected arguments"
221248
);
222249
});
@@ -235,6 +262,7 @@ test.serial("ui5 build --dependency-definition --config", async (t) => {
235262
filePath: "dependencies.yaml",
236263
rootConfigPath: "ui5-test.yaml",
237264
versionOverride: undefined,
265+
cacheMode: "Default",
238266
}, "generateProjectGraph.graphFromStaticFile got called with expected arguments"
239267
);
240268
});
@@ -254,6 +282,7 @@ test.serial("ui5 build --dependency-definition --config --framework-version", as
254282
filePath: "dependencies.yaml",
255283
rootConfigPath: "ui5-test.yaml",
256284
versionOverride: "1.99.0",
285+
cacheMode: "Default",
257286
}, "generateProjectGraph.graphFromStaticFile got called with expected arguments"
258287
);
259288
});

test/lib/cli/commands/serve.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ function getDefaultArgv() {
2424
"sapCspPolicies": false,
2525
"serve-csp-reports": false,
2626
"serveCspReports": false,
27+
"cache-mode": "Default",
28+
"cacheMode": "Default",
2729
"$0": "ui5"
2830
};
2931
}
@@ -87,6 +89,7 @@ test.serial("ui5 serve: default", async (t) => {
8789
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
8890
rootConfigPath: undefined, versionOverride: undefined,
8991
workspaceConfigPath: undefined, workspaceName: undefined,
92+
cacheMode: "Default",
9093
}]);
9194

9295
t.is(t.context.consoleOutput, `Server started
@@ -132,6 +135,7 @@ test.serial("ui5 serve --h2", async (t) => {
132135
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
133136
rootConfigPath: undefined, versionOverride: undefined,
134137
workspaceConfigPath: undefined, workspaceName: undefined,
138+
cacheMode: "Default",
135139
}]);
136140

137141
t.is(t.context.consoleOutput, `Server started
@@ -173,6 +177,7 @@ test.serial("ui5 serve --accept-remote-connections", async (t) => {
173177
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
174178
rootConfigPath: undefined, versionOverride: undefined,
175179
workspaceConfigPath: undefined, workspaceName: undefined,
180+
cacheMode: "Default",
176181
}]);
177182

178183
t.is(t.context.consoleOutput, `
@@ -216,6 +221,7 @@ test.serial("ui5 serve --open", async (t) => {
216221
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
217222
rootConfigPath: undefined, versionOverride: undefined,
218223
workspaceConfigPath: undefined, workspaceName: undefined,
224+
cacheMode: "Default",
219225
}]);
220226

221227
t.is(t.context.consoleOutput, `Server started
@@ -256,6 +262,7 @@ test.serial("ui5 serve --open (opens default url)", async (t) => {
256262
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
257263
rootConfigPath: undefined, versionOverride: undefined,
258264
workspaceConfigPath: undefined, workspaceName: undefined,
265+
cacheMode: "Default",
259266
}]);
260267

261268
t.is(t.context.consoleOutput, `Server started
@@ -297,6 +304,7 @@ test.serial("ui5 serve --config", async (t) => {
297304
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
298305
rootConfigPath: fakePath, versionOverride: undefined,
299306
workspaceConfigPath: undefined, workspaceName: undefined,
307+
cacheMode: "Default",
300308
}]);
301309

302310
t.is(t.context.consoleOutput, `Server started
@@ -332,6 +340,7 @@ test.serial("ui5 serve --dependency-definition", async (t) => {
332340
t.is(graph.graphFromStaticFile.callCount, 1);
333341
t.deepEqual(graph.graphFromStaticFile.getCall(0).args, [{
334342
filePath: fakePath, versionOverride: undefined,
343+
cacheMode: "Default",
335344
}]);
336345

337346
t.is(t.context.consoleOutput, `Server started
@@ -367,6 +376,43 @@ test.serial("ui5 serve --framework-version", async (t) => {
367376
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
368377
rootConfigPath: undefined, versionOverride: "1.234.5",
369378
workspaceConfigPath: undefined, workspaceName: undefined,
379+
cacheMode: "Default",
380+
}]);
381+
382+
t.is(t.context.consoleOutput, `Server started
383+
URL: http://localhost:8080
384+
`);
385+
386+
t.is(server.serve.callCount, 1);
387+
t.deepEqual(server.serve.getCall(0).args, [
388+
fakeGraph,
389+
{
390+
acceptRemoteConnections: false,
391+
cert: undefined,
392+
changePortIfInUse: true,
393+
h2: false,
394+
key: undefined,
395+
port: 8080,
396+
sendSAPTargetCSP: false,
397+
serveCSPReports: false,
398+
simpleIndex: false,
399+
}
400+
]);
401+
});
402+
403+
test.serial("ui5 serve --cache-mode", async (t) => {
404+
const {argv, serve, graph, server, fakeGraph} = t.context;
405+
406+
argv.cacheMode = "Force";
407+
408+
await serve.handler(argv);
409+
410+
t.is(graph.graphFromStaticFile.callCount, 0);
411+
t.is(graph.graphFromPackageDependencies.callCount, 1);
412+
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
413+
rootConfigPath: undefined, versionOverride: undefined,
414+
workspaceConfigPath: undefined, workspaceName: undefined,
415+
cacheMode: "Force",
370416
}]);
371417

372418
t.is(t.context.consoleOutput, `Server started
@@ -402,6 +448,7 @@ test.serial("ui5 serve --workspace", async (t) => {
402448
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
403449
rootConfigPath: undefined, versionOverride: undefined,
404450
workspaceConfigPath: undefined, workspaceName: "dolphin",
451+
cacheMode: "Default",
405452
}]);
406453

407454
t.is(t.context.consoleOutput, `Server started
@@ -437,6 +484,7 @@ test.serial("ui5 serve --no-workspace", async (t) => {
437484
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
438485
rootConfigPath: undefined, versionOverride: undefined,
439486
workspaceConfigPath: undefined, workspaceName: null,
487+
cacheMode: "Default",
440488
}]);
441489

442490
t.is(t.context.consoleOutput, `Server started
@@ -473,6 +521,7 @@ test.serial("ui5 serve --workspace-config", async (t) => {
473521
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
474522
rootConfigPath: undefined, versionOverride: undefined,
475523
workspaceConfigPath: fakePath, workspaceName: undefined,
524+
cacheMode: "Default",
476525
}]);
477526

478527
t.is(t.context.consoleOutput, `Server started
@@ -508,6 +557,7 @@ test.serial("ui5 serve --sap-csp-policies", async (t) => {
508557
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
509558
rootConfigPath: undefined, versionOverride: undefined,
510559
workspaceConfigPath: undefined, workspaceName: undefined,
560+
cacheMode: "Default",
511561
}]);
512562

513563
t.is(t.context.consoleOutput, `Server started
@@ -543,6 +593,7 @@ test.serial("ui5 serve --serve-csp-reports", async (t) => {
543593
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
544594
rootConfigPath: undefined, versionOverride: undefined,
545595
workspaceConfigPath: undefined, workspaceName: undefined,
596+
cacheMode: "Default",
546597
}]);
547598

548599
t.is(t.context.consoleOutput, `Server started
@@ -578,6 +629,7 @@ test.serial("ui5 serve --simple-index", async (t) => {
578629
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
579630
rootConfigPath: undefined, versionOverride: undefined,
580631
workspaceConfigPath: undefined, workspaceName: undefined,
632+
cacheMode: "Default",
581633
}]);
582634

583635
t.is(t.context.consoleOutput, `Server started
@@ -620,6 +672,7 @@ test.serial("ui5 serve with ui5.yaml port setting", async (t) => {
620672
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
621673
rootConfigPath: undefined, versionOverride: undefined,
622674
workspaceConfigPath: undefined, workspaceName: undefined,
675+
cacheMode: "Default",
623676
}]);
624677

625678
t.is(t.context.consoleOutput, `Server started
@@ -669,6 +722,7 @@ test.serial("ui5 serve --h2 with ui5.yaml port setting", async (t) => {
669722
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
670723
rootConfigPath: undefined, versionOverride: undefined,
671724
workspaceConfigPath: undefined, workspaceName: undefined,
725+
cacheMode: "Default",
672726
}]);
673727

674728
t.is(t.context.consoleOutput, `Server started
@@ -725,6 +779,7 @@ test.serial("ui5 serve --h2 with ui5.yaml port setting and port CLI argument", a
725779
t.deepEqual(graph.graphFromPackageDependencies.getCall(0).args, [{
726780
rootConfigPath: undefined, versionOverride: undefined,
727781
workspaceConfigPath: undefined, workspaceName: undefined,
782+
cacheMode: "Default",
728783
}]);
729784

730785
t.is(t.context.consoleOutput, `Server started

0 commit comments

Comments
 (0)