Skip to content

Commit 83c5332

Browse files
committed
fix: prompt when running init if project already has a config
1 parent 9335b5c commit 83c5332

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ This will ask you few questions about your project and generate a new project in
4141
- TypeScript definitions (uses `tsc` to generate declaration files)
4242
- Android AAR files
4343

44-
If you created a project with `create-react-native-library`, `react-native-builder-bob` is already pre-configured to build your project. You don't need to configure it again.
44+
If you created a project with `create-react-native-library`, `react-native-builder-bob` is **already pre-configured to build your project**. You don't need to configure it again.
4545

4646
The following configuration steps are for projects not created with `create-react-native-library`.
4747

packages/create-react-native-library/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ Usage:
88
npx create-react-native-library@latest react-native-awesome-library
99
```
1010

11+
This will ask you few questions about your project and generate a new project in a folder named `awesome-library`.
12+
1113
See more details on the [GitHub repository](https://github.com/callstack/react-native-builder-bob).

packages/react-native-builder-bob/src/index.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ const FLOW_PRGAMA_REGEX = /\*?\s*@(flow)\b/m;
2626
// eslint-disable-next-line babel/no-unused-expressions
2727
yargs
2828
.command('init', 'configure the package to use bob', {}, async () => {
29-
const pak = path.join(root, 'package.json');
30-
3129
if (isGitDirty()) {
3230
const { shouldContinue } = await prompts({
3331
type: 'confirm',
@@ -37,16 +35,34 @@ yargs
3735
});
3836

3937
if (!shouldContinue) {
40-
process.exit(1);
38+
process.exit(0);
4139
}
4240
}
4341

42+
const pak = path.join(root, 'package.json');
43+
4444
if (!(await fs.pathExists(pak))) {
4545
logger.exit(
4646
`Couldn't find a 'package.json' file in '${root}'. Are you in a project folder?`
4747
);
4848
}
4949

50+
const pkg = JSON.parse(await fs.readFile(pak, 'utf-8'));
51+
const result = explorer.search();
52+
53+
if (result?.config && pkg.devDependencies && name in pkg.devDependencies) {
54+
const { shouldContinue } = await prompts({
55+
type: 'confirm',
56+
name: 'shouldContinue',
57+
message: `The project seems to be already configured with bob. Do you want to overwrite the existing configuration?`,
58+
initial: false,
59+
});
60+
61+
if (!shouldContinue) {
62+
process.exit(0);
63+
}
64+
}
65+
5066
const { source } = await prompts({
5167
type: 'text',
5268
name: 'source',
@@ -72,8 +88,6 @@ yargs
7288
return;
7389
}
7490

75-
const pkg = JSON.parse(await fs.readFile(pak, 'utf-8'));
76-
7791
pkg.devDependencies = Object.fromEntries(
7892
[
7993
...Object.entries(pkg.devDependencies || {}),

0 commit comments

Comments
 (0)