Files
react-native/packages/react-native/scripts/ios-prebuild/utils.js
T
Riccardo Cipolleschi f37e983255 Back out "Add more logging around computeNightlyTarballURL" (#52510)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/52510

We reverted this change in the 0.81 release branch

## Changelog:
[Internal] -

Reviewed By: cortinico

Differential Revision: D78007905

fbshipit-source-id: fec3df04423300571f629da19bf95cd82c952f12
2025-07-09 08:12:58 -07:00

110 lines
3.1 KiB
JavaScript

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
/*:: import type {BuildFlavor} from './types'; */
const {execSync} = require('child_process');
const fs = require('fs');
/**
* Creates a folder if it does not exist
* @param {string} folderPath - The path to the folder
* @returns {string} The path to the created or existing folder
*/
function createFolderIfNotExists(folderPath /*:string*/) /*: string */ {
if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath, {recursive: true});
if (!fs.existsSync(folderPath)) {
throw new Error(`Failed to create folder: ${folderPath}`);
}
}
return folderPath;
}
function throwIfOnEden() {
try {
execSync('eden info', {stdio: 'ignore'});
} catch (error) {
// eden info failed, we are not on Eden, do nothing
return;
}
throw new Error('Cannot prepare the iOS prebuilds on an Eden checkout');
}
function createLogger(
prefix /*: string */,
) /*: (message: string, level?: 'info' | 'warning' | 'error') => void */ {
return function (
message /*: string */,
level /*: 'info' | 'warning' | 'error' */ = 'info',
) {
// Simple log coloring for terminal output
const resolvedPrefix = `[${prefix}] `;
let colorFn = (x /*:string*/) => x;
if (process.stdout.isTTY) {
if (level === 'info') colorFn = x => `\x1b[32m${x}\x1b[0m`;
else if (level === 'error') colorFn = x => `\x1b[31m${x}\x1b[0m`;
else colorFn = x => `\x1b[33m${x}\x1b[0m`;
}
console.log(colorFn(resolvedPrefix) + message);
};
}
async function computeNightlyTarballURL(
version /*: string */,
buildType /*: BuildFlavor */,
artifactCoordinate /*: string */,
artifactName /*: string */,
) /*: Promise<string> */ {
const xmlUrl = `https://central.sonatype.com/repository/maven-snapshots/com/facebook/react/${artifactCoordinate}/${version}-SNAPSHOT/maven-metadata.xml`;
const response = await fetch(xmlUrl);
if (!response.ok) {
return '';
}
const xmlText = await response.text();
// Extract the <snapshot> block
const snapshotMatch = xmlText.match(/<snapshot>([\s\S]*?)<\/snapshot>/);
if (!snapshotMatch) {
return '';
}
const snapshotContent = snapshotMatch[1];
// Extract <timestamp> from the snapshot block
const timestampMatch = snapshotContent.match(/<timestamp>(.*?)<\/timestamp>/);
if (!timestampMatch) {
return '';
}
const timestamp = timestampMatch[1];
// Extract <buildNumber> from the snapshot block
const buildNumberMatch = snapshotContent.match(
/<buildNumber>(.*?)<\/buildNumber>/,
);
if (!buildNumberMatch) {
return '';
}
const buildNumber = buildNumberMatch[1];
const fullVersion = `${version}-${timestamp}-${buildNumber}`;
const finalUrl = `https://central.sonatype.com/repository/maven-snapshots/com/facebook/react/${artifactCoordinate}/${version}-SNAPSHOT/${artifactCoordinate}-${fullVersion}-${artifactName}`;
return finalUrl;
}
module.exports = {
createFolderIfNotExists,
throwIfOnEden,
createLogger,
computeNightlyTarballURL,
};