Skip to content

Commit 5ec5cc3

Browse files
committed
Merge branch 'develop'
2 parents fc86988 + 8d297e0 commit 5ec5cc3

File tree

22 files changed

+21493
-5
lines changed

22 files changed

+21493
-5
lines changed

.babelrc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"plugins": [
3+
["module-resolver", {
4+
"root": ["./dist"],
5+
"alias": {
6+
"_": "./dist",
7+
"_apis": "./dist/apis",
8+
"_models": "./dist/models",
9+
"_utils": "./dist/utils"
10+
}
11+
}]
12+
]
13+
}

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
jest.config.js
2+
node_modules
3+
dist

.eslintrc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"root": true,
3+
"env": {
4+
"node": true,
5+
"jest/globals": true
6+
},
7+
"parser": "@typescript-eslint/parser",
8+
"parserOptions": {
9+
"project": [
10+
"./tsconfig.json",
11+
"./tests/tsconfig.json"
12+
]
13+
},
14+
"plugins": [
15+
"@typescript-eslint",
16+
"jest"
17+
],
18+
"extends": [
19+
"airbnb-typescript/base",
20+
"plugin:@typescript-eslint/recommended",
21+
"plugin:@typescript-eslint/recommended-requiring-type-checking",
22+
"plugin:jest/recommended",
23+
"plugin:jest/style"
24+
],
25+
"rules": {
26+
// Already covered by TypeScript compiler
27+
"import/default": "off",
28+
// Already covered by TypeScript compiler
29+
"import/no-unresolved": "off",
30+
"import/order": [
31+
"error",
32+
{
33+
"alphabetize": {"order": "asc"}
34+
}
35+
],
36+
"no-use-before-define": "off",
37+
"@typescript-eslint/require-await": "off",
38+
"@typescript-eslint/no-use-before-define": "warn",
39+
"@typescript-eslint/no-unused-vars": [
40+
"warn", { "argsIgnorePattern": "^_" }
41+
]
42+
}
43+
}

.github/FUNDING.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: [iamWing]
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: ['https://paypal.me/iamWing0w0']

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,7 @@ Thumbs.db
3838
dist/**/*
3939

4040
# ignore yarn.lock
41-
yarn.lock
41+
yarn.lock
42+
43+
# IDE settings
44+
.vscode/settings.json

