Skip to content

Commit

Permalink
[FEATURE] Build the manifest-bundle.zip for applications and libraries
Browse files Browse the repository at this point in the history
This commit enables the manifest-bundle.zip creation for applications
and libraries by default in the regular ui5 build. The manifest-bundle.zip
contains the manifest.json files of the application and libary such as
the ones for the nested components. In addition, the manifest bundler
checks for linked i18n resources in the manifest.json from sap.app/i18n
and includes those i18n resources into the manifest-bundle.zip as well.
The tests have been enhanced to validate the existence of the manifest-bundle.zip
and also special checks for the content of the bundle.

Fixes: https://github.com/SAP/ui5-builder/issues/144
  • Loading branch information
petermuessig committed Apr 12, 2019
1 parent dd653c8 commit f53aeea
Show file tree
Hide file tree
Showing 26 changed files with 396 additions and 28 deletions.
3 changes: 2 additions & 1 deletion lib/processors/bundlers/manifestBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ module.exports = ({resources, options}) => {
});
zip.end();

const pathPrefix = "/resources/" + options.namespace + "/";
const res = resourceFactory.createResource({
path: "/" + options.bundleName,
path: pathPrefix + options.bundleName,
stream: zip.outputStream
});
resolve([res]);
Expand Down
37 changes: 21 additions & 16 deletions lib/tasks/bundlers/generateManifestBundle.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const log = require("@ui5/logger").getLogger("builder:tasks:bundlers:generateManifestBundle");
const manifestBundler = require("../../processors/bundlers/manifestBundler");
const DESCRIPTOR = "manifest.json";
const PROPERTIES_EXT = ".properties";
Expand All @@ -11,25 +12,29 @@ const BUNDLE_NAME = "manifest-bundle.zip";
* @param {Object} parameters Parameters
* @param {module:@ui5/fs.DuplexCollection} parameters.workspace DuplexCollection to read and write files
* @param {Object} parameters.options Options
* @param {string} parameters.options.namespace Namespace of the application
* @param {string} parameters.options.projectName Project name
* @param {string} parameters.options.namespace Namespace of the application/library
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
*/
module.exports = function({workspace, options}) {
return workspace.byGlobSource(`/**/{${DESCRIPTOR},*${PROPERTIES_EXT}}`)
return workspace.byGlob(`/**/{${DESCRIPTOR},*${PROPERTIES_EXT}}`)
.then((allResources) => {
return manifestBundler({
resources: allResources,
options: {
descriptor: DESCRIPTOR,
propertiesExtension: PROPERTIES_EXT,
bundleName: BUNDLE_NAME,
namespace: options.namespace
}
});
})
.then((processedResources) => {
return Promise.all(processedResources.map((resource) => {
return workspace.write(resource);
}));
if (allResources.length > 0) {
return manifestBundler({
resources: allResources,
options: {
descriptor: DESCRIPTOR,
propertiesExtension: PROPERTIES_EXT,
bundleName: BUNDLE_NAME,
namespace: options.namespace
}
}).then((processedResources) => {
return Promise.all(processedResources.map((resource) => {
return workspace.write(resource);
}));
});
} else {
log.verbose(`Could not find a "${DESCRIPTOR}" file for project ${options.projectName}, creation of "${BUNDLE_NAME}" is skipped!`);
}
});
};
19 changes: 11 additions & 8 deletions lib/types/application/ApplicationBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@ class ApplicationBuilder extends AbstractBuilder {
});
});

