-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathcheckVersionAndUpdateBuildInfo.js
More file actions
53 lines (45 loc) · 1.8 KB
/
checkVersionAndUpdateBuildInfo.js
File metadata and controls
53 lines (45 loc) · 1.8 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
/**
* Pre-commit script that checks if package.json version has changed
* and updates build info if necessary
*/
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
const packageJsonPath = path.join(__dirname, '../package.json');
const buildInfoPath = path.join(__dirname, '../src/itblBuildInfo.ts');
// Read current package.json
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
const currentVersion = packageJson.version;
// Read current build info file
let buildInfoVersion = null;
if (fs.existsSync(buildInfoPath)) {
const buildInfoContent = fs.readFileSync(buildInfoPath, 'utf8');
const versionMatch = buildInfoContent.match(/version:\s*['"`]([^'"`]+)['"`]/);
if (versionMatch) {
buildInfoVersion = versionMatch[1];
}
}
console.log(`Current package.json version: ${currentVersion}`);
console.log(`Current build info version: ${buildInfoVersion}`);
// Check if versions are different
if (currentVersion !== buildInfoVersion) {
console.log('Version mismatch detected. Updating build info...');
try {
// Run the build info update
execSync('yarn add_build_info', { stdio: 'inherit' });
// Check if the file was actually modified
const gitStatus = execSync('git status --porcelain src/itblBuildInfo.ts', { encoding: 'utf8' });
if (gitStatus.trim()) {
console.log('Build info file was updated. Adding to commit...');
execSync('git add src/itblBuildInfo.ts', { stdio: 'inherit' });
console.log('Build info file has been staged for commit.');
} else {
console.log('Build info file was not modified.');
}
} catch (error) {
console.error('Error updating build info:', error.message);
process.exit(1);
}
} else {
console.log('Version is up to date. No build info update needed.');
}