Skip to content

Commit

Permalink
Merge pull request #2799 from opral/niklasbuchfink/fink-18-show-fink-…
Browse files Browse the repository at this point in the history
…version-in-ui

feat: show Fink version in Footer
  • Loading branch information
NiklasBuchfink authored May 21, 2024
2 parents 92cbc50 + a2da7d3 commit 0ffb94f
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -375,3 +375,6 @@ inlang/source-code/paraglide/paraglide-solidstart/example/.solid
*.h.ts.mjs
**/vite.config.ts.timestamp-*
**/vite.config.js.timestamp-*

# Fink version.json
inlang/source-code/editor/version.json
1 change: 0 additions & 1 deletion inlang/source-code/editor/.gitignore

This file was deleted.

4 changes: 2 additions & 2 deletions inlang/source-code/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"type": "module",
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build -- --max_old_space_size=1200000 && tsc --noEmit",
"dev": "node ./scripts/updateVersion.js && vite",
"build": "node ./scripts/updateVersion.js && vite build -- --max_old_space_size=1200000 && tsc --noEmit",
"production": "NODE_ENV=production tsx ./src/server/main.ts",
"---- TEST ----------------------------------------------------------": "",
"test": "paraglide-js compile --project ../../../project.inlang",
Expand Down
53 changes: 53 additions & 0 deletions inlang/source-code/editor/scripts/updateVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { execSync } from "node:child_process"
import fs from "node:fs"

// Function to execute shell commands
function execCommand(command) {
try {
return execSync(command).toString()
} catch (error) {
console.error(`Error executing command: ${command}`, error)
return undefined
}
}

// Function to update the version.json file
function updateVersionFile() {
// Fetch package versions
const pnpmOutput = execCommand("pnpm m ls --depth -1 --json")
if (!pnpmOutput) return

const packages = JSON.parse(pnpmOutput)
const inlangVersion = packages.find((pkg) => pkg.name === "@inlang/sdk").version
const lixVersion = packages.find((pkg) => pkg.name === "@lix-js/client").version
// if working directory is not clean set commit hash to "dev"
const gitStatus = execCommand("git status --porcelain")
const commitHash = gitStatus ? "dev" : execCommand("git rev-parse HEAD").trim()

// Read the current version.json
const versionFilePath = "./version.json"
// Create version.json if it does not exist
if (!fs.existsSync(versionFilePath)) {
fs.writeFileSync(
versionFilePath,
`{
"@inlang/sdk": "",
"@lix-js/client": "",
"commit-hash": ""
}
`
)
}
const versionFile = JSON.parse(fs.readFileSync(versionFilePath))

// Update version.json file
versionFile["@inlang/sdk"] = inlangVersion
versionFile["@lix-js/client"] = lixVersion
versionFile["commit-hash"] = commitHash

// Write the updated version.json
fs.writeFileSync(versionFilePath, JSON.stringify(versionFile, undefined, 2))
}

// Execute the update
updateVersionFile()
50 changes: 24 additions & 26 deletions inlang/source-code/editor/src/interface/editor/Footer.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { For, Show } from "solid-js"
import { For } from "solid-js"
import IconGithub from "~icons/cib/github"
import IconDiscord from "~icons/cib/discord"
import Link from "#src/renderer/Link.jsx"
import IconQuestionMark from "~icons/material-symbols/question-mark"
import version from "../../../version.json"

export const getFinkResourcesLinks = () => {
return [
Expand Down Expand Up @@ -68,10 +68,10 @@ const Footer = () => {
return (
<footer class="bg-background border-t border-surface-200 py-4 px-4 overflow-visible">
<div class="max-w-7xl mx-auto flex justify-between gap-4 xl:px-4 h-6">
<div class="flex items-center justify-between">
<div class="flex items-center justify-between w-24">
<p class="text-sm text-surface-500">© {new Date().getFullYear().toString()} Opral</p>
</div>
<div class="flex gap-4 mr-[67.21px]">
<div class="flex gap-4">
<For each={socialMediaLinks}>
{(link) => (
<Link
Expand All @@ -85,31 +85,29 @@ const Footer = () => {
)}
</For>
</div>
<div class="relative">
<sl-dropdown prop:placement="top-end" prop:distance={4} class="peer">
<button slot="trigger" class="bg-surface-900 rounded-full p-1">
<IconQuestionMark class="w-4 h-4 text-background" />
<div class="flex items-center justify-end w-24">
<sl-dropdown prop:distance={8}>
<button slot="trigger" class="text-sm text-surface-500">
{version["commit-hash"].slice(0, 7)}
</button>
<sl-menu class="w-fit">
<For each={getFinkResourcesLinks()}>
{(link) => (
<>
<sl-menu-item>
<a href={link.href} target="_blank">
{link.name}
</a>
</sl-menu-item>
<Show when={link.name === "About the ecosystem"}>
<div class="w-full border-b border-surface-200 my-1" />
</Show>
</>
)}
</For>
<sl-menu class="flex flex-col px-4 py-3 text-sm w-60">
<span class="font-medium mb-2">Deployed version</span>
<div class="flex justify-between">
<span>Commit hash: {""}</span>
<a href={`https://github.com/opral/monorepo/commit/${version["commit-hash"]}`} target="_blank" class="text-primary">
{version["commit-hash"].slice(0, 7)}
</a>
</div>
<div class="flex justify-between">
<span>SDK version:</span>
<span>{version["@inlang/sdk"]}</span>
</div>
<div class="flex justify-between">
<span>Lix client version:</span>
<span>{version["@lix-js/client"]}</span>
</div>
</sl-menu>
</sl-dropdown>
<div class="opacity-0 transition-opacity peer-hover:opacity-100 absolute text-sm bg-inverted-surface text-on-inverted-surface py-1 px-2 rounded right-0 bottom-8 whitespace-nowrap">
Help and resources
</div>
</div>
</div>
</footer>
Expand Down

0 comments on commit 0ffb94f

Please sign in to comment.