Skip to content

Commit ef29e22

Browse files
committed
refactor: extract rn version printer
1 parent af94f67 commit ef29e22

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

packages/create-react-native-library/src/index.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
type Args,
1919
} from './input';
2020
import { getDependencyVersionsFromExample } from './exampleApp/dependencies';
21-
import { printErrorHelp, printNextSteps } from './inform';
21+
import { printErrorHelp, printNextSteps, printUsedRNVersion } from './inform';
2222

2323
const FALLBACK_BOB_VERSION = '0.32.0';
2424

@@ -82,22 +82,8 @@ async function create(_argv: yargs.Arguments<Args>) {
8282

8383
await fs.mkdirp(folder);
8484

85-
if (answers.reactNativeVersion != null) {
86-
if (config.example === 'vanilla') {
87-
console.log(
88-
`${kleur.blue('ℹ')} Using ${kleur.cyan(
89-
`react-native@${answers.reactNativeVersion}`
90-
)} for the example`
91-
);
92-
} else {
93-
console.warn(
94-
`${kleur.yellow(
95-
'⚠'
96-
)} Ignoring --react-native-version for unsupported example type: ${kleur.cyan(
97-
config.example
98-
)}`
99-
);
100-
}
85+
if (answers.reactNativeVersion !== null) {
86+
printUsedRNVersion(answers.reactNativeVersion, config);
10187
}
10288

10389
const spinner = ora().start();

packages/create-react-native-library/src/inform.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,24 @@ export function printErrorHelp(message: string, error: Error) {
122122

123123
process.exit(1);
124124
}
125+
126+
export function printUsedRNVersion(
127+
version: string,
128+
config: TemplateConfiguration
129+
) {
130+
if (config.example === 'vanilla') {
131+
console.log(
132+
`${kleur.blue('ℹ')} Using ${kleur.cyan(
133+
`react-native@${version}`
134+
)} for the example`
135+
);
136+
} else {
137+
console.warn(
138+
`${kleur.yellow(
139+
'⚠'
140+
)} Ignoring --react-native-version for unsupported example type: ${kleur.cyan(
141+
config.example
142+
)}`
143+
);
144+
}
145+
}

0 commit comments

Comments
 (0)