55 * @format
66 */
77
8- import chalk from 'chalk' ;
98import { execSync } from 'child_process' ;
109import * as findUp from 'find-up' ;
10+ import { styleText } from 'node:util' ;
1111import * as fs from 'fs' ;
1212import * as npmFetch from 'npm-registry-fetch' ;
1313import prompts from 'prompts' ;
@@ -60,7 +60,7 @@ function getNpmRegistryUrl(): string {
6060}
6161
6262function getReactNativeAppName ( ) {
63- console . log ( `Reading ${ chalk . cyan ( 'application name' ) } from package.json…` ) ;
63+ console . log ( `Reading ${ styleText ( 'cyan' , 'application name' ) } from package.json…` ) ;
6464 const cwd = process . cwd ( ) ;
6565 const pkgJsonPath = findUp . sync ( 'package.json' , { cwd} ) ;
6666 if ( ! pkgJsonPath ) {
@@ -73,7 +73,7 @@ function getReactNativeAppName() {
7373 if ( ! name ) {
7474 const appJsonPath = findUp . sync ( 'app.json' , { cwd} ) ;
7575 if ( appJsonPath ) {
76- console . log ( `Reading ${ chalk . cyan ( 'application name' ) } from app.json…` ) ;
76+ console . log ( `Reading ${ styleText ( 'cyan' , 'application name' ) } from app.json…` ) ;
7777 name = JSON . parse ( fs . readFileSync ( appJsonPath , 'utf8' ) ) . name ;
7878 }
7979 }
@@ -84,7 +84,7 @@ function getReactNativeAppName() {
8484}
8585
8686function getPackageVersion ( packageName : string , exitOnError : boolean = true ) {
87- console . log ( `Reading ${ chalk . cyan ( packageName ) } version from node_modules…` ) ;
87+ console . log ( `Reading ${ styleText ( 'cyan' , packageName ) } version from node_modules…` ) ;
8888
8989 try {
9090 const pkgJsonPath = require . resolve ( `${ packageName } /package.json` , {
@@ -112,8 +112,8 @@ function getReactNativeMacOSVersion() {
112112}
113113
114114function errorOutOnUnsupportedVersionOfReactNative ( rnVersion : string ) : never {
115- const version = chalk . cyan ( rnVersion ) ;
116- const supportedVersions = chalk . cyan ( '>=0.60' ) ;
115+ const version = styleText ( 'cyan' , rnVersion ) ;
116+ const supportedVersions = styleText ( 'cyan' , '>=0.60' ) ;
117117 printError (
118118 `Unsupported version of ${ RNPKG } : ${ version } \n${ MACOSPKG } supports ${ RNPKG } versions ${ supportedVersions } ` ,
119119 ) ;
@@ -208,16 +208,16 @@ function isProjectUsingYarn(cwd: string) {
208208 * Outputs decorated version of the package for the CLI
209209 */
210210function printPkg ( name : string , version ?: string ) {
211- return `${ chalk . yellow ( name ) } ${
212- version ? `${ chalk . grey ( ' @') } ${ chalk . cyan ( version ) } ` : ''
211+ return `${ styleText ( 'yellow' , name ) } ${
212+ version ? `${ styleText ( 'gray' , ' @') } ${ styleText ( 'cyan' , version ) } ` : ''
213213 } `;
214214}
215215
216216/**
217217 * Prints decorated version of console.error to the CLI
218218 */
219219function printError ( message : string , ...optionalParams : any [ ] ) {
220- console . error ( chalk . red ( chalk . bold ( message ) ) , ...optionalParams ) ;
220+ console . error ( styleText ( [ 'red' , ' bold' ] , message ) , ...optionalParams ) ;
221221}
222222
223223/**
@@ -237,8 +237,8 @@ async function validatePeerDependencies(
237237 const requiredRN = peerDeps [ RNPKG ] ;
238238 if ( ! semver . satisfies ( installedRNVersion , requiredRN ) ) {
239239 console . warn (
240- chalk . yellow (
241- `\n${ chalk . bold ( 'Warning:' ) } ${ printPkg (
240+ styleText ( 'yellow' ,
241+ `\n${ styleText ( 'bold' , 'Warning:' ) } ${ printPkg (
242242 MACOSPKG ,
243243 macosVersion ,
244244 ) } requires ${ printPkg ( RNPKG , requiredRN ) } , ` +
@@ -278,7 +278,7 @@ async function validatePeerDependencies(
278278
279279 if ( ! argv . version ) {
280280 console . log (
281- `Latest matching version of ${ chalk . green ( MACOSPKG ) } for ${ printPkg (
281+ `Latest matching version of ${ styleText ( 'green' , MACOSPKG ) } for ${ printPkg (
282282 RNPKG ,
283283 reactNativeVersion ,
284284 ) } is ${ printPkg ( MACOSPKG , reactNativeMacOSResolvedVersion ) } .`,
@@ -287,20 +287,20 @@ async function validatePeerDependencies(
287287 if ( semver . prerelease ( reactNativeMacOSResolvedVersion ) ) {
288288 console . warn (
289289 `
290- ${ printPkg ( MACOSPKG , reactNativeMacOSResolvedVersion ) } is a ${ chalk . bgYellow (
290+ ${ printPkg ( MACOSPKG , reactNativeMacOSResolvedVersion ) } is a ${ styleText ( 'bgYellow' ,
291291 'pre-release' ,
292292 ) } version.
293293The latest supported version is ${ printPkg (
294294 MACOSPKG ,
295295 reactNativeMacOSLatestVersion ,
296296 ) } .
297- You can either downgrade your version of ${ chalk . yellow ( RNPKG ) } to ${ chalk . cyan (
297+ You can either downgrade your version of ${ styleText ( 'yellow' , RNPKG ) } to ${ styleText ( 'cyan' ,
298298 getMatchingReactNativeSemVerForReactNativeMacOSVersion (
299299 reactNativeMacOSLatestVersion ,
300300 ) ,
301- ) } , or continue with a ${ chalk . bgYellow (
301+ ) } , or continue with a ${ styleText ( 'bgYellow' ,
302302 'pre-release' ,
303- ) } version of ${ chalk . yellow ( MACOSPKG ) } .
303+ ) } version of ${ styleText ( 'yellow' , MACOSPKG ) } .
304304` ,
305305 ) ;
306306
@@ -358,16 +358,16 @@ You can either downgrade your version of ${chalk.yellow(RNPKG)} to ${chalk.cyan(
358358 `Failed to install ${ printPkg ( MACOSPKG , version ) } .\n` +
359359 `This can happen if there is a peer dependency mismatch between ` +
360360 `${ RNPKG } and ${ MACOSPKG } .\n` +
361- `Check that your installed version of ${ chalk . yellow ( RNPKG ) } is compatible ` +
361+ `Check that your installed version of ${ styleText ( 'yellow' , RNPKG ) } is compatible ` +
362362 `with ${ printPkg ( MACOSPKG , version ) } .` ,
363363 ) ;
364364 process . exit ( EXITCODE_UNKNOWN_ERROR ) ;
365365 }
366366
367- console . log ( `${ pkgLatest } ${ chalk . green ( 'successfully installed!' ) } ` ) ;
367+ console . log ( `${ pkgLatest } ${ styleText ( 'green' , 'successfully installed!' ) } ` ) ;
368368 } else {
369369 console . log (
370- `${ chalk . green ( 'Latest version' ) } of ${ pkgLatest } already installed.` ,
370+ `${ styleText ( 'green' , 'Latest version' ) } of ${ pkgLatest } already installed.` ,
371371 ) ;
372372 }
373373
0 commit comments