Skip to content

Commit 0199f08

Browse files
committed
Added new server with graphql setup
1 parent 15c50a6 commit 0199f08

36 files changed

+895
-0
lines changed

packages/iracing-server/.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
trim_trailing_whitespace = true
7+
insert_final_newline = true
8+
9+
[*.md]
10+
insert_final_newline = false
11+
trim_trailing_whitespace = false
12+
13+
[*.{js,jsx,json,ts,tsx,yml}]
14+
indent_size = 2
15+
indent_style = space

packages/iracing-server/.env.example

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
NODE_ENV=development
2+
APPLICATION_NAME=boilerplate
3+
APP_SERVER=1.0.0
4+
HOST=0.0.0.0
5+
PORT=5000

packages/iracing-server/.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
node_modules
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"parser": "@typescript-eslint/parser",
7+
"parserOptions": {
8+
"ecmaVersion": 12,
9+
"sourceType": "module"
10+
},
11+
"plugins": ["@typescript-eslint"],
12+
"extends": [
13+
"eslint:recommended",
14+
"plugin:@typescript-eslint/recommended",
15+
"prettier"
16+
],
17+
"rules": {}
18+
}
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

packages/iracing-server/.gitignore

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
6+
# Dependencies
7+
node_modules/
8+
9+
# Coverage
10+
coverage
11+
12+
# Transpiled files
13+
build/
14+
15+
# VS Code
16+
.vscode
17+
!.vscode/tasks.js
18+
19+
# JetBrains IDEs
20+
.idea/
21+
22+
# Optional npm cache directory
23+
.npm
24+
25+
# Optional eslint cache
26+
.eslintcache
27+
28+
# Misc
29+
.DS_Store
30+
31+
.env
32+
*report.html
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
coverage

packages/iracing-server/.prettierrc

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "all",
4+
"useTabs": false,
5+
"printWidth": 120,
6+
"tabWidth": 2,
7+
"overrides": [
8+
{
9+
"files": "*.yaml",
10+
"options": {
11+
"tadWidth": 2,
12+
"printWidth": 40,
13+
"singleQuote": true
14+
}
15+
}
16+
]
17+
}

