forked from SAP/ui5-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebugFileCreator.js
50 lines (47 loc) · 1.44 KB
/
debugFileCreator.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
});
});
};