this.addTask("generateManifestBundle", () => {
const generateManifestBundle = tasks.generateManifestBundle;
return generateManifestBundle({
workspace: resourceCollections.workspace,
options: {
namespace: project.metadata.namespace
}
if (project.metadata.namespace) {
this.addTask("generateManifestBundle", () => {
const generateManifestBundle = tasks.generateManifestBundle;
return generateManifestBundle({
workspace: resourceCollections.workspace,
options: {
projectName: project.metadata.name,
namespace: project.metadata.namespace
}
});
});
});
}

const componentPreload = project.builder && project.builder.componentPreload;
if (componentPreload) {
Expand Down
14 changes: 13 additions & 1 deletion lib/types/library/LibraryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const tasks = { // can't require index.js due to circular dependency

class LibraryBuilder extends AbstractBuilder {
addStandardTasks({resourceCollections, project, parentLogger}) {
const namespace = project.metadata.name.replace(/\./g, "/");

this.addTask("replaceCopyright", () => {
const replaceCopyright = tasks.replaceCopyright;
return replaceCopyright({
Expand Down Expand Up @@ -53,7 +55,6 @@ class LibraryBuilder extends AbstractBuilder {

patterns.push(...excludes);
}
const namespace = project.metadata.name.replace(/\./g, "/");

return generateJsdoc({
workspace: resourceCollections.workspace,
Expand Down Expand Up @@ -108,6 +109,17 @@ class LibraryBuilder extends AbstractBuilder {
});
});

this.addTask("generateManifestBundle", () => {
const generateManifestBundle = tasks.generateManifestBundle;
return generateManifestBundle({
workspace: resourceCollections.workspace,
options: {
projectType: project.type,
namespace
}
});
});

this.addTask("generateLibraryPreload", () => {
const generateLibraryPreload = tasks.generateLibraryPreload;
return generateLibraryPreload({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
title=embedded-i18n
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
title=embedded-i18n_de
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "id1.embedded",
"type": "component",
"applicationVersion": {
"version": "1.2.2"
},
"embeddedBy": "../",
"title": "{{title}}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
title=app-i18n
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
title=app-i18n_de
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"_version": "1.1.0",
"sap.app": {
"_version": "1.1.0",
"id": "id1",
"type": "application",
"applicationVersion": {
"version": "1.2.2"
},
"embeds": ["embedded"],
"title": "{{title}}"
}
}
34 changes: 34 additions & 0 deletions test/expected/build/library.k/dest/resources/library/k/.library
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

<name>library.k</name>
<vendor>SAP SE</vendor>
<copyright>Some fancy copyright</copyright>
<version>1.0.0</version>

<title>{{title}}</title>
<documentation>{{description}}</documentation>

<dependencies>
<dependency>
<libraryName>sap.ui.core</libraryName>
</dependency>
</dependencies>

<appData>
<manifest xmlns="http://www.sap.com/ui5/buildext/manifest">
<i18n>messagebundle.properties</i18n>
<offline>false</offline>
<deviceTypes desktop="true" phone="true" tablet="true" />
<supportedTheme>sap_belize</supportedTheme>
<supportedTheme>sap_belize_plus</supportedTheme>
<supportedTheme>sap_belize_hcw</supportedTheme>
<supportedTheme>sap_belize_hcb</supportedTheme>
<contentDensities cozy="true" compact="false" />
</manifest>
<ownership xmlns="http://www.sap.com/ui5/buildext/ownership">
<component>NOT-ME</component>
</ownership>
</appData>

</library>
30 changes: 30 additions & 0 deletions test/expected/build/library.k/dest/resources/library/k/library.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*!
* Some fancy copyright
*/
sap.ui.define([
'sap/ui/core/Core',
], function(Core) {

"use strict";

sap.ui.getCore().initLibrary({
name : "library.k",
version: "1.0.0",
dependencies : ["sap.ui.core"],
types: [
"library.k.AnyType"
],
interfaces: [
"library.k.IAny"
],
controls: [
"library.k.AnyControl"
],
elements: [
"library.k.AnyElement"
],
});

return thisLib;

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"_version": "1.9.0",
"sap.app": {
"id": "library.k",
"type": "library",
"embeds": [],
"applicationVersion": {
"version": "1.0.0"
},
"title": "{{title}}",
"description": "{{description}}",
"resources": "resources.json",
"offline": true
},
"sap.ui": {
"technology": "UI5",
"supportedThemes": []
},
"sap.ui5": {
"dependencies": {
"minUI5Version": "1.0",
"libs": {}
},
"library": {
"i18n": "messagebundle.properties",
"content": {
"controls": [
"library.k.AnyControl"
],
"elements": [
"library.k.AnyElement"
],
"types": [
"library.k.AnyType"
],
"interfaces": [
"library.k.IAny"
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"_version": "1.9.0",
"sap.app": {
"id": "library.k",
"type": "library",
"embeds": [],
"i18n": "messagebundle.properties",
"applicationVersion": {
"version": "1.0.0"
},
"title": "{{title}}",
"description": "{{description}}",
"ach": "NOT-ME",
"resources": "resources.json",
"offline": false
},
"sap.ui": {
"technology": "UI5",
"deviceTypes": {
"desktop": true,
"tablet": true,
"phone": true
},
"supportedThemes": []
},
"sap.ui5": {
"dependencies": {
"minUI5Version": "1.0",
"libs": {
"sap.ui.core": {
"minVersion": "1.0.0"
}
}
},
"contentDensities": {
"cozy": true,
"compact": false
},
"library": {
"i18n": true,
"content": {
"controls": [
"library.k.AnyControl"
],
"elements": [
"library.k.AnyElement"
],
"types": [
"library.k.AnyType"
],
"interfaces": [
"library.k.IAny"
]
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title=a title
description=a description
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title=a title
description=a description
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title=a title
description=a description
9 changes: 9 additions & 0 deletions test/fixtures/library.k/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "library.j",
"version": "1.0.0",
"description": "Simple SAPUI5 based library for testing JSDoc builds",
"dependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
}
}
12 changes: 12 additions & 0 deletions test/fixtures/library.k/src/library/k/.library
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<library xmlns="http://www.sap.com/sap.ui.library.xsd" >

<name>library.k</name>
<vendor>SAP SE</vendor>
<copyright>Some fancy copyright</copyright>
<version>1.0.0</version>

<title>{{title}}</title>
<documentation>{{description}}</documentation>

</library>
30 changes: 30 additions & 0 deletions test/fixtures/library.k/src/library/k/library.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*!
* Some fancy copyright
*/
sap.ui.define([
'sap/ui/core/Core',
], function(Core) {

"use strict";

sap.ui.getCore().initLibrary({
name : "library.k",
version: "1.0.0",
dependencies : [],
types: [
"library.k.AnyType"
],
interfaces: [
"library.k.IAny"
],
controls: [
"library.k.AnyControl"
],
elements: [
"library.k.AnyElement"
],
});

return thisLib;

});
Loading

0 comments on commit f53aeea

Please sign in to comment.