mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: Track current version (#2731)
This commit is contained in:
parent
3a130cb102
commit
001880ba88
4 changed files with 44 additions and 13 deletions
|
@ -5,23 +5,40 @@ const path = require("path");
|
|||
const versionFile = path.join("build", "version.json");
|
||||
const indexFile = path.join("build", "index.html");
|
||||
|
||||
const zero = (digit) => `0${digit}`.slice(-2);
|
||||
const versionDate = (date) => date.toISOString().replace(".000", "");
|
||||
|
||||
const versionDate = (date) => {
|
||||
const date_ = `${date.getFullYear()}-${zero(date.getMonth() + 1)}-${zero(
|
||||
date.getDate(),
|
||||
)}`;
|
||||
const time = `${zero(date.getHours())}-${zero(date.getMinutes())}-${zero(
|
||||
date.getSeconds(),
|
||||
)}`;
|
||||
return `${date_}-${time}`;
|
||||
const commitHash = () => {
|
||||
try {
|
||||
return require("child_process")
|
||||
.execSync("git rev-parse --short HEAD")
|
||||
.toString()
|
||||
.trim();
|
||||
} catch {
|
||||
return "none";
|
||||
}
|
||||
};
|
||||
|
||||
const now = new Date();
|
||||
const commitDate = (hash) => {
|
||||
try {
|
||||
const unix = require("child_process")
|
||||
.execSync(`git show -s --format=%ct ${hash}`)
|
||||
.toString()
|
||||
.trim();
|
||||
const date = new Date(parseInt(unix) * 1000);
|
||||
return versionDate(date);
|
||||
} catch {
|
||||
return versionDate(new Date());
|
||||
}
|
||||
};
|
||||
|
||||
const getFullVersion = () => {
|
||||
const hash = commitHash();
|
||||
return `${commitDate(hash)}-${hash}`;
|
||||
};
|
||||
|
||||
const data = JSON.stringify(
|
||||
{
|
||||
version: versionDate(now),
|
||||
version: getFullVersion(),
|
||||
},
|
||||
undefined,
|
||||
2,
|
||||
|
@ -34,7 +51,7 @@ fs.readFile(indexFile, "utf8", (error, data) => {
|
|||
if (error) {
|
||||
return console.error(error);
|
||||
}
|
||||
const result = data.replace(/{version}/g, versionDate(now));
|
||||
const result = data.replace(/{version}/g, getFullVersion());
|
||||
|
||||
fs.writeFile(indexFile, result, "utf8", (error) => {
|
||||
if (error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue