Skip to content

Commit

Permalink
fix: use eslint to format ts,js,json,md and yml, goodbye prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
rubiin committed Oct 3, 2023
1 parent e040a6b commit 3da5323
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ LICENSE
.swcrc
.git
.husky
.prettierrc
makefile
justfile
test
33 changes: 13 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,18 @@ Now you can start the application witt `npx cross-env NODE_ENV=dev yarn start`.
- 🔐 **Helmet** - secure HTTP headers
- 😴 **Insomnia** - Insomnia config for endpoints
- 📏 **ESLint** — Pluggable JavaScript linter
- 💖 **Prettier** - Opinionated Code Formatter

## Available Scripts

- `yarn start` - Start application
- `yarn start:dev` - Start application in watch mode
- `yarn start:prod` - Start built application
- `yarn start:hmr` - Start application with hot module replacement
- `yarn format` - Formats all the files inside src using prettier with config provided in `.prettierrc`
- `yarn lint` - Uses eslint to lint all the files inside src with config provided in `.eslintrc.cjs`
- `yarn orm migration:create` - Uses Mikroorm to create a migration file
- `yarn orm migration:up` - This command is used to run availablexisting migration files.
- `yarn orm migration:down` - This command is used to rollback migration.
- `yarn orm seeder:run` - This command is used to run existing seeders in `src/common/database`.
- `npm run start` - Start application
- `npm run start:dev` - Start application in watch mode
- `npm run start:prod` - Start built application
- `npm run start:hmr` - Start application with hot module replacement
- `npm run lint` - Uses eslint to lint all the files inside src with config provided in `eslint.config.js`
- `npm run orm migration:create` - Uses Mikroorm to create a migration file
- `npm run orm migration:up` - This command is used to run availablexisting migration files.
- `npm run orm migration:down` - This command is used to rollback migration.
- `npm run orm seeder:run` - This command is used to run existing seeders in `src/common/database`.

All the scripts require `NODE_ENV` flag

Expand All @@ -146,26 +144,24 @@ installing [just](https://github.com/casey/just#packages) and then running `just
- Also remove the unwanted config variables from the env file
- Make sure you create a env file under `env` directory with name like `.env.something`.The portion after .env is
the `NODE_ENV` value which will be required while running the app
- Also make sure you have ssl files inside `src/resources/ssl` if you tend to use ssl. Replace the sample files with
your ssl files but keep the name same. Additionally

## Migration and seeding

Migrations are used to update the database schema. The migration files are stored in `migrations` directory.

```sh
npx cross-env NODE_ENV=dev yarn orm migration:up # applies migration for dev env
npx cross-env NODE_ENV=dev npm run orm migration:up # applies migration for dev env
```

Seeding is used to insert data into the database. The seeding files are stored in `common/database/seeders` directory.

```sh
npx cross-env USER_PASSWORD=Test@1234 NODE_ENV=dev yarn orm seeder:run # seeds data for dev env with all user password set as Test@1234
npx cross-env USER_PASSWORD=Test@1234 NODE_ENV=dev npm run orm seeder:run # seeds data for dev env with all user password set as Test@1234
```

## Start application

- `npx cross-env NODE_ENV=[env name] yarn start`
- `npx cross-env NODE_ENV=[env name] npm run start`
- View automatically generated swagger api docs by browsing to `http://localhost:[port]/docs`
- View automatically generated swagger stats dashboard by browsing to `http://localhost:[port]/stats`. The username and
password is the values set in the env file under `SWAGGER_USERNAME` and `SWAGGER_PASS` respectively
Expand Down Expand Up @@ -209,16 +205,13 @@ authentication of the token.

# Deployment

You need to have `docker` and `docker-compose` (not the compose plugin) installed. Also since we are using `makefiles`
for deployment, you need to have `make` installed.
You need to have `docker` and `docker-compose` installed. The image environment variable values can be found at the compose file

```sh
ENV=dev sh ./scripts/deploy.sh # deploys dev environment (.env.dev used)
ENV=prod sh ./scripts/deploy.sh # deploys prod environment (.env.prod used)
```

The password for `redis` and `rabbitmq` is `Test@1234` can be changed in the make file under `deploy` script

More docs found at `docs` folder

<h2 align="center">Do you use this template?<br/>Don't be shy to give it a star! ★</h2>
Expand Down
17 changes: 9 additions & 8 deletions docs/linting.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
- [Configuration](#configuration)
- [FAQ](#faq)

This project uses Typescript Eslint, and Prettier to catch errors and avoid bike-shedding by enforcing a common code
This project uses Typescript Eslint to catch errors and avoid bike-shedding by enforcing a common code
style.

## Languages

- **TypeScript** is linted by Typescript Eslint and formatted by Prettier
- **JSON** is formatted by Prettier
- **TypeScript** is linted and formatted by Typescript Eslint.

## Scripts

Expand All @@ -24,12 +23,12 @@ There are a few different contexts in which the linters run.

```bash
# Lint all files without auto-fixing
yarn lint
npm run lint
```

```bash
# Lint all files, fixing many violations automatically
yarn lint:fix
npm run lint:fix
```

See `package.json` to update.
Expand All @@ -47,8 +46,10 @@ In supported editors, all files will be linted and show under the linter errors
This boilerplate ships with opinionated defaults, but you can edit each tools configuration in the following config
files:

- [ESLint](https://eslint.org/docs/user-guide/configuring)
- `.eslintrc.cjs`
- [ESLint](https://eslint.org/docs/latest/use/configure/configuration-files-new)
- `eslint.config.js`

Note: This uses eslint flat config, which is the recommended way to configure eslint.

## FAQ

Expand All @@ -60,5 +61,5 @@ files:
possible, because dynamic configurations are simply more powerful, able to respond to environment variables and much
more.

The linting rules can be found at [eslint-plugin-unicorn](https://github.com/sindresorhus/eslint-plugin-unicorn) which
The linting rules can be found at [@rubiin/eslint-config](https://github.com/rubiin/eslint-config) which
has more than 100 powerful ESLint rules that help prevent bugs and enforce conventions.

0 comments on commit 3da5323

Please sign in to comment.