|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +import { readFileSync } from 'fs'; |
| 4 | +import { fileURLToPath } from 'url'; |
| 5 | +import { dirname, join } from 'path'; |
| 6 | + |
| 7 | +const __filename = fileURLToPath(import.meta.url); |
| 8 | +const __dirname = dirname(__filename); |
| 9 | +const projectRoot = join(__dirname, '..'); |
| 10 | + |
| 11 | +interface PackageJson { |
| 12 | + version: string; |
| 13 | + [key: string]: any; |
| 14 | +} |
| 15 | + |
| 16 | +interface ManifestJson { |
| 17 | + version: string; |
| 18 | + [key: string]: any; |
| 19 | +} |
| 20 | + |
| 21 | +function readJsonFile<T>(filePath: string): T { |
| 22 | + try { |
| 23 | + const content = readFileSync(filePath, 'utf8'); |
| 24 | + return JSON.parse(content) as T; |
| 25 | + } catch (error) { |
| 26 | + console.error(`Error reading ${filePath}:`, (error as Error).message); |
| 27 | + process.exit(1); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +function main(): void { |
| 32 | + console.log('Checking version consistency between package.json and manifest.json...'); |
| 33 | + |
| 34 | + const packageJsonPath = join(projectRoot, 'package.json'); |
| 35 | + const manifestJsonPath = join(projectRoot, 'manifest.json'); |
| 36 | + |
| 37 | + const packageJson = readJsonFile<PackageJson>(packageJsonPath); |
| 38 | + const manifestJson = readJsonFile<ManifestJson>(manifestJsonPath); |
| 39 | + |
| 40 | + const packageVersion = packageJson.version; |
| 41 | + const manifestVersion = manifestJson.version; |
| 42 | + |
| 43 | + console.log(`package.json version: ${packageVersion}`); |
| 44 | + console.log(`manifest.json version: ${manifestVersion}`); |
| 45 | + |
| 46 | + if (packageVersion === manifestVersion) { |
| 47 | + console.log('✅ Versions match!'); |
| 48 | + process.exit(0); |
| 49 | + } else { |
| 50 | + console.error('❌ Version mismatch detected!'); |
| 51 | + console.error(`Expected both files to have the same version, but found:`); |
| 52 | + console.error(` package.json: ${packageVersion}`); |
| 53 | + console.error(` manifest.json: ${manifestVersion}`); |
| 54 | + console.error('Please update both files to have matching versions.'); |
| 55 | + process.exit(1); |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +main(); |
0 commit comments