Skip to content

Commit e969c89

Browse files
authored
refactor(crnl): split the index file (#688)
### Summary The previous `index.ts` file of `create-react-native-library` was too long and complicated to maintain. This PR splits the file a bit ### Test plan 1. We have to make sure that the behavior hasn't changed at all. CI pipeline is the best way to check this.
1 parent 97baa78 commit e969c89

File tree

10 files changed

+1135
-929
lines changed

10 files changed

+1135
-929
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import assert from 'node:assert';
2+
import path from 'path';
3+
import fs from 'fs-extra';
4+
import type { ExampleApp } from '../input';
5+
6+
export async function getDependencyVersionsFromExampleApp(
7+
folder: string,
8+
exampleAppType: ExampleApp
9+
) {
10+
const examplePackageJson = await fs.readJSON(
11+
path.join(folder, 'example', 'package.json')
12+
);
13+
14+
const react: string = examplePackageJson.dependencies?.react;
15+
assert(
16+
react !== undefined,
17+
"The generated example app doesn't have React installed."
18+
);
19+
const reactNative: string = examplePackageJson.dependencies?.['react-native'];
20+
assert(
21+
reactNative !== undefined,
22+
"The generated example app doesn't have React Native installed."
23+
);
24+
25+
const devDependencies: Record<string, string> = {
26+
react,
27+
'react-native': reactNative,
28+
};
29+
30+
if (exampleAppType === 'vanilla') {
31+
// React Native doesn't provide the community CLI as a dependency.
32+
// We have to get read the version from the example app and put to the root package json
33+
const exampleCommunityCLIVersion =
34+
examplePackageJson.devDependencies['@react-native-community/cli'];
35+
assert(
36+
exampleCommunityCLIVersion !== undefined,
37+
"The generated example app doesn't have community CLI installed"
38+
);
39+
40+
devDependencies['@react-native-community/cli'] = exampleCommunityCLIVersion;
41+
}
42+
43+
return {
44+
devDependencies,
45+
};
46+
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import fs from 'fs-extra';
22
import path from 'path';
33
import https from 'https';
4-
import { spawn } from './spawn';
5-
import sortObjectKeys from './sortObjectKeys';
6-
7-
export type ExampleType = 'vanilla' | 'test-app' | 'expo' | 'none';
4+
import { spawn } from '../utils/spawn';
5+
import sortObjectKeys from '../utils/sortObjectKeys';
6+
import type { ExampleApp } from '../input';
87

98
const FILES_TO_DELETE = [
109
'__tests__',
@@ -50,7 +49,7 @@ export default async function generateExampleApp({
5049
bobVersion,
5150
reactNativeVersion = 'latest',
5251
}: {
53-
type: ExampleType;
52+
type: ExampleApp;
5453
dest: string;
5554
arch: 'new' | 'mixed' | 'legacy';
5655
project: {

0 commit comments

Comments
 (0)