Add hybrid versioning scripts, version shown in app footer

This commit is contained in:
2026-01-16 16:55:13 +00:00
parent 966006db6a
commit 5bd9780ac0
8 changed files with 214 additions and 11 deletions

45
scripts/bump-version.js Normal file
View File

@@ -0,0 +1,45 @@
// scripts/bump-version.js - Manual version bump script
const fs = require('fs');
const path = require('path');
const args = process.argv.slice(2);
const bumpType = args[0] || 'patch'; // patch, minor, major
if (!['patch', 'minor', 'major'].includes(bumpType)) {
console.error('Usage: npm run version:bump [patch|minor|major]');
console.error(' patch: 0.2.1 → 0.2.2 (bug fixes)');
console.error(' minor: 0.2.1 → 0.3.0 (new features)');
console.error(' major: 0.2.1 → 1.0.0 (breaking changes)');
process.exit(1);
}
const packagePath = path.join(__dirname, '../package.json');
const pkg = require(packagePath);
const [major, minor, patch] = pkg.version.split('.').map(Number);
let newVersion;
switch (bumpType) {
case 'major':
newVersion = `${major + 1}.0.0`;
break;
case 'minor':
newVersion = `${major}.${minor + 1}.0`;
break;
case 'patch':
default:
newVersion = `${major}.${minor}.${patch + 1}`;
break;
}
const oldVersion = pkg.version;
pkg.version = newVersion;
fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2) + '\n');
console.log(`✓ Bumped version: ${oldVersion}${newVersion}`);
console.log(`\nNext steps:`);
console.log(` 1. Review the change: git diff package.json`);
console.log(` 2. Commit: git add package.json && git commit -m "Bump version to ${newVersion}"`);
console.log(` 3. (Optional) Tag: git tag v${newVersion}`);
console.log(` 4. Build to see full version: npm run build`);

View File

@@ -0,0 +1,63 @@
// scripts/generate-version.js - Generate version info from git
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const pkg = require('../package.json');
try {
const gitHash = execSync('git rev-parse --short HEAD').toString().trim();
const gitBranch = execSync('git rev-parse --abbrev-ref HEAD').toString().trim();
const gitDate = execSync('git log -1 --format=%cd --date=format:%Y-%m-%d').toString().trim();
const isDirty = execSync('git status --porcelain').toString().trim() !== '';
const version = {
version: `${pkg.version}+${gitHash}${isDirty ? '-dirty' : ''}`,
semver: pkg.version,
commit: gitHash,
branch: gitBranch,
buildDate: new Date().toISOString(),
gitDate: gitDate,
};
fs.writeFileSync(
path.join(__dirname, '../src/version.json'),
JSON.stringify(version, null, 2)
);
// Also generate version.ts for better Vite/TypeScript compatibility
const versionTs = `// Auto-generated by scripts/generate-version.js
export const VERSION_INFO = ${JSON.stringify(version, null, 2)} as const;
`;
fs.writeFileSync(
path.join(__dirname, '../src/version.ts'),
versionTs
);
console.log(`✓ Generated version: ${version.version}`);
console.log(` Semver: ${version.semver}, Commit: ${version.commit}, Branch: ${version.branch}`);
} catch (error) {
console.warn('⚠ Could not generate git version, using package.json fallback');
const version = {
version: pkg.version,
semver: pkg.version,
commit: 'unknown',
branch: 'unknown',
buildDate: new Date().toISOString(),
gitDate: 'unknown',
};
fs.writeFileSync(
path.join(__dirname, '../src/version.json'),
JSON.stringify(version, null, 2)
);
const versionTs = `// Auto-generated by scripts/generate-version.js
export const VERSION_INFO = ${JSON.stringify(version, null, 2)} as const;
`;
fs.writeFileSync(
path.join(__dirname, '../src/version.ts'),
versionTs
);
console.log(`✓ Fallback version: ${version.version}`);
}