Skip to content

Commit d8a277f

Browse files
authored
refactor: updated vite config to inject add version metadata into the app on build (#841)
* refactor: removes commit.json and used vite.config to load these variables * updated precommit hook * updated the pre start script * updated the workflows
1 parent 56edbc4 commit d8a277f

File tree

10 files changed

+63
-79
lines changed

10 files changed

+63
-79
lines changed

.github/workflows/commit.yaml

Lines changed: 0 additions & 39 deletions
This file was deleted.

.github/workflows/update-stable.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ jobs:
166166
- name: Commit and Tag Release
167167
run: |
168168
git pull
169-
echo "{ \"commit\": \"$COMMIT_HASH\", \"version\": \"$NEW_VERSION\" }" > app/commit.json
170-
git add package.json pnpm-lock.yaml changelog.md app/commit.json
169+
git add package.json pnpm-lock.yaml changelog.md
171170
git commit -m "chore: release version ${{ steps.bump_version.outputs.new_version }}"
172171
git tag "v${{ steps.bump_version.outputs.new_version }}"
173172
git push

.husky/pre-commit

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,4 @@ if ! pnpm lint; then
2929
exit 1
3030
fi
3131

32-
# Update commit.json with the latest commit hash
33-
echo "Updating commit.json with the latest commit hash..."
34-
COMMIT_HASH=$(git rev-parse HEAD)
35-
if [ $? -ne 0 ]; then
36-
echo "❌ Failed to get commit hash. Ensure you are in a git repository."
37-
exit 1
38-
fi
39-
40-
echo "{ \"commit\": \"$COMMIT_HASH\" }" > app/commit.json
41-
git add app/commit.json
42-
4332
echo "👍 All checks passed! Committing changes..."

app/commit.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/components/settings/debug/DebugTab.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useCallback, useEffect, useState } from 'react';
22
import { useSettings } from '~/lib/hooks/useSettings';
3-
import commit from '~/commit.json';
43
import { toast } from 'react-toastify';
54
import { providerBaseUrlEnvKeys } from '~/utils/constants';
65

@@ -44,11 +43,16 @@ interface CommitData {
4443
version?: string;
4544
}
4645

47-
const connitJson: CommitData = commit;
46+
const connitJson: CommitData = {
47+
commit: __COMMIT_HASH,
48+
version: __APP_VERSION,
49+
};
4850

4951
const LOCAL_PROVIDERS = ['Ollama', 'LMStudio', 'OpenAILike'];
52+
5053
const versionHash = connitJson.commit;
5154
const versionTag = connitJson.version;
55+
5256
const GITHUB_URLS = {
5357
original: 'https://api.github.com/repos/stackblitz-labs/bolt.diy/commits/main',
5458
fork: 'https://api.github.com/repos/Stijnus/bolt.new-any-llm/commits/main',
@@ -524,7 +528,7 @@ export default function DebugTab() {
524528
<div className="mt-3 pt-3 border-t border-bolt-elements-surface-hover">
525529
<p className="text-xs text-bolt-elements-textSecondary">Version</p>
526530
<p className="text-sm font-medium text-bolt-elements-textPrimary font-mono">
527-
{versionHash.slice(0, 7)}
531+
{connitJson.commit.slice(0, 7)}
528532
<span className="ml-2 text-xs text-bolt-elements-textSecondary">
529533
(v{versionTag || '0.0.1'}) - {isLatestBranch ? 'nightly' : 'stable'}
530534
</span>

app/components/settings/providers/ProvidersTab.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export default function ProvidersTab() {
3535
newFilteredProviders.sort((a, b) => a.name.localeCompare(b.name));
3636

3737
// Split providers into regular and URL-configurable
38-
const regular = newFilteredProviders.filter(p => !URL_CONFIGURABLE_PROVIDERS.includes(p.name));
39-
const urlConfigurable = newFilteredProviders.filter(p => URL_CONFIGURABLE_PROVIDERS.includes(p.name));
38+
const regular = newFilteredProviders.filter((p) => !URL_CONFIGURABLE_PROVIDERS.includes(p.name));
39+
const urlConfigurable = newFilteredProviders.filter((p) => URL_CONFIGURABLE_PROVIDERS.includes(p.name));
4040

4141
setFilteredProviders([...regular, ...urlConfigurable]);
4242
}, [providers, searchTerm, isLocalModel]);
@@ -112,8 +112,8 @@ export default function ProvidersTab() {
112112
);
113113
};
114114

115-
const regularProviders = filteredProviders.filter(p => !URL_CONFIGURABLE_PROVIDERS.includes(p.name));
116-
const urlConfigurableProviders = filteredProviders.filter(p => URL_CONFIGURABLE_PROVIDERS.includes(p.name));
115+
const regularProviders = filteredProviders.filter((p) => !URL_CONFIGURABLE_PROVIDERS.includes(p.name));
116+
const urlConfigurableProviders = filteredProviders.filter((p) => URL_CONFIGURABLE_PROVIDERS.includes(p.name));
117117