.vscode/launch.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Debug",
11+
"cwd": "${workspaceRoot}",
12+
"protocol": "inspector",
13+
"port": 9229,
14+
"runtimeExecutable": "npm",
15+
"runtimeArgs": ["run-script", "debug"]
16+
},
17+
{
18+
"type": "node",
19+
"name": "Jest tests",
20+
"request": "launch",
21+
"runtimeExecutable": "npm",
22+
"args": [
23+
"run-script",
24+
"test"
25+
],
26+
"cwd": "${workspaceFolder}",
27+
"console": "integratedTerminal",
28+
"protocol": "inspector",
29+
"internalConsoleOptions": "neverOpen",
30+
},
31+
]
32+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Devtography
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# TypeScript Fastify Backend Boilerplate
2+
3+
Opinionated TypeScript based backend service boilerplate with Fastify.
4+
5+
## Getting started
6+
```sh
7+
# clone this repo
8+
git clone https://github.com/Devtography/typescript-fastify-backend-boilerplate.git
9+
```
10+
Or generate a new repo on GitHub using this template [here](https://github.com/Devtography/typescript-fastify-backend-boilerplate/generate)
11+
12+
```json
13+
// edit the following fields in package.json for your own project
14+
{
15+
"name": your-project-name,
16+
"version": whatever-you-like,
17+
"description": your-own-description,
18+
"author": who's-the-author?,
19+
"license": if-you-don't-want-to-use-MIT,
20+
"repository": type-and-link-of-your-repo,
21+
"keywords": keywords-of-your-project,
22+
"bugs": issue-page-of-your-repo,
23+
"homepage": homepage-of-your-repo
24+
}
25+
```
26+
27+
Then install all the `node_modules` needed by executing the following command:
28+
```sh
29+
cd folder-containing-the-cloned-boilerplate
30+
npm install --also-dev
31+
```
32+
33+
Manually create folders `src/models` & `src/utils` (folder structure shown
34+
below) as Git doesn't include empty folders.
35+
36+
That's it. You're ready to rock.
37+
38+
## Usage
39+
There're currently 4 NPM commands preconfigured in `package.json`, they are:
40+
41+
`npm run build` - Removes everything from `dist/`, then compile your `.ts` files
42+
into `JavaScript` with `tsc`, and use `babel` to correct the module require
43+
paths.
44+
45+
`npm run debug` - runs the `fastify` server with `ts-node-dev` with `NODE_ENV`
46+
set as `development` for debug. The `fastify` server will respawn on file saved
47+
under this mode.
48+
49+
`npm run test` - runs your `Jest` tests under `tests/` with coverage reports.
50+
51+
`npm run watch-test` - same as `npm run test` but execute on file saved
52+
automatically.
53+
54+
For `vscode` users, 2 launch configs - `Debug` & `Jest tests` are included in
55+
this boilerplate. Use those launch configs to run your app / `Jest` tests if
56+
you need the breakpoints to work.
57+
58+
## Folder structure
59+
```
60+
typescript-fastify-backend-boilerplate/
61+
| - .vscode/
62+
| | - launch.json //- Preconfigured vscode debug settings
63+
| - node_modules/
64+
| - dist/ //- Generated by `tsc` automatically
65+
| - src/
66+
| | - apis/ //- Folder which `fastify-autoload` looks for
67+
| | | - {routes}/ //- Create folders for your routes
68+
| | | - index.ts //- APIs on `/`
69+
| | - models/
70+
| | - utils/
71+
| | - app.ts //- Module where Fastify is initialled
72+
| | - server.ts //- Entry point
73+
| - tests/ //- Unit tests
74+
| | - apis/
75+
| | | - index.test.ts
76+
| | | - {routes}.test.ts
77+
| | - app.test.ts
78+
| | - tsconfig.json //- tsconfig to stop TypeScript & ESLint complaining
79+
| - .babelrc //- To correct import paths in `tsc` compiled files
80+
| - .eslintignore
81+
| - .eslintrc
82+
| - .gitignore
83+
| - jest.config.js
84+
| - LICENSE
85+
| - package-lock.json
86+
| - package.json
87+
| - README.md
88+
| - tsconfig.json
89+
```
90+
91+
## Author
92+
[Wing Chau](https://github.com/iamWing) [@Devtography]
93+
94+
## Support the project
95+
Contributions via pull requests are welcome and encouraged. If there's anything
96+
you consider essential that should be included in this boilerplate, please don't
97+
hesitate to implement yourself and make a pull request :)
98+
99+
Same as the other open sources projects in [@Devtography], I maintain & further
100+
develop this boilerplate with my free time. If you found my work useful and
101+
wanna support me keep on doing all these, please consider
102+
[donate/sponsor](https://github.com/sponsors/iamWing) me.
103+
104+
## License
105+
TypeScript Fastify Backend Boilerplate is open source software
106+
[licensed as MIT](LICENSE).
107+
108+
[@Devtography]: https://github.com/Devtography

jest.config.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const { pathsToModuleNameMapper } = require('ts-jest/utils')
2+
const { compilerOptions } = require('./tsconfig.json')
3+
4+
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
5+
module.exports = config = {
6+
testEnvironment: 'node',
7+
globals: {
8+
'ts-test': {
9+
tsconfig: 'tsconfig.json'
10+
}
11+
},
12+
moduleFileExtensions: ['ts', 'js', 'json'],
13+
moduleNameMapper: pathsToModuleNameMapper(
14+
compilerOptions.paths,
15+
{ prefix: '<rootDir>/' }
16+
),
17+
transform: {
18+
'^.+\\.(ts|tsx)$': 'ts-jest'
19+
},
20+
testMatch: [
21+
'**/tests/**/*.test.(ts|js)'
22+
],
23+
verbose: true,
24+
};

0 commit comments

Comments
 (0)