/
githubmr
/
facebook-react-native
Обзор
Документация
Войти
/
githubmr
/
facebook-react-native
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/react-native/scripts/ios-prebuild/utils.js
109 строк
3 KB
Riccardo Cipolleschi
Back out "Add more logging around computeNightlyTarballURL" (#52510)
09 июл 2025, 18:12
09 июл 2025, 18:12
f37e983
Код
Авторство
О чём код?
/** * 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, };