diff --git a/index.js b/index.js index 5098d4d28..8eedf56c0 100644 --- a/index.js +++ b/index.js @@ -12,11 +12,12 @@ const ui5Builder = { versionInfoGenerator: require("./lib/processors/versionInfoGenerator") }, tasks: { - generateAppPreload: require("./lib/tasks/bundlers/generateAppPreload"), + generateComponentPreload: require("./lib/tasks/bundlers/generateComponentPreload"), generateFlexChangesBundle: require("./lib/tasks/bundlers/generateFlexChangesBundle"), generateLibraryPreload: require("./lib/tasks/bundlers/generateLibraryPreload"), generateManifestBundle: require("./lib/tasks/bundlers/generateManifestBundle"), generateStandaloneAppBundle: require("./lib/tasks/bundlers/generateStandaloneAppBundle"), + generateBundle: require("./lib/tasks/bundlers/generateBundle"), buildThemes: require("./lib/tasks/buildThemes"), createDebugFiles: require("./lib/tasks/createDebugFiles"), generateVersionInfo: require("./lib/tasks/generateVersionInfo"), diff --git a/lib/builder/builder.js b/lib/builder/builder.js index cec101faa..aadb1d81b 100644 --- a/lib/builder/builder.js +++ b/lib/builder/builder.js @@ -11,8 +11,9 @@ const definedTasks = { generateVersionInfo: require("../tasks/generateVersionInfo"), generateManifestBundle: require("../tasks/bundlers/generateManifestBundle"), generateFlexChangesBundle: require("../tasks/bundlers/generateFlexChangesBundle"), - generateAppPreload: require("../tasks/bundlers/generateAppPreload"), + generateComponentPreload: require("../tasks/bundlers/generateComponentPreload"), generateStandaloneAppBundle: require("../tasks/bundlers/generateStandaloneAppBundle"), + generateBundle: require("../tasks/bundlers/generateBundle"), generateLibraryPreload: require("../tasks/bundlers/generateLibraryPreload") }; @@ -182,7 +183,7 @@ function composeTaskList({dev, selfContained, includedTasks, excludedTasks}) { if (selfContained) { // No preloads, bundle only - selectedTasks.generateAppPreload = false; + selectedTasks.generateComponentPreload = false; selectedTasks.generateStandaloneAppBundle = true; selectedTasks.generateLibraryPreload = false; } diff --git a/lib/lbt/analyzer/ComponentAnalyzer.js b/lib/lbt/analyzer/ComponentAnalyzer.js index 8ffc659d1..58fb8fc0c 100644 --- a/lib/lbt/analyzer/ComponentAnalyzer.js +++ b/lib/lbt/analyzer/ComponentAnalyzer.js @@ -50,12 +50,12 @@ class ComponentAnalyzer { } let manifestName = resource.name.replace(/Component\.js$/, "manifest.json"); - let manifestResource = await this._pool.findResource(manifestName); - let fileContent = await manifestResource.buffer(); try { + let manifestResource = await this._pool.findResource(manifestName); + let fileContent = await manifestResource.buffer(); this._analyzeManifest( JSON.parse(fileContent.toString()), info ); } catch (err) { - // ignore + log.error("an error occurred while analyzing component %s (ignored)", resource.name, err); } return info; diff --git a/lib/lbt/analyzer/FioriElementsAnalyzer.js b/lib/lbt/analyzer/FioriElementsAnalyzer.js index a16b8b9b1..97502c961 100644 --- a/lib/lbt/analyzer/FioriElementsAnalyzer.js +++ b/lib/lbt/analyzer/FioriElementsAnalyzer.js @@ -94,9 +94,9 @@ class FioriElementsAnalyzer { } let manifestName = resource.name.replace(/Component\.js$/, "manifest.json"); - let manifestResource = await this._pool.findResource(manifestName); - let fileContent = await manifestResource.buffer(); try { + let manifestResource = await this._pool.findResource(manifestName); + let fileContent = await manifestResource.buffer(); await this._analyzeManifest( JSON.parse(fileContent.toString()), info ); } catch (err) { log.error("an error occurred while analyzing template app %s (ignored)", resource.name, err); diff --git a/lib/lbt/analyzer/SmartTemplateAnalyzer.js b/lib/lbt/analyzer/SmartTemplateAnalyzer.js index 3ca2292d1..b03c3b8ac 100644 --- a/lib/lbt/analyzer/SmartTemplateAnalyzer.js +++ b/lib/lbt/analyzer/SmartTemplateAnalyzer.js @@ -53,9 +53,9 @@ class TemplateComponentAnalyzer { } let manifestName = resource.name.replace(/Component\.js$/, "manifest.json"); - let manifestResource = await this._pool.findResource(manifestName); - let fileContent = await manifestResource.buffer(); try { + let manifestResource = await this._pool.findResource(manifestName); + let fileContent = await manifestResource.buffer(); await this._analyzeManifest( JSON.parse(fileContent.toString()), info ); } catch (err) { log.error("an error occurred while analyzing template app %s (ignored)", resource.name, err); diff --git a/lib/processors/bundlers/moduleBundler.js b/lib/processors/bundlers/moduleBundler.js index a1c237bbb..1c9d6b148 100644 --- a/lib/processors/bundlers/moduleBundler.js +++ b/lib/processors/bundlers/moduleBundler.js @@ -44,7 +44,8 @@ class LocatorResourcePool extends ResourcePool { * @param {Object} parameters Parameters * @param {Resource[]} parameters.resources Resources * @param {Object} parameters.options Options - * @param {string} parameters.options.bundleDefinition Module bundle definition + * @param {Object} parameters.options.bundleDefinition Module bundle definition + * @param {Object} parameters.options.bundleOptions Module bundle options * @returns {Promise} Promise resolving with module bundle resources */ module.exports = function({resources, options}) { @@ -54,17 +55,25 @@ module.exports = function({resources, options}) { const pool = new LocatorResourcePool(); const builder = new BundleBuilder(pool); + const bundleOptions = options.bundleOptions || {optimize: true}; + return pool.prepare( resources ). - then( () => builder.createBundle(options.bundleDefinition, {optimize: true}) ). - then( ({name, content, bundleInfo}) => { - // console.log("creating bundle as '%s'", "/resources/" + name); - const resource = new EvoResource({ - path: "/resources/" + name, - string: content - }); - return [resource]; - // return source.write(resource).then( - // () => ({name, content, bundleInfo}) - // ); + then( () => builder.createBundle(options.bundleDefinition, bundleOptions) ). + then( (results) => { + let bundles; + if (results instanceof Array) { + bundles = results; + } else { + bundles = [results]; + } + + return Promise.all(bundles.map(function({name, content, bundleInfo}) { + console.log("creating bundle as '%s'", "/resources/" + name); + const resource = new EvoResource({ + path: "/resources/" + name, + string: content + }); + return resource; + })); }); }; diff --git a/lib/tasks/bundlers/generateAppPreload.js b/lib/tasks/bundlers/generateAppPreload.js deleted file mode 100644 index 363f09f75..000000000 --- a/lib/tasks/bundlers/generateAppPreload.js +++ /dev/null @@ -1,50 +0,0 @@ -const moduleBundler = require("../../processors/bundlers/moduleBundler"); -const ReaderCollectionPrioritized = require("@ui5/fs").ReaderCollectionPrioritized; - -/** - * Task to for application bundling. - * - * @module builder/tasks/bundlers/generateAppPreload - * @param {Object} parameters Parameters - * @param {DuplexCollection} parameters.workspace DuplexCollection to read and write files - * @param {AbstractReader} parameters.dependencies Reader or Collection to read dependency files - * @param {Object} parameters.options Options - * @param {string} parameters.options.namespace Project namespace - * @returns {Promise} Promise resolving with undefined once data has been written - */ -module.exports = function({workspace, dependencies, options}) { - const combo = new ReaderCollectionPrioritized({ - name: `appBundler - prioritize workspace over dependencies: ${options.projectName}`, - readers: [workspace, dependencies] - }); - return combo.byGlob("/**/*.{js,json,xml,html,properties,library}") - .then((resources) => { - return moduleBundler({ - resources, - options: { - bundleDefinition: { - name: `${options.namespace}/Component-preload.js`, - defaultFileTypes: [".js", ".fragment.xml", ".view.xml", ".properties", ".json"], - sections: [ - { - mode: "preload", - filters: [ - `${options.namespace}/`, - `!${options.namespace}/test/`, - `!${options.namespace}/*.html` - ], - resolve: false, - resolveConditional: false, - renderer: false - } - ] - } - } - }); - }) - .then((processedResources) => { - return Promise.all(processedResources.map((resource) => { - return workspace.write(resource); - })); - }); -}; diff --git a/lib/tasks/bundlers/generateBundle.js b/lib/tasks/bundlers/generateBundle.js new file mode 100644 index 000000000..d14b50782 --- /dev/null +++ b/lib/tasks/bundlers/generateBundle.js @@ -0,0 +1,36 @@ +const moduleBundler = require("../../processors/bundlers/moduleBundler"); +const ReaderCollectionPrioritized = require("@ui5/fs").ReaderCollectionPrioritized; + +/** + * Generates a bundle based on the given bundle definition + * + * @module builder/tasks/bundlers/generateBundle + * @param {Object} parameters Parameters + * @param {DuplexCollection} parameters.workspace DuplexCollection to read and write files + * @param {Collection} parameters.dependencies Collection to read dependency files + * @param {Object} parameters.options Options + * @param {string} parameters.options.projectName Project name + * @param {Object} parameters.options.bundleDefintion Module bundle definition + * @param {Object} parameters.options.bundleOptions Module bundle options + * @returns {Promise} Promise resolving with undefined once data has been written + */ +module.exports = function({workspace, dependencies, options}) { + const combo = new ReaderCollectionPrioritized({ + name: `libraryBundler - prioritize workspace over dependencies: ${options.projectName}`, + readers: [workspace, dependencies] + }); + + return combo.byGlob("/resources/**/*.{js,json,xml,html,properties,library}").then((resources) => { + return moduleBundler({ + options: { + bundleDefinition: options.bundleDefinition, + bundleOptions: options.bundleOptions + }, + resources + }).then((bundles) => { + bundles.forEach((bundle) => { + workspace.write(bundle); + }); + }); + }); +}; diff --git a/lib/tasks/bundlers/generateComponentPreload.js b/lib/tasks/bundlers/generateComponentPreload.js new file mode 100644 index 000000000..1689cd5c1 --- /dev/null +++ b/lib/tasks/bundlers/generateComponentPreload.js @@ -0,0 +1,86 @@ +const path = require("path"); +const moduleBundler = require("../../processors/bundlers/moduleBundler"); +const ReaderCollectionPrioritized = require("@ui5/fs").ReaderCollectionPrioritized; + +/** + * Task to for application bundling. + * + * @module builder/tasks/bundlers/generateComponentPreload + * @param {Object} parameters Parameters + * @param {DuplexCollection} parameters.workspace DuplexCollection to read and write files + * @param {AbstractReader} parameters.dependencies Reader or Collection to read dependency files + * @param {Object} parameters.options Options + * @param {string} parameters.options.projectName Project name + * @param {Array} parameters.options.paths Array of paths (or glob patterns) for component files + * @param {Array} parameters.options.namespaces Array of component namespaces + * @returns {Promise} Promise resolving with undefined once data has been written + */ +module.exports = function({workspace, dependencies, options}) { + const combo = new ReaderCollectionPrioritized({ + name: `generateComponentPreload - prioritize workspace over dependencies: ${options.projectName}`, + readers: [workspace, dependencies] + }); + + return combo.byGlob("/resources/**/*.{js,json,xml,html,properties,library}") + .then(async (resources) => { + let namespaces = []; + if (options.paths) { + namespaces = await Promise.all(options.paths.map(async (componentPath) => { + const components = await combo.byGlob("/resources/" + componentPath); + return components.map((component) => { + console.log(component.getPath()); + console.log(path.dirname(component.getPath())); + return path.dirname(component.getPath()).replace(/^\/resources\//i, ""); + }); + })); + } + if (options.namespaces) { + namespaces.push(...options.namespaces); + } + + namespaces = Array.prototype.concat.apply([], namespaces); + if (!namespaces || !namespaces.length) { + throw new Error("generateComponentPreload: No component namespace(s) " + + `found for project: ${options.projectName}`); + } + + return Promise.all(namespaces.map((namespace) => { + var filters = [ + `${namespace}/`, + `!${namespace}/test/`, + `!${namespace}/*.html` + ]; + + // Exclude other namespaces + namespaces.forEach((ns) => { + if (ns !== namespace && ns.indexOf(namespace) === 0) { + filters.push(`!${ns}/`); + } + }); + + return moduleBundler({ + resources, + options: { + bundleDefinition: { + name: `${namespace}/Component-preload.js`, + defaultFileTypes: [".js", ".fragment.xml", ".view.xml", ".properties", ".json"], + sections: [ + { + mode: "preload", + filters: filters, + resolve: false, + resolveConditional: false, + renderer: false + } + ] + } + } + }); + })); + }) + .then((processedResources) => { + return Promise.all(processedResources.map((resource) => { + return workspace.write(resource[0]); + })); + }); +}; diff --git a/lib/tasks/bundlers/generateStandaloneAppBundle.js b/lib/tasks/bundlers/generateStandaloneAppBundle.js index f30c2af0a..34c541bdd 100644 --- a/lib/tasks/bundlers/generateStandaloneAppBundle.js +++ b/lib/tasks/bundlers/generateStandaloneAppBundle.js @@ -9,6 +9,7 @@ const ReaderCollectionPrioritized = require("@ui5/fs").ReaderCollectionPrioritiz * @param {DuplexCollection} parameters.workspace DuplexCollection to read and write files * @param {AbstractReader} parameters.dependencies Reader or Collection to read dependency files * @param {Object} parameters.options Options + * @param {string} parameters.options.projectName Project name * @param {string} parameters.options.namespace Project namespace * @returns {Promise} Promise resolving with undefined once data has been written */ @@ -17,7 +18,7 @@ module.exports = function({workspace, dependencies, options}) { name: `appBundlerStandalone - prioritize workspace over dependencies: ${options.projectName}`, readers: [workspace, dependencies] }); - return combo.byGlob("/**/*.{js,json,xml,html,properties,library}") + return combo.byGlob("/resources/**/*.{js,json,xml,html,properties,library}") .then((resources) => { const isEvo = resources.find((resource) => { return resource.getPath() === "/resources/ui5loader.js"; diff --git a/lib/types/AbstractBuilder.js b/lib/types/AbstractBuilder.js index e8ed559b7..b07e261a5 100644 --- a/lib/types/AbstractBuilder.js +++ b/lib/types/AbstractBuilder.js @@ -51,7 +51,11 @@ class AbstractBuilder { continue; } - taskChain = taskChain.then(this.wrapTask(taskName, this.tasks[taskName])); + let taskFunction = this.tasks[taskName]; + + if (typeof taskFunction === "function") { + taskChain = taskChain.then(this.wrapTask(taskName, taskFunction)); + } } return taskChain; } diff --git a/lib/types/application/ApplicationBuilder.js b/lib/types/application/ApplicationBuilder.js index 2acc77fb1..b718eb960 100644 --- a/lib/types/application/ApplicationBuilder.js +++ b/lib/types/application/ApplicationBuilder.js @@ -1,10 +1,11 @@ const AbstractBuilder = require("../AbstractBuilder"); const tasks = { // can't require index.js due to circular dependency - generateAppPreload: require("../../tasks/bundlers/generateAppPreload"), + generateComponentPreload: require("../../tasks/bundlers/generateComponentPreload"), generateFlexChangesBundle: require("../../tasks/bundlers/generateFlexChangesBundle"), generateLibraryPreload: require("../../tasks/bundlers/generateLibraryPreload"), generateManifestBundle: require("../../tasks/bundlers/generateManifestBundle"), generateStandaloneAppBundle: require("../../tasks/bundlers/generateStandaloneAppBundle"), + generateBundle: require("../../tasks/bundlers/generateBundle"), buildThemes: require("../../tasks/buildThemes"), createDebugFiles: require("../../tasks/createDebugFiles"), generateVersionInfo: require("../../tasks/generateVersionInfo"), @@ -24,8 +25,9 @@ class ApplicationBuilder extends AbstractBuilder { "createDebugFiles", "generateFlexChangesBundle", "generateManifestBundle", - "generateAppPreload", + "generateComponentPreload", "generateStandaloneAppBundle", + "generateBundle", "uglify", "generateVersionInfo" ]; @@ -82,16 +84,22 @@ class ApplicationBuilder extends AbstractBuilder { }); }); - this.addTask("generateAppPreload", () => { - const generateAppPreload = tasks.generateAppPreload; - return generateAppPreload({ - workspace: resourceCollections.workspace, - dependencies: resourceCollections.dependencies, - options: { - namespace: project.metadata.namespace - } + const componentPreload = project.builder && project.builder.componentPreload; + if (componentPreload) { + const generateComponentPreload = tasks.generateComponentPreload; + + this.addTask("generateComponentPreload", async () => { + return generateComponentPreload({ + workspace: resourceCollections.workspace, + dependencies: resourceCollections.dependencies, + options: { + projectName: project.metadata.name, + paths: componentPreload.paths, + namespaces: componentPreload.namespaces + } + }); }); - }); + } this.addTask("generateStandaloneAppBundle", () => { const generateStandaloneAppBundle = tasks.generateStandaloneAppBundle; @@ -99,11 +107,29 @@ class ApplicationBuilder extends AbstractBuilder { workspace: resourceCollections.workspace, dependencies: resourceCollections.dependencies, options: { + projectName: project.metadata.name, namespace: project.metadata.namespace } }); }); + const bundles = project.builder && project.builder.bundles; + if (bundles) { + this.addTask("generateBundle", () => { + return Promise.all(bundles.map((bundle) => { + return tasks.generateBundle({ + workspace: resourceCollections.workspace, + dependencies: resourceCollections.dependencies, + options: { + projectName: project.metadata.name, + bundleDefinition: bundle.bundleDefinition, + bundleOptions: bundle.bundleOptions + } + }); + })); + }); + } + this.addTask("uglify", () => { const uglify = tasks.uglify; return uglify({ diff --git a/lib/types/library/LibraryBuilder.js b/lib/types/library/LibraryBuilder.js index 0fdcc1f0c..aea97a457 100644 --- a/lib/types/library/LibraryBuilder.js +++ b/lib/types/library/LibraryBuilder.js @@ -1,7 +1,8 @@ const AbstractBuilder = require("../AbstractBuilder"); const tasks = { // can't require index.js due to circular dependency - generateAppPreload: require("../../tasks/bundlers/generateAppPreload"), + generateComponentPreload: require("../../tasks/bundlers/generateComponentPreload"), generateFlexChangesBundle: require("../../tasks/bundlers/generateFlexChangesBundle"), + generateBundle: require("../../tasks/bundlers/generateBundle"), generateLibraryPreload: require("../../tasks/bundlers/generateLibraryPreload"), generateManifestBundle: require("../../tasks/bundlers/generateManifestBundle"), generateStandaloneAppBundle: require("../../tasks/bundlers/generateStandaloneAppBundle"), @@ -17,14 +18,16 @@ class LibraryBuilder extends AbstractBuilder { constructor({resourceCollections, project, parentLogger}) { super({project, parentLogger}); - // All availble library tasks in execution order + // All available library tasks in execution order this.availableTasks = [ "replaceCopyright", "replaceVersion", - "buildThemes", - "generateLibraryPreload", "createDebugFiles", - "uglify", + "generateComponentPreload", + "generateBundle", + "generateLibraryPreload", + "buildThemes", + "uglify" ]; this.addTask("replaceCopyright", () => { @@ -49,19 +52,33 @@ class LibraryBuilder extends AbstractBuilder { }); }); - this.addTask("buildThemes", () => { - const buildThemes = tasks.buildThemes; - return buildThemes({ + this.addTask("createDebugFiles", () => { + const createDebugFiles = tasks.createDebugFiles; + return createDebugFiles({ workspace: resourceCollections.workspace, - dependencies: resourceCollections.dependencies, options: { - projectName: project.metadata.name, - librariesPattern: "/resources/**/*.library", - inputPattern: "/resources/**/themes/*/library.source.less" + pattern: "/resources/**/*.js" } }); }); + const componentPreload = project.builder && project.builder.componentPreload; + if (componentPreload) { + const generateComponentPreload = tasks.generateComponentPreload; + + this.addTask("generateComponentPreload", () => { + return generateComponentPreload({ + workspace: resourceCollections.workspace, + dependencies: resourceCollections.dependencies, + options: { + projectName: project.metadata.name, + paths: componentPreload.paths, + namespaces: componentPreload.namespaces + } + }); + }); + } + this.addTask("generateLibraryPreload", () => { const generateLibraryPreload = tasks.generateLibraryPreload; return generateLibraryPreload({ @@ -73,12 +90,32 @@ class LibraryBuilder extends AbstractBuilder { }); }); - this.addTask("createDebugFiles", () => { - const createDebugFiles = tasks.createDebugFiles; - return createDebugFiles({ + const bundles = project.builder && project.builder.bundles; + if (bundles) { + this.addTask("generateBundle", () => { + return Promise.all(bundles.map((bundle) => { + return tasks.generateBundle({ + workspace: resourceCollections.workspace, + dependencies: resourceCollections.dependencies, + options: { + projectName: project.metadata.name, + bundleDefinition: bundle.bundleDefinition, + bundleOptions: bundle.bundleOptions + } + }); + })); + }); + } + + this.addTask("buildThemes", () => { + const buildThemes = tasks.buildThemes; + return buildThemes({ workspace: resourceCollections.workspace, + dependencies: resourceCollections.dependencies, options: { - pattern: "/resources/**/*.js" + projectName: project.metadata.name, + librariesPattern: "/resources/**/*.library", + inputPattern: "/resources/**/themes/*/library.source.less" } }); }); diff --git a/test/expected/build/application.g/dest/Component-dbg.js b/test/expected/build/application.g/dest/Component-dbg.js new file mode 100644 index 000000000..fd86d4bd8 --- /dev/null +++ b/test/expected/build/application.g/dest/Component-dbg.js @@ -0,0 +1,8 @@ +sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ + "use strict"; + return UIComponent.extend('application.g.Component', { + metadata: { + manifest: "json" + } + }); +}); \ No newline at end of file diff --git a/test/expected/build/application.g/dest/Component-preload.js b/test/expected/build/application.g/dest/Component-preload.js new file mode 100644 index 000000000..63306be75 --- /dev/null +++ b/test/expected/build/application.g/dest/Component-preload.js @@ -0,0 +1,9 @@ +jQuery.sap.registerPreloadedModules({ +"version":"2.0", +"modules":{ + "application/g/Component-dbg.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{metadata:{manifest:"json"}})}); +}, + "application/g/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{metadata:{manifest:"json"}})}); +}, + "application/g/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.g","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}' +}}); diff --git a/test/expected/build/application.g/dest/Component.js b/test/expected/build/application.g/dest/Component.js new file mode 100644 index 000000000..6fdb761a9 --- /dev/null +++ b/test/expected/build/application.g/dest/Component.js @@ -0,0 +1 @@ +sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{metadata:{manifest:"json"}})}); \ No newline at end of file diff --git a/test/expected/build/application.g/dest/manifest.json b/test/expected/build/application.g/dest/manifest.json new file mode 100644 index 000000000..6fe9d5250 --- /dev/null +++ b/test/expected/build/application.g/dest/manifest.json @@ -0,0 +1,13 @@ +{ + "_version": "1.1.0", + "sap.app": { + "_version": "1.1.0", + "id": "application.g", + "type": "application", + "applicationVersion": { + "version": "1.2.2" + }, + "embeds": ["embedded"], + "title": "{{title}}" + } +} \ No newline at end of file diff --git a/test/expected/build/application.g/dest/subcomponentA/Component-dbg.js b/test/expected/build/application.g/dest/subcomponentA/Component-dbg.js new file mode 100644 index 000000000..5f1b47a8a --- /dev/null +++ b/test/expected/build/application.g/dest/subcomponentA/Component-dbg.js @@ -0,0 +1,8 @@ +sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ + "use strict"; + return UIComponent.extend('application.g.subcomponentA.Component', { + metadata: { + manifest: "json" + } + }); +}); \ No newline at end of file diff --git a/test/expected/build/application.g/dest/subcomponentA/Component-preload.js b/test/expected/build/application.g/dest/subcomponentA/Component-preload.js new file mode 100644 index 000000000..9571723f8 --- /dev/null +++ b/test/expected/build/application.g/dest/subcomponentA/Component-preload.js @@ -0,0 +1,9 @@ +jQuery.sap.registerPreloadedModules({ +"version":"2.0", +"modules":{ + "application/g/subcomponentA/Component-dbg.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentA.Component",{metadata:{manifest:"json"}})}); +}, + "application/g/subcomponentA/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentA.Component",{metadata:{manifest:"json"}})}); +}, + "application/g/subcomponentA/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.g.subcomponentA","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}' +}}); diff --git a/test/expected/build/application.g/dest/subcomponentA/Component.js b/test/expected/build/application.g/dest/subcomponentA/Component.js new file mode 100644 index 000000000..0d3fd6ccc --- /dev/null +++ b/test/expected/build/application.g/dest/subcomponentA/Component.js @@ -0,0 +1 @@ +sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentA.Component",{metadata:{manifest:"json"}})}); \ No newline at end of file diff --git a/test/expected/build/application.g/dest/subcomponentA/manifest.json b/test/expected/build/application.g/dest/subcomponentA/manifest.json new file mode 100644 index 000000000..ac1f84ae8 --- /dev/null +++ b/test/expected/build/application.g/dest/subcomponentA/manifest.json @@ -0,0 +1,13 @@ +{ + "_version": "1.1.0", + "sap.app": { + "_version": "1.1.0", + "id": "application.g.subcomponentA", + "type": "application", + "applicationVersion": { + "version": "1.2.2" + }, + "embeds": ["embedded"], + "title": "{{title}}" + } +} \ No newline at end of file diff --git a/test/expected/build/application.g/dest/subcomponentB/Component-dbg.js b/test/expected/build/application.g/dest/subcomponentB/Component-dbg.js new file mode 100644 index 000000000..5fb07ed25 --- /dev/null +++ b/test/expected/build/application.g/dest/subcomponentB/Component-dbg.js @@ -0,0 +1,8 @@ +sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ + "use strict"; + return UIComponent.extend('application.g.subcomponentB.Component', { + metadata: { + manifest: "json" + } + }); +}); \ No newline at end of file diff --git a/test/expected/build/application.g/dest/subcomponentB/Component-preload.js b/test/expected/build/application.g/dest/subcomponentB/Component-preload.js new file mode 100644 index 000000000..c00b76164 --- /dev/null +++ b/test/expected/build/application.g/dest/subcomponentB/Component-preload.js @@ -0,0 +1,9 @@ +jQuery.sap.registerPreloadedModules({ +"version":"2.0", +"modules":{ + "application/g/subcomponentB/Component-dbg.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentB.Component",{metadata:{manifest:"json"}})}); +}, + "application/g/subcomponentB/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentB.Component",{metadata:{manifest:"json"}})}); +}, + "application/g/subcomponentB/manifest.json":'{"_version":"1.1.0","sap.app":{"_version":"1.1.0","id":"application.g.subcomponentB","type":"application","applicationVersion":{"version":"1.2.2"},"embeds":["embedded"],"title":"{{title}}"}}' +}}); diff --git a/test/expected/build/application.g/dest/subcomponentB/Component.js b/test/expected/build/application.g/dest/subcomponentB/Component.js new file mode 100644 index 000000000..c8af2ace9 --- /dev/null +++ b/test/expected/build/application.g/dest/subcomponentB/Component.js @@ -0,0 +1 @@ +sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.subcomponentB.Component",{metadata:{manifest:"json"}})}); \ No newline at end of file diff --git a/test/expected/build/application.g/dest/subcomponentB/manifest.json b/test/expected/build/application.g/dest/subcomponentB/manifest.json new file mode 100644 index 000000000..84cd1802f --- /dev/null +++ b/test/expected/build/application.g/dest/subcomponentB/manifest.json @@ -0,0 +1,13 @@ +{ + "_version": "1.1.0", + "sap.app": { + "_version": "1.1.0", + "id": "application.g.subcomponentB", + "type": "application", + "applicationVersion": { + "version": "1.2.2" + }, + "embeds": ["embedded"], + "title": "{{title}}" + } +} \ No newline at end of file diff --git a/test/expected/build/application.h/dest/Component.js b/test/expected/build/application.h/dest/Component.js new file mode 100644 index 000000000..acf57e86e --- /dev/null +++ b/test/expected/build/application.h/dest/Component.js @@ -0,0 +1 @@ +sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.h.Component",{metadata:{manifest:"json"}})}); \ No newline at end of file diff --git a/test/expected/build/application.h/dest/manifest.json b/test/expected/build/application.h/dest/manifest.json new file mode 100644 index 000000000..0c7cbf74c --- /dev/null +++ b/test/expected/build/application.h/dest/manifest.json @@ -0,0 +1,13 @@ +{ + "_version": "1.1.0", + "sap.app": { + "_version": "1.1.0", + "id": "application.g", + "type": "application", + "applicationVersion": { + "version": "1.2.2" + }, + "embeds": ["embedded"], + "title": "{{title}}" + } +} diff --git a/test/expected/build/application.h/dest/sectionsA/customBundle.js b/test/expected/build/application.h/dest/sectionsA/customBundle.js new file mode 100644 index 000000000..3a8371325 --- /dev/null +++ b/test/expected/build/application.h/dest/sectionsA/customBundle.js @@ -0,0 +1,8 @@ +jQuery.sap.registerPreloadedModules({ +"version":"2.0", +"modules":{ + "application/h/sectionsA/section1.js":function(){sap.ui.define(["sap/m/Button"],function(n){console.log("Section 1 included")}); +}, + "application/h/sectionsA/section3.js":function(){sap.ui.define(["sap/m/Button"],function(n){console.log("Section 3 included")}); +} +}}); diff --git a/test/expected/build/application.h/dest/sectionsA/section1.js b/test/expected/build/application.h/dest/sectionsA/section1.js new file mode 100644 index 000000000..1ec2e3184 --- /dev/null +++ b/test/expected/build/application.h/dest/sectionsA/section1.js @@ -0,0 +1 @@ +sap.ui.define(["sap/m/Button"],function(n){console.log("Section 1 included")}); \ No newline at end of file diff --git a/test/expected/build/application.h/dest/sectionsA/section2.js b/test/expected/build/application.h/dest/sectionsA/section2.js new file mode 100644 index 000000000..a446217a5 --- /dev/null +++ b/test/expected/build/application.h/dest/sectionsA/section2.js @@ -0,0 +1 @@ +sap.ui.define(["sap/m/Button"],function(n){console.log("Section 2 included")}); \ No newline at end of file diff --git a/test/expected/build/application.h/dest/sectionsA/section3.js b/test/expected/build/application.h/dest/sectionsA/section3.js new file mode 100644 index 000000000..8358bbe01 --- /dev/null +++ b/test/expected/build/application.h/dest/sectionsA/section3.js @@ -0,0 +1 @@ +sap.ui.define(["sap/m/Button"],function(n){console.log("Section 3 included")}); \ No newline at end of file diff --git a/test/expected/build/application.h/dest/sectionsB/customBundle.js b/test/expected/build/application.h/dest/sectionsB/customBundle.js new file mode 100644 index 000000000..53acb8710 --- /dev/null +++ b/test/expected/build/application.h/dest/sectionsB/customBundle.js @@ -0,0 +1,10 @@ +jQuery.sap.registerPreloadedModules({ +"version":"2.0", +"modules":{ + "application/h/sectionsB/section1.js":function(){sap.ui.define(["sap/m/Button"],function(n){console.log("Section 1 included")}); +}, + "application/h/sectionsB/section2.js":function(){sap.ui.define(["sap/m/Button"],function(n){console.log("Section 2 included")}); +}, + "application/h/sectionsB/section3.js":function(){sap.ui.define(["sap/m/Button"],function(n){console.log("Section 3 included")}); +} +}}); diff --git a/test/expected/build/application.h/dest/sectionsB/section1.js b/test/expected/build/application.h/dest/sectionsB/section1.js new file mode 100644 index 000000000..1ec2e3184 --- /dev/null +++ b/test/expected/build/application.h/dest/sectionsB/section1.js @@ -0,0 +1 @@ +sap.ui.define(["sap/m/Button"],function(n){console.log("Section 1 included")}); \ No newline at end of file diff --git a/test/expected/build/application.h/dest/sectionsB/section2.js b/test/expected/build/application.h/dest/sectionsB/section2.js new file mode 100644 index 000000000..a446217a5 --- /dev/null +++ b/test/expected/build/application.h/dest/sectionsB/section2.js @@ -0,0 +1 @@ +sap.ui.define(["sap/m/Button"],function(n){console.log("Section 2 included")}); \ No newline at end of file diff --git a/test/expected/build/application.h/dest/sectionsB/section3.js b/test/expected/build/application.h/dest/sectionsB/section3.js new file mode 100644 index 000000000..8358bbe01 --- /dev/null +++ b/test/expected/build/application.h/dest/sectionsB/section3.js @@ -0,0 +1 @@ +sap.ui.define(["sap/m/Button"],function(n){console.log("Section 3 included")}); \ No newline at end of file diff --git a/test/expected/build/library.h/dest/resources/components/Component-preload.js b/test/expected/build/library.h/dest/resources/components/Component-preload.js new file mode 100644 index 000000000..622663ccd --- /dev/null +++ b/test/expected/build/library.h/dest/resources/components/Component-preload.js @@ -0,0 +1,6 @@ +jQuery.sap.registerPreloadedModules({ +"version":"2.0", +"modules":{ + "components/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{})}); +} +}}); diff --git a/test/expected/build/library.h/dest/resources/components/Component.js b/test/expected/build/library.h/dest/resources/components/Component.js new file mode 100644 index 000000000..422a97071 --- /dev/null +++ b/test/expected/build/library.h/dest/resources/components/Component.js @@ -0,0 +1 @@ +sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{})}); \ No newline at end of file diff --git a/test/expected/build/library.h/dest/resources/components/subcomponent1/Component-preload.js b/test/expected/build/library.h/dest/resources/components/subcomponent1/Component-preload.js new file mode 100644 index 000000000..4262abefb --- /dev/null +++ b/test/expected/build/library.h/dest/resources/components/subcomponent1/Component-preload.js @@ -0,0 +1,6 @@ +jQuery.sap.registerPreloadedModules({ +"version":"2.0", +"modules":{ + "components/subcomponent1/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{})}); +} +}}); diff --git a/test/expected/build/library.h/dest/resources/components/subcomponent1/Component.js b/test/expected/build/library.h/dest/resources/components/subcomponent1/Component.js new file mode 100644 index 000000000..422a97071 --- /dev/null +++ b/test/expected/build/library.h/dest/resources/components/subcomponent1/Component.js @@ -0,0 +1 @@ +sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{})}); \ No newline at end of file diff --git a/test/expected/build/library.h/dest/resources/components/subcomponent2/Component-preload.js b/test/expected/build/library.h/dest/resources/components/subcomponent2/Component-preload.js new file mode 100644 index 000000000..dbbdb68a4 --- /dev/null +++ b/test/expected/build/library.h/dest/resources/components/subcomponent2/Component-preload.js @@ -0,0 +1,6 @@ +jQuery.sap.registerPreloadedModules({ +"version":"2.0", +"modules":{ + "components/subcomponent2/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{})}); +} +}}); diff --git a/test/expected/build/library.h/dest/resources/components/subcomponent2/Component.js b/test/expected/build/library.h/dest/resources/components/subcomponent2/Component.js new file mode 100644 index 000000000..422a97071 --- /dev/null +++ b/test/expected/build/library.h/dest/resources/components/subcomponent2/Component.js @@ -0,0 +1 @@ +sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{})}); \ No newline at end of file diff --git a/test/expected/build/library.h/dest/resources/components/subcomponent3/Component-preload.js b/test/expected/build/library.h/dest/resources/components/subcomponent3/Component-preload.js new file mode 100644 index 000000000..192e3d2dc --- /dev/null +++ b/test/expected/build/library.h/dest/resources/components/subcomponent3/Component-preload.js @@ -0,0 +1,6 @@ +jQuery.sap.registerPreloadedModules({ +"version":"2.0", +"modules":{ + "components/subcomponent3/Component.js":function(){sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{})}); +} +}}); diff --git a/test/expected/build/library.h/dest/resources/components/subcomponent3/Component.js b/test/expected/build/library.h/dest/resources/components/subcomponent3/Component.js new file mode 100644 index 000000000..422a97071 --- /dev/null +++ b/test/expected/build/library.h/dest/resources/components/subcomponent3/Component.js @@ -0,0 +1 @@ +sap.ui.define(["sap/ui/core/UIComponent"],function(n){"use strict";return n.extend("application.g.Component",{})}); \ No newline at end of file diff --git a/test/expected/build/library.h/dest/resources/library/h/.library b/test/expected/build/library.h/dest/resources/library/h/.library new file mode 100644 index 000000000..8d1e46775 --- /dev/null +++ b/test/expected/build/library.h/dest/resources/library/h/.library @@ -0,0 +1,11 @@ + + + + library.h + SAP SE + Some fancy copyright + ${version} + + Library D + + diff --git a/test/expected/build/library.h/dest/resources/library/h/customBundle.js b/test/expected/build/library.h/dest/resources/library/h/customBundle.js new file mode 100644 index 000000000..63f8aca7b --- /dev/null +++ b/test/expected/build/library.h/dest/resources/library/h/customBundle.js @@ -0,0 +1,19 @@ +jQuery.sap.registerPreloadedModules({ +"version":"2.0", +"modules":{ + "library/h/file.js":function(){/*! + * Some fancy copyright + */ +console.log(" File "); +}, + "library/h/library.js":function(){/*! + * Some fancy copyright + */ +console.log(" Library "); +}, + "library/h/some.js":function(){/*! + * Some fancy copyright + */ +console.log(" Some "); +} +}}); diff --git a/test/expected/build/library.h/dest/resources/library/h/file.js b/test/expected/build/library.h/dest/resources/library/h/file.js new file mode 100644 index 000000000..bcf866e67 --- /dev/null +++ b/test/expected/build/library.h/dest/resources/library/h/file.js @@ -0,0 +1,4 @@ +/*! + * Some fancy copyright + */ +console.log(" File "); \ No newline at end of file diff --git a/test/expected/build/library.h/dest/resources/library/h/library.js b/test/expected/build/library.h/dest/resources/library/h/library.js new file mode 100644 index 000000000..6900e2218 --- /dev/null +++ b/test/expected/build/library.h/dest/resources/library/h/library.js @@ -0,0 +1,4 @@ +/*! + * Some fancy copyright + */ +console.log(" Library "); \ No newline at end of file diff --git a/test/expected/build/library.h/dest/resources/library/h/not.js b/test/expected/build/library.h/dest/resources/library/h/not.js new file mode 100644 index 000000000..c249a10c8 --- /dev/null +++ b/test/expected/build/library.h/dest/resources/library/h/not.js @@ -0,0 +1,4 @@ +/*! + * Some fancy copyright + */ +console.log(" Not including "); \ No newline at end of file diff --git a/test/expected/build/library.h/dest/resources/library/h/some.js b/test/expected/build/library.h/dest/resources/library/h/some.js new file mode 100644 index 000000000..98e1e6665 --- /dev/null +++ b/test/expected/build/library.h/dest/resources/library/h/some.js @@ -0,0 +1,4 @@ +/*! + * Some fancy copyright + */ +console.log(" Some "); \ No newline at end of file diff --git a/test/expected/build/library.h/dest/test-resources/library/d/Test.html b/test/expected/build/library.h/dest/test-resources/library/d/Test.html new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/application.g/package.json b/test/fixtures/application.g/package.json new file mode 100644 index 000000000..53a868722 --- /dev/null +++ b/test/fixtures/application.g/package.json @@ -0,0 +1,13 @@ +{ + "name": "application.g", + "version": "1.0.0", + "description": "Simple SAPUI5 based application", + "main": "index.html", + "dependencies": { + "library.d": "file:../library.d", + "collection": "file:../collection" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + } +} diff --git a/test/fixtures/application.g/webapp/Component.js b/test/fixtures/application.g/webapp/Component.js new file mode 100644 index 000000000..fd86d4bd8 --- /dev/null +++ b/test/fixtures/application.g/webapp/Component.js @@ -0,0 +1,8 @@ +sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ + "use strict"; + return UIComponent.extend('application.g.Component', { + metadata: { + manifest: "json" + } + }); +}); \ No newline at end of file diff --git a/test/fixtures/application.g/webapp/manifest.json b/test/fixtures/application.g/webapp/manifest.json new file mode 100644 index 000000000..6fe9d5250 --- /dev/null +++ b/test/fixtures/application.g/webapp/manifest.json @@ -0,0 +1,13 @@ +{ + "_version": "1.1.0", + "sap.app": { + "_version": "1.1.0", + "id": "application.g", + "type": "application", + "applicationVersion": { + "version": "1.2.2" + }, + "embeds": ["embedded"], + "title": "{{title}}" + } +} \ No newline at end of file diff --git a/test/fixtures/application.g/webapp/subcomponentA/Component.js b/test/fixtures/application.g/webapp/subcomponentA/Component.js new file mode 100644 index 000000000..5f1b47a8a --- /dev/null +++ b/test/fixtures/application.g/webapp/subcomponentA/Component.js @@ -0,0 +1,8 @@ +sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ + "use strict"; + return UIComponent.extend('application.g.subcomponentA.Component', { + metadata: { + manifest: "json" + } + }); +}); \ No newline at end of file diff --git a/test/fixtures/application.g/webapp/subcomponentA/manifest.json b/test/fixtures/application.g/webapp/subcomponentA/manifest.json new file mode 100644 index 000000000..ac1f84ae8 --- /dev/null +++ b/test/fixtures/application.g/webapp/subcomponentA/manifest.json @@ -0,0 +1,13 @@ +{ + "_version": "1.1.0", + "sap.app": { + "_version": "1.1.0", + "id": "application.g.subcomponentA", + "type": "application", + "applicationVersion": { + "version": "1.2.2" + }, + "embeds": ["embedded"], + "title": "{{title}}" + } +} \ No newline at end of file diff --git a/test/fixtures/application.g/webapp/subcomponentB/Component.js b/test/fixtures/application.g/webapp/subcomponentB/Component.js new file mode 100644 index 000000000..5fb07ed25 --- /dev/null +++ b/test/fixtures/application.g/webapp/subcomponentB/Component.js @@ -0,0 +1,8 @@ +sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ + "use strict"; + return UIComponent.extend('application.g.subcomponentB.Component', { + metadata: { + manifest: "json" + } + }); +}); \ No newline at end of file diff --git a/test/fixtures/application.g/webapp/subcomponentB/manifest.json b/test/fixtures/application.g/webapp/subcomponentB/manifest.json new file mode 100644 index 000000000..84cd1802f --- /dev/null +++ b/test/fixtures/application.g/webapp/subcomponentB/manifest.json @@ -0,0 +1,13 @@ +{ + "_version": "1.1.0", + "sap.app": { + "_version": "1.1.0", + "id": "application.g.subcomponentB", + "type": "application", + "applicationVersion": { + "version": "1.2.2" + }, + "embeds": ["embedded"], + "title": "{{title}}" + } +} \ No newline at end of file diff --git a/test/fixtures/application.h/package.json b/test/fixtures/application.h/package.json new file mode 100644 index 000000000..b49c3b7ed --- /dev/null +++ b/test/fixtures/application.h/package.json @@ -0,0 +1,13 @@ +{ + "name": "application.h", + "version": "1.0.0", + "description": "Simple SAPUI5 based application", + "main": "index.html", + "dependencies": { + "library.d": "file:../library.d", + "collection": "file:../collection" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + } +} diff --git a/test/fixtures/application.h/ui5.yaml b/test/fixtures/application.h/ui5.yaml new file mode 100644 index 000000000..2a7b13a54 --- /dev/null +++ b/test/fixtures/application.h/ui5.yaml @@ -0,0 +1,29 @@ +--- +specVersion: "0.1" +type: application +metadata: + name: application.g +builder: + bundles: + - name: sap/ushell/bootstrap/cdm.js + defaultFileTypes: + - ".js" + sections: + - mode: raw + filters: + - ui5loader.js + - ui5loader-autoconfig.js + declareModules: false + resolve: true + - mode: preload + name: sap/ushell/bootstrap/common + filters: + - sap/ushell/bootstrap/cdm/cdm-def.js + resolve: true + - mode: require + filters: + - sap/ushell/bootstrap/cdm/cdm-def.js + componentPreload: + - "application/g" + - "application/g/subcomponentA" + - "application/g/subcomponentB" \ No newline at end of file diff --git a/test/fixtures/application.h/webapp/Component.js b/test/fixtures/application.h/webapp/Component.js new file mode 100644 index 000000000..cb9bd4068 --- /dev/null +++ b/test/fixtures/application.h/webapp/Component.js @@ -0,0 +1,8 @@ +sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ + "use strict"; + return UIComponent.extend('application.h.Component', { + metadata: { + manifest: "json" + } + }); +}); diff --git a/test/fixtures/application.h/webapp/manifest.json b/test/fixtures/application.h/webapp/manifest.json new file mode 100644 index 000000000..0c7cbf74c --- /dev/null +++ b/test/fixtures/application.h/webapp/manifest.json @@ -0,0 +1,13 @@ +{ + "_version": "1.1.0", + "sap.app": { + "_version": "1.1.0", + "id": "application.g", + "type": "application", + "applicationVersion": { + "version": "1.2.2" + }, + "embeds": ["embedded"], + "title": "{{title}}" + } +} diff --git a/test/fixtures/application.h/webapp/sectionsA/section1.js b/test/fixtures/application.h/webapp/sectionsA/section1.js new file mode 100644 index 000000000..ac4a81296 --- /dev/null +++ b/test/fixtures/application.h/webapp/sectionsA/section1.js @@ -0,0 +1,3 @@ +sap.ui.define(["sap/m/Button"], function(Button) { + console.log("Section 1 included"); +}); diff --git a/test/fixtures/application.h/webapp/sectionsA/section2.js b/test/fixtures/application.h/webapp/sectionsA/section2.js new file mode 100644 index 000000000..e009c8286 --- /dev/null +++ b/test/fixtures/application.h/webapp/sectionsA/section2.js @@ -0,0 +1,3 @@ +sap.ui.define(["sap/m/Button"], function(Button) { + console.log("Section 2 included"); +}); diff --git a/test/fixtures/application.h/webapp/sectionsA/section3.js b/test/fixtures/application.h/webapp/sectionsA/section3.js new file mode 100644 index 000000000..5fd9349d4 --- /dev/null +++ b/test/fixtures/application.h/webapp/sectionsA/section3.js @@ -0,0 +1,3 @@ +sap.ui.define(["sap/m/Button"], function(Button) { + console.log("Section 3 included"); +}); diff --git a/test/fixtures/application.h/webapp/sectionsB/section1.js b/test/fixtures/application.h/webapp/sectionsB/section1.js new file mode 100644 index 000000000..ac4a81296 --- /dev/null +++ b/test/fixtures/application.h/webapp/sectionsB/section1.js @@ -0,0 +1,3 @@ +sap.ui.define(["sap/m/Button"], function(Button) { + console.log("Section 1 included"); +}); diff --git a/test/fixtures/application.h/webapp/sectionsB/section2.js b/test/fixtures/application.h/webapp/sectionsB/section2.js new file mode 100644 index 000000000..e009c8286 --- /dev/null +++ b/test/fixtures/application.h/webapp/sectionsB/section2.js @@ -0,0 +1,3 @@ +sap.ui.define(["sap/m/Button"], function(Button) { + console.log("Section 2 included"); +}); diff --git a/test/fixtures/application.h/webapp/sectionsB/section3.js b/test/fixtures/application.h/webapp/sectionsB/section3.js new file mode 100644 index 000000000..5fd9349d4 --- /dev/null +++ b/test/fixtures/application.h/webapp/sectionsB/section3.js @@ -0,0 +1,3 @@ +sap.ui.define(["sap/m/Button"], function(Button) { + console.log("Section 3 included"); +}); diff --git a/test/fixtures/library.g/ui5.yaml b/test/fixtures/library.g/ui5.yaml deleted file mode 100644 index 9c5281718..000000000 --- a/test/fixtures/library.g/ui5.yaml +++ /dev/null @@ -1,5 +0,0 @@ ---- -specVersion: "0.1" -type: library -metadata: - name: library.g diff --git a/test/fixtures/library.h/main/src/components/Component.js b/test/fixtures/library.h/main/src/components/Component.js new file mode 100644 index 000000000..998e27dce --- /dev/null +++ b/test/fixtures/library.h/main/src/components/Component.js @@ -0,0 +1,5 @@ +sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ + "use strict"; + return UIComponent.extend('application.g.Component', { + }); +}); diff --git a/test/fixtures/library.h/main/src/components/subcomponent1/Component.js b/test/fixtures/library.h/main/src/components/subcomponent1/Component.js new file mode 100644 index 000000000..998e27dce --- /dev/null +++ b/test/fixtures/library.h/main/src/components/subcomponent1/Component.js @@ -0,0 +1,5 @@ +sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ + "use strict"; + return UIComponent.extend('application.g.Component', { + }); +}); diff --git a/test/fixtures/library.h/main/src/components/subcomponent2/Component.js b/test/fixtures/library.h/main/src/components/subcomponent2/Component.js new file mode 100644 index 000000000..998e27dce --- /dev/null +++ b/test/fixtures/library.h/main/src/components/subcomponent2/Component.js @@ -0,0 +1,5 @@ +sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ + "use strict"; + return UIComponent.extend('application.g.Component', { + }); +}); diff --git a/test/fixtures/library.h/main/src/components/subcomponent3/Component.js b/test/fixtures/library.h/main/src/components/subcomponent3/Component.js new file mode 100644 index 000000000..998e27dce --- /dev/null +++ b/test/fixtures/library.h/main/src/components/subcomponent3/Component.js @@ -0,0 +1,5 @@ +sap.ui.define(["sap/ui/core/UIComponent"], function(UIComponent){ + "use strict"; + return UIComponent.extend('application.g.Component', { + }); +}); diff --git a/test/fixtures/library.h/main/src/library/h/.library b/test/fixtures/library.h/main/src/library/h/.library new file mode 100644 index 000000000..8d1e46775 --- /dev/null +++ b/test/fixtures/library.h/main/src/library/h/.library @@ -0,0 +1,11 @@ + + + + library.h + SAP SE + Some fancy copyright + ${version} + + Library D + + diff --git a/test/fixtures/library.h/main/src/library/h/file.js b/test/fixtures/library.h/main/src/library/h/file.js new file mode 100644 index 000000000..c38081004 --- /dev/null +++ b/test/fixtures/library.h/main/src/library/h/file.js @@ -0,0 +1,4 @@ +/*! + * ${copyright} + */ +console.log(' File '); diff --git a/test/fixtures/library.h/main/src/library/h/library.js b/test/fixtures/library.h/main/src/library/h/library.js new file mode 100644 index 000000000..c5b4fdcfd --- /dev/null +++ b/test/fixtures/library.h/main/src/library/h/library.js @@ -0,0 +1,4 @@ +/*! + * ${copyright} + */ +console.log(' Library '); diff --git a/test/fixtures/library.h/main/src/library/h/not.js b/test/fixtures/library.h/main/src/library/h/not.js new file mode 100644 index 000000000..778bfa1f5 --- /dev/null +++ b/test/fixtures/library.h/main/src/library/h/not.js @@ -0,0 +1,4 @@ +/*! + * ${copyright} + */ +console.log(' Not including '); diff --git a/test/fixtures/library.h/main/src/library/h/some.js b/test/fixtures/library.h/main/src/library/h/some.js new file mode 100644 index 000000000..f14efacd4 --- /dev/null +++ b/test/fixtures/library.h/main/src/library/h/some.js @@ -0,0 +1,4 @@ +/*! + * ${copyright} + */ +console.log(' Some '); diff --git a/test/fixtures/library.h/main/test/library/d/Test.html b/test/fixtures/library.h/main/test/library/d/Test.html new file mode 100644 index 000000000..e69de29bb diff --git a/test/fixtures/library.h/package.json b/test/fixtures/library.h/package.json new file mode 100644 index 000000000..f930ef082 --- /dev/null +++ b/test/fixtures/library.h/package.json @@ -0,0 +1,9 @@ +{ + "name": "library.h", + "version": "1.0.0", + "description": "Simple SAPUI5 based library", + "dependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + } +} diff --git a/test/lib/builder/builder.js b/test/lib/builder/builder.js index c66e73a15..182ff3fd2 100644 --- a/test/lib/builder/builder.js +++ b/test/lib/builder/builder.js @@ -7,7 +7,10 @@ const assert = chai.assert; const ui5Builder = require("../../../"); const builder = ui5Builder.builder; const applicationAPath = path.join(__dirname, "..", "..", "fixtures", "application.a"); +const applicationGPath = path.join(__dirname, "..", "..", "fixtures", "application.g"); +const applicationHPath = path.join(__dirname, "..", "..", "fixtures", "application.h"); const libraryDPath = path.join(__dirname, "..", "..", "fixtures", "library.d"); +const libraryHPath = path.join(__dirname, "..", "..", "fixtures", "library.h"); const libraryEPath = path.join(__dirname, "..", "..", "fixtures", "library.e"); const recursive = require("recursive-readdir"); @@ -31,14 +34,12 @@ test("Build application.a", (t) => { return builder.build({ tree: applicationATree, destPath, - excludedTasks: ["generateAppPreload", "generateStandaloneAppBundle", "generateVersionInfo"] + excludedTasks: ["generateComponentPreload", "generateStandaloneAppBundle", "generateVersionInfo"] }).then(() => { return findFiles(expectedPath); }).then((expectedFiles) => { - console.log(expectedFiles); // Check for all directories and files assert.directoryDeepEqual(destPath, expectedPath); - console.log("after assert"); // Check for all file contents expectedFiles.forEach((expectedFile) => { const relativeFile = path.relative(expectedPath, expectedFile); @@ -73,6 +74,75 @@ test("Build application.a [dev mode]", (t) => { }); }); +test("Build application.g", (t) => { + const destPath = "./test/tmp/build/application.g/dest"; + const expectedPath = "./test/expected/build/application.g/dest"; + + return builder.build({ + tree: applicationGTree, + destPath, + excludedTasks: ["generateStandaloneAppBundle", "generateVersionInfo"] + }).then(() => { + return findFiles(expectedPath); + }).then((expectedFiles) => { + // Check for all directories and files + assert.directoryDeepEqual(destPath, expectedPath); + // Check for all file contents + expectedFiles.forEach((expectedFile) => { + const relativeFile = path.relative(expectedPath, expectedFile); + const destFile = path.join(destPath, relativeFile); + assert.fileEqual(destFile, expectedFile); + }); + t.pass(); + }); +}); + +test("Build application.g with component preload paths", (t) => { + const destPath = "./test/tmp/build/application.g/dest"; + const expectedPath = "./test/expected/build/application.g/dest"; + + return builder.build({ + tree: applicationGTreeComponentPreloadPaths, + destPath, + excludedTasks: ["generateStandaloneAppBundle", "generateVersionInfo"] + }).then(() => { + return findFiles(expectedPath); + }).then((expectedFiles) => { + // Check for all directories and files + assert.directoryDeepEqual(destPath, expectedPath); + // Check for all file contents + expectedFiles.forEach((expectedFile) => { + const relativeFile = path.relative(expectedPath, expectedFile); + const destFile = path.join(destPath, relativeFile); + assert.fileEqual(destFile, expectedFile); + }); + t.pass(); + }); +}); + +test("Build application.h", (t) => { + const destPath = "./test/tmp/build/application.h/dest"; + const expectedPath = "./test/expected/build/application.h/dest"; + + return builder.build({ + tree: applicationHTree, + destPath, + excludedTasks: ["createDebugFiles", "generateComponentPreload", "generateStandaloneAppBundle", "generateVersionInfo"] + }).then(() => { + return findFiles(expectedPath); + }).then((expectedFiles) => { + // Check for all directories and files + assert.directoryDeepEqual(destPath, expectedPath); + // Check for all file contents + expectedFiles.forEach((expectedFile) => { + const relativeFile = path.relative(expectedPath, expectedFile); + const destFile = path.join(destPath, relativeFile); + assert.fileEqual(destFile, expectedFile); + }); + t.pass(); + }); +}); + test("Build library.d with copyright from .library file", (t) => { const destPath = "./test/tmp/build/library.d/dest"; const expectedPath = "./test/expected/build/library.d/dest"; @@ -121,6 +191,30 @@ test("Build library.e with copyright from settings of ui5.yaml", (t) => { }); }); +test("Build library.h with custom bundles and component-preloads", (t) => { + const destPath = "./test/tmp/build/library.h/dest"; + const expectedPath = "./test/expected/build/library.h/dest"; + + return builder.build({ + tree: libraryHTree, + destPath, + excludedTasks: ["createDebugFiles", "generateLibraryPreload"] + }).then(() => { + return findFiles(expectedPath); + }).then((expectedFiles) => { + // Check for all directories and files + assert.directoryDeepEqual(destPath, expectedPath); + + // Check for all file contents + expectedFiles.forEach((expectedFile) => { + const relativeFile = path.relative(expectedPath, expectedFile); + const destFile = path.join(destPath, relativeFile); + assert.fileEqual(destFile, expectedFile); + t.pass(); + }); + }); +}); + const applicationATree = { "id": "application.a", @@ -246,6 +340,130 @@ const applicationATree = { } }; +const applicationGTree = { + "id": "application.g", + "version": "1.0.0", + "path": applicationGPath, + "_level": 0, + "specVersion": "0.1", + "type": "application", + "metadata": { + "name": "application.g", + "namespace": "application/g" + }, + "dependencies": [], + "resources": { + "configuration": { + "paths": { + "webapp": "webapp" + } + }, + "pathMappings": { + "/": "webapp" + } + }, + "builder": { + "componentPreload": { + "namespaces": [ + "application/g", + "application/g/subcomponentA", + "application/g/subcomponentB" + ] + } + } +}; + +const applicationGTreeComponentPreloadPaths = { + "id": "application.g", + "version": "1.0.0", + "path": applicationGPath, + "_level": 0, + "specVersion": "0.1", + "type": "application", + "metadata": { + "name": "application.g", + "namespace": "application/g" + }, + "dependencies": [], + "resources": { + "configuration": { + "paths": { + "webapp": "webapp" + } + }, + "pathMappings": { + "/": "webapp" + } + }, + "builder": { + "componentPreload": { + "paths": [ + "application/g/**/Component.js" + ] + } + } +}; + +const applicationHTree = { + "id": "application.h", + "version": "1.0.0", + "path": applicationHPath, + "_level": 0, + "specVersion": "0.1", + "type": "application", + "metadata": { + "name": "application.h", + "namespace": "application/h" + }, + "dependencies": [], + "resources": { + "configuration": { + "paths": { + "webapp": "webapp" + } + }, + "pathMappings": { + "/": "webapp" + } + }, + "builder": { + "bundles": [{ + "bundleDefinition": { + "name": "application/h/sectionsA/customBundle.js", + "defaultFileTypes": [".js"], + "sections": [{ + "mode": "preload", + "filters": [ + "application/h/sectionsA/", + "!application/h/sectionsA/section2**", + ] + }], + "sort": true + }, + "bundleOptions": { + "optimize": true, + "usePredefinedCalls": true + } + }, + { + "bundleDefinition": { + "name": "application/h/sectionsB/customBundle.js", + "defaultFileTypes": [".js"], + "sections": [{ + "mode": "preload", + "filters": [ + "application/h/sectionsB/" + ] + }] + }, + "bundleOptions": { + "optimize": true, + "usePredefinedCalls": true + } + }] + } +}; + const libraryDTree = { "id": "library.d", "version": "1.0.0", @@ -272,6 +490,63 @@ const libraryDTree = { } }; +const libraryHTree = { + "id": "library.h", + "version": "1.0.0", + "path": libraryHPath, + "dependencies": [], + "_level": 0, + "specVersion": "0.1", + "type": "library", + "metadata": { + "name": "library.h", + "copyright": "Some fancy copyright" + }, + "resources": { + "configuration": { + "paths": { + "src": "main/src", + "test": "main/test" + } + }, + "pathMappings": { + "/resources/": "main/src", + "/test-resources/": "main/test" + } + }, + "builder": { + "bundles": [{ + "bundleDefinition": { + "name": "library/h/customBundle.js", + "defaultFileTypes": [".js"], + "sections": [{ + "mode": "preload", + "filters": [ + "library/h/some.js", + "library/h/library.js", + "library/h/file.js", + "!library/h/not.js" + ], + "resolve": false, + "renderer": false + }] + }, + "bundleOptions": { + "optimize": true, + "usePredefinedCalls": true + } + }], + "componentPreload": { + "namespaces": [ + "components", + "components/subcomponent1", + "components/subcomponent2", + "components/subcomponent3" + ] + } + } +}; + const libraryETree = { "id": "library.e", "version": "1.0.0", diff --git a/test/lib/tasks/bundlers/generateManifestBundle.js b/test/lib/tasks/bundlers/generateManifestBundle.js index 0d3c03be5..4d7fa56f4 100644 --- a/test/lib/tasks/bundlers/generateManifestBundle.js +++ b/test/lib/tasks/bundlers/generateManifestBundle.js @@ -160,6 +160,7 @@ const applicationBTree = { } } ], + "builder": {}, "_level": 0, "specVersion": "0.1", "type": "application",