@ui5/builder
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -5,4 +5,14 @@ # Changelog | ||
A list of unreleased changes can be found [here](https://github.com/SAP/ui5-builder/compare/v0.1.0...HEAD). | ||
A list of unreleased changes can be found [here](https://github.com/SAP/ui5-builder/compare/v0.1.1...HEAD). | ||
<a name="v0.1.1"></a> | ||
## [v0.1.1] - 2018-07-02 | ||
### Bug Fixes | ||
- iterate over routes using a for loop if it is an object ([#31](https://github.com/SAP/ui5-builder/issues/31)) [`e9823f6`](https://github.com/SAP/ui5-builder/commit/e9823f68cf038b5fde172916e483a01d5eb88f1f) | ||
### Internal Changes | ||
- Task createDebugFiles checks path before writes ([#43](https://github.com/SAP/ui5-builder/issues/43)) [`57427c8`](https://github.com/SAP/ui5-builder/commit/57427c8d712b8b936a1a3070fe3110da54fdbdb7) | ||
- Create and integrate a new task 'generateLibraryManifest' ([#26](https://github.com/SAP/ui5-builder/issues/26)) [`000a6fe`](https://github.com/SAP/ui5-builder/commit/000a6fee49555cb266a1c575cde719e1091d1066) | ||
<a name="v0.1.0"></a> | ||
@@ -59,3 +69,4 @@ ## [v0.1.0] - 2018-06-26 | ||
[v0.1.1]: https://github.com/SAP/ui5-builder/compare/v0.1.0...v0.1.1 | ||
[v0.1.0]: https://github.com/SAP/ui5-builder/compare/v0.0.2...v0.1.0 | ||
[v0.0.2]: https://github.com/SAP/ui5-builder/compare/v0.0.1...v0.0.2 |
@@ -11,2 +11,3 @@ const log = require("@ui5/logger").getGroupLogger("builder:builder"); | ||
buildThemes: require("../tasks/buildThemes"), | ||
generateLibraryManifest: require("../tasks/generateLibraryManifest"), | ||
generateVersionInfo: require("../tasks/generateVersionInfo"), | ||
@@ -13,0 +14,0 @@ generateManifestBundle: require("../tasks/bundlers/generateManifestBundle"), |
@@ -120,14 +120,13 @@ /** | ||
if ( routing ) { | ||
// console.log("routing: ", routing); | ||
routing.routes.forEach( (route) => { | ||
let target = routing.targets[route.target]; | ||
if ( target && target.viewName ) { | ||
let module = ModuleName.fromUI5LegacyName( | ||
(routing.config.viewPath ? routing.config.viewPath + "." : "") + | ||
target.viewName, ".view." + routing.config.viewType.toLowerCase() ); | ||
log.verbose("converting route to view dependency ", module); | ||
// TODO make this a conditional dependency, depending on the pattern? | ||
info.addDependency(module); | ||
if (Array.isArray(routing.routes)) { | ||
routing.routes.forEach((route) => this._visitRoute(route, routing, info)); | ||
} else { | ||
for (let key in routing.routes) { | ||
if (!routing.routes.hasOwnProperty(key)) { | ||
continue; | ||
} | ||
const route = routing.routes[key]; | ||
this._visitRoute(route, routing, info); | ||
} | ||
}); | ||
} | ||
} | ||
@@ -137,4 +136,24 @@ | ||
} | ||
/** | ||
* called for any route, this adds the view used by a route as a dependency. | ||
* | ||
* @param {object} route the single route | ||
* @param {object} routing the full routing object from the manifest | ||
* @param {ModuleInfo} info ModuleInfo object that should be enriched | ||
* @private | ||
*/ | ||
_visitRoute( route, routing, info ) { | ||
const viewPath = routing.config.viewPath ? routing.config.viewPath + "." : ""; | ||
const viewType = routing.config.viewType.toLowerCase(); | ||
const target = routing.targets[route.target]; | ||
if ( target && target.viewName ) { | ||
const module = ModuleName.fromUI5LegacyName(viewPath + target.viewName, ".view." + viewType); | ||
log.verbose("converting route to view dependency ", module); | ||
// TODO make this a conditional dependency, depending on the pattern? | ||
info.addDependency(module); | ||
} | ||
} | ||
} | ||
module.exports = ComponentAnalyzer; |
@@ -82,2 +82,26 @@ "use strict"; | ||
/** | ||
* Converts an AST node of type 'ArrayExpression' into an array of strings, | ||
* assuming that each item in the array literal is a string literal. | ||
* | ||
* Depending on the parameter skipNonStringLiterals, unexpected items | ||
* in the array are either ignored or cause the method to fail with | ||
* a TypeError. | ||
* | ||
* @param {ESTree} array | ||
* @param {boolean } skipNonStringLiterals | ||
* @throws {TypeError} | ||
* @returns {string[]} | ||
*/ | ||
function getStringArray(array, skipNonStringLiterals) { | ||
return array.elements.reduce( (result, item) => { | ||
if ( isString(item) ) { | ||
result.push(item.value); | ||
} else if ( !skipNonStringLiterals ) { | ||
throw new TypeError("array element is not a string literal:" + item.type); | ||
} | ||
return result; | ||
}, []); | ||
} | ||
module.exports = { | ||
@@ -93,3 +117,4 @@ isString, | ||
findOwnProperty, | ||
getValue | ||
getValue, | ||
getStringArray | ||
}; |
const copier = require("./resourceCopier"); | ||
const util = require("util"); | ||
@@ -11,10 +12,39 @@ /** | ||
*/ | ||
module.exports = function({resources}) { | ||
return copier({ | ||
resources: resources, | ||
options: { | ||
pattern: /((\.view|\.fragment|\.controller)?\.js)/, | ||
replacement: "-dbg$1" | ||
} | ||
module.exports = function({resources, fs}) { | ||
const options = { | ||
pattern: /((\.view|\.fragment|\.controller)?\.js)/, | ||
replacement: "-dbg$1" | ||
}; | ||
const stat = util.promisify(fs.stat); | ||
return Promise.all( | ||
resources.map((resource) => { | ||
// check whether the debug resource path is already used in the | ||
// previous tasks | ||
return stat(resource.getPath().replace(options.pattern, options.replacement)) | ||
.then( | ||
// if the file can be found, it should be filtered out from creating debug file | ||
() => false, | ||
(err) => { | ||
if (err.code === "ENOENT") { | ||
// if the file can't be found, it should be included in creating debug file | ||
return resource; | ||
} | ||
// if it's other error, forward it | ||
throw err; | ||
} | ||
); | ||
}) | ||
).then((results) => { | ||
// filter out the resouces whose debug source path is already used | ||
return results.filter((result) => { | ||
return !!result; | ||
}); | ||
}).then((filteredResources) => { | ||
return copier({ | ||
resources: filteredResources, | ||
options: options | ||
}); | ||
}); | ||
}; |
const dbg = require("../processors/debugFileCreator"); | ||
const fsInterface = require("@ui5/fs").fsInterface; | ||
@@ -21,2 +22,3 @@ /** | ||
return dbg({ | ||
fs: fsInterface(workspace), | ||
resources: allResources | ||
@@ -23,0 +25,0 @@ }).then((processedResources) => { |
@@ -11,2 +11,3 @@ const AbstractBuilder = require("../AbstractBuilder"); | ||
createDebugFiles: require("../../tasks/createDebugFiles"), | ||
generateLibraryManifest: require("../../tasks/generateLibraryManifest"), | ||
generateVersionInfo: require("../../tasks/generateVersionInfo"), | ||
@@ -28,2 +29,3 @@ replaceCopyright: require("../../tasks/replaceCopyright"), | ||
"generateBundle", | ||
"generateLibraryManifest", | ||
"generateLibraryPreload", | ||
@@ -74,2 +76,13 @@ "buildThemes", | ||
this.addTask("generateLibraryManifest", () => { | ||
const generateLibraryManifest = tasks.generateLibraryManifest; | ||
return generateLibraryManifest({ | ||
workspace: resourceCollections.workspace, | ||
dependencies: resourceCollections.dependencies, | ||
options: { | ||
projectName: project.metadata.name | ||
} | ||
}); | ||
}); | ||
this.addTask("generateLibraryPreload", () => { | ||
@@ -76,0 +89,0 @@ const generateLibraryPreload = tasks.generateLibraryPreload; |
{ | ||
"name": "@ui5/builder", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "UI5 Build and Development Tooling - Builder", | ||
@@ -113,2 +113,3 @@ "author": "SAP SE (https://www.sap.com)", | ||
"replacestream": "^4.0.3", | ||
"semver": "^5.5.0", | ||
"uglify-es": "^3.2.2", | ||
@@ -115,0 +116,0 @@ "xml2js": "^0.4.17" |
@@ -1,4 +0,2 @@ | ||
jQuery.sap.registerPreloadedModules({ | ||
"version":"2.0", | ||
"modules":{ | ||
sap.ui.require.preload({ | ||
"library/h/file.js":function(){/*! | ||
@@ -19,2 +17,2 @@ * Some fancy copyright | ||
} | ||
}}); | ||
}); |
@@ -13,4 +13,6 @@ const {test} = require("ava"); | ||
const libraryDPath = path.join(__dirname, "..", "..", "fixtures", "library.d"); | ||
const libraryEPath = path.join(__dirname, "..", "..", "fixtures", "library.e"); | ||
const libraryIPath = path.join(__dirname, "..", "..", "fixtures", "library.i"); | ||
const libraryHPath = path.join(__dirname, "..", "..", "fixtures", "library.h"); | ||
const libraryEPath = path.join(__dirname, "..", "..", "fixtures", "library.e"); | ||
const libraryCore = path.join(__dirname, "..", "..", "fixtures", "sap.ui.core-evo"); | ||
@@ -31,2 +33,14 @@ const recursive = require("recursive-readdir"); | ||
function cloneProjectTree(tree) { | ||
let clone = JSON.parse(JSON.stringify(tree)); | ||
function increaseDepth(node) { | ||
node._level++; | ||
if ( Array.isArray(node.dependencies) ) { | ||
node.dependencies.forEach(increaseDepth); | ||
} | ||
} | ||
increaseDepth(clone); | ||
return clone; | ||
} | ||
test("Build application.a", (t) => { | ||
@@ -220,3 +234,27 @@ const destPath = "./test/tmp/build/application.a/dest"; | ||
test("Build library.i with manifest info taken from .library and library.js", (t) => { | ||
const destPath = "./test/tmp/build/library.i/dest"; | ||
const expectedPath = "./test/expected/build/library.i/dest"; | ||
return builder.build({ | ||
tree: libraryITree, | ||
destPath, | ||
excludedTasks: ["createDebugFiles", "generateLibraryPreload", "uglify"] | ||
}).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 = { | ||
@@ -474,3 +512,27 @@ "id": "application.a", | ||
"path": libraryDPath, | ||
"dependencies": [], | ||
"dependencies": [ | ||
{ | ||
"id": "sap.ui.core-evo", | ||
"version": "1.0.0", | ||
"path": libraryCore, | ||
"dependencies": [], | ||
"_level": 1, | ||
"specVersion": "0.1", | ||
"type": "library", | ||
"metadata": { | ||
"name": "sap.ui.core", | ||
"copyright": "Some fancy copyright" | ||
}, | ||
"resources": { | ||
"configuration": { | ||
"paths": { | ||
"src": "main/src" | ||
} | ||
}, | ||
"pathMappings": { | ||
"/resources/": "main/src" | ||
} | ||
} | ||
} | ||
], | ||
"_level": 0, | ||
@@ -497,2 +559,52 @@ "specVersion": "0.1", | ||
const libraryETree = { | ||
"id": "library.e", | ||
"version": "1.0.0", | ||
"path": libraryEPath, | ||
"dependencies": [ | ||
{ | ||
"id": "sap.ui.core-evo", | ||
"version": "1.0.0", | ||
"path": libraryCore, | ||
"dependencies": [], | ||
"_level": 1, | ||
"specVersion": "0.1", | ||
"type": "library", | ||
"metadata": { | ||
"name": "sap.ui.core", | ||
"copyright": "Some fancy copyright" | ||
}, | ||
"resources": { | ||
"configuration": { | ||
"paths": { | ||
"src": "main/src" | ||
} | ||
}, | ||
"pathMappings": { | ||
"/resources/": "main/src" | ||
} | ||
} | ||
} | ||
], | ||
"_level": 0, | ||
"specVersion": "0.1", | ||
"type": "library", | ||
"metadata": { | ||
"name": "library.e", | ||
"copyright": "UI development toolkit for HTML5 (OpenUI5)\n * (c) Copyright 2009-xxx SAP SE or an SAP affiliate company.\n * Licensed under the Apache License, Version 2.0 - see LICENSE.txt." | ||
}, | ||
"resources": { | ||
"configuration": { | ||
"paths": { | ||
"src": "src", | ||
"test": "test" | ||
} | ||
}, | ||
"pathMappings": { | ||
"/resources/": "src", | ||
"/test-resources/": "test" | ||
} | ||
} | ||
}; | ||
const libraryHTree = { | ||
@@ -502,3 +614,27 @@ "id": "library.h", | ||
"path": libraryHPath, | ||
"dependencies": [], | ||
"dependencies": [ | ||
{ | ||
"id": "sap.ui.core-evo", | ||
"version": "1.0.0", | ||
"path": libraryCore, | ||
"dependencies": [], | ||
"_level": 1, | ||
"specVersion": "0.1", | ||
"type": "library", | ||
"metadata": { | ||
"name": "sap.ui.core", | ||
"copyright": "Some fancy copyright" | ||
}, | ||
"resources": { | ||
"configuration": { | ||
"paths": { | ||
"src": "main/src" | ||
} | ||
}, | ||
"pathMappings": { | ||
"/resources/": "main/src" | ||
} | ||
} | ||
} | ||
], | ||
"_level": 0, | ||
@@ -534,3 +670,4 @@ "specVersion": "0.1", | ||
"library/h/file.js", | ||
"!library/h/not.js" | ||
"!library/h/not.js", | ||
"!library/h/components/" | ||
], | ||
@@ -548,6 +685,6 @@ "resolve": false, | ||
"namespaces": [ | ||
"components", | ||
"components/subcomponent1", | ||
"components/subcomponent2", | ||
"components/subcomponent3" | ||
"library/h/components", | ||
"library/h/components/subcomponent1", | ||
"library/h/components/subcomponent2", | ||
"library/h/components/subcomponent3" | ||
] | ||
@@ -558,7 +695,32 @@ } | ||
const libraryETree = { | ||
"id": "library.e", | ||
const libraryITree = { | ||
"id": "library.i", | ||
"version": "1.0.0", | ||
"path": libraryEPath, | ||
"dependencies": [], | ||
"path": libraryIPath, | ||
"dependencies": [ | ||
{ | ||
"id": "sap.ui.core-evo", | ||
"version": "1.0.0", | ||
"path": libraryCore, | ||
"dependencies": [], | ||
"_level": 1, | ||
"specVersion": "0.1", | ||
"type": "library", | ||
"metadata": { | ||
"name": "sap.ui.core", | ||
"copyright": "Some fancy copyright" | ||
}, | ||
"resources": { | ||
"configuration": { | ||
"paths": { | ||
"src": "main/src" | ||
} | ||
}, | ||
"pathMappings": { | ||
"/resources/": "main/src" | ||
} | ||
} | ||
}, | ||
cloneProjectTree(libraryDTree) | ||
], | ||
"_level": 0, | ||
@@ -568,4 +730,4 @@ "specVersion": "0.1", | ||
"metadata": { | ||
"name": "library.e", | ||
"copyright": "UI development toolkit for HTML5 (OpenUI5)\n * (c) Copyright 2009-xxx SAP SE or an SAP affiliate company.\n * Licensed under the Apache License, Version 2.0 - see LICENSE.txt." | ||
"name": "library.i", | ||
"copyright": "Some fancy copyright" | ||
}, | ||
@@ -575,11 +737,12 @@ "resources": { | ||
"paths": { | ||
"src": "src", | ||
"test": "test" | ||
"src": "main/src", | ||
"test": "main/test" | ||
} | ||
}, | ||
"pathMappings": { | ||
"/resources/": "src", | ||
"/test-resources/": "test" | ||
"/resources/": "main/src", | ||
"/test-resources/": "main/test" | ||
} | ||
} | ||
}; | ||
@@ -236,1 +236,44 @@ const {test} = require("ava"); | ||
}); | ||
test("dbg file creation should not overwrite the existing -dbg file", (t) => { | ||
const sourceAdapter = resourceFactory.createAdapter({ | ||
virBasePath: "/" | ||
}); | ||
const content = "console.log('Hello World');"; | ||
const resource = resourceFactory.createResource({ | ||
path: "/test1.js", | ||
string: content | ||
}); | ||
const contentDebug = "console.log('Hello Debug World')"; | ||
const debugResource = resourceFactory.createResource({ | ||
path: "/test1-dbg.js", | ||
string: contentDebug | ||
}); | ||
const workspace = resourceFactory.createWorkspace({ | ||
reader: sourceAdapter | ||
}); | ||
return Promise.all([ | ||
sourceAdapter.write(resource), | ||
workspace.write(debugResource) | ||
]).then(() => { | ||
return tasks.createDebugFiles({ | ||
workspace, | ||
options: { | ||
pattern: "/**/*.js" | ||
} | ||
}).then(() => { | ||
return workspace.byPath("/test1-dbg.js").then((resource) => { | ||
if (!resource) { | ||
t.fail("Could not find the existing /test1-dbg.js"); | ||
} else { | ||
return resource.getBuffer(); | ||
} | ||
}); | ||
}).then((buffer) => { | ||
t.deepEqual(buffer.toString(), contentDebug, "Content of /test1-dbg.js is correct"); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
348999
283
8800
15
+ Addedsemver@^5.5.0
+ Addedsemver@5.7.2(transitive)