diff --git a/README.md b/README.md index bd83323..6bc8e34 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/docs/CREATING_FILES.md b/docs/CREATING_FILES.md index 29f7899..9b6a0d4 100644 --- a/docs/CREATING_FILES.md +++ b/docs/CREATING_FILES.md @@ -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 @@ -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 * +``` + +- 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 * -f +``` + +- This will create the navigation file for all existed screens in the `src/screens//` 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: @@ -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 ( @@ -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 @@ -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. diff --git a/docs/DELETING_FILES.md b/docs/DELETING_FILES.md index 034b3c5..b5cb6ee 100644 --- a/docs/DELETING_FILES.md +++ b/docs/DELETING_FILES.md @@ -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 +``` diff --git a/docs/NOTES.md b/docs/NOTES.md index 1cc601a..922e200 100644 --- a/docs/NOTES.md +++ b/docs/NOTES.md @@ -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 +``` diff --git a/docs/TOC.md b/docs/TOC.md index 4a45881..481bb5a 100644 --- a/docs/TOC.md +++ b/docs/TOC.md @@ -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)