Skip to content

Commit

Permalink
Merge pull request #8 from Omar-Belghaouti/docs/documentation
Browse files Browse the repository at this point in the history
Docs: Add more documentation
  • Loading branch information
omdxp authored May 13, 2022
2 parents d24d922 + 687958a commit 19332de
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Or
yarn add react-native-help-create --dev
```

- If you want to use it without installing it (using npm cache) run:

```sh
npx react-native-help-create --help
```

## How to use it?

Please follow [this documentation](docs/TOC.md) to see how to use this helper command.
Expand Down
112 changes: 111 additions & 1 deletion docs/CREATING_FILES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

- `rnhc` will not overwrite the existed implementation for all of the `create` commands.

- If you want to overwrite the existed implementation for a specific `create` command you can add the `--overwrite` or `-o` option at the end of the command.

The following points shows how to use the `create` command.

## Components
Expand Down Expand Up @@ -461,6 +463,78 @@ export const Navigation = () => {
};
```

4. To create a navigation file for multiple screens that resides at the root of the `src/screens/` folder, you can run this:

```sh
rnhc create -n <navigation-type> *
```

- This will create the navigation file for all existed screens in the `src/screens/` folder.

You can also run this command to create a navigation file for multiple screens that resides in a specific path under the `src/screens/` folder:

```sh
rnhc create -n <navigation-type> * -f <folder-path>
```

- This will create the navigation file for all existed screens in the `src/screens/<folder-path>/` folder.

- The wildcard `*` can work also for the nested navigations.

- All the sub folders should contain the navigation files so it can be added to the navigation file you want to create, for example take this structure:

```sh
src
└───screens
│ navigation.jsx
├───folder
│ │
│ ├───screen-one
│ │ │ index.jsx
│ │ │ styles.js
│ │ │
│ │ └───functions
│ │ index.js
│ │
│ └───screen-two
│ │ index.jsx
│ │ styles.js
│ │
│ └───functions
│ index.js
├───screen-three
│ │ index.jsx
│ │ styles.js
│ │
│ └───functions
│ index.js
└───screen-four
│ index.jsx
│ styles.js
└───functions
index.js
```

When you try to create a navigation like this:

```sh
rnhc create -n stack *
```

It will contain only `screen-three` and `screen-four` because the `src/screens/folder` does not contain a navigation file.

So if you want to create a navigation file for all existed screens in the `src/screens/` folder, you must take in consideration that all subfolders must contain a navigation file first and then you can either update the navigation file or create a new one.

By updating it means overwriting in other words, so you can just do this:

```sh
rnhc create -n stack * -o
```

## Templates

You can create your screens and components with your defined templates by following these steps:
Expand All @@ -473,7 +547,7 @@ You can create your screens and components with your defined templates by follow
import React, { useEffect } from "react";
import { View, Text } from "react-native";

export default function Component() {
export default function __COMPONENT__() {
useEffect(() => {}, []);

return (
Expand All @@ -486,6 +560,8 @@ export default function Component() {

- There is a restriction in naming these templates which is you should not put dots (`.`) between the name, like this (`component.WithUseEffect.jsx`). It should only contain one dot that makes the extension file like we're doing above.

- You should type `__COMPONENT__` in the template file and it will be replaced with the component name you want to create.

3. After creating your template you can use them to create components or screens as the following:

```sh
Expand Down Expand Up @@ -686,3 +762,37 @@ export const mainReducer = combineReducers({
general,
});
```

## Configuration

With the above steps, you can now create a configuration file which will be used by `rnhc` to create your files with your custom config.

- To create a default configuration file run:

```sh
rnhc create --config
```

- This will create a `rnhc.config.json` file at the root of your project. The file will contain the following:

```json
{
"withStyles": true,
"withFunctions": true,
"withProps": true,
"defaultExports": true,
"componentsRoot": "./src/components",
"screensRoot": "./src/screens",
"reduxRoot": "./src/redux"
}
```

1. `withStyles`: if true, create `styles.js` (or `styles.ts`) file for components and pages, if false, don't create `styles.js` (or `styles.ts`) file, default is true.
2. `withFunctions`: if true, create `functions` folder for pages, if false, don't create `functions` folder, default is true.
3. `withProps`: if true, create props `interface` for components and pages (in TS only), if false, don't create props `interface`, default is true.
4. `defaultExports`: if true, create default export for components and pages, if false, create named export for components and pages, default is true.
5. `componentsRoot`: the root folder for components, default is `./src/components`.
6. `screensRoot`: the root folder for screens, default is `./src/screens`.
7. `reduxRoot`: the root folder for redux, default is `./src/redux`.

- If no configuration file is found or you don't specify some of the configuration, the default configuration will be used.
16 changes: 16 additions & 0 deletions docs/DELETING_FILES.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,19 @@ rnhc delete -r
```sh
src/redux/ does not exist
```

## Configuration

- To delete a configuration file run:

```sh
rnhc delete --config
```

- This will delete the `rnhc.config.json` file at the root of the project.

- If `rnhc.config.json` does not exist, `rnhc` will prompt:

```sh
rnhc.config.json does not exist
```
20 changes: 20 additions & 0 deletions docs/NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,23 @@ rnhc create -s test-screen --ts
```sh
rnhc create -s world-to-react
```

- You can always overwrite your implementation using the `--overwrite` or `-o` option, for example:

```sh
rnhc create -c test-component -o
```

```sh
rnhc create -s test-screen -o
```

```sh
rnhc create -r -o
```

- This is helpful when you want to update your navigation files, for example you already have a navigation file in `src/screens/` folder and you want to update it with the new screens you created:

```sh
rnhc create -n stack * --overwrite
```
2 changes: 2 additions & 0 deletions docs/TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
- [Navigations](./CREATING_FILES.md#navigations)
- [Using templates](./CREATING_FILES.md#templates)
- [Redux](./CREATING_FILES.md#redux)
- [Using configuration](./CREATING_FILES.md#configuration)
3. [Deleting Files](./DELETING_FILES.md)
- [Components](./DELETING_FILES.md#components)
- [Screens](./DELETING_FILES.md#screens)
- [Navigations](./DELETING_FILES.md#navigations)
- [Redux](./DELETING_FILES.md#redux)
- [Configuration](./DELETING_FILES.md#configuration)
4. [Combining Files](./COMBINING_FILES.md)
- [Components](./COMBINING_FILES.md#components)
- [Screens](./COMBINING_FILES.md#screens)
Expand Down

0 comments on commit 19332de

Please sign in to comment.