|
35 | 35 | * }} ProjectConfig |
36 | 36 | */ |
37 | 37 |
|
38 | | -const chalk = require('chalk'); |
39 | | -const child_process = require('child_process'); |
40 | | -const path = require('path'); |
| 38 | +const child_process = require('node:child_process'); |
| 39 | +const path = require('node:path'); |
41 | 40 |
|
42 | | -const {logger, CLIError, getDefaultUserTerminal} = (() => { |
43 | | - const cli = require.resolve('@react-native-community/cli/package.json'); |
| 41 | +const colors = (() => { |
| 42 | + const {WriteStream} = require('node:tty'); |
| 43 | + if (WriteStream.prototype.hasColors() && |
| 44 | + !process.env.NODE_TEST_CONTEXT && |
| 45 | + process.env.NODE_ENV !== 'test' |
| 46 | + ) { |
| 47 | + return { |
| 48 | + bold: (s) => '\u001B[1m' + s + '\u001B[22m', |
| 49 | + dim: (s) => '\u001B[2m' + s + '\u001B[22m', |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + const passthrough = (s) => s; |
| 54 | + return { bold: passthrough, dim: passthrough }; |
| 55 | +})(); |
| 56 | + |
| 57 | +const {logger, CLIError, getDefaultUserTerminal} = ((projectRoot = process.cwd()) => { |
| 58 | + const cli = require.resolve('@react-native-community/cli/package.json', {paths: [projectRoot]}); |
44 | 59 | const options = {paths: [path.dirname(cli)]}; |
45 | 60 | const tools = require.resolve('@react-native-community/cli-tools', options); |
46 | 61 | return require(tools); |
@@ -92,7 +107,7 @@ function parseArgs(ctx, args) { |
92 | 107 | logger.info( |
93 | 108 | `Found Xcode ${ |
94 | 109 | xcodeProject.isWorkspace ? 'workspace' : 'project' |
95 | | - } "${chalk.bold(xcodeProject.name)}"`, |
| 110 | + } "${colors.bold(xcodeProject.name)}"`, |
96 | 111 | ); |
97 | 112 |
|
98 | 113 | return {sourceDir, xcodeProject, scheme}; |
@@ -146,7 +161,7 @@ async function run(sourceDir, xcodeProject, scheme, args) { |
146 | 161 | .trim(); |
147 | 162 |
|
148 | 163 | logger.info( |
149 | | - `Launching app "${chalk.bold(bundleID)}" from "${chalk.bold(appPath)}"`, |
| 164 | + `Launching app "${colors.bold(bundleID)}" from "${colors.bold(appPath)}"`, |
150 | 165 | ); |
151 | 166 |
|
152 | 167 | child_process.exec( |
@@ -179,7 +194,7 @@ function buildProject(sourceDir, xcodeProject, scheme, args) { |
179 | 194 | scheme, |
180 | 195 | ]; |
181 | 196 | logger.info( |
182 | | - `Building ${chalk.dim( |
| 197 | + `Building ${colors.dim( |
183 | 198 | `(using "xcodebuild ${xcodebuildArgs.join(' ')}")`, |
184 | 199 | )}`, |
185 | 200 | ); |
|
0 commit comments