38 lines
1.3 KiB
JavaScript
38 lines
1.3 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
import { readFile } from 'node:fs/promises'
|
|
import { pathToFileURL } from 'node:url'
|
|
|
|
const SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/
|
|
|
|
export async function resolveInternalReleaseVersion(configPath, explicitVersion = '') {
|
|
const config = JSON.parse(await readFile(configPath, 'utf8'))
|
|
const configuredVersion = String(config.version ?? '').trim()
|
|
|
|
if (!SEMVER.test(configuredVersion)) {
|
|
throw new Error(`tauri.conf.json must contain a valid semantic version; received: ${configuredVersion || '<empty>'}`)
|
|
}
|
|
|
|
const requestedVersion = explicitVersion.trim()
|
|
if (requestedVersion && requestedVersion !== configuredVersion) {
|
|
throw new Error(`Requested version ${requestedVersion} does not match configured version ${configuredVersion}`)
|
|
}
|
|
|
|
return configuredVersion
|
|
}
|
|
|
|
if (import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
const configPath = process.argv[2]
|
|
if (!configPath) {
|
|
console.error('Usage: node scripts/internal-release-version.mjs <tauri.conf.json> [expected-version]')
|
|
process.exit(2)
|
|
}
|
|
|
|
try {
|
|
console.log(await resolveInternalReleaseVersion(configPath, process.argv[3] ?? ''))
|
|
} catch (error) {
|
|
console.error(error instanceof Error ? error.message : String(error))
|
|
process.exit(1)
|
|
}
|
|
}
|