-
-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathpatch_ios_podspec.js
More file actions
100 lines (79 loc) · 3.15 KB
/
patch_ios_podspec.js
File metadata and controls
100 lines (79 loc) · 3.15 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env node
/**
* Standalone script to patch iOS podspec file with app version and revision
*
* Usage:
* node scripts/patch_ios_podspec.js [webf-directory]
*
* If no directory is specified, defaults to 'webf' relative to the project root.
*/
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
/**
* Patch the iOS podspec file with app version and revision
* @param {string} webfDir - Path to the WebF package directory
*/
function patchIOSPodspec(webfDir) {
console.log('Patching iOS podspec file...');
try {
// Get git revision
const gitHead = execSync('git rev-parse --short HEAD', {
encoding: 'utf-8',
cwd: path.join(__dirname, '../')
}).trim();
// Get full version string with QuickJS info
const fullAppVer = execSync('node bridge/scripts/get_app_ver.js', {
encoding: 'utf-8',
cwd: path.join(__dirname, '../')
}).trim();
// Extract just the app version and QuickJS version
const appVerMatch = fullAppVer.match(/^([\w\.\+\-]+)\/QuickJS: (.+)$/);
const appVer = appVerMatch ? appVerMatch[1] : fullAppVer;
const quickjsVer = appVerMatch ? appVerMatch[2].trim() : '2025-04-26'; // Default if not found
const podspecPath = path.join(webfDir, 'ios/webf.podspec');
if (!fs.existsSync(podspecPath)) {
console.error(`Error: iOS podspec not found at ${podspecPath}`);
process.exit(1);
}
// Read the podspec file
let podspecContent = fs.readFileSync(podspecPath, { encoding: 'utf-8' });
// Replace APP_REV, APP_VERSION, and CONFIG_VERSION in podspec
podspecContent = podspecContent.replace(/APP_REV=\\\\"[^\\]*\\\\"/, `APP_REV=\\\\"${gitHead}\\\\"`);
podspecContent = podspecContent.replace(/APP_VERSION=\\\\"[^\\]*\\\\"/, `APP_VERSION=\\\\"${appVer}\\\\"`);
podspecContent = podspecContent.replace(/CONFIG_VERSION=\\\\"[^\\]*\\\\"/, `CONFIG_VERSION=\\\\"${quickjsVer}\\\\"`);
// Write the updated content back
fs.writeFileSync(podspecPath, podspecContent);
console.log(`✅ iOS podspec patched successfully:`);
console.log(` Revision: ${gitHead}`);
console.log(` Version: ${appVer}`);
console.log(` QuickJS: ${quickjsVer}`);
console.log(` File: ${podspecPath}`);
} catch (error) {
console.error('❌ Error patching iOS podspec:', error.message);
process.exit(1);
}
}
// Main execution
function main() {
// Parse command line arguments
const args = process.argv.slice(2);
// Default to 'webf' directory if no argument provided
const webfDir = args[0] || path.join(__dirname, '../webf');
// Convert to absolute path
const absoluteWebfDir = path.resolve(webfDir);
console.log(`Using WebF directory: ${absoluteWebfDir}`);
// Check if the directory exists
if (!fs.existsSync(absoluteWebfDir)) {
console.error(`Error: WebF directory does not exist: ${absoluteWebfDir}`);
process.exit(1);
}
// Patch the iOS podspec
patchIOSPodspec(absoluteWebfDir);
}
// Run the script if called directly
if (require.main === module) {
main();
}
// Export for use as a module
module.exports = { patchIOSPodspec };