refactor: fix output paths

This commit is contained in:
Ben Allfree
2025-12-06 17:15:17 -08:00
parent 3a543de36b
commit b7c5eaa8d0
2 changed files with 240 additions and 245 deletions
+36 -36
View File
@@ -1,49 +1,49 @@
import { execSync } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
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 __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');
const FIRMWARE_DIR = path.resolve(__dirname, "../vendor/firmware")
const OUTPUT_FILE = path.resolve(__dirname, "../constants/versions.ts")
function getVersions() {
try {
// Fetch tags from the meshtastic remote
execSync('git fetch meshtastic --tags', { cwd: FIRMWARE_DIR, encoding: 'utf-8' });
// 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' }));
try {
// Fetch tags from the meshtastic remote
execSync("git fetch meshtastic --tags", { cwd: FIRMWARE_DIR, encoding: "utf-8" })
return tags;
} catch (error) {
console.error('Error getting git tags:', error);
return [];
}
// 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;
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`);
fs.writeFileSync(OUTPUT_FILE, content)
console.log(`Generated ${OUTPUT_FILE} with ${versions.length} versions`)
}
const versions = getVersions();
generateFile(versions);
const versions = getVersions()
generateFile(versions)