mirror of
https://github.com/MeshEnvy/mesh-forge.git
synced 2026-08-02 06:53:14 +02:00
feat: Implement firmware versioning for custom builds by generating available versions, adding version selection to profiles, and integrating it into the custom build workflow.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { execSync } from 'node:child_process';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
const FIRMWARE_DIR = path.resolve(__dirname, '../vendor/firmware');
|
||||
const OUTPUT_FILE = path.resolve(__dirname, '../src/constants/versions.ts');
|
||||
|
||||
function getVersions() {
|
||||
try {
|
||||
// Run git tag in the firmware directory
|
||||
const output = execSync('git tag', { cwd: FIRMWARE_DIR, encoding: 'utf-8' });
|
||||
|
||||
// Filter and sort tags
|
||||
// We are looking for tags like v2.5.0...
|
||||
const tags = output
|
||||
.split('\n')
|
||||
.map(tag => tag.trim())
|
||||
.filter(tag => tag.startsWith('v') && tag.includes('.'))
|
||||
// Simple sort for now, ideally semver sort but string sort works okay for fixed format vX.Y.Z
|
||||
// We want reverse sort to show latest first
|
||||
.sort((a, b) => b.localeCompare(a, undefined, { numeric: true, sensitivity: 'base' }));
|
||||
|
||||
return tags;
|
||||
} catch (error) {
|
||||
console.error('Error getting git tags:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function generateFile(versions) {
|
||||
const content = `// This file is auto-generated by scripts/generate-versions.js
|
||||
export const VERSIONS = ${JSON.stringify(versions, null, '\t')} as const;
|
||||
|
||||
export type FirmwareVersion = typeof VERSIONS[number];
|
||||
`;
|
||||
|
||||
fs.writeFileSync(OUTPUT_FILE, content);
|
||||
console.log(`Generated ${OUTPUT_FILE} with ${versions.length} versions`);
|
||||
}
|
||||
|
||||
const versions = getVersions();
|
||||
generateFile(versions);
|
||||
Reference in New Issue
Block a user