Skip to content

Commit 26ae42c

Browse files
committed
refactor(project): Align getReader API internals with ComponentProjects
Cherry-picked from: SAP/ui5-project@82b20ee JIRA: CPOUI5FOUNDATION-1174
1 parent 9c6fd13 commit 26ae42c

2 files changed

Lines changed: 50 additions & 39 deletions

File tree

packages/project/lib/specifications/types/Module.js

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,10 @@ class Module extends Project {
6969
// Apply builder excludes to all styles but "runtime"
7070
const excludes = style === "runtime" ? [] : this.getBuilderResourcesExcludes();
7171

72-
const readers = this._paths.map(({name, virBasePath, fsBasePath}) => {
73-
return resourceFactory.createReader({
74-
name,
75-
virBasePath,
76-
fsBasePath,
77-
project: this,
78-
excludes
79-
});
80-
});
81-
if (readers.length === 1) {
82-
return readers[0];
83-
}
84-
const readerCollection = resourceFactory.createReaderCollection({
85-
name: `Reader collection for module project ${this.getName()}`,
86-
readers
87-
});
72+
const reader = this._getReader(excludes);
8873
return resourceFactory.createReaderCollectionPrioritized({
8974
name: `Reader/Writer collection for project ${this.getName()}`,
90-
readers: [this._getWriter(), readerCollection]
75+
readers: [this._getWriter(), reader]
9176
});
9277
}
9378

@@ -98,7 +83,8 @@ class Module extends Project {
9883
* @returns {@ui5/fs/ReaderCollection} A reader collection instance
9984
*/
10085
getWorkspace() {
101-
const reader = this.getReader();
86+
const excludes = this.getBuilderResourcesExcludes();
87+
const reader = this._getReader(excludes);
10288

10389
const writer = this._getWriter();
10490
return resourceFactory.createWorkspace({
@@ -107,6 +93,25 @@ class Module extends Project {
10793
});
10894
}
10995

96+
_getReader(excludes) {
97+
const readers = this._paths.map(({name, virBasePath, fsBasePath}) => {
98+
return resourceFactory.createReader({
99+
name,
100+
virBasePath,
101+
fsBasePath,
102+
project: this,
103+
excludes
104+
});
105+
});
106+
if (readers.length === 1) {
107+
return readers[0];
108+
}
109+
return resourceFactory.createReaderCollection({
110+
name: `Reader collection for module project ${this.getName()}`,
111+
readers
112+
});
113+
}
114+
110115
_getWriter() {
111116
if (!this._writer) {
112117
this._writer = resourceFactory.createAdapter({

packages/project/lib/specifications/types/ThemeLibrary.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,26 +76,7 @@ class ThemeLibrary extends Project {
7676
// Apply builder excludes to all styles but "runtime"
7777
const excludes = style === "runtime" ? [] : this.getBuilderResourcesExcludes();
7878

79-
let reader = resourceFactory.createReader({
80-
fsBasePath: this.getSourcePath(),
81-
virBasePath: "/resources/",
82-
name: `Runtime resources reader for theme-library project ${this.getName()}`,
83-
project: this,
84-
excludes
85-
});
86-
if (this._testPathExists) {
87-
const testReader = resourceFactory.createReader({
88-
fsBasePath: fsPath.join(this.getRootPath(), this._testPath),
89-
virBasePath: "/test-resources/",
90-
name: `Runtime test-resources reader for theme-library project ${this.getName()}`,
91-
project: this,
92-
excludes
93-
});
94-
reader = resourceFactory.createReaderCollection({
95-
name: `Reader collection for theme-library project ${this.getName()}`,
96-
readers: [reader, testReader]
97-
});
98-
}
79+
const reader = this._getReader(excludes);
9980
const writer = this._getWriter();
10081

10182
return resourceFactory.createReaderCollectionPrioritized({
@@ -115,7 +96,8 @@ class ThemeLibrary extends Project {
11596
* @returns {@ui5/fs/DuplexCollection} DuplexCollection
11697
*/
11798
getWorkspace() {
118-
const reader = this.getReader();
99+
const excludes = this.getBuilderResourcesExcludes();
100+
const reader = this._getReader(excludes);
119101

120102
const writer = this._getWriter();
121103
return resourceFactory.createWorkspace({
@@ -124,6 +106,30 @@ class ThemeLibrary extends Project {
124106
});
125107
}
126108

109+
_getReader(excludes) {
110+
let reader = resourceFactory.createReader({
111+
fsBasePath: this.getSourcePath(),
112+
virBasePath: "/resources/",
113+
name: `Runtime resources reader for theme-library project ${this.getName()}`,
114+
project: this,
115+
excludes
116+
});
117+
if (this._testPathExists) {
118+
const testReader = resourceFactory.createReader({
119+
fsBasePath: fsPath.join(this.getRootPath(), this._testPath),
120+
virBasePath: "/test-resources/",
121+
name: `Runtime test-resources reader for theme-library project ${this.getName()}`,
122+
project: this,
123+
excludes
124+
});
125+
reader = resourceFactory.createReaderCollection({
126+
name: `Reader collection for theme-library project ${this.getName()}`,
127+
readers: [reader, testReader]
128+
});
129+
}
130+
return reader;
131+
}
132+
127133
_getWriter() {
128134
if (!this._writer) {
129135
this._writer = resourceFactory.createAdapter({

0 commit comments

Comments
 (0)