Skip to content

Commit

Permalink
fix: prompt when running init if project already has a config
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Jul 4, 2023
1 parent 9335b5c commit 83c5332
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ This will ask you few questions about your project and generate a new project in
- TypeScript definitions (uses `tsc` to generate declaration files)
- Android AAR files

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.
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.

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

Expand Down
2 changes: 2 additions & 0 deletions packages/create-react-native-library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ Usage:
npx create-react-native-library@latest react-native-awesome-library
```

This will ask you few questions about your project and generate a new project in a folder named `awesome-library`.

See more details on the [GitHub repository](https://github.com/callstack/react-native-builder-bob).
24 changes: 19 additions & 5 deletions packages/react-native-builder-bob/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ const FLOW_PRGAMA_REGEX = /\*?\s*@(flow)\b/m;
// eslint-disable-next-line babel/no-unused-expressions
yargs
.command('init', 'configure the package to use bob', {}, async () => {
const pak = path.join(root, 'package.json');

if (isGitDirty()) {
const { shouldContinue } = await prompts({
type: 'confirm',
Expand All @@ -37,16 +35,34 @@ yargs
});

if (!shouldContinue) {
process.exit(1);
process.exit(0);
}
}

const pak = path.join(root, 'package.json');

if (!(await fs.pathExists(pak))) {
logger.exit(
`Couldn't find a 'package.json' file in '${root}'. Are you in a project folder?`
);
}

const pkg = JSON.parse(await fs.readFile(pak, 'utf-8'));
const result = explorer.search();

if (result?.config && pkg.devDependencies && name in pkg.devDependencies) {
const { shouldContinue } = await prompts({
type: 'confirm',
name: 'shouldContinue',
message: `The project seems to be already configured with bob. Do you want to overwrite the existing configuration?`,
initial: false,
});

if (!shouldContinue) {
process.exit(0);
}
}

const { source } = await prompts({
type: 'text',
name: 'source',
Expand All @@ -72,8 +88,6 @@ yargs
return;
}

const pkg = JSON.parse(await fs.readFile(pak, 'utf-8'));

pkg.devDependencies = Object.fromEntries(
[
...Object.entries(pkg.devDependencies || {}),
Expand Down

0 comments on commit 83c5332

Please sign in to comment.