UNPKG

@ui5/builder

Version:
51 lines (47 loc) 1.47 kB
const copier = require("./resourceCopier"); const util = require("util"); /** * Creates *-dbg.js files for all supplied resources. * * @public * @alias module:@ui5/builder.processors.debugFileCreator * @param {Object} parameters Parameters * @param {module:@ui5/fs.Resource[]} parameters.resources List of resources to be processed * @returns {Promise<module:@ui5/fs.Resource[]>} Promise resolving with debug resources */ 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 }); }); };