Skip to content

Commit

Permalink
feat: add preserveNonBundled option & simplify omitNonBundled prop
Browse files Browse the repository at this point in the history
  • Loading branch information
dfenerski committed Feb 16, 2024
1 parent 77917eb commit 39a8740
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 22 deletions.
31 changes: 21 additions & 10 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
* Boolean flag whether to omit source map files from the build result
* @param {boolean} parameters.options.configuration.omitTSFiles
* Boolean flag whether to omit TS files from the build result
* @param {boolean} parameters.options.configuration.omitNonBundledJSXMLFiles
* @param {boolean} parameters.options.configuration.omitNonBundled
* Boolean flag whether to omit non-bundled JS and XML files from the build result
* @param {string[]} parameters.options.configuration.omitDirs
* List of any addtional directories to be omitted from the final build result
* @param {string[]} parameters.options.configuration.preserveNonBundled
* List of glob patterns which should be kept despite not being bundled. List has no effect if `omitNonBundled` is set to false.
* @param {@ui5/builder.tasks.TaskUtil} parameters.taskUtil
* Specification Version-dependent interface to a TaskUtil instance.
* See the corresponding API reference for details:
Expand Down Expand Up @@ -59,14 +61,12 @@ module.exports = async function ({
options.configuration?.omitTSFiles === undefined
? true
: options.configuration.omitTSFiles;
const omitNonBundledJSXMLFiles =
options.configuration?.omitNonBundledJSXMLFiles === undefined
const omitNonBundled =
options.configuration?.omitNonBundled === undefined
? true
: options.configuration.omitNonBundledJSXMLFiles;
const omitDirs =
options.configuration?.omitDirs === undefined
? ['test', 'i18n']
: options.configuration.omitDirs;
: options.configuration.omitNonBundled;
const omitDirs = options.configuration?.omitDirs || ['test', 'i18n'];
const preserveNonBundled = options.configuration?.preserveNonBundled || [];
// Get all application related resources
const dbgResources = omitDbgFiles ? await workspace.byGlob('**/*dbg*') : [];
const sourceMapResources = omitSourceMapFiles
Expand All @@ -80,8 +80,19 @@ module.exports = async function ({
}
return resources;
})();
const nonBundledResources = omitNonBundledJSXMLFiles
? await workspace.byGlob('**/*.{js,xml}')
const preservedNonBundledResources = await (async () => {
const resources = [];
for (const pattern of preserveNonBundled) {
resources.push(...(await workspace.byGlob(pattern)));
}
return resources;
})();
const nonBundledResources = omitNonBundled
? (await workspace.byGlob('**/*.{js,xml}')).filter((resource) => {
return !preservedNonBundledResources.some((preservedResource) =>
resource.getPath().includes(preservedResource.getPath()),
);
})
: [];
// Collect unconditionally omitted resources & mark them for omission
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ builder:
configuration:
omitDbgFiles: false
omitSourceMapFiles: false
omitNonBundledJSXMLFiles: false
omitNonBundled: false
omitTSFiles: false
omitDirs: []
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ builder:
afterTask: generateComponentPreload
configuration:
omitDbgFiles: false
omitNonBundledJSXMLFiles: false
omitNonBundled: false
---
specVersion: '3.0'
kind: extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ builder:
configuration:
omitDbgFiles: false
omitSourceMapFiles: false
omitNonBundledJSXMLFiles: false
omitNonBundled: false
omitDirs: ['controller', 'model', 'properties']
---
specVersion: '3.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ builder:
configuration:
omitDbgFiles: false
omitSourceMapFiles: false
omitNonBundledJSXMLFiles: false
omitNonBundled: false
---
specVersion: '3.0'
kind: extension
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(() => {
console.error('This file should not be deleted.');
})();
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ builder:
configuration:
omitDbgFiles: false
omitSourceMapFiles: false
omitNonBundledJSXMLFiles: false
omitNonBundled: false
omitTSFiles: false
omitDirs: []
---
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
specVersion: '3.0'
metadata:
name: com.github.dfenerski.library
type: library
framework:
name: OpenUI5
version: 1.120.6
libraries:
- name: sap.ui.core
- name: themelib_sap_horizon
- name: themelib_sap_fiori_3
builder:
customTasks:
- name: ui5-tooling-transpile-task
afterTask: replaceVersion
configuration:
generateTsInterfaces: true # always generate the TS interfaces in build
- name: ui5-task-no-debug-files
afterTask: generateLibraryPreload
configuration:
preserveNonBundled: ['**/scripts-custom/**/*']
---
specVersion: '3.0'
kind: extension
type: task
metadata:
name: ui5-task-no-debug-files
task:
path: ../../../lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ builder:
afterTask: generateLibraryPreload
configuration:
omitDbgFiles: false
omitNonBundledJSXMLFiles: false
omitNonBundled: false
---
specVersion: '3.0'
kind: extension
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ builder:
configuration:
omitDbgFiles: false
omitSourceMapFiles: false
omitNonBundledJSXMLFiles: false
omitNonBundled: false
omitDirs: ['themes']
---
specVersion: '3.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ builder:
configuration:
omitDbgFiles: false
omitSourceMapFiles: false
omitNonBundledJSXMLFiles: false
omitNonBundled: false
---
specVersion: '3.0'
kind: extension
Expand Down
50 changes: 46 additions & 4 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ describe('lib', () => {
assert.equal(existsSync(Paths.dotLibrary), true);
assert.equal(existsSync(Paths.libraryPreload), true);
assert.equal(existsSync(Paths.manifest), true);
assert.equal(readdirSync(libSrc).length, 30);
assert.equal(readdirSync(libSrc).length, 31);
});

it('should output both dbg & normal assets when both flags are raised', (ctx: SuiteContext) => {
Expand Down Expand Up @@ -491,7 +491,7 @@ describe('lib', () => {
assert.equal(existsSync(Paths.libraryPreload), true);
assert.equal(existsSync(Paths.library), true);
assert.equal(existsSync(Paths.manifest), true);
assert.equal(readdirSync(libSrc).length, 13);
assert.equal(readdirSync(libSrc).length, 14);
});

it('should output dbg, sourceMap & normal assets when flags are raised', (ctx: SuiteContext) => {
Expand Down Expand Up @@ -558,7 +558,7 @@ describe('lib', () => {
assert.equal(existsSync(Paths.library), true);
assert.equal(existsSync(Paths.libraryMap), true);
assert.equal(existsSync(Paths.manifest), true);
assert.equal(readdirSync(libSrc).length, 23);
assert.equal(readdirSync(libSrc).length, 24);
});

it('should output TS assets when flag is raised', (ctx: SuiteContext) => {
Expand Down Expand Up @@ -644,7 +644,49 @@ describe('lib', () => {
themes: resolve(libSrc, 'themes'),
};
assert.equal(existsSync(Paths.themes), false);
assert.equal(readdirSync(libSrc).length, 22);
assert.equal(readdirSync(libSrc).length, 23);
});

it('should respect preserveNonBundled patterns', (ctx: SuiteContext) => {
const ui5 = {
yaml: resolve(
'./test/__assets__/com.github.dfenerski.library/ui5.preserveNonBundled.yaml',
),
};
spawnSync(
`ui5 build --config "${ui5.yaml}" --dest "${resolve(
`${ctx.tmpDir}/dist`,
)}"`,
{
stdio: 'inherit',
shell: true,
cwd: resolve('./test/__assets__/com.github.dfenerski.library'),
},
);
const libSrc = resolve(
ctx.tmpDir!,
'dist',
'resources',
'com',
'github',
'dfenerski',
'library',
);
const Paths = {
themes: resolve(libSrc, 'themes'),
scriptsCustom: resolve(libSrc, 'scripts-custom'),
fiddle: resolve(libSrc, 'scripts-custom', 'dontDeleteMe.js'),
dotLibrary: resolve(libSrc, '.library'),
libraryPreload: resolve(libSrc, 'library-preload.js'),
manifest: resolve(libSrc, 'manifest.json'),
};
assert.equal(existsSync(Paths.themes), true);
assert.equal(existsSync(Paths.scriptsCustom), true);
assert.equal(existsSync(Paths.fiddle), true);
assert.equal(existsSync(Paths.dotLibrary), true);
assert.equal(existsSync(Paths.libraryPreload), true);
assert.equal(existsSync(Paths.manifest), true);
assert.equal(readdirSync(libSrc).length, 8);
});
});

Expand Down

0 comments on commit 39a8740

Please sign in to comment.