Skip to content

Commit 7c39302

Browse files
committed
display hash of build commit
1 parent dbc1f34 commit 7c39302

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/settings/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.1",
@@ -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
9+
console.warn('Could not retrieve git hash:', e)
10+
}
11+
const filePath = 'src/settings/hash.json'
12+
const fileContent = JSON.stringify({ hash })
13+
writeFileSync(filePath, fileContent)

frontend/webEditor/src/settings/SettingsUi.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { HideEdgeNames, SETTINGS, SimplifyNodeNames } from "./Settings";
66
import { EditorModeController } from "./editorMode";
77
import { Theme, ThemeManager } from "./Theme";
88
import { ShownLabels, ShownLabelsValue } from "./ShownLabels";
9+
import hashJson from './hash.json'
910

1011
@injectable()
1112
export class SettingsUI extends AccordionUiExtension {
@@ -42,13 +43,29 @@ export class SettingsUI extends AccordionUiExtension {
4243
this.addBooleanSwitch(grid, "Hide Edge Names", this.hideEdgeNames);
4344
this.addBooleanSwitch(grid, "Simplify Node Names", this.simplifyNodeNames);
4445
this.addSwitch(grid, "Read Only", this.editorModeController, { true: "view", false: "edit" });
46+
contentElement.appendChild(this.buildCommitHash())
4547
}
4648

4749
protected initializeHeaderContent(headerElement: HTMLElement): void {
4850
headerElement.classList.add("settings-accordion-icon");
4951
headerElement.innerText = "Settings";
5052
}
5153

54+
private buildCommitHash(): HTMLElement {
55+
const holder = document.createElement('div')
56+
holder.id = 'hashHolder'
57+
holder.innerHTML = 'Commit:'
58+
59+
const link = document.createElement('a')
60+
link.innerHTML = hashJson.hash.substring(0, 6)
61+
link.href = `https://github.com/DataFlowAnalysis/OnlineEditor/tree/${hashJson.hash}`
62+
link.id = 'hash'
63+
link.target = '_blank'
64+
65+
holder.appendChild(link)
66+
return holder
67+
}
68+
5269
private addBooleanSwitch(container: HTMLElement, title: string, value: SettingsValue<boolean>): void {
5370
this.addSwitch<boolean>(container, title, value, { true: true, false: false });
5471
}

frontend/webEditor/src/settings/settingsUi.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,11 @@ input:checked + .slider:before {
108108
.slider.round:before {
109109
border-radius: 50%;
110110
}
111+
112+
.settings-ui #hashHolder {
113+
font-size: small;
114+
margin-top: 8px;
115+
display: flex;
116+
gap: 2px;
117+
}
118+

0 commit comments

Comments
 (0)