Skip to content

Commit

Permalink
fix: Commit ID not injected to php file when build
Browse files Browse the repository at this point in the history
  • Loading branch information
KawaiiZapic committed Nov 7, 2024
1 parent cc506f9 commit 543ca6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 10 additions & 11 deletions plugins/Matecho.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ export default (config?: MatechoPluginConfig): Plugin => {
if (id.endsWith("_actual_php.html")) {
return (await readFile(id.replace("_actual_php.html", ".php")))
.toString()
.replaceAll("<%= CommitID %>", config.CommitID ?? "unknown")
.replaceAll(
"<%= CompatibilityUserAgentRegex %>",
JSON.stringify(
getUserAgentRegex({
ignoreMinor: true,
allowHigherVersions: true
}).toString()
).slice(1, -1)
)
.replace(/<\?(?:php|).+?(\?>|$)/gis, match => {
const token = "PHPCode" + hash(match) + Date.now();
codeTokens[token] = match;
Expand All @@ -218,17 +228,6 @@ export default (config?: MatechoPluginConfig): Plugin => {
},
transformIndexHtml(html, ctx) {
let r = html;
r = r
.replaceAll(
"<%= CompatibilityUserAgentRegex %>",
JSON.stringify(
getUserAgentRegex({
ignoreMinor: true,
allowHigherVersions: true
}).toString()
).slice(1, -1)
)
.replaceAll("__COMMIT_ID__", config.CommitID ?? "");
ctx.filename = ctx.filename.replace("_actual_php.html", ".php");
if (env.command !== "serve") {
Object.entries(codeTokens).forEach(([token, code]) => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package Matecho
* @author KawaiiZapic
* @version __COMMIT_ID__
* @version <%= CommitID %>
* @link https://github.com/KawaiiZapic/Matecho
*/

Expand Down

0 comments on commit 543ca6a

Please sign in to comment.