File size: 2,942 Bytes
d97b8f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**

 * Pre-build script to automatically increment the patch version

 * This script runs before each build to bump the patch version

 */

import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

// Get current file's directory in ESM
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

// Create a debug log file
const logFile = path.resolve(__dirname, '../../increment-debug.log');
fs.writeFileSync(logFile, `Script started at ${new Date().toISOString()}\n`, 'utf8');

// Log function that writes to both console and file
const log = (message) => {
  console.log(message);
  fs.appendFileSync(logFile, message + '\n', 'utf8');
};

log('====================================');
log('πŸ“¦ VERSION INCREMENT SCRIPT RUNNING');
log('====================================');

// Path to the version.ts file
const versionFilePath = path.resolve(__dirname, '../lib/version.ts');
// Path to package.json
const packageJsonPath = path.resolve(__dirname, '../../package.json');

try {
  // Read the current version.ts file
  const versionFileContent = fs.readFileSync(versionFilePath, 'utf8');
  
  // Extract current version values
  const versionMatch = versionFileContent.match(/export const APP_VERSION: Version = {\s*major: (\d+),\s*minor: (\d+),\s*patch: (\d+)\s*};/);
  
  if (!versionMatch) {
    const errorMsg = '❌ Could not find version information in version.ts';
    log(errorMsg);
    process.exit(1);
  }
  
  const currentMajor = parseInt(versionMatch[1]);
  const currentMinor = parseInt(versionMatch[2]);
  const currentPatch = parseInt(versionMatch[3]);
  
  // Increment patch version
  const newPatch = currentPatch + 1;
  
  log(`πŸ”„ Incrementing version from ${currentMajor}.${currentMinor}.${currentPatch} to ${currentMajor}.${currentMinor}.${newPatch}`);
  
  // Update version.ts
  const updatedVersionContent = versionFileContent.replace(
    /export const APP_VERSION: Version = {\s*major: \d+,\s*minor: \d+,\s*patch: \d+\s*};/,
    `export const APP_VERSION: Version = {\n  major: ${currentMajor},\n  minor: ${currentMinor},\n  patch: ${newPatch}\n};`
  );
  
  fs.writeFileSync(versionFilePath, updatedVersionContent, 'utf8');
  log('βœ… Updated version.ts successfully');
  
  // Update package.json
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
  packageJson.version = `${currentMajor}.${currentMinor}.${newPatch}`;
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), 'utf8');
  log('βœ… Updated package.json successfully');
  
  log('====================================');
  log(`πŸ“ NEW VERSION: ${currentMajor}.${currentMinor}.${newPatch}`);
  log('====================================');
  
} catch (error) {
  const errorMsg = `❌ Error updating version: ${error.message}`;
  log(errorMsg);
  process.exit(1);
}