From a2331a26af5ed87a4eff60a8bad99dd017fb4317 Mon Sep 17 00:00:00 2001 From: saisilinus Date: Thu, 7 Apr 2022 19:27:34 +0300 Subject: [PATCH] docs: Add README --- CODE_OF_CONDUCT.md | 76 ++++++++++++ CONTRIBUTING.md | 32 +++++ LICENSE | 21 ++++ README.md | 288 ++++++++++++--------------------------------- TODO.md | 9 +- 5 files changed, 211 insertions(+), 215 deletions(-) create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..41a93bc --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at hagopj13@gmail.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..9327de3 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,32 @@ +# Contributing + +First off, thank you so much for taking the time to contribute. All contributions are more than welcome! + +## How can I contribute? + +If you have an awesome new feature that you want to implement or you found a bug that you would like to fix, here are some instructions to guide you through the process: + +- **Create an issue** to explain and discuss the details +- **Fork the repo** +- **Clone the repo** and set it up (check out the [manual installation](https://github.com/saisilinus/node-express-mongoose-typescript-boilerplate.git#manual-installation) section in README.md) +- **Implement** the necessary changes +- **Create tests** to keep the code coverage high +- **Send a pull request** + +## Guidelines + +### Git commit messages + +- Limit the subject line to 72 characters +- Capitalize the first letter of the subject line +- Use the present tense ("Add feature" instead of "Added feature") +- Separate the subject from the body with a blank line +- Reference issues and pull requests in the body + +### Coding style guide + +We are using ESLint to ensure a consistent code style in the project, based on [Airbnb's JS style guide](https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb-base). + +Some other ESLint plugins are also being used, such as the [Prettier](https://github.com/prettier/eslint-plugin-prettier) and [Jest](https://github.com/jest-community/eslint-plugin-jest) plugins. + +Please make sure that the code you are pushing conforms to the style guides mentioned above. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1dcb301 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Linus Saisi + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 5fec7de..3c9076b 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,8 @@ cp .env.example .env - [Features](#features) - [Commands](#commands) +- [Making Changes](#making-changes) +- [Linting Errors After Compiling](#linting-errors-after-compiling) - [Environment Variables](#environment-variables) - [Project Structure](#project-structure) - [API Documentation](#api-documentation) @@ -36,7 +38,13 @@ cp .env.example .env - [Authorization](#authorization) - [Logging](#logging) - [Custom Mongoose Plugins](#custom-mongoose-plugins) + - [To JSON Plugin](#tojson) + - [Hide to JSON Plugin](#hidetojson) + - [Paginate Plugin](#paginate) - [Linting](#linting) +- [Contributing](#contributing) +- [Inspirations](#inspirations) +- [License](#license) ## Features @@ -78,6 +86,18 @@ Running in production: yarn start ``` +Compiling to JS from TS + +```bash +yarn compile +``` + +Compiling to JS from TS in watch mode + +```bash +yarn compile:watch +``` + Testing: ```bash @@ -120,6 +140,24 @@ yarn prettier yarn prettier:fix ``` +## Making Changes + +Add your changes to TypeScript(.ts) files which are in the src folder. +Compile your TS files to JS by running `yarn compile` + +```bash +yarn compile +``` + +Manually fix remaining linting errors in the JS files + +## Linting Errors After Compiling + +After compiling, you are likely to get linting errors since some were disabled through comments in TypeScript files. Currently, the following files get linting errors after running `yarn compile`: + - dist/modules/errors/error.js: fix -> `// eslint-disable-next-line no-unused-vars` + - dist/modules/toJSON/hideToJSON.plugin.js: fix -> `/* eslint-disable no-param-reassign */` + - dist/modules/toJSON/toJSON.plugin.js: fix -> `/* eslint-disable no-param-reassign */` + ## Environment Variables The environment variables can be found and modified in the `.env` file. They come with these default values: @@ -151,218 +189,26 @@ EMAIL_FROM=support@yourapp.com ## Project Structure ``` -├── dist -│ ├── app.js -│ ├── app.js.map -│ ├── config -│ │ ├── config.js -│ │ ├── config.js.map -│ │ ├── roles.js -│ │ └── roles.js.map -│ ├── index.js -│ ├── index.js.map -│ ├── modules -│ │ ├── auth -│ │ │ ├── auth.controller.js -│ │ │ ├── auth.controller.js.map -│ │ │ ├── auth.middleware.js -│ │ │ ├── auth.middleware.js.map -│ │ │ ├── auth.service.js -│ │ │ ├── auth.service.js.map -│ │ │ ├── auth.test.js -│ │ │ ├── auth.test.js.map -│ │ │ ├── auth.validation.js -│ │ │ ├── auth.validation.js.map -│ │ │ ├── index.js -│ │ │ ├── index.js.map -│ │ │ ├── passport.js -│ │ │ └── passport.js.map -│ │ ├── email -│ │ │ ├── email.interfaces.js -│ │ │ ├── email.interfaces.js.map -│ │ │ ├── email.service.js -│ │ │ ├── email.service.js.map -│ │ │ ├── index.js -│ │ │ └── index.js.map -│ │ ├── errors -│ │ │ ├── ApiError.js -│ │ │ ├── ApiError.js.map -│ │ │ ├── error.js -│ │ │ ├── error.js.map -│ │ │ ├── error.test.js -│ │ │ ├── error.test.js.map -│ │ │ ├── index.js -│ │ │ └── index.js.map -│ │ ├── jest -│ │ │ ├── setupTestDB.js -│ │ │ └── setupTestDB.js.map -│ │ ├── logger -│ │ │ ├── index.js -│ │ │ ├── index.js.map -│ │ │ ├── logger.js -│ │ │ ├── logger.js.map -│ │ │ ├── morgan.js -│ │ │ └── morgan.js.map -│ │ ├── paginate -│ │ │ ├── paginate.plugin.js -│ │ │ └── paginate.plugin.js.map -│ │ ├── swagger -│ │ │ ├── components.yaml -│ │ │ ├── swagger.definition.js -│ │ │ └── swagger.definition.js.map -│ │ ├── toJSON -│ │ │ ├── hideToJSON.plugin.js -│ │ │ ├── hideToJSON.plugin.js.map -│ │ │ ├── index.js -│ │ │ ├── index.js.map -│ │ │ ├── toJSON.plugin.js -│ │ │ └── toJSON.plugin.js.map -│ │ ├── token -│ │ │ ├── index.js -│ │ │ ├── index.js.map -│ │ │ ├── token.fixture.js -│ │ │ ├── token.fixture.js.map -│ │ │ ├── token.interfaces.js -│ │ │ ├── token.interfaces.js.map -│ │ │ ├── token.model.js -│ │ │ ├── token.model.js.map -│ │ │ ├── token.service.js -│ │ │ ├── token.service.js.map -│ │ │ ├── token.types.js -│ │ │ └── token.types.js.map -│ │ ├── user -│ │ │ ├── index.js -│ │ │ ├── index.js.map -│ │ │ ├── user.controller.js -│ │ │ ├── user.controller.js.map -│ │ │ ├── user.fixture.js -│ │ │ ├── user.fixture.js.map -│ │ │ ├── user.interfaces.js -│ │ │ ├── user.interfaces.js.map -│ │ │ ├── user.model.js -│ │ │ ├── user.model.js.map -│ │ │ ├── user.model.test.js -│ │ │ ├── user.model.test.js.map -│ │ │ ├── user.service.js -│ │ │ ├── user.service.js.map -│ │ │ ├── user.test.js -│ │ │ ├── user.test.js.map -│ │ │ ├── user.validation.js -│ │ │ └── user.validation.js.map -│ │ ├── utils -│ │ │ ├── catchAsync.js -│ │ │ ├── catchAsync.js.map -│ │ │ ├── index.js -│ │ │ ├── index.js.map -│ │ │ ├── pick.js -│ │ │ ├── pick.js.map -│ │ │ ├── rateLimiter.js -│ │ │ └── rateLimiter.js.map -│ │ └── validate -│ │ ├── custom.validation.js -│ │ ├── custom.validation.js.map -│ │ ├── index.js -│ │ ├── index.js.map -│ │ ├── validate.middleware.js -│ │ └── validate.middleware.js.map -│ └── routes -│ └── v1 -│ ├── auth.route.js -│ ├── auth.route.js.map -│ ├── index.js -│ ├── index.js.map -│ ├── swagger.route.js -│ ├── swagger.route.js.map -│ ├── user.route.js -│ └── user.route.js.map -├── docker-compose.dev.yml -├── docker-compose.prod.yml -├── docker-compose.test.yml -├── docker-compose.yml -├── Dockerfile -├── ecosystem.config.json -├── jest.config.cjs +. +├── dist # Destination files +│ ├── app.js # Express App +│ ├── app.js.map # TS source map file +│ ├── config # Environment variables and other configurations +│ ├── index.js # App entry file +│ ├── index.js.map # TS source map file +│ ├── modules # Modules such as models, controllers, services +│ └── routes # Routes +├── src # Source files +│ ├── app.ts # Express App +│ ├── config # Environment variables and other configurations +│ ├── custom.d.ts # File for extending types from node modules +│ ├── declaration.d.ts # File for declaring modules without types +│ ├── index.ts # App entry file +│ ├── modules # Modules such as models, controllers, services +│ └── routes # Routes +├── TODO.md # TODO List ├── package.json -├── package-lock.json -├── README.md -├── src -│ ├── app.ts -│ ├── config -│ │ ├── config.ts -│ │ └── roles.ts -│ ├── custom.d.ts -│ ├── declaration.d.ts -│ ├── index.ts -│ ├── modules -│ │ ├── auth -│ │ │ ├── auth.controller.ts -│ │ │ ├── auth.middleware.ts -│ │ │ ├── auth.service.ts -│ │ │ ├── auth.test.ts -│ │ │ ├── auth.validation.ts -│ │ │ ├── index.ts -│ │ │ └── passport.ts -│ │ ├── email -│ │ │ ├── email.interfaces.ts -│ │ │ ├── email.service.ts -│ │ │ └── index.ts -│ │ ├── errors -│ │ │ ├── ApiError.ts -│ │ │ ├── error.test.ts -│ │ │ ├── error.ts -│ │ │ └── index.ts -│ │ ├── jest -│ │ │ └── setupTestDB.ts -│ │ ├── logger -│ │ │ ├── index.ts -│ │ │ ├── logger.ts -│ │ │ └── morgan.ts -│ │ ├── paginate -│ │ │ └── paginate.plugin.ts -│ │ ├── swagger -│ │ │ └── swagger.definition.ts -│ │ ├── toJSON -│ │ │ ├── hideToJSON.plugin.ts -│ │ │ ├── index.ts -│ │ │ └── toJSON.plugin.ts -│ │ ├── token -│ │ │ ├── index.ts -│ │ │ ├── token.fixture.ts -│ │ │ ├── token.interfaces.ts -│ │ │ ├── token.model.ts -│ │ │ ├── token.service.ts -│ │ │ └── token.types.ts -│ │ ├── user -│ │ │ ├── index.ts -│ │ │ ├── user.controller.ts -│ │ │ ├── user.fixture.ts -│ │ │ ├── user.interfaces.ts -│ │ │ ├── user.model.test.ts -│ │ │ ├── user.model.ts -│ │ │ ├── user.service.ts -│ │ │ ├── user.test.ts -│ │ │ └── user.validation.ts -│ │ ├── utils -│ │ │ ├── catchAsync.ts -│ │ │ ├── index.ts -│ │ │ ├── pick.ts -│ │ │ └── rateLimiter.ts -│ │ └── validate -│ │ ├── custom.validation.ts -│ │ ├── index.ts -│ │ └── validate.middleware.ts -│ └── routes -│ └── v1 -│ ├── auth.route.ts -│ ├── index.ts -│ ├── swagger.route.ts -│ └── user.route.ts -├── TODO.md -├── treefile.md -├── tsconfig.json -├── tsconfig.tsbuildinfo -├── yarn-error.log -└── yarn.lock +└── README.md ``` ## API Documentation @@ -548,6 +394,14 @@ The toJSON plugin applies the following changes in the toJSON transform call: - removes \_\_v, createdAt, updatedAt, and any schema path that has private: true - replaces \_id with id +### hideToJSON + +The hideToJSON plugin applies the following changes in the toJSON transform call: + +- removes \_\_v, createdAt, updatedAt +- replaces \_id with id +- allows user to dynamically hide field by passing schema paths + ### paginate The paginate plugin adds the `paginate` static method to the mongoose schema. @@ -598,3 +452,15 @@ To modify the ESLint configuration, update the `.eslintrc.json` file. To modify To prevent a certain file or directory from being linted, add it to `.eslintignore` and `.prettierignore`. To maintain a consistent coding style across different IDEs, the project contains `.editorconfig` + +## Contributing + +Contributions are more than welcome! Please check out the [contributing guide](CONTRIBUTING.md). + +## Inspirations + +- [hagopj13/node-express-boilerplate](https://github.com/hagopj13/node-express-boilerplate.git) + +## License + +[MIT](LICENSE) diff --git a/TODO.md b/TODO.md index 41595f8..49ad5cc 100644 --- a/TODO.md +++ b/TODO.md @@ -1,13 +1,14 @@ ### Deployment Tasks -- [ ] Add README +- [x] Add README - [ ] Add Changelog -- [ ] Add Code of Conduct -- [ ] Add Contributing rules +- [x] Add Code of Conduct +- [x] Add Contributing rules - [ ] Add GitHub CI - [ ] Set up GitHub CI - [ ] Add GitHub CI Badge -- [ ] Fix swagger components issue +- [x] Fix swagger components issue +- [x] Add License ### Testing Tasks