Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
69 lines
2.1 KiB
JavaScript
Executable File
69 lines
2.1 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
/**
|
|
* Require a package version bump before pushing changes to the frontend repo.
|
|
* Usage: node scripts/check-version-bump.mjs <remote_sha> <local_sha>
|
|
*/
|
|
import { execFileSync } from 'node:child_process'
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
const PACKAGE_PATH = 'package.json'
|
|
const ZERO = '0000000000000000000000000000000000000000'
|
|
const [remoteSha, localSha] = process.argv.slice(2)
|
|
|
|
function gitShow(ref, filePath) {
|
|
try {
|
|
return execFileSync('git', ['show', `${ref}:${filePath}`], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] })
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
function readVersion(raw) {
|
|
try {
|
|
const version = JSON.parse(raw).version
|
|
return typeof version === 'string' ? version.trim() : null
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
function isGreater(local, remote) {
|
|
const parse = (version) => /^([0-9]+)\.([0-9]+)\.([0-9]+)(?:[-+].*)?$/.exec(version)?.slice(1).map(Number)
|
|
const localParts = parse(local)
|
|
const remoteParts = parse(remote)
|
|
|
|
if (!localParts || !remoteParts) return local !== remote
|
|
for (let index = 0; index < localParts.length; index += 1) {
|
|
if (localParts[index] > remoteParts[index]) return true
|
|
if (localParts[index] < remoteParts[index]) return false
|
|
}
|
|
return false
|
|
}
|
|
|
|
if (!remoteSha || !localSha) {
|
|
console.error('Usage: check-version-bump.mjs <remote_sha> <local_sha>')
|
|
process.exit(1)
|
|
}
|
|
|
|
if (remoteSha === ZERO || localSha === ZERO || remoteSha === localSha) process.exit(0)
|
|
|
|
const localVersion = readVersion(gitShow(localSha, PACKAGE_PATH) ?? readFileSync(PACKAGE_PATH, 'utf8'))
|
|
const remoteRaw = gitShow(remoteSha, PACKAGE_PATH)
|
|
const remoteVersion = remoteRaw ? readVersion(remoteRaw) : null
|
|
|
|
if (!localVersion) {
|
|
console.error(`❌ Could not read version from ${PACKAGE_PATH}`)
|
|
process.exit(1)
|
|
}
|
|
|
|
if (!remoteVersion) process.exit(0)
|
|
|
|
if (!isGreater(localVersion, remoteVersion)) {
|
|
console.error('\n❌ Push blocked: bump package.json version before pushing.')
|
|
console.error(` remote: ${remoteVersion}`)
|
|
console.error(` local: ${localVersion}\n`)
|
|
process.exit(1)
|
|
}
|
|
|
|
console.log(`✓ Frontend version bumped: ${remoteVersion} → ${localVersion}`)
|