-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add transformation of apps index.html in self-contained bui…
…ld (#137) BREAKING CHANGE: When running a self-contained build on an application project, the index.html will be transformed by adopting the UI5 bootstrap script tag to load the custom bundle file instead.
- Loading branch information
Showing
11 changed files
with
672 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const log = require("@ui5/logger").getLogger("builder:processors:bootstrapHtmlTransformer"); | ||
const cheerio = require("cheerio"); | ||
|
||
/** | ||
* Transforms the UI5 bootstrap of a HTML resource files. | ||
* | ||
* @module builder/processors/bootstrapHtmlTransformer | ||
* @param {Object} parameters Parameters | ||
* @param {module:@ui5/fs.Resource[]} parameters.resources List of resources to be processed | ||
* @param {Object} [parameters.options] Options | ||
* @param {string} [parameters.options.src] Bootstrap "src" that should be used | ||
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with the cloned resources | ||
*/ | ||
module.exports = function({resources, options}) { | ||
async function processResource(resource) { | ||
const content = await resource.getString(); | ||
const $ = cheerio.load(content); | ||
const bootstrapScript = $("script#sap-ui-bootstrap"); | ||
if (bootstrapScript.length === 1) { | ||
bootstrapScript.attr("src", options.src); | ||
resource.setString($.html()); | ||
} else if (bootstrapScript.length > 1) { | ||
log.warn("Skipping bootstrap transformation. Found multiple bootstrap script tags with id=sap-ui-bootstrap."); | ||
} else { | ||
log.warn("Skipping bootstrap transformation. Could not find bootstrap script tag with id=sap-ui-bootstrap."); | ||
} | ||
return resource; | ||
} | ||
|
||
return Promise.all(resources.map(processResource)); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const log = require("@ui5/logger").getLogger("builder:tasks:transformBootstrapHtml"); | ||
const bootstrapHtmlTransformer = require("../processors/bootstrapHtmlTransformer"); | ||
|
||
/** | ||
* Task for transforming the application bootstrap HTML file. | ||
* | ||
* @module builder/tasks/transformBootstrapHtml | ||
* @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.projectName Project name | ||
* @param {string} parameters.options.namespace Project namespace | ||
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written | ||
*/ | ||
module.exports = async function({workspace, options}) { | ||
if (!options.namespace) { | ||
log.warn(`Skipping bootstrap transformation due to missing namespace of project "${options.projectName}".`); | ||
return; | ||
} | ||
const resource = await workspace.byPath(`/resources/${options.namespace}/index.html`); | ||
if (!resource) { | ||
log.warn(`Skipping bootstrap transformation due to missing index.html in project "${options.projectName}".`); | ||
return; | ||
} | ||
const processedResources = await bootstrapHtmlTransformer({ | ||
resources: [resource], | ||
options: { | ||
src: "resources/sap-ui-custom.js" | ||
} | ||
}); | ||
await Promise.all(processedResources.map((resource) => workspace.write(resource))); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.