118118
return (
119119
<div className="p-4">
@@ -128,22 +128,19 @@ export default function ProvidersTab() {
128128
</div>
129129

130130
{/* Regular Providers Grid */}
131-
<div className="grid grid-cols-2 gap-4 mb-8">
132-
{regularProviders.map(renderProviderCard)}
133-
</div>
131+
<div className="grid grid-cols-2 gap-4 mb-8">{regularProviders.map(renderProviderCard)}</div>
134132

135133
{/* URL Configurable Providers Section */}
136134
{urlConfigurableProviders.length > 0 && (
137135
<div className="mt-8">
138136
<h3 className="text-lg font-semibold mb-2 text-bolt-elements-textPrimary">Experimental Providers</h3>
139137
<p className="text-sm text-bolt-elements-textSecondary mb-4">
140-
These providers are experimental and allow you to run AI models locally or connect to your own infrastructure. They require additional setup but offer more flexibility.
138+
These providers are experimental and allow you to run AI models locally or connect to your own
139+
infrastructure. They require additional setup but offer more flexibility.
141140
</p>
142-
<div className="space-y-4">
143-
{urlConfigurableProviders.map(renderProviderCard)}
144-
</div>
141+
<div className="space-y-4">{urlConfigurableProviders.map(renderProviderCard)}</div>
145142
</div>
146143
)}
147144
</div>
148145
);
149-
}
146+
}

app/lib/hooks/useSettings.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ import { useCallback, useEffect, useState } from 'react';
1212
import Cookies from 'js-cookie';
1313
import type { IProviderSetting, ProviderInfo } from '~/types/model';
1414
import { logStore } from '~/lib/stores/logs'; // assuming logStore is imported from this location
15-
import commit from '~/commit.json';
1615

1716
interface CommitData {
1817
commit: string;
1918
version?: string;
2019
}
2120

22-
const commitJson: CommitData = commit;
21+
const versionData: CommitData = {
22+
commit: __COMMIT_HASH,
23+
version: __APP_VERSION,
24+
};
2325

2426
export function useSettings() {
2527
const providers = useStore(providersStore);
@@ -34,7 +36,7 @@ export function useSettings() {
3436
const checkIsStableVersion = async () => {
3537
try {
3638
const stableResponse = await fetch(
37-
`https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/refs/tags/v${commitJson.version}/app/commit.json`,
39+
`https://raw.githubusercontent.com/stackblitz-labs/bolt.diy/refs/tags/v${versionData.version}/app/commit.json`,
3840
);
3941

4042
if (!stableResponse.ok) {
@@ -44,7 +46,7 @@ export function useSettings() {
4446

4547
const stableData = (await stableResponse.json()) as CommitData;
4648

47-
return commit.commit === stableData.commit;
49+
return versionData.commit === stableData.commit;
4850
} catch (error) {
4951
console.warn('Error checking stable version:', error);
5052
return false;
@@ -105,16 +107,16 @@ export function useSettings() {
105107
let checkCommit = Cookies.get('commitHash');
106108

107109
if (checkCommit === undefined) {
108-
checkCommit = commit.commit;
110+
checkCommit = versionData.commit;
109111
}
110112

111-
if (savedLatestBranch === undefined || checkCommit !== commit.commit) {
113+
if (savedLatestBranch === undefined || checkCommit !== versionData.commit) {
112114
// If setting hasn't been set by user, check version
113115
checkIsStableVersion().then((isStable) => {
114116
const shouldUseLatest = !isStable;
115117
latestBranchStore.set(shouldUseLatest);
116118
Cookies.set('isLatestBranch', String(shouldUseLatest));
117-
Cookies.set('commitHash', String(commit.commit));
119+
Cookies.set('commitHash', String(versionData.commit));
118120
});
119121
} else {
120122
latestBranchStore.set(savedLatestBranch === 'true');

app/vite-env.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
declare const __COMMIT_HASH: string;
2+
declare const __APP_VERSION: string;

pre-start.cjs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
1-
const { commit } = require('./app/commit.json');
1+
const { execSync } =require('child_process');
2+
3+
// Get git hash with fallback
4+
const getGitHash = () => {
5+
try {
6+
return execSync('git rev-parse --short HEAD').toString().trim();
7+
} catch {
8+
return 'no-git-info';
9+
}
10+
};
11+
12+
let commitJson = {
13+
hash: JSON.stringify(getGitHash()),
14+
version: JSON.stringify(process.env.npm_package_version),
15+
};
216

317
console.log(`
418
★═══════════════════════════════════════★
519
B O L T . D I Y
620
⚡️ Welcome ⚡️
721
★═══════════════════════════════════════★
822
`);
9-
console.log('📍 Current Commit Version:', commit);
10-
console.log(' Please wait until the URL appears here')
11-
console.log('★═══════════════════════════════════════★');
23+
console.log('📍 Current Version Tag:', `v${commitJson.version}`);
24+
console.log('📍 Current Commit Version:', commitJson.hash);
25+
console.log(' Please wait until the URL appears here');
26+
console.log('★═══════════════════════════════════════★');

vite.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,24 @@ import { nodePolyfills } from 'vite-plugin-node-polyfills';
55
import { optimizeCssModules } from 'vite-plugin-optimize-css-modules';
66
import tsconfigPaths from 'vite-tsconfig-paths';
77

8+
import { execSync } from 'child_process';
9+
10+
// Get git hash with fallback
11+
const getGitHash = () => {
12+
try {
13+
return execSync('git rev-parse --short HEAD').toString().trim();
14+
} catch {
15+
return 'no-git-info';
16+
}
17+
};
18+
19+
820
export default defineConfig((config) => {
921
return {
22+
define: {
23+
__COMMIT_HASH__: JSON.stringify(getGitHash()),
24+
__APP_VERSION__: JSON.stringify(process.env.npm_package_version),
25+
},
1026
build: {
1127
target: 'esnext',
1228
},

0 commit comments

Comments
 (0)