forked from SAP/ui5-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresourceCopier.js
24 lines (23 loc) · 998 Bytes
/
resourceCopier.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* Copy files to a different path.
*
* @public
* @alias module:@ui5/builder.processors.resourceCopier
* @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.pattern] Search pattern for path
* @param {string} [parameters.options.replacement] Replacement string for path
* @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with the cloned resources
*/
module.exports = function({resources, options}) {
if (!options.pattern || typeof options.replacement !== "string") {
return Promise.reject(new Error("[resourceCopier] Invalid options: Missing pattern or replacement."));
}
return Promise.all(resources.map((resource) => {
return resource.clone().then((newResource) => {
newResource.setPath(newResource.getPath().replace(options.pattern, options.replacement));
return newResource;
});
}));
};