Skip to content

Commit b6dc55f

Browse files
authored
Merge pull request #52 from DataFlowAnalysis/commit-hash
2 parents 5c7ee49 + f1f7bb6 commit b6dc55f

File tree

5 files changed

+45
-1
lines changed

5 files changed

+45
-1
lines changed

frontend/webEditor/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
dist
3+
src/helpUi/hash.json

frontend/webEditor/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"type": "git",
77
"url": "https://github.com/DataFlowAnalysis/OnlineEditor.git"
88
},
9+
"type": "module",
910
"devDependencies": {
1011
"@eslint/eslintrc": "^3.3.3",
1112
"@eslint/js": "^9.39.2",
@@ -32,7 +33,11 @@
3233
"preview": "vite preview",
3334
"format": "prettier --write \"./**/*.{html,css,ts,tsx,json}\"",
3435
"lint": "eslint --max-warnings 0 --no-warn-ignored",
35-
"prepare": "husky"
36+
"prepare": "husky",
37+
"postprepare": "npm run fetch-hash",
38+
"prebuild": "npm run fetch-hash",
39+
"predev": "npm run fetch-hash",
40+
"fetch-hash": "node ./scripts/fetchHash.js"
3641
},
3742
"lint-staged": {
3843
"*.{html,css,ts,tsx,json}": [
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { writeFileSync } from 'fs'
2+
import { execSync } from 'child_process'
3+
4+
let hash = 'unknown'
5+
try {
6+
hash = execSync('git rev-parse HEAD').toString().trim()
7+
} catch (e) {
8+
// eslint-disable-next-line no-console, no-undef
9+
console.warn('Could not retrieve git hash:', e)
10+
}
11+
const filePath = 'src/helpUi/hash.json'
12+
const fileContent = JSON.stringify({ hash })
13+
writeFileSync(filePath, fileContent)

frontend/webEditor/src/helpUi/helpUi.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@
1414
vertical-align: text-top;
1515
margin-right: 4px;
1616
}
17+
18+
#hashHolder {
19+
font-size: small;
20+
margin-top: 4px;
21+
display: flex;
22+
gap: 2px;
23+
}
1724
}

frontend/webEditor/src/helpUi/helpUi.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { injectable } from "inversify";
22
import "./helpUi.css";
33
import { AccordionUiExtension } from "../accordionUiExtension";
4+
import hashJson from "./hash.json";
45

56
@injectable()
67
export class HelpUI extends AccordionUiExtension {
@@ -35,9 +36,26 @@ export class HelpUI extends AccordionUiExtension {
3536
<p><kbd>Esc</kbd>: Disable current creation tool</p>
3637
<p>Toggle Creation Tool: Refer to key in the tool palette</p>
3738
`;
39+
40+
contentElement.appendChild(this.buildCommitHash());
3841
}
3942
protected initializeHeaderContent(headerElement: HTMLElement) {
4043
headerElement.classList.add("help-accordion-icon");
4144
headerElement.innerText = "Keyboard Shortcuts | Help";
4245
}
46+
47+
private buildCommitHash(): HTMLElement {
48+
const holder = document.createElement("div");
49+
holder.id = "hashHolder";
50+
holder.innerHTML = "Commit:";
51+
52+
const link = document.createElement("a");
53+
link.innerHTML = hashJson.hash.substring(0, 6);
54+
link.href = `https://github.com/DataFlowAnalysis/OnlineEditor/tree/${hashJson.hash}`;
55+
link.id = "hash";
56+
link.target = "_blank";
57+
58+
holder.appendChild(link);
59+
return holder;
60+
}
4361
}

0 commit comments

Comments
 (0)