@nx/docker
Version:
47 lines (46 loc) • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.interpolateVersionPattern = interpolateVersionPattern;
const git_utils_1 = require("nx/src/utils/git-utils");
const tokenRegex = /\{([^|{}]+)(?:\|([^{}]+))?\}/g;
function formatDate(date, format) {
const year = String(date.getFullYear());
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return format
.replace(/YYYY/g, year)
.replace(/YY/g, year.slice(-2))
.replace(/MM/g, month)
.replace(/DD/g, day)
.replace(/HH/g, hours)
.replace(/mm/g, minutes)
.replace(/ss/g, seconds);
}
function interpolateVersionPattern(versionPattern, data) {
const commitSha = (0, git_utils_1.getLatestCommitSha)();
const substitutions = {
projectName: data.projectName ?? '',
currentDate: data.currentDate ?? new Date(),
commitSha: data.commitSha ?? commitSha,
shortCommitSha: data.shortCommitSha ?? commitSha.slice(0, 7),
};
return versionPattern.replace(tokenRegex, (match, identifier, format) => {
const value = substitutions[identifier];
if (value === undefined) {
return match; // Keep original token if no data
}
// Handle date formatting
if (identifier === 'currentDate') {
if (format) {
return formatDate(value, format);
}
else {
return value.toISOString();
}
}
return value;
});
}