Skip to content

Commit 21f6c7b

Browse files
committed
Specifications: Align reader getters
1 parent f4c4874 commit 21f6c7b

File tree

4 files changed

+73
-39
lines changed

4 files changed

+73
-39
lines changed

lib/specifications/types/Application.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,45 @@ class Application extends ComponentProject {
2727

2828
/* === Resource Access === */
2929
/**
30+
* Get a resource reader for the sources of the project (excluding any test resources)
31+
*
3032
* @public
33+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
3134
*/
3235
getSourceReader() {
3336
return resourceFactory.createReader({
3437
fsBasePath: fsPath.join(this.getPath(), this._webappPath),
35-
virBasePath: `/resources/${this.getNamespace()}/`,
38+
virBasePath: "/",
3639
name: `Source reader for application project ${this.getName()}`
3740
});
3841
}
3942

4043
/**
44+
* Get a resource reader for accessing the project resources the same way the UI5 runtime would do
45+
*
4146
* @public
47+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
4248
*/
4349
getRuntimeReader() {
4450
return resourceFactory.createReader({
4551
fsBasePath: fsPath.join(this.getPath(), this._webappPath),
4652
virBasePath: "/", // Applications are served at "/"
47-
name: `Source reader for application project ${this.getName()}`
53+
name: `Runtime reader for application project ${this.getName()}`
4854
});
4955
}
5056

5157
/**
58+
* Get a resource reader for accessing the project resources during the build process
59+
*
5260
* @public
61+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
5362
*/
5463
getBuildtimeReader() {
55-
return this.getSourceReader();
64+
return resourceFactory.createReader({
65+
fsBasePath: fsPath.join(this.getPath(), this._webappPath),
66+
virBasePath: `/resources/${this.getNamespace()}/`,
67+
name: `Buildtime reader for application project ${this.getName()}`
68+
});
5669
}
5770

5871
/* === Internals === */
@@ -184,7 +197,7 @@ class Application extends ComponentProject {
184197
if (this._pManifests[filePath]) {
185198
return this._pManifests[filePath];
186199
}
187-
return this._pManifests[filePath] = this.getRuntimeReader().byPath(filePath)
200+
return this._pManifests[filePath] = this.getSourceReader().byPath(filePath)
188201
.then(async (resource) => {
189202
if (!resource) {
190203
throw new Error(

lib/specifications/types/Library.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,36 @@ class Library extends ComponentProject {
4040

4141
/* === Resource Access === */
4242
/**
43+
* Get a resource reader for the sources of the project (excluding any test resources)
44+
*
4345
* @public
46+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
4447
*/
4548
getSourceReader() {
4649
return resourceFactory.createReader({
4750
fsBasePath: fsPath.join(this.getPath(), this._srcPath),
48-
virBasePath: "/resources/",
51+
virBasePath: "/",
4952
name: `Source reader for library project ${this.getName()}`
5053
});
5154
}
5255

5356
/**
57+
* Get a resource reader for accessing the project resources the same way the UI5 runtime would do
58+
*
5459
* @public
60+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
5561
*/
5662
getRuntimeReader() {
57-
let reader = this.getSourceReader();
63+
let reader = resourceFactory.createReader({
64+
fsBasePath: fsPath.join(this.getPath(), this._srcPath),
65+
virBasePath: "/resources/",
66+
name: `Runtime resources reader for library project ${this.getName()}`
67+
});
5868
if (this._testPathExists) {
5969
const testReader = resourceFactory.createReader({
6070
fsBasePath: fsPath.join(this.getPath(), this._testPath),
6171
virBasePath: "/test-resources/",
62-
name: `Test reader for library project ${this.getName()}`
72+
name: `Runtime test-resources reader for library project ${this.getName()}`
6373
});
6474
reader = resourceFactory.createReaderCollection({
6575
name: `Reader collection for library project ${this.getName()}`,
@@ -70,7 +80,10 @@ class Library extends ComponentProject {
7080
}
7181

7282
/**
83+
* Get a resource reader for accessing the project resources during the build process
84+
*
7385
* @public
86+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
7487
*/
7588
getBuildtimeReader() {
7689
// Same as runtime
@@ -265,17 +278,16 @@ class Library extends ComponentProject {
265278
}
266279

267280
namespace = libraryNs.replace(/\./g, "/");
268-
269-
const namespaceFromPath = this._getNamespaceFromDirPath(namespacePath);
270-
if (namespaceFromPath !== namespace) {
281+
namespacePath = namespacePath.replace("/", ""); // remove leading slash
282+
if (namespacePath !== namespace) {
271283
throw new Error(
272284
`Detected namespace "${namespace}" does not match detected directory ` +
273-
`structure "${namespaceFromPath}" for project ${this.getName()}`);
285+
`structure "${namespacePath}" for project ${this.getName()}`);
274286
}
275287
} else {
276288
try {
277289
const libraryJsPath = await this._getLibraryJsPath();
278-
namespace = this._getNamespaceFromDirPath(posixPath.dirname(libraryJsPath));
290+
namespace = posixPath.dirname(libraryJsPath);
279291
if (!namespace || namespace === "/") {
280292
throw new Error(`Found library.js file in root directory. ` +
281293
`Expected it to be in namespace directory.`);
@@ -351,22 +363,6 @@ class Library extends ComponentProject {
351363
return {};
352364
}
353365

354-
_getNamespaceFromDirPath(dirPath) {
355-
const virtualBasePath = "/resources/";
356-
357-
if (!dirPath.startsWith(virtualBasePath)) {
358-
if (virtualBasePath === dirPath + "/") {
359-
// The given file path does not contain a namespace path
360-
// It is equal to the source base path
361-
// Therefore return an empty namespace
362-
return "";
363-
}
364-
throw new Error(`Given directory path ${dirPath} is not based on the ` +
365-
`expected base path ${virtualBasePath}.`);
366-
}
367-
return dirPath.replace(virtualBasePath, "");
368-
}
369-
370366
/**
371367
* Determines library copyright from given project configuration with fallback to .library.
372368
*

lib/specifications/types/Module.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,23 @@ class Module extends Project {
1616

1717
/* === Resource Access === */
1818
/**
19+
* Get a resource reader for the sources of the project (excluding any test resources)
20+
*
1921
* @public
22+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
2023
*/
2124
getSourceReader() {
25+
// TODO
26+
throw new Error("Not sure what is expected here");
27+
}
28+
29+
/**
30+
* Get a resource reader for accessing the project resources the same way the UI5 runtime would do
31+
*
32+
* @public
33+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
34+
*/
35+
getRuntimeReader() {
2236
const readers = this._paths.map((readerArgs) => resourceFactory.createReader(readerArgs));
2337
if (readers.length === 1) {
2438
return readers[0];
@@ -30,17 +44,14 @@ class Module extends Project {
3044
}
3145

3246
/**
47+
* Get a resource reader for accessing the project resources during the build process
48+
*
3349
* @public
34-
*/
35-
getRuntimeReader() {
36-
return this.getSourceReader();
37-
}
38-
39-
/**
40-
* @public
50+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
4151
*/
4252
getBuildtimeReader() {
43-
return this.getSourceReader();
53+
// Same as runtime
54+
return this.getRuntimeReader();
4455
}
4556

4657
/* === Internals === */

lib/specifications/types/ThemeLibrary.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,37 @@ class ThemeLibrary extends Project {
1717

1818
/* === Resource Access === */
1919
/**
20+
* Get a resource reader for the sources of the project (excluding any test resources)
21+
*
2022
* @public
23+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
2124
*/
2225
getSourceReader() {
2326
return resourceFactory.createReader({
2427
fsBasePath: fsPath.join(this.getPath(), this._srcPath),
25-
virBasePath: "/resources/",
28+
virBasePath: "/",
2629
name: `Source reader for theme-library project ${this.getName()}`
2730
});
2831
}
2932

33+
3034
/**
35+
* Get a resource reader for accessing the project resources the same way the UI5 runtime would do
36+
*
3137
* @public
38+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
3239
*/
3340
getRuntimeReader() {
34-
let reader = this.getSourceReader();
41+
let reader = resourceFactory.createReader({
42+
fsBasePath: fsPath.join(this.getPath(), this._srcPath),
43+
virBasePath: "/resources/",
44+
name: `Runtime resources reader for theme-library project ${this.getName()}`
45+
});
3546
if (this._testPathExists) {
3647
const testReader = resourceFactory.createReader({
3748
fsBasePath: fsPath.join(this.getPath(), this._testPath),
3849
virBasePath: "/test-resources/",
39-
name: `Test reader for theme-library project ${this.getName()}`
50+
name: `Runtime test-resources reader for theme-library project ${this.getName()}`
4051
});
4152
reader = resourceFactory.createReaderCollection({
4253
name: `Reader collection for theme-library project ${this.getName()}`,
@@ -47,7 +58,10 @@ class ThemeLibrary extends Project {
4758
}
4859

4960
/**
61+
* Get a resource reader for accessing the project resources during the build process
62+
*
5063
* @public
64+
* @returns {module:@ui5/fs.ReaderCollection} Reader collection
5165
*/
5266
getBuildtimeReader() {
5367
// Same as runtime

0 commit comments

Comments
 (0)