diff --git a/packages/react-native/scripts/ios-prebuild.js b/packages/react-native/scripts/ios-prebuild.js index 332d4d6e2a3..a0dbe3b6da8 100644 --- a/packages/react-native/scripts/ios-prebuild.js +++ b/packages/react-native/scripts/ios-prebuild.js @@ -11,7 +11,7 @@ const {prepareHermesArtifactsAsync} = require('./ios-prebuild/hermes'); const { createFolderIfNotExists, - prebuildLog, + createLogger, throwIfOnEden, } = require('./ios-prebuild/utils'); const {execSync} = require('child_process'); @@ -24,6 +24,8 @@ const packageJsonPath = path.join( 'package.json', ); +const prebuildLog = createLogger('Prebuild'); + // $FlowIgnore[unsupported-syntax] const {version: currentVersion} = require(packageJsonPath); diff --git a/packages/react-native/scripts/ios-prebuild/hermes.js b/packages/react-native/scripts/ios-prebuild/hermes.js index 5f9033acab9..7bbf94a0bed 100644 --- a/packages/react-native/scripts/ios-prebuild/hermes.js +++ b/packages/react-native/scripts/ios-prebuild/hermes.js @@ -8,12 +8,15 @@ * @format */ +const {createLogger} = require('./utils'); const {execSync} = require('child_process'); const fs = require('fs'); const path = require('path'); const stream = require('stream'); const {promisify} = require('util'); + const pipeline = promisify(stream.pipeline); +const hermesLog = createLogger('Hermes'); /** * Downloads hermes artifacts from the specified version and build type. If you want to specify a specific @@ -359,22 +362,6 @@ function abort(message /*: string */) { throw new Error(message); } -function hermesLog( - message /*: string */, - level /*: 'info' | 'warning' | 'error' */ = 'warning', -) { - // Simple log coloring for terminal output - const prefix = '[Hermes] '; - 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(prefix + message)); -} - module.exports = { prepareHermesArtifactsAsync, }; diff --git a/packages/react-native/scripts/ios-prebuild/utils.js b/packages/react-native/scripts/ios-prebuild/utils.js index 7f5143dbd55..a433c28cf6e 100644 --- a/packages/react-native/scripts/ios-prebuild/utils.js +++ b/packages/react-native/scripts/ios-prebuild/utils.js @@ -37,24 +37,28 @@ function throwIfOnEden() { throw new Error('Cannot prepare the iOS prebuilds on an Eden checkout'); } -function prebuildLog( - message /*: string */, - level /*: 'info' | 'warning' | 'error' */ = 'warning', -) { - // Simple log coloring for terminal output - const prefix = '[Prebuild] '; - 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`; - } +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(prefix + message)); + console.log(colorFn(resolvedPrefix) + message); + }; } module.exports = { createFolderIfNotExists, throwIfOnEden, - prebuildLog, + createLogger, };