-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added docs for path alias, date-fns and directory structure. (#171)
- Loading branch information
1 parent
eeeab8a
commit 7574998
Showing
5 changed files
with
106 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Date Time Library To Use | ||
|
||
Use **date-fns** for any of your date time needs. Do not use **moment.js** or any other DateTime library, nor should you directly use the DateTime API offered by JS/TS. | ||
|
||
We used to have moment.js as our main DateTime library, but switched to date-fns for very good reasons that can be found [here](https://github.com/you-dont-need/You-Dont-Need-Momentjs). | ||
|
||
## Use date-fns please! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Add Path Aliases | ||
|
||
Follow the steps below to add your own path alias. | ||
|
||
### 1. Determine the name and the destination to point to for your path alias | ||
|
||
The name of the path alias should be in UpperCamelCase and it should be as short and concise as possible. | ||
|
||
The destination to point to should not coincide with the destination that an already existing path alias points to. We don't want multiple path aliases pointing to the same place. | ||
|
||
### 2. Navigate to ./tsconfig.paths.json and add your path alias | ||
|
||
Go to the `paths` property of `compilerOptions` and add a new key-value pair | ||
|
||
- `"@YourPathAlias": ["DestinationPathToReplace"]` | ||
|
||
Example: `"@Pages": ["src/pages"]` | ||
|
||
### 3. Navigate to ./config-overrides.js and add your path alias | ||
|
||
Go to the line starting with `module.exports` (should be at the end of the file) then look at `addWebpackAlias`. Add your path alias as a parameter to `addWebpackAlias` | ||
|
||
- `'@YourPathAlias': path.resolve(__dirname, 'DestinationPathToReplace')` | ||
|
||
Example: `'@Images': path.resolve(__dirname, './src/images')` | ||
|
||
### 4. Navigate to ./eslintrc and add your path alias | ||
|
||
Go to the `rules` property of the config JSON object, then to the `import/order` property of `rules`. Then, go to the `pathGroups` property and add your path alias | ||
|
||
``` | ||
{ | ||
"pattern": "@YourPathAlias/*", | ||
"group": "internal" | ||
} | ||
``` | ||
|
||
Example: | ||
|
||
``` | ||
{ | ||
"pattern": "@Constants/*", | ||
"group": "internal" | ||
} | ||
``` | ||
|
||
### 5. Restart VSCode to start using the path alias | ||
|
||
Now you can use the path aliases whenever you need to, making import statements much cleaner and easier to read! | ||
|
||
**Please make sure that your path alias string and destination path string all match up across all three files mentioned** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Path Aliases | ||
|
||
## Definition | ||
|
||
A path alias is a string mapped to a specific file/folder path that can be either relative or absolute. | ||
|
||
A path alias still represents the actual file/folder path and has the option of reaching to the subfolder(s) and subfile(s) of the path it replaces (if that path leads to a folder). | ||
|
||
## Rationale | ||
|
||
Writing the filepaths for import statements can be a big pain. An example of this is: | ||
|
||
- The folder **src/pages/EventDetailsPage/components/EventDetails** has an index.tsx file. This index file imports components Tag, Card and Button from **src/components**. | ||
- This means that to import Tag, Card and Button from **src/components** to index.tsx without using path aliases, a developer would have to write an import statement like this: `import { Tag, Card, Button } from '../../../../components';`. | ||
- This is rather cumbersome to write and unclean to look at, which will multiply even more if there are multiple files/folders to import from. | ||
|
||
To greatly alleviate this issue, path aliases were onboarded. They help make the import paths a lot less burdensome to write and to look at. | ||
|
||
## Available Path Aliases | ||
|
||
Currently in this codebase, there are 8 path aliases in total. They are: | ||
|
||
- `@Pages` - Points to **src/pages** | ||
- `@Constants` - Points to **src/constants** | ||
- `@SharedComponents` - Points to **src/components** | ||
- `@Services` - Points to **src/services** | ||
- `@HOCs` - Points to **src/HOCs** | ||
- `@Images` - Points to **src/images** | ||
- `@Contexts` - Points to **src/contexts** | ||
- `@Config` - Points to **src/config** | ||
|
||
## Usage | ||
|
||
`import <Stuff being imported from file/folder> from '<Path alias>';` | ||
|
||
To use the example elaborated earlier in the _Rationale_ paragraph, using path aliases would give: | ||
`import { Tag, Card, Button } from '@SharedComponents';` | ||
|
||
## Add More Path Aliases | ||
|
||
Refer to this [doc](./add_path_alias.md). |