Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui-task-zipper): new option additionalDirectories #1093

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions packages/ui5-task-zipper/lib/zipper.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const absoluteToRelativePaths = (buffer, zip) => {
* @param {object} [parameters.options.configuration] Task configuration if given in ui5.yaml
* @param {string} [parameters.options.configuration.archiveName] ZIP archive name (defaults to project namespace)
* @param {string} [parameters.options.configuration.additionalFiles] List of additional files to be included
* @param {string} [parameters.options.configuration.additionalDirectories] List of additional directories to be included
* @param {object} parameters.taskUtil the task utilities
* @returns {Promise<undefined>} Promise resolving with undefined once data has been written
*/
Expand Down Expand Up @@ -81,9 +82,9 @@ module.exports = async function ({ log, workspace, dependencies, options, taskUt
: dependencies._readers.filter((reader) => {
const projectName = determineProjectName(reader);
return includeDependencies.indexOf(projectName) !== -1;
}),
}),
name: "Filtered reader collection of ui5-task-zipper",
});
});

// retrieve the resource path prefix (to get all application resources)
const prefixPath = `/resources/${options.projectNamespace}/`;
Expand All @@ -93,7 +94,12 @@ module.exports = async function ({ log, workspace, dependencies, options, taskUt
try {
const wsResources = await workspace.byGlob(`/resources/**`);
const depResources = await deps.byGlob(`**`);
allResources = [...wsResources, ...depResources];
let additionalDirResources = [];
const additionalDirectories = options?.configuration?.additionalDirectories ?? [];
for (let dir of additionalDirectories) {
additionalDirResources = [...additionalDirResources, ...(await deps.byGlob(`${dir}/**`, { nodir: false }))];
}
allResources = [...wsResources, ...depResources, ...additionalDirResources];
} catch (e) {
log.error(`Couldn't read resources: ${e}`);
}
Expand Down Expand Up @@ -126,7 +132,7 @@ module.exports = async function ({ log, workspace, dependencies, options, taskUt
} else {
log.warn(`Duplicate resource path found: ${resourcePath}! Skipping...`);
}
})
}),
);
// include the additional files from the project
const additionalFiles = options?.configuration?.additionalFiles;
Expand All @@ -139,6 +145,7 @@ module.exports = async function ({ log, workspace, dependencies, options, taskUt
for (const [filePathSource, filePathTarget] of Object.entries(additionalFiles)) {
isDebug && log.info(`Adding ${filePathSource} to archive at path ${filePathTarget}.`);
zip.addFile(path.join(process.cwd(), filePathSource), filePathTarget || filePathSource);
zip.ad;
}
}
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
specVersion: "3.0"
metadata:
name: ui5-app
type: application
framework:
name: OpenUI5
version: "1.129.0"
libraries:
- name: sap.m
- name: sap.ui.core
- name: sap.ui.layout
- name: themelib_sap_horizon
builder:
customTasks:
- name: ui5-task-zipper
afterTask: generateVersionInfo
configuration:
debug: true
archiveName: "customZipName"
additionalDirectories:
- testDir
19 changes: 18 additions & 1 deletion packages/ui5-task-zipper/test/zipper.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require("path");
const { rmSync, existsSync, readdirSync } = require("fs");
const { spawnSync } = require("child_process");
const crypto = require("crypto");
// const crypto = require("crypto");
const yauzl = require("yauzl");

const test = require("ava");
Expand Down Expand Up @@ -68,6 +68,23 @@ test.afterEach.always(async (t) => {
rmSync(t.context.tmpDir, { recursive: true, force: true });
});

test("archive creation w/ additional directories", async (t) => {
const ui5 = { yaml: path.resolve("./test/__assets__/ui5-app/ui5.additionalDirectories.yaml") };
spawnSync(`ui5 build --config ${ui5.yaml} --dest ${t.context.tmpDir}/dist`, {
stdio: "inherit", // > don't include stdout in test output,
shell: true,
cwd: path.resolve(__dirname, "../../../showcases/ui5-app"),
});
// default options packs to $app-id.zip
const targetZip = path.resolve(t.context.tmpDir, "dist", "customZipName.zip");
t.true(existsSync(targetZip));
const allDepsFound = await Promise.all([
promisifiedNeedleInHaystack(targetZip, "testDir/README.md"),
promisifiedNeedleInHaystack(targetZip, "testDir/subFolder/testFile.js")
]);
t.true(allDepsFound.every((dep) => dep === true));
});

test("archive creation w/ additional files", async (t) => {
const ui5 = { yaml: path.resolve("./test/__assets__/ui5-app/ui5.additionalFiles.yaml") };
spawnSync(`ui5 build --config ${ui5.yaml} --dest ${t.context.tmpDir}/dist`, {
Expand Down
19 changes: 19 additions & 0 deletions showcases/ui5-app/testDir/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Additional Directories in Zip File

This is a sample folder that should be copied with all content into the zip
file using builder task `ui5-task-zipper` using the configuration property
`additionalDirectories`

Below is an example configuration:

```yaml
builder:
customTasks:
- name: ui5-task-zipper
afterTask: generateVersionInfo
configuration:
debug: true
archiveName: "customZipName"
additionalDirectories:
- testDir
```
Empty file.