packages/iracing-server/CHANGELOG.md

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# [1.2.4]
2+
3+
- When a class calls an outside function now still have a prefix in logger message
4+
- Add a `customLogger` class
5+
- Use `reflect-metadata` to store and retrieve when write a log
6+
- Modify `logGroup`, and `container` config to adapt new logger
7+
8+
# [1.2.3]
9+
10+
- Add decorator `logGroup` to add called method to logger prefix
11+
12+
# [1.2.2]
13+
14+
- Add Github `CodeQL` pipeline
15+
16+
# [1.2.1]
17+
18+
- Update `README`
19+
20+
# [1.2.0]
21+
22+
- Add IOC container using [inversify](https://www.npmjs.com/package/inversify)
23+
- Fix script `npm start`
24+
25+
# [1.1.2]
26+
27+
- Up version to get sample log when running `npm publish` for tech blog
28+
29+
# [1.1.1]
30+
31+
- Update `README`
32+
33+
# [1.1.0]
34+
35+
- Add npm command `init`
36+
- Add option pipeline selection, currently supported CircleCI and Github
37+
- Update `README`
38+
39+
# [1.0.5]
40+
41+
- Add npm command `typescript-maker my-project`
42+
- Update `README`

packages/iracing-server/README.md

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# node-typescript-boilerplate
2+
3+
[![TypeScript version][ts-badge]][typescript-4-3]
4+
[![Node.js version][nodejs-badge]][nodejs]
5+
6+
👩🏻‍💻 Developer Ready: A comprehensive template for Typescript Express.Js projects.
7+
8+
🏃🏽 Instant Value: All basic tools included and configured:
9+
10+
- [TypeScript][typescript] [4.3][typescript-4-3]
11+
- [ESLint][eslint] with some initial rules recommendation
12+
- [Jest][jest] for fast unit testing and code coverage
13+
- Type definitions for Node.js and Jest
14+
- [Prettier][prettier] to enforce consistent code style
15+
- NPM [scripts](#available-scripts) for common operations
16+
- Simple example of TypeScript code and unit test
17+
- .editorconfig for consistent file format
18+
19+
## Getting Started
20+
21+
This project is intended to be used with the latest Active LTS release of [Node.js][nodejs].
22+
23+
### Using NPM
24+
25+
This package is used to generate Typescript project, so I recommend to install it **globally**. Then run command to create new project whenever we want
26+
27+
```
28+
npm install -g typescript-maker
29+
30+
# Generate new project
31+
32+
typescript-maker init my-project
33+
```
34+
35+
### Available options
36+
```
37+
- ioc : setup IOC container using [inversify](https://www.npmjs.com/package/inversify) (default: normal express)
38+
- p --pipeline <pipeline tool>: setup pipeline template (default: CircleCI)
39+
```
40+
41+
### Create pipeline template
42+
```
43+
# currently it just supports 'circleci' or 'github'
44+
45+
typescript-maker create-pipeline circleci
46+
```
47+
48+
### Use as a repository template
49+
50+
To start, just click the **[Use template][repo-template-action]** link (or the green button). Then, select which pipeline you gonna use by moving that one out of `pipeline` folder and removing `pipeline` folder. Start adding your code in the `src` and unit tests in the `__tests__` directories.
51+
52+
### Clone repository
53+
54+
To clone the repository, use the following commands:
55+
56+
```sh
57+
git clone https://github.com/Maithanhdanh/express-typescript-biolerplate.git
58+
cd express-typescript-biolerplate
59+
npm install
60+
```
61+
62+
## Note
63+
64+
- A new decorator `logGroup` is add to version `1.2.3`.
65+
- It will add called method to logger prefix by **modifying the definition of the class and method**
66+
67+
## Changelog
68+
[ChangeLog](https://github.com/Maithanhdanh/express-typescript-boilerplate/blob/main/CHANGELOG.md)
69+
70+
[ts-badge]: https://img.shields.io/badge/TypeScript-4.3-blue.svg
71+
[nodejs-badge]: https://img.shields.io/badge/Node.js->=%2014.16-blue.svg
72+
[nodejs]: https://nodejs.org/dist/latest-v14.x/docs/api/
73+
[typescript]: https://www.typescriptlang.org/
74+
[typescript-4-3]: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-3.html
75+
[jest]: https://facebook.github.io/jest/
76+
[eslint]: https://github.com/eslint/eslint
77+
[prettier]: https://prettier.io
78+
[repo-template-action]: https://github.com/Maithanhdanh/express-typescript-biolerplate.git

packages/iracing-server/SECURITY.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
Use this section to tell people about which versions of your project are
6+
currently being supported with security updates.
7+
8+
| Version | Supported |
9+
| ------- | ------------------ |
10+
| 5.1.x | :white_check_mark: |
11+
| 5.0.x | :x: |
12+
| 4.0.x | :white_check_mark: |
13+
| < 4.0 | :x: |
14+
15+
## Reporting a Vulnerability
16+
17+
Use this section to tell people how to report a vulnerability.
18+
19+
Tell them where to go, how often they can expect to get an update on a
20+
reported vulnerability, what to expect if the vulnerability is accepted or
21+
declined, etc.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
process.env = {
2+
...process.env,
3+
HOST: 'localhost',
4+
PORT: '5000',
5+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import supertest from 'supertest';
2+
import { createServer } from '@config/express';
3+
4+
describe('Server', () => {
5+
const app = createServer();
6+
7+
it('should pass', (done) => {
8+
supertest(app).get('/health').expect('UP', done);
9+
});
10+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
process.env.PORT = '3001';
2+
import express from 'express';
3+
import { Server } from 'net';
4+
5+
console.log('process.version', process.version);
6+
7+
describe('Index', () => {
8+
it('should work', async () => {
9+
const listen = jest.spyOn(Server.prototype, 'listen');
10+
jest.mock('@config/express', () => ({
11+
createServer: jest.fn().mockReturnValue(express()),
12+
}));
13+
await import('@server/index');
14+
expect(listen).toBeCalled();
15+
const server = listen.mock.results[0].value as Server;
16+
setImmediate(() => {
17+
server.close();
18+
});
19+
listen.mockRestore();
20+
});
21+
});
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const SupportedPipelineTools = {
2+
GITHUB: 'github',
3+
CIRCLECI: 'circleci',
4+
};
5+
6+
const PipelinePathMapper = {
7+
[SupportedPipelineTools.GITHUB]: '.github/workflows',
8+
[SupportedPipelineTools.CIRCLECI]: '.circleci',
9+
};
10+
11+
const PipelineConfigMapper = {
12+
[SupportedPipelineTools.GITHUB]: `${
13+
PipelinePathMapper[SupportedPipelineTools.GITHUB]
14+
}/nodejs.yml`,
15+
[SupportedPipelineTools.CIRCLECI]: `${
16+
PipelinePathMapper[SupportedPipelineTools.CIRCLECI]
17+
}/config.yml`,
18+
};
19+
20+
const GIT_REPO =
21+
'https://github.com/Maithanhdanh/express-typescript-boilerplate.git';
22+
23+
module.exports = {
24+
SupportedPipelineTools,
25+
GIT_REPO,
26+
PipelinePathMapper,
27+
PipelineConfigMapper,
28+
};
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#! /usr/bin/env node
2+
3+
'use strict';
4+
5+
const path = require('path');
6+
const { Command } = require('commander');
7+
const program = new Command();
8+
const { setupPackage, createPipelineTemplate } = require('./setupTemplate');
9+
const { setupFolder, validateSupportedPipeline } = require('./validator');
10+
11+
program
12+
.command('init <project_name>')
13+
.description('Initialize a new project')
14+
.option(
15+
'-p, --pipeline_tool <pipeline>',
16+
`pipeline tool [circleci, github]`,
17+
'cirlceci',
18+
)
19+
.option('-ioc, --ioc', `IOC container`)
20+
.action((projectName, options) => {
21+
const { pipeline_tool: pipelineTool, ioc } = options;
22+
23+
const currentPath = process.cwd();
24+
const projectPath = path.join(currentPath, projectName);
25+
26+
setupFolder(projectPath);
27+
28+
setupPackage(projectPath, pipelineTool, ioc);
29+
});
30+
31+
program
32+
.command('create-pipeline <pipeline_tool>')
33+
.description('Create pipeline template')
34+
.action((pipelineTool) => {
35+
validateSupportedPipeline(pipelineTool);
36+
37+
const currentPath = process.cwd();
38+
39+
createPipelineTemplate(currentPath, pipelineTool);
40+
});
41+
42+
program.parse(process.argv);

0 commit comments

Comments
 (0)