-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathreplaceVersion.js
More file actions
41 lines (38 loc) · 1.26 KB
/
replaceVersion.js
File metadata and controls
41 lines (38 loc) · 1.26 KB
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
import stringReplacer from "../processors/stringReplacer.js";
/**
* @public
* @module @ui5/builder/tasks/replaceVersion
*/
/**
* Task to replace the version <code>${version}</code>.
*
* @public
* @function default
* @static
*
* @param {object} parameters Parameters
* @param {@ui5/fs/DuplexCollection} parameters.workspace DuplexCollection to read and write files
* @param {object} parameters.options Options
* @param {string} parameters.options.pattern Pattern to locate the files to be processed
* @param {string} parameters.options.version Replacement version
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
*/
export default async function({workspace, buildCache, options: {pattern, version}}) {
let resources = await workspace.byGlob(pattern);
if (buildCache.hasCache()) {
const changedPaths = buildCache.getChangedProjectResourcePaths();
resources = resources.filter((resource) => changedPaths.has(resource.getPath()));
}
const processedResources = await stringReplacer({
resources,
options: {
pattern: /\$\{(?:project\.)?version\}/g,
replacement: version
}
});
await Promise.all(processedResources.map((resource) => {
if (resource) {
return workspace.write(resource);
}
}));
}