forked from tonyantony300/alt-sendme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-version.js
More file actions
executable file
·61 lines (51 loc) · 1.77 KB
/
validate-version.js
File metadata and controls
executable file
·61 lines (51 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env node
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 rootPackageJsonPath = path.join(__dirname, '../package.json')
const tauriConfigPath = path.join(__dirname, '../src-tauri/tauri.conf.json')
const cargoTomlPath = path.join(__dirname, '../src-tauri/Cargo.toml')
const readmePath = path.join(__dirname, '../README.md')
const rootPackageJson = JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf8'))
const sourceVersion = rootPackageJson.version
if (!sourceVersion) {
console.error('Error: No version found in src-tauri/package.json')
process.exit(1)
}
const versions = {
'package.json': JSON.parse(fs.readFileSync(rootPackageJsonPath, 'utf8'))
.version,
'src-tauri/tauri.conf.json': JSON.parse(
fs.readFileSync(tauriConfigPath, 'utf8')
).version,
'src-tauri/Cargo.toml': (() => {
const cargoToml = fs.readFileSync(cargoTomlPath, 'utf8')
const match = cargoToml.match(/^version = "([\d.]+)"/m)
return match ? match[1] : null
})(),
'README.md badge': (() => {
const readme = fs.readFileSync(readmePath, 'utf8')
const match = readme.match(
/\[badge-version\]:\s*https:\/\/img\.shields\.io\/badge\/version-([\d.]+)-blue/
)
return match ? match[1] : null
})(),
}
let allMatch = true
const mismatches = []
for (const [file, version] of Object.entries(versions)) {
if (version !== sourceVersion) {
allMatch = false
mismatches.push({ file, found: version, expected: sourceVersion })
}
}
if (!allMatch) {
console.error('Version mismatch detected!')
mismatches.forEach(({ file, found, expected }) => {
console.error(` - ${file}: found "${found}", expected "${expected}"`)
})
process.exit(1)
}
process.exit(0)