-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathreplaceBuildtime.js
More file actions
55 lines (51 loc) · 1.57 KB
/
replaceBuildtime.js
File metadata and controls
55 lines (51 loc) · 1.57 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import stringReplacer from "../processors/stringReplacer.js";
function pad(v) {
return String(v).padStart(2, "0");
}
function getTimestamp() {
const date = new Date();
const year = date.getFullYear();
const month = pad(date.getMonth() + 1);
const day = pad(date.getDate());
const hours = pad(date.getHours());
const minutes = pad(date.getMinutes());
// yyyyMMdd-HHmm
return year + month + day + "-" + hours + minutes;
}
/**
* @public
* @module @ui5/builder/tasks/replaceBuildtime
*/
/**
* Task to replace the buildtime <code>${buildtime}</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
* @returns {Promise<undefined>} Promise resolving with <code>undefined</code> once data has been written
*/
export default async function({workspace, buildCache, options: {pattern}}) {
let resources = await workspace.byGlob(pattern);
if (buildCache.hasCache()) {
const changedPaths = buildCache.getChangedProjectResourcePaths();
resources = resources.filter((resource) => changedPaths.has(resource.getPath()));
}
const timestamp = getTimestamp();
const processedResources = await stringReplacer({
resources,
options: {
pattern: "${buildtime}",
replacement: timestamp
}
});
return Promise.all(processedResources.map((resource) => {
if (resource) {
return workspace.write(resource);
}
}));
}