express-generator-typescript 2.7.11 → 2.7.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +0 -0
- package/README.md +0 -0
- package/lib/cli.js +0 -0
- package/lib/express-generator-typescript.js +44 -11
- package/lib/project-files/.prettierignore +12 -0
- package/lib/project-files/.prettierrc.json +15 -0
- package/lib/project-files/README.md +54 -65
- package/lib/project-files/config/.env.development +0 -0
- package/lib/project-files/config/.env.production +0 -0
- package/lib/project-files/config/.env.test +0 -0
- package/lib/project-files/eslint.config.ts +46 -100
- package/lib/project-files/gitignore +0 -2
- package/lib/project-files/package.json +62 -56
- package/lib/project-files/src/common/constants/HttpStatusCodes.ts +393 -394
- package/lib/project-files/src/common/constants/Paths.ts +15 -15
- package/lib/project-files/src/common/constants/{EnvVars.ts → env.ts} +28 -19
- package/lib/project-files/src/common/utils/{misc.ts → number-utils.ts} +10 -11
- package/lib/project-files/src/common/utils/route-errors.ts +35 -36
- package/lib/project-files/src/common/utils/validators.ts +14 -14
- package/lib/project-files/src/{index.ts → main.ts} +24 -27
- package/lib/project-files/src/models/User.ts +73 -72
- package/lib/project-files/src/models/common/IModel.ts +4 -0
- package/lib/project-files/src/public/stylesheets/users.css +50 -48
- package/lib/project-files/src/repos/MockOrm.ts +57 -63
- package/lib/project-files/src/repos/UserRepo.ts +131 -133
- package/lib/project-files/src/repos/{database.json → common/database.json} +0 -0
- package/lib/project-files/src/repos/common/database.test.json +1 -0
- package/lib/project-files/src/routes/UserRoutes.ts +77 -69
- package/lib/project-files/src/routes/{index.ts → apiRouter.ts} +28 -28
- package/lib/project-files/src/routes/common/{types.ts → express-types.ts} +9 -10
- package/lib/project-files/src/routes/common/{utils.ts → parseReq.ts} +19 -16
- package/lib/project-files/src/server.ts +79 -84
- package/lib/project-files/src/services/{UserService/index.ts → UserService.ts} +64 -58
- package/lib/project-files/src/views/users.html +118 -132
- package/lib/project-files/tests/common/{utils.ts → comparators.ts} +38 -55
- package/lib/project-files/tests/common/error-utils.ts +25 -0
- package/lib/project-files/tests/common/{types.ts → supertest-types.ts} +15 -16
- package/lib/project-files/tests/{aux/setup.ts → support/agent.ts} +23 -26
- package/lib/project-files/tests/users.test.ts +131 -123
- package/lib/project-files/tsconfig.json +29 -35
- package/lib/project-files/tsconfig.prod.json +27 -30
- package/lib/project-files/vitest.config.mts +21 -18
- package/package.json +1 -1
- package/lib/project-files/config.ts +0 -22
- package/lib/project-files/scripts/build.ts +0 -28
- package/lib/project-files/scripts/common/utils.ts +0 -93
- package/lib/project-files/src/common/constants/index.ts +0 -11
- package/lib/project-files/src/models/common/types.ts +0 -5
- package/lib/project-files/src/repos/database.test.json +0 -1
- package/lib/project-files/src/services/UserService/constants.ts +0 -5
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
File without changes
|
package/lib/cli.js
CHANGED
|
File without changes
|
|
@@ -9,18 +9,51 @@ const path = require('path'),
|
|
|
9
9
|
Constants
|
|
10
10
|
******************************************************************************/
|
|
11
11
|
|
|
12
|
-
// Project folder paths
|
|
13
12
|
const PROJECT_FOLDER_PATH = './project-files';
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
'
|
|
14
|
+
const DEPENDENCIES = [
|
|
15
|
+
'cookie-parser',
|
|
16
|
+
'dayjs',
|
|
17
|
+
'dotenv',
|
|
18
|
+
'express',
|
|
19
|
+
'helmet',
|
|
20
|
+
'jet-env',
|
|
21
|
+
'jet-logger',
|
|
22
|
+
'jet-paths',
|
|
18
23
|
'jet-validators',
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
'jsonfile',
|
|
25
|
+
'module-alias',
|
|
26
|
+
'morgan',
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
const DEV_DEPENDENCIES = [
|
|
30
|
+
'@eslint/js',
|
|
31
|
+
'@swc/core',
|
|
32
|
+
'@trivago/prettier-plugin-sort-imports',
|
|
33
|
+
'@types/cookie-parser',
|
|
34
|
+
'@types/find',
|
|
35
|
+
'@types/fs-extra',
|
|
36
|
+
'@types/jsonfile',
|
|
37
|
+
'@types/module-alias',
|
|
38
|
+
'@types/morgan',
|
|
39
|
+
'@types/node',
|
|
40
|
+
'@types/supertest',
|
|
41
|
+
'eslint',
|
|
42
|
+
'eslint-config-prettier',
|
|
43
|
+
'eslint-plugin-n',
|
|
44
|
+
'find',
|
|
45
|
+
'fs-extra',
|
|
46
|
+
'jiti',
|
|
47
|
+
'nodemon',
|
|
48
|
+
'prettier',
|
|
49
|
+
'supertest',
|
|
50
|
+
'ts-node',
|
|
51
|
+
'tsconfig-paths',
|
|
52
|
+
'typescript',
|
|
53
|
+
'typescript-eslint',
|
|
54
|
+
'vitest',
|
|
55
|
+
];
|
|
56
|
+
|
|
24
57
|
|
|
25
58
|
// "ncp" options
|
|
26
59
|
const ncpOpts = {
|
|
@@ -91,8 +124,8 @@ function renameGitigoreFile(destination) {
|
|
|
91
124
|
function downloadNodeModules(destination, useYarn) {
|
|
92
125
|
const options = { cwd: destination };
|
|
93
126
|
// Setup dependencies string
|
|
94
|
-
let depStr = DEPENDENCIES,
|
|
95
|
-
devDepStr = DEV_DEPENDENCIES;
|
|
127
|
+
let depStr = DEPENDENCIES.join(' '),
|
|
128
|
+
devDepStr = DEV_DEPENDENCIES.join(' ');
|
|
96
129
|
// Setup download command
|
|
97
130
|
let downloadLibCmd,
|
|
98
131
|
downloadDepCmd;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"plugins": ["@trivago/prettier-plugin-sort-imports"],
|
|
3
|
+
"importOrder": [
|
|
4
|
+
"<THIRD_PARTY_MODULES>",
|
|
5
|
+
"^@src/[^/]+(/.*)?$",
|
|
6
|
+
"^\\.(?!.*\\.css$).*$",
|
|
7
|
+
"^.+\\.css$"
|
|
8
|
+
],
|
|
9
|
+
"importOrderSeparation": true,
|
|
10
|
+
"importOrderSortSpecifiers": true,
|
|
11
|
+
"importOrderCaseInsensitive": true,
|
|
12
|
+
"singleQuote": true,
|
|
13
|
+
"printWidth": 80,
|
|
14
|
+
"tabWidth": 2
|
|
15
|
+
}
|
|
@@ -1,65 +1,54 @@
|
|
|
1
|
-
## About
|
|
2
|
-
|
|
3
|
-
This project was created with [express-generator-typescript](https://github.com/seanpmaxwell/express-generator-typescript).
|
|
4
|
-
|
|
5
|
-
**IMPORTANT** for demo purposes I had to disable `helmet` in production. In any real world app you should change these 3 lines of code in `src/server.ts`:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
### `npm run dev` or `npm run dev:
|
|
27
|
-
|
|
28
|
-
Run the server in development mode.<br/>
|
|
29
|
-
|
|
30
|
-
**IMPORTANT** development mode uses `swc` for performance reasons which DOES NOT check for typescript errors. Run `npm run type-check` to check for type errors. NOTE: you should use your IDE to prevent most type errors.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
### `npm run
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
Run the production build (Must be built first).
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
### `npm run type-check`
|
|
59
|
-
|
|
60
|
-
Check for typescript errors.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
## Additional Notes
|
|
64
|
-
|
|
65
|
-
- If `npm run dev` gives you issues with bcrypt on MacOS you may need to run: `npm rebuild bcrypt --build-from-source`.
|
|
1
|
+
## About
|
|
2
|
+
|
|
3
|
+
This project was created with [express-generator-typescript](https://github.com/seanpmaxwell/express-generator-typescript).
|
|
4
|
+
|
|
5
|
+
**IMPORTANT** for demo purposes I had to disable `helmet` in production. In any real world app you should change these 3 lines of code in `src/server.ts`:
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
// eslint-disable-next-line n/no-process-env
|
|
9
|
+
if (!process.env.DISABLE_HELMET) {
|
|
10
|
+
app.use(helmet());
|
|
11
|
+
}
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
To just this:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
app.use(helmet());
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Available Scripts
|
|
21
|
+
|
|
22
|
+
### `npm run clean-install`
|
|
23
|
+
|
|
24
|
+
Remove the existing `node_modules/` folder, `package-lock.json`, and reinstall all library modules.
|
|
25
|
+
|
|
26
|
+
### `npm run dev` or `npm run dev:watch` (hot reloading)
|
|
27
|
+
|
|
28
|
+
Run the server in development mode.<br/>
|
|
29
|
+
|
|
30
|
+
**IMPORTANT** development mode uses `swc` for performance reasons which DOES NOT check for typescript errors. Run `npm run type-check` to check for type errors. NOTE: you should use your IDE to prevent most type errors.
|
|
31
|
+
|
|
32
|
+
### `npm test`
|
|
33
|
+
|
|
34
|
+
Run unit-tests with <a href="https://vitest.dev/guide/">vitest</a>.
|
|
35
|
+
|
|
36
|
+
### `npm run lint`
|
|
37
|
+
|
|
38
|
+
Check for linting errors.
|
|
39
|
+
|
|
40
|
+
### `npm run build`
|
|
41
|
+
|
|
42
|
+
Build the project for production.
|
|
43
|
+
|
|
44
|
+
### `npm start`
|
|
45
|
+
|
|
46
|
+
Run the production build (Must be built first).
|
|
47
|
+
|
|
48
|
+
### `npm run type-check`
|
|
49
|
+
|
|
50
|
+
Check for typescript errors.
|
|
51
|
+
|
|
52
|
+
## Additional Notes
|
|
53
|
+
|
|
54
|
+
- If `npm run dev` gives you issues with bcrypt on MacOS you may need to run: `npm rebuild bcrypt --build-from-source`.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,100 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
export default defineConfig(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
'
|
|
38
|
-
'
|
|
39
|
-
'
|
|
40
|
-
|
|
41
|
-
'
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
],
|
|
48
|
-
'@typescript-eslint/no-unused-vars': [
|
|
49
|
-
'warn',
|
|
50
|
-
{
|
|
51
|
-
argsIgnorePattern: '^_',
|
|
52
|
-
varsIgnorePattern: '^_',
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
'@typescript-eslint/no-unsafe-enum-comparison': 0,
|
|
56
|
-
'@typescript-eslint/no-unnecessary-type-parameters': 0,
|
|
57
|
-
'@stylistic/no-extra-semi': 'warn',
|
|
58
|
-
'max-len': [
|
|
59
|
-
'warn',
|
|
60
|
-
{
|
|
61
|
-
'code': 80,
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
'@stylistic/semi': ['warn', 'always'],
|
|
65
|
-
'@stylistic/member-delimiter-style': ['warn', {
|
|
66
|
-
'multiline': {
|
|
67
|
-
'delimiter': 'comma',
|
|
68
|
-
'requireLast': true,
|
|
69
|
-
},
|
|
70
|
-
'singleline': {
|
|
71
|
-
'delimiter': 'comma',
|
|
72
|
-
'requireLast': false,
|
|
73
|
-
},
|
|
74
|
-
'overrides': {
|
|
75
|
-
'interface': {
|
|
76
|
-
'singleline': {
|
|
77
|
-
'delimiter': 'semi',
|
|
78
|
-
'requireLast': false,
|
|
79
|
-
},
|
|
80
|
-
'multiline': {
|
|
81
|
-
'delimiter': 'semi',
|
|
82
|
-
'requireLast': true,
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
}],
|
|
87
|
-
'@typescript-eslint/no-non-null-assertion': 0,
|
|
88
|
-
'@typescript-eslint/no-unused-expressions': 'warn',
|
|
89
|
-
'comma-dangle': ['warn', 'always-multiline'],
|
|
90
|
-
'no-console': 1,
|
|
91
|
-
'no-extra-boolean-cast': 0,
|
|
92
|
-
'indent': ['warn', 2],
|
|
93
|
-
'quotes': ['warn', 'single'],
|
|
94
|
-
'n/no-process-env': 1,
|
|
95
|
-
'n/no-missing-import': 0,
|
|
96
|
-
'n/no-unpublished-import': 0,
|
|
97
|
-
'prefer-const': 'warn',
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
);
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import eslintConfigPrettier from 'eslint-config-prettier/flat';
|
|
3
|
+
import n from 'eslint-plugin-n';
|
|
4
|
+
import { defineConfig, globalIgnores } from 'eslint/config';
|
|
5
|
+
import tseslint from 'typescript-eslint';
|
|
6
|
+
|
|
7
|
+
export default defineConfig([
|
|
8
|
+
// global ignores
|
|
9
|
+
globalIgnores(['**/dist/**']),
|
|
10
|
+
// linting rules (code quality only)
|
|
11
|
+
{
|
|
12
|
+
files: ['**/*.{ts,tsx}'],
|
|
13
|
+
extends: [
|
|
14
|
+
js.configs.recommended,
|
|
15
|
+
...tseslint.configs.recommendedTypeChecked,
|
|
16
|
+
],
|
|
17
|
+
languageOptions: {
|
|
18
|
+
parser: tseslint.parser,
|
|
19
|
+
parserOptions: {
|
|
20
|
+
project: './tsconfig.json',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
plugins: {
|
|
24
|
+
n,
|
|
25
|
+
},
|
|
26
|
+
rules: {
|
|
27
|
+
// code quality / correctness
|
|
28
|
+
'@typescript-eslint/no-unused-vars': [
|
|
29
|
+
'warn',
|
|
30
|
+
{
|
|
31
|
+
argsIgnorePattern: '^_',
|
|
32
|
+
caughtErrorsIgnorePattern: '^_',
|
|
33
|
+
destructuredArrayIgnorePattern: '^_',
|
|
34
|
+
ignoreRestSiblings: true,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
'no-console': 'warn',
|
|
38
|
+
'no-extra-boolean-cast': 'off',
|
|
39
|
+
'no-process-env': 'warn',
|
|
40
|
+
// node correctness
|
|
41
|
+
'n/no-extraneous-import': 'error'
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
// MUST be last — disables ALL formatting rules
|
|
45
|
+
eslintConfigPrettier,
|
|
46
|
+
]);
|
|
@@ -1,56 +1,62 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "express-typescript-example",
|
|
3
|
-
"version": "0.0.0",
|
|
4
|
-
"scripts": {
|
|
5
|
-
"build": "
|
|
6
|
-
"clean-install": "rm -rf ./node_modules && rm -r package-lock.json && npm i",
|
|
7
|
-
"dev": "
|
|
8
|
-
"dev:
|
|
9
|
-
"lint": "eslint .",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"@
|
|
37
|
-
"@
|
|
38
|
-
"@
|
|
39
|
-
"@types/
|
|
40
|
-
"@types/
|
|
41
|
-
"@types/
|
|
42
|
-
"@types/
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "express-typescript-example",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "npm run lint && tsc --project tsconfig.prod.json",
|
|
6
|
+
"clean-install": "rm -rf ./node_modules && rm -r package-lock.json && npm i",
|
|
7
|
+
"dev": "DOTENV_CONFIG_PATH=./config/.env.development ts-node ./src/main",
|
|
8
|
+
"dev:watch": "nodemon --exec \"npm run dev\" --watch ./src --ext .ts",
|
|
9
|
+
"lint": "eslint .",
|
|
10
|
+
"format": "prettier --write .",
|
|
11
|
+
"start": "DOTENV_CONFIG_PATH=./config/.env.production node -r dotenv/config -r module-alias/register ./dist/main.js",
|
|
12
|
+
"test": "NODE_ENV=test vitest",
|
|
13
|
+
"type-check": "tsc -b --noEmit"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=16.0.0"
|
|
17
|
+
},
|
|
18
|
+
"_moduleAliases": {
|
|
19
|
+
"@src": "dist"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"cookie-parser": "^1.4.7",
|
|
23
|
+
"dayjs": "^1.11.19",
|
|
24
|
+
"dotenv": "^17.2.3",
|
|
25
|
+
"express": "^5.2.1",
|
|
26
|
+
"helmet": "^8.1.0",
|
|
27
|
+
"jet-env": "^1.1.6",
|
|
28
|
+
"jet-logger": "^2.2.3",
|
|
29
|
+
"jet-paths": "^2.0.1",
|
|
30
|
+
"jet-validators": "^2.2.5",
|
|
31
|
+
"jsonfile": "^6.2.0",
|
|
32
|
+
"module-alias": "^2.2.3",
|
|
33
|
+
"morgan": "^1.10.1"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@eslint/js": "^9.39.2",
|
|
37
|
+
"@swc/core": "^1.15.8",
|
|
38
|
+
"@trivago/prettier-plugin-sort-imports": "^6.0.2",
|
|
39
|
+
"@types/cookie-parser": "^1.4.10",
|
|
40
|
+
"@types/find": "^0.2.4",
|
|
41
|
+
"@types/fs-extra": "^11.0.4",
|
|
42
|
+
"@types/jsonfile": "^6.1.4",
|
|
43
|
+
"@types/module-alias": "^2.0.4",
|
|
44
|
+
"@types/morgan": "^1.9.10",
|
|
45
|
+
"@types/node": "^25.0.9",
|
|
46
|
+
"@types/supertest": "^6.0.3",
|
|
47
|
+
"eslint": "^9.39.2",
|
|
48
|
+
"eslint-config-prettier": "^10.1.8",
|
|
49
|
+
"eslint-plugin-n": "^17.23.2",
|
|
50
|
+
"find": "^0.3.0",
|
|
51
|
+
"fs-extra": "^11.3.3",
|
|
52
|
+
"jiti": "^2.6.1",
|
|
53
|
+
"nodemon": "^3.1.11",
|
|
54
|
+
"prettier": "^3.8.0",
|
|
55
|
+
"supertest": "^7.2.2",
|
|
56
|
+
"ts-node": "^10.9.2",
|
|
57
|
+
"tsconfig-paths": "^4.2.0",
|
|
58
|
+
"typescript": "^5.9.3",
|
|
59
|
+
"typescript-eslint": "^8.53.0",
|
|
60
|
+
"vitest": "^4.0.17"
|
|
61
|
+
}
|
|
62
|
+
}
|