53 lines
1.6 KiB
JavaScript
53 lines
1.6 KiB
JavaScript
import { execSync } from 'child_process';
|
|
import fs from 'fs';
|
|
import https from 'https';
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
const url =
|
|
'https://github.com/tomhula/JecnaAPI/releases/download/v10.3.5/JecnaapiIOS-v10.3.5-xcframework.zip';
|
|
const iosDir = path.join(__dirname, '..', 'ios');
|
|
const zipPath = path.join(iosDir, 'framework.zip');
|
|
|
|
if (fs.existsSync(path.join(iosDir, 'JecnaapiIOS.xcframework'))) {
|
|
console.log('JecnaapiIOS XCFramework already exists.');
|
|
process.exit(0);
|
|
}
|
|
|
|
console.log('Downloading JecnaapiIOS XCFramework...');
|
|
|
|
function download(url, dest) {
|
|
return new Promise((resolve, reject) => {
|
|
https
|
|
.get(url, (res) => {
|
|
if (res.statusCode === 301 || res.statusCode === 302) {
|
|
return download(res.headers.location, dest).then(resolve).catch(reject);
|
|
}
|
|
if (res.statusCode !== 200) {
|
|
return reject(new Error(`Server responded with status code ${res.statusCode}`));
|
|
}
|
|
const file = fs.createWriteStream(dest);
|
|
res.pipe(file);
|
|
file.on('finish', () => {
|
|
file.close(resolve);
|
|
});
|
|
})
|
|
.on('error', reject);
|
|
});
|
|
}
|
|
|
|
download(url, zipPath)
|
|
.then(() => {
|
|
console.log('Unzipping framework...');
|
|
execSync(`unzip -o -q "${zipPath}" -d "${iosDir}"`);
|
|
fs.unlinkSync(zipPath);
|
|
console.log('iOS framework successfully linked.');
|
|
})
|
|
.catch((err) => {
|
|
console.error('Failed to download framework:', err);
|
|
process.exit(1);
|
|
});
|