const { readdirSync, readFileSync, writeFileSync } = require("fs"); const { minify } = require("html-minifier-terser"); const { extname, join } = require("path"); const { execSync } = require("child_process"); const OUT_PATH = "out"; const HTML_MINIFIER_CONFIG = { collapseBooleanAttributes: true, collapseInlineTagWhitespace: true, collapseWhitespace: true, decodeEntities: true, includeAutoGeneratedTags: false, minifyJS: true, minifyURLs: true, processConditionalComments: true, processScripts: ["text/html"], removeAttributeQuotes: true, removeComments: true, removeEmptyAttributes: true, removeOptionalTags: true, removeRedundantAttributes: true, removeScriptTypeAttributes: true, removeStyleLinkTypeAttributes: true, sortAttributes: true, sortClassName: true, trimCustomFragments: true, useShortDoctype: true, }; 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 } 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(/