Skip to content

Commit 6a2f3da

Browse files
committed
fix: convert enum to union type
1 parent c53fbb7 commit 6a2f3da

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,7 @@ type Answers = {
144144
withRecommendedOptions?: boolean;
145145
};
146146

147-
export enum ExampleType {
148-
Vanilla = 'vanilla',
149-
TestApp = 'test-app',
150-
Expo = 'expo',
151-
}
147+
export type ExampleType = 'vanilla' | 'test-app' | 'expo';
152148

153149
const LANGUAGE_CHOICES: {
154150
title: string;
@@ -639,11 +635,7 @@ async function create(argv: yargs.Arguments<any>) {
639635
: 'legacy';
640636

641637
const example =
642-
hasExample && !local
643-
? type === 'library'
644-
? ExampleType.Expo
645-
: hasExample
646-
: null;
638+
hasExample && !local ? (type === 'library' ? 'expo' : hasExample) : null;
647639

648640
const project = slug.replace(/^(react-native-|@[^/]+\/)/, '');
649641

@@ -729,7 +721,7 @@ async function create(argv: yargs.Arguments<any>) {
729721
await fs.mkdirp(folder);
730722

731723
if (reactNativeVersion != null) {
732-
if (example === ExampleType.Expo) {
724+
if (example === 'expo') {
733725
console.warn(
734726
`${kleur.yellow('⚠')} Ignoring --react-native-version for Expo example`
735727
);

packages/create-react-native-library/src/utils/generateExampleApp.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import fs from 'fs-extra';
22
import path from 'path';
33
import https from 'https';
44
import { spawn } from './spawn';
5-
import { ExampleType } from './../index';
5+
import type { ExampleType } from './../index';
66

77
const FILES_TO_DELETE = [
88
'__tests__',
@@ -108,13 +108,13 @@ export default async function generateExampleApp({
108108
let args: string[] = [];
109109

110110
switch (type) {
111-
case ExampleType.Vanilla:
111+
case 'vanilla':
112112
args = vanillaArgs;
113113
break;
114-
case ExampleType.TestApp:
114+
case 'test-app':
115115
args = testAppArgs;
116116
break;
117-
case ExampleType.Expo:
117+
case 'expo':
118118
args = expoArgs;
119119
break;
120120
}
@@ -149,7 +149,7 @@ export default async function generateExampleApp({
149149
'build:ios': `cd ios && xcodebuild -workspace ${projectName}Example.xcworkspace -scheme ${projectName}Example -configuration Debug -sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO`,
150150
};
151151

152-
if (type !== ExampleType.Expo) {
152+
if (type !== 'expo') {
153153
Object.assign(scripts, SCRIPTS_TO_ADD);
154154
}
155155

@@ -160,7 +160,7 @@ export default async function generateExampleApp({
160160

161161
Object.assign(devDependencies, PACKAGES_TO_ADD_DEV);
162162

163-
if (type === ExampleType.Expo) {
163+
if (type === 'expo') {
164164
const sdkVersion = dependencies.expo.split('.')[0].replace(/[^\d]/, '');
165165

166166
let bundledNativeModules: Record<string, string>;
@@ -204,7 +204,7 @@ export default async function generateExampleApp({
204204
spaces: 2,
205205
});
206206

207-
if (type !== ExampleType.Expo) {
207+
if (type !== 'expo') {
208208
let gradleProperties = await fs.readFile(
209209
path.join(directory, 'android', 'gradle.properties'),
210210
'utf8'

0 commit comments

Comments
 (0)