From 56f5a980eb015ebba790a451cc4930602f166f78 Mon Sep 17 00:00:00 2001 From: Dustin Brett Date: Sat, 31 Aug 2024 10:11:13 -0700 Subject: [PATCH] Add repo url into code/html --- scripts/minifyHtml.js | 64 +++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/scripts/minifyHtml.js b/scripts/minifyHtml.js index 96d86c69..b0aff0d0 100644 --- a/scripts/minifyHtml.js +++ b/scripts/minifyHtml.js @@ -28,24 +28,48 @@ const HTML_MINIFIER_CONFIG = { useShortDoctype: true, }; -const COMMIT_HASH_LENGTH = 7; -let commit = ""; +const getCommitHash = () => { + const COMMIT_HASH_LENGTH = 7; + let commit = ""; -try { - commit = execSync(`git rev-parse --short=${COMMIT_HASH_LENGTH} HEAD`, { - cwd: __dirname, - }) - .toString() - .trim(); -} catch { - // Ignore failure to get commit hash from git -} + try { + commit = execSync(`git rev-parse --short=${COMMIT_HASH_LENGTH} HEAD`, { + cwd: __dirname, + }) + .toString() + .trim(); + } catch { + // Ignore failure to get commit hash from git + } -if (!commit) { - commit = - process.env.npm_package_gitHead?.slice(0, COMMIT_HASH_LENGTH - 1) || - new Date().toISOString().slice(0, 10); -} + if (!commit) { + commit = + process.env.npm_package_gitHead?.slice(0, COMMIT_HASH_LENGTH - 1) || + new Date().toISOString().slice(0, 10); + } + + return commit; +}; + +const getRepoUrl = () => { + let url = ""; + + try { + url = execSync("git config --get remote.origin.url", { + cwd: __dirname, + }) + .toString() + .trim(); + + if (url.endsWith(".git")) { + url = url.slice(0, -4); + } + } catch { + // Ignore failure to get commit hash from git + } + + return url; +}; const CODE_REPLACE_FUNCTIONS = [ (html) => html.replace(/