express-generator-typescript 2.7.3 → 2.7.5
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/README-git +85 -0
- package/README.md +2 -67
- package/bin/cli.js +0 -0
- package/lib/express-generator-typescript.js +2 -2
- package/lib/project-files/eslint.config.ts +15 -10
- package/lib/project-files/package.json +3 -4
- package/lib/project-files/scripts/build.ts +8 -45
- package/lib/project-files/scripts/common/utils.ts +94 -0
- package/lib/project-files/src/common/constants/ENV.ts +3 -3
- package/lib/project-files/src/common/constants/HTTP_STATUS_CODES.ts +82 -0
- package/lib/project-files/src/common/constants/index.ts +6 -6
- package/lib/project-files/src/common/util/route-errors.ts +4 -2
- package/lib/project-files/src/repos/MockOrm.ts +7 -6
- package/lib/project-files/src/repos/UserRepo.ts +2 -1
- package/lib/project-files/src/repos/database.json +1 -1
- package/lib/project-files/src/repos/database.test.json +1 -1
- package/lib/project-files/src/routes/UserRoutes.ts +5 -5
- package/lib/project-files/src/routes/index.ts +6 -6
- package/lib/project-files/src/server.ts +9 -7
- package/lib/project-files/src/services/UserService.ts +3 -3
- package/lib/project-files/tests/common/Paths.ts +1 -1
- package/lib/project-files/tests/users.test.ts +18 -18
- package/package.json +1 -1
- package/README-npm +0 -20
- package/lib/project-files/src/common/constants/HttpStatusCodes.ts +0 -391
- /package/lib/project-files/src/common/constants/{Paths.ts → PATHS.ts} +0 -0
package/README-git
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<img alt='overnightjs' src='https://github.com/seanpmaxwell/express-generator-typescript/raw/master/express-typescript.png' border='0'>
|
|
2
|
+
|
|
3
|
+
[Express](https://www.npmjs.com/package/express) with [TypeScript's](https://www.npmjs.com/package/typescript) application generator.
|
|
4
|
+
|
|
5
|
+
<a href="https://www.npmjs.com/package/express-generator-typescript" target="_blank"><img src="https://img.shields.io/npm/v/express-generator-typescript.svg" alt="NPM Version" /></a>
|
|
6
|
+
<a href="https://www.npmjs.com/package/express-generator-typescript" target="_blank"><img src="https://img.shields.io/npm/l/express-generator-typescript.svg" alt="Package License" /></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/express-generator-typescript" target="_blank"><img src="https://img.shields.io/npm/dm/express-generator-typescript.svg" alt="NPM Downloads" /></a>
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## What is it?
|
|
11
|
+
|
|
12
|
+
Creates a new express application similar to the _express-generator_ module. Except this new application is configured to use TypeScript instead of plain JavaScript.
|
|
13
|
+
|
|
14
|
+
This project complies with Typescript best practices listed <a href="https://github.com/seanpmaxwell/Typescript-Best-Practices/blob/main/README.md">here</a>.
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## Why express-generator-typescript?
|
|
18
|
+
|
|
19
|
+
NodeJS is great for the rapid development of web-projects, but is often neglected because of the lack of type safety. TypeScript solves this issue and (along with its linter file) can even make your code more robust than some other static languages like Java.
|
|
20
|
+
|
|
21
|
+
There are some other tools out there to generate express apps with TypeScript such as _express-generator-ts_, but these either haven't been updated in a while or install a lot of junk in your project (such as an ORM).
|
|
22
|
+
|
|
23
|
+
Due to the heavy use of single-page-applications, no view-engine is configured by default. Express is only setup with the minimal settings for calling APIs and serving an index.html file. All the tools you need to run for development (while restarting on changes), building, testing, and running for production are packaged with this library.
|
|
24
|
+
|
|
25
|
+
In addition, relative paths are also setup, so you don't have to go through the trouble of installing and configuring _tsconfig-paths_ and _module-alias_. Just make sure to update `paths` in _tsconfig.json_ and `_moduleAliases` in _preload.js_ if you want to add/edit the relative paths.
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## Sample-project
|
|
29
|
+
|
|
30
|
+
When you run _express-generator-typescript_, it sets up a simple application with routes for adding, updating, deleting, and fetching user objects. This is just to demonstrate how routing is done with express.
|
|
31
|
+
|
|
32
|
+
### `--with-auth` option no longer available for version 2.5+
|
|
33
|
+
|
|
34
|
+
For the command-line, you used to be able to pass the `--with-auth` option to generate an app which required a login before using the routes; however, maintaining two separate projects became quite cumbersome. If you want an example of how to do authentication in expressjs with json-web-tokens you can refer to this sample project <a href="https://github.com/seanpmaxwell/express-jsonwebtoken-demo">here</a>.
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
$ Just use 'npx'
|
|
41
|
+
Or
|
|
42
|
+
$ npm install -g express-generator-typescript
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
The quickest way to get started is use npx and pass in the name of the project you want to create. If you don't specify a project name, the default _express-gen-ts_ will be used instead. If you want to use `yarn` instead of `npm`, pass the option `--use-yarn`.
|
|
49
|
+
|
|
50
|
+
Create the app:<br/>
|
|
51
|
+
With no options: `$ npx express-generator-typescript`<br/>
|
|
52
|
+
With all options (order doesn't matter): `$ npx express-generator-typescript --use-yarn "project name"`
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
Start your express-generator-typescript app in development mode at `http://localhost:3000/`:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
$ cd "project name" && npm run dev
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
## Available commands for the server.
|
|
63
|
+
|
|
64
|
+
- Run the server in development mode: `npm run dev` or `npm run dev:hot`.
|
|
65
|
+
- Run all unit-tests: `npm run test` or `npm run test:hot`.
|
|
66
|
+
- Run a single unit-test: `npm run test -- "name of test file" (i.e. users.test.ts)`.
|
|
67
|
+
- Check for linting errors: `npm run lint`.
|
|
68
|
+
- Build the project for production: `npm run build`.
|
|
69
|
+
- Run the production build: `npm start`.
|
|
70
|
+
- Check for typescript errors: `npm run type-check`.
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## Debugging
|
|
74
|
+
|
|
75
|
+
During development, _express-generator-typescript_ uses `nodemon` to restart the server when changes are detected. If you want to enable debugging for node, you'll need to modify the nodemon configurations. This is located under `nodemonConfig:` in `package.json` for the server and `./spec/nodemon.json` for unit-testing. For the `exec` property, replace `ts-node` with `node --inspect -r ts-node/register`.
|
|
76
|
+
|
|
77
|
+
<br/>
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
Happy web deving :)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
## License
|
|
84
|
+
|
|
85
|
+
[MIT](LICENSE)
|
package/README.md
CHANGED
|
@@ -12,74 +12,9 @@
|
|
|
12
12
|
Creates a new express application similar to the _express-generator_ module. Except this new application is configured to use TypeScript instead of plain JavaScript.
|
|
13
13
|
|
|
14
14
|
This project complies with Typescript best practices listed <a href="https://github.com/seanpmaxwell/Typescript-Best-Practices/blob/main/README.md">here</a>.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
## Why express-generator-typescript?
|
|
18
|
-
|
|
19
|
-
NodeJS is great for the rapid development of web-projects, but is often neglected because of the lack of type safety. TypeScript solves this issue and (along with its linter file) can even make your code more robust than some other static languages like Java.
|
|
20
|
-
|
|
21
|
-
There are some other tools out there to generate express apps with TypeScript such as _express-generator-ts_, but these either haven't been updated in a while or install a lot of junk in your project (such as an ORM).
|
|
22
|
-
|
|
23
|
-
Due to the heavy use of single-page-applications, no view-engine is configured by default. Express is only setup with the minimal settings for calling APIs and serving an index.html file. All the tools you need to run for development (while restarting on changes), building, testing, and running for production are packaged with this library.
|
|
24
|
-
|
|
25
|
-
In addition, relative paths are also setup, so you don't have to go through the trouble of installing and configuring _tsconfig-paths_ and _module-alias_. Just make sure to update `paths` in _tsconfig.json_ and `_moduleAliases` in _preload.js_ if you want to add/edit the relative paths.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
## Sample-project
|
|
29
|
-
|
|
30
|
-
When you run _express-generator-typescript_, it sets up a simple application with routes for adding, updating, deleting, and fetching user objects. This is just to demonstrate how routing is done with express.
|
|
31
|
-
|
|
32
|
-
### `--with-auth` option no longer available for version 2.5+
|
|
33
|
-
|
|
34
|
-
For the command-line, you used to be able to pass the `--with-auth` option to generate an app which required a login before using the routes; however, maintaining two separate projects became quite cumbersome. If you want an example of how to do authentication in expressjs with json-web-tokens you can refer to this sample project <a href="https://github.com/seanpmaxwell/express-jsonwebtoken-demo">here</a>.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
## Installation
|
|
38
|
-
|
|
39
|
-
```sh
|
|
40
|
-
$ Just use 'npx'
|
|
41
|
-
Or
|
|
42
|
-
$ npm install -g express-generator-typescript
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
## Quick Start
|
|
47
|
-
|
|
48
|
-
The quickest way to get started is use npx and pass in the name of the project you want to create. If you don't specify a project name, the default _express-gen-ts_ will be used instead. If you want to use `yarn` instead of `npm`, pass the option `--use-yarn`.
|
|
49
|
-
|
|
50
|
-
Create the app:<br/>
|
|
51
|
-
With no options: `$ npx express-generator-typescript`<br/>
|
|
52
|
-
With all options (order doesn't matter): `$ npx express-generator-typescript --use-yarn "project name"`
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
Start your express-generator-typescript app in development mode at `http://localhost:3000/`:
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
$ cd "project name" && npm run dev
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
## Available commands for the server.
|
|
63
|
-
|
|
64
|
-
- Run the server in development mode: `npm run dev` or `npm run dev:hot`.
|
|
65
|
-
- Run all unit-tests: `npm run test` or `npm run test:hot`.
|
|
66
|
-
- Run a single unit-test: `npm run test -- "name of test file" (i.e. users.test.ts)`.
|
|
67
|
-
- Check for linting errors: `npm run lint`.
|
|
68
|
-
- Build the project for production: `npm run build`.
|
|
69
|
-
- Run the production build: `npm start`.
|
|
70
|
-
- Check for typescript errors: `npm run type-check`.
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
## Debugging
|
|
74
|
-
|
|
75
|
-
During development, _express-generator-typescript_ uses `nodemon` to restart the server when changes are detected. If you want to enable debugging for node, you'll need to modify the nodemon configurations. This is located under `nodemonConfig:` in `package.json` for the server and `./spec/nodemon.json` for unit-testing. For the `exec` property, replace `ts-node` with `node --inspect -r ts-node/register`.
|
|
76
|
-
|
|
77
15
|
<br/>
|
|
78
16
|
|
|
79
17
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
## License
|
|
18
|
+
## Documenation
|
|
84
19
|
|
|
85
|
-
|
|
20
|
+
Please refer to the official <a href="https://github.com/seanpmaxwell/express-generator-typescript">github repo</a> for the most up-to-date documentation.
|
package/bin/cli.js
CHANGED
|
File without changes
|
|
@@ -19,8 +19,8 @@ const DEPENDENCIES = 'express dotenv morgan cookie-parser jet-logger ' +
|
|
|
19
19
|
DEV_DEPENDENCIES = 'ts-node typescript nodemon find supertest vitest ' +
|
|
20
20
|
'@types/node @types/find @types/morgan @types/cookie-parser ' +
|
|
21
21
|
'@types/supertest fs-extra tsconfig-paths jiti @swc/core @types/jsonfile ' +
|
|
22
|
-
'@types/fs-extra @types/module-alias @stylistic/eslint-plugin
|
|
23
|
-
'@eslint/js typescript-eslint eslint-plugin-n
|
|
22
|
+
'@types/fs-extra @types/module-alias @stylistic/eslint-plugin eslint ' +
|
|
23
|
+
'@eslint/js typescript-eslint eslint-plugin-n';
|
|
24
24
|
|
|
25
25
|
// "ncp" options
|
|
26
26
|
const ncpOpts = {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import eslint from '@eslint/js';
|
|
2
2
|
import tseslint from 'typescript-eslint';
|
|
3
|
-
import
|
|
4
|
-
import stylisticTs from '@stylistic/eslint-plugin-ts';
|
|
3
|
+
import stylistic from '@stylistic/eslint-plugin';
|
|
5
4
|
import nodePlugin from 'eslint-plugin-n';
|
|
5
|
+
import { defineConfig } from 'eslint/config';
|
|
6
6
|
|
|
7
|
-
export default
|
|
7
|
+
export default defineConfig(
|
|
8
8
|
eslint.configs.recommended,
|
|
9
9
|
nodePlugin.configs['flat/recommended-script'],
|
|
10
10
|
...tseslint.configs.strictTypeChecked,
|
|
11
11
|
...tseslint.configs.stylisticTypeChecked,
|
|
12
|
-
{
|
|
12
|
+
{
|
|
13
13
|
ignores: [
|
|
14
14
|
'**/node_modules/*',
|
|
15
15
|
'**/*.mjs',
|
|
@@ -26,8 +26,7 @@ export default tseslint.config(
|
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
plugins: {
|
|
29
|
-
'@stylistic
|
|
30
|
-
'@stylistic/ts': stylisticTs,
|
|
29
|
+
'@stylistic': stylistic,
|
|
31
30
|
},
|
|
32
31
|
},
|
|
33
32
|
{
|
|
@@ -46,18 +45,24 @@ export default tseslint.config(
|
|
|
46
45
|
'@typescript-eslint/restrict-plus-operands': [
|
|
47
46
|
'warn', { allowNumberAndString: true },
|
|
48
47
|
],
|
|
49
|
-
'@typescript-eslint/no-unused-vars':
|
|
48
|
+
'@typescript-eslint/no-unused-vars': [
|
|
49
|
+
'warn',
|
|
50
|
+
{
|
|
51
|
+
argsIgnorePattern: '^_',
|
|
52
|
+
varsIgnorePattern: '^_',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
50
55
|
'@typescript-eslint/no-unsafe-enum-comparison': 0,
|
|
51
56
|
'@typescript-eslint/no-unnecessary-type-parameters': 0,
|
|
52
|
-
'@stylistic/
|
|
57
|
+
'@stylistic/no-extra-semi': 'warn',
|
|
53
58
|
'max-len': [
|
|
54
59
|
'warn',
|
|
55
60
|
{
|
|
56
61
|
'code': 80,
|
|
57
62
|
},
|
|
58
63
|
],
|
|
59
|
-
'@stylistic/
|
|
60
|
-
'@stylistic/
|
|
64
|
+
'@stylistic/semi': ['warn', 'always'],
|
|
65
|
+
'@stylistic/member-delimiter-style': ['warn', {
|
|
61
66
|
'multiline': {
|
|
62
67
|
'delimiter': 'comma',
|
|
63
68
|
'requireLast': true,
|
|
@@ -24,15 +24,14 @@
|
|
|
24
24
|
"jet-env": "^1.1.4",
|
|
25
25
|
"jet-logger": "^2.0.1",
|
|
26
26
|
"jet-paths": "^1.1.0",
|
|
27
|
-
"jet-validators": "^1.
|
|
27
|
+
"jet-validators": "^1.5.0",
|
|
28
28
|
"jsonfile": "^6.1.0",
|
|
29
29
|
"module-alias": "^2.2.3",
|
|
30
30
|
"morgan": "^1.10.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@eslint/js": "^9.25.1",
|
|
34
|
-
"@stylistic/eslint-plugin
|
|
35
|
-
"@stylistic/eslint-plugin-ts": "^4.2.0",
|
|
34
|
+
"@stylistic/eslint-plugin": "^5.5.0",
|
|
36
35
|
"@swc/core": "^1.11.22",
|
|
37
36
|
"@types/cookie-parser": "^1.4.8",
|
|
38
37
|
"@types/find": "^0.2.4",
|
|
@@ -52,7 +51,7 @@
|
|
|
52
51
|
"ts-node": "^10.9.2",
|
|
53
52
|
"tsconfig-paths": "^4.2.0",
|
|
54
53
|
"typescript": "^5.8.3",
|
|
55
|
-
"typescript-eslint": "^8.
|
|
54
|
+
"typescript-eslint": "^8.32.0",
|
|
56
55
|
"vitest": "^3.1.2"
|
|
57
56
|
}
|
|
58
57
|
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
1
|
import logger from 'jet-logger';
|
|
3
|
-
import
|
|
2
|
+
import { copy, copyFilesRec, exec, remove } from './common/utils';
|
|
4
3
|
|
|
5
4
|
|
|
5
|
+
/******************************************************************************
|
|
6
|
+
Run
|
|
7
|
+
******************************************************************************/
|
|
8
|
+
|
|
6
9
|
/**
|
|
7
10
|
* Start
|
|
8
11
|
*/
|
|
@@ -10,12 +13,10 @@ import childProcess from 'child_process';
|
|
|
10
13
|
try {
|
|
11
14
|
// Remove current build
|
|
12
15
|
await remove('./dist/');
|
|
13
|
-
await exec('npm run lint', '
|
|
14
|
-
await exec('tsc --
|
|
16
|
+
await exec('npm run lint', '../');
|
|
17
|
+
await exec('tsc --project tsconfig.prod.json', '../');
|
|
15
18
|
// Copy
|
|
16
|
-
await
|
|
17
|
-
await copy('./src/views', './dist/views');
|
|
18
|
-
await copy('./src/repos/database.json', './dist/repos/database.json');
|
|
19
|
+
await copyFilesRec('./src', './dist', ['.ts']);
|
|
19
20
|
await copy('./temp/config.js', './config.js');
|
|
20
21
|
await copy('./temp/src', './dist');
|
|
21
22
|
await remove('./temp/');
|
|
@@ -26,41 +27,3 @@ import childProcess from 'child_process';
|
|
|
26
27
|
}
|
|
27
28
|
})();
|
|
28
29
|
|
|
29
|
-
/**
|
|
30
|
-
* Remove file
|
|
31
|
-
*/
|
|
32
|
-
function remove(loc: string): Promise<void> {
|
|
33
|
-
return new Promise((res, rej) => {
|
|
34
|
-
return fs.remove(loc, err => {
|
|
35
|
-
return (!!err ? rej(err) : res());
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Copy file.
|
|
42
|
-
*/
|
|
43
|
-
function copy(src: string, dest: string): Promise<void> {
|
|
44
|
-
return new Promise((res, rej) => {
|
|
45
|
-
return fs.copy(src, dest, err => {
|
|
46
|
-
return (!!err ? rej(err) : res());
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Do command line command.
|
|
53
|
-
*/
|
|
54
|
-
function exec(cmd: string, loc: string): Promise<void> {
|
|
55
|
-
return new Promise((res, rej) => {
|
|
56
|
-
return childProcess.exec(cmd, {cwd: loc}, (err, stdout, stderr) => {
|
|
57
|
-
if (!!stdout) {
|
|
58
|
-
logger.info(stdout);
|
|
59
|
-
}
|
|
60
|
-
if (!!stderr) {
|
|
61
|
-
logger.warn(stderr);
|
|
62
|
-
}
|
|
63
|
-
return (!!err ? rej(err) : res());
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import fs from 'fs-extra';
|
|
2
|
+
import logger from 'jet-logger';
|
|
3
|
+
import childProcess from 'child_process';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/******************************************************************************
|
|
8
|
+
Functions
|
|
9
|
+
*******************************************************************************
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Copy file.
|
|
13
|
+
*/
|
|
14
|
+
export function copy(src: string, dest: string): Promise<void> {
|
|
15
|
+
return new Promise((res, rej) => {
|
|
16
|
+
return fs.copy(src, dest, err => {
|
|
17
|
+
return (!!err ? rej(err) : res());
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Remove file
|
|
24
|
+
*/
|
|
25
|
+
export function remove(loc: string): Promise<void> {
|
|
26
|
+
return new Promise((res, rej) => {
|
|
27
|
+
return fs.remove(loc, err => {
|
|
28
|
+
return (!!err ? rej(err) : res());
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Run command-line command.
|
|
35
|
+
*/
|
|
36
|
+
export function exec(cmd: string, loc = './'): Promise<string> {
|
|
37
|
+
// Setup directory
|
|
38
|
+
const callingDir = path.dirname(require.main?.filename ?? './'),
|
|
39
|
+
cwd = path.join(callingDir, loc);
|
|
40
|
+
// Wrap in promise
|
|
41
|
+
return new Promise((res, rej) =>
|
|
42
|
+
childProcess.exec(cmd, { cwd }, (err, stdout, stderr) => {
|
|
43
|
+
if (!!stdout) {
|
|
44
|
+
logger.info(stdout);
|
|
45
|
+
}
|
|
46
|
+
if (!!stderr) {
|
|
47
|
+
logger.err(stderr);
|
|
48
|
+
}
|
|
49
|
+
if (!!err) {
|
|
50
|
+
return rej(err);
|
|
51
|
+
} else if (!!stderr) {
|
|
52
|
+
return rej(new Error(stderr));
|
|
53
|
+
} else {
|
|
54
|
+
return res(stdout);
|
|
55
|
+
}
|
|
56
|
+
}),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Recursively search for a folder for all files and copy them to the new
|
|
62
|
+
* destination keeping their paths relative to the "src" param.
|
|
63
|
+
*
|
|
64
|
+
* Example:
|
|
65
|
+
* If file "./src/foo/bar.txt" exists then:
|
|
66
|
+
* copyFilesRec('./src', './dest') => ["./dest/foo/bar.txt"]
|
|
67
|
+
*
|
|
68
|
+
* @param excludeExt Exlude a list of file extensions.
|
|
69
|
+
*/
|
|
70
|
+
export async function copyFilesRec(
|
|
71
|
+
src: string,
|
|
72
|
+
dest: string,
|
|
73
|
+
excludeExt?: string[],
|
|
74
|
+
): Promise<void> {
|
|
75
|
+
const copyReqs: Promise<void>[] = [];
|
|
76
|
+
try {
|
|
77
|
+
const entries = await fs.readdir(src, { withFileTypes: true });
|
|
78
|
+
for (const entry of entries) {
|
|
79
|
+
const currPath = src + '/' + entry.name,
|
|
80
|
+
currDest = dest + '/' + entry.name,
|
|
81
|
+
ext = path.extname(entry.name);
|
|
82
|
+
if (entry.isFile() && !excludeExt?.includes(ext)) {
|
|
83
|
+
const req = fs.copy(currPath, currDest);
|
|
84
|
+
copyReqs.push(req);
|
|
85
|
+
} else if (entry.isDirectory()) {
|
|
86
|
+
const req = copyFilesRec(currPath, currDest, excludeExt);
|
|
87
|
+
copyReqs.push(req);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
} catch (error) {
|
|
91
|
+
logger.err(`Error searching in ${src}: ` + String(error));
|
|
92
|
+
}
|
|
93
|
+
await Promise.all(copyReqs);
|
|
94
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import jetEnv, { num } from 'jet-env';
|
|
2
|
-
import {
|
|
2
|
+
import { isValueOf } from 'jet-validators';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { NODE_ENVS } from '.';
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
/******************************************************************************
|
|
@@ -9,7 +9,7 @@ import { NodeEnvs } from '.';
|
|
|
9
9
|
******************************************************************************/
|
|
10
10
|
|
|
11
11
|
const ENV = jetEnv({
|
|
12
|
-
NodeEnv:
|
|
12
|
+
NodeEnv: isValueOf(NODE_ENVS),
|
|
13
13
|
Port: num,
|
|
14
14
|
});
|
|
15
15
|
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable max-len */
|
|
2
|
+
|
|
3
|
+
import { ValueOf } from 'jet-validators';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Hypertext Transfer Protocol (HTTP) response status codes.
|
|
8
|
+
* @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
|
|
9
|
+
*
|
|
10
|
+
* This file was copied from here: https://gist.github.com/scokmen/f813c904ef79022e84ab2409574d1b45
|
|
11
|
+
*/
|
|
12
|
+
const HTTP_STATUS_CODES = {
|
|
13
|
+
Continue: 100,
|
|
14
|
+
SwitchingProtocols: 101,
|
|
15
|
+
Processing: 102,
|
|
16
|
+
Ok: 200,
|
|
17
|
+
Created: 201,
|
|
18
|
+
Accepted: 202,
|
|
19
|
+
NonAuthoritativeInformation: 203,
|
|
20
|
+
NoContent: 204,
|
|
21
|
+
ResetContent: 205,
|
|
22
|
+
PartialContent: 206,
|
|
23
|
+
MultiStatus: 207,
|
|
24
|
+
AlreadyReported: 208,
|
|
25
|
+
ImUsed: 226,
|
|
26
|
+
MultipleChoices: 300,
|
|
27
|
+
MovedPermanently: 301,
|
|
28
|
+
Found: 302,
|
|
29
|
+
SeeOther: 303,
|
|
30
|
+
NotModified: 304,
|
|
31
|
+
UseProxy: 305,
|
|
32
|
+
SwitchProxy: 306,
|
|
33
|
+
TemporaryRedirect: 307,
|
|
34
|
+
PermanentRedirect: 308,
|
|
35
|
+
BadRequest: 400,
|
|
36
|
+
Unauthorized: 401,
|
|
37
|
+
PaymentRequired: 402,
|
|
38
|
+
Forbidden: 403,
|
|
39
|
+
NotFound: 404,
|
|
40
|
+
MethodNotAllowed: 405,
|
|
41
|
+
NotAcceptable: 406,
|
|
42
|
+
ProxyAuthenticationRequired: 407,
|
|
43
|
+
RequestTimeout: 408,
|
|
44
|
+
Conflict: 409,
|
|
45
|
+
Gone: 410,
|
|
46
|
+
LengthRequired: 411,
|
|
47
|
+
PreconditionFailed: 412,
|
|
48
|
+
PayloadTooLarge: 413,
|
|
49
|
+
UriTooLong: 414,
|
|
50
|
+
UnsupportedMediaType: 415,
|
|
51
|
+
RangeNotSatisfiable: 416,
|
|
52
|
+
ExpectationFailed: 417,
|
|
53
|
+
IamaTeapot: 418,
|
|
54
|
+
MisdirectedRequest: 421,
|
|
55
|
+
UnprocessableEntity: 422,
|
|
56
|
+
Locked: 423,
|
|
57
|
+
FailedDependency: 424,
|
|
58
|
+
UpgradeRequired: 426,
|
|
59
|
+
PreconditionRequired: 428,
|
|
60
|
+
TooManyRequests: 429,
|
|
61
|
+
RequestHeaderFieldsTooLarge: 431,
|
|
62
|
+
UnavailableForLegalReasons: 451,
|
|
63
|
+
InternalServerError: 500,
|
|
64
|
+
NotImplemented: 501,
|
|
65
|
+
BadGateway: 502,
|
|
66
|
+
ServiceUnavailable: 503,
|
|
67
|
+
GatewayTimeout: 504,
|
|
68
|
+
HttpVersionNotSupported: 505,
|
|
69
|
+
VariantAlsoNegotiates: 506,
|
|
70
|
+
InsuffientStorage: 507,
|
|
71
|
+
LoopDetected: 508,
|
|
72
|
+
NotExtended: 510,
|
|
73
|
+
NetworkAuthenticationRequired: 511,
|
|
74
|
+
} as const;
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
/******************************************************************************
|
|
78
|
+
Export default
|
|
79
|
+
******************************************************************************/
|
|
80
|
+
|
|
81
|
+
export type HttpStatusCodes = ValueOf<typeof HTTP_STATUS_CODES>;
|
|
82
|
+
export default HTTP_STATUS_CODES;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
/******************************************************************************
|
|
3
|
-
|
|
3
|
+
Constants
|
|
4
4
|
******************************************************************************/
|
|
5
5
|
|
|
6
6
|
// NOTE: These need to match the names of your ".env" files
|
|
7
|
-
export
|
|
8
|
-
Dev
|
|
9
|
-
Test
|
|
10
|
-
Production
|
|
11
|
-
}
|
|
7
|
+
export const NODE_ENVS = {
|
|
8
|
+
Dev: 'development',
|
|
9
|
+
Test: 'test',
|
|
10
|
+
Production: 'production',
|
|
11
|
+
} as const;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { IParseObjectError } from 'jet-validators/utils';
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import HTTP_STATUS_CODES, {
|
|
4
|
+
HttpStatusCodes,
|
|
5
|
+
} from '@src/common/constants/HTTP_STATUS_CODES';
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
/******************************************************************************
|
|
@@ -32,6 +34,6 @@ export class ValidationError extends RouteError {
|
|
|
32
34
|
message: ValidationError.MESSAGE,
|
|
33
35
|
errors,
|
|
34
36
|
});
|
|
35
|
-
super(
|
|
37
|
+
super(HTTP_STATUS_CODES.BadRequest, msg);
|
|
36
38
|
}
|
|
37
39
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import jsonfile from 'jsonfile';
|
|
2
2
|
|
|
3
3
|
import ENV from '@src/common/constants/ENV';
|
|
4
|
-
import {
|
|
4
|
+
import { NODE_ENVS } from '@src/common/constants';
|
|
5
5
|
import { IUser } from '@src/models/User';
|
|
6
6
|
|
|
7
7
|
|
|
@@ -10,7 +10,7 @@ import { IUser } from '@src/models/User';
|
|
|
10
10
|
******************************************************************************/
|
|
11
11
|
|
|
12
12
|
const DB_FILE_NAME = (
|
|
13
|
-
ENV.NodeEnv ===
|
|
13
|
+
ENV.NodeEnv === NODE_ENVS.Test
|
|
14
14
|
? 'database.test.json'
|
|
15
15
|
: 'database.json'
|
|
16
16
|
);
|
|
@@ -20,7 +20,7 @@ const DB_FILE_NAME = (
|
|
|
20
20
|
Types
|
|
21
21
|
******************************************************************************/
|
|
22
22
|
|
|
23
|
-
interface
|
|
23
|
+
interface IDatabase {
|
|
24
24
|
users: IUser[];
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -32,14 +32,15 @@ interface IDb {
|
|
|
32
32
|
/**
|
|
33
33
|
* Fetch the json from the file.
|
|
34
34
|
*/
|
|
35
|
-
function openDb(): Promise<
|
|
36
|
-
return jsonfile.readFile(__dirname + '/' + DB_FILE_NAME) as
|
|
35
|
+
function openDb(): Promise<IDatabase> {
|
|
36
|
+
return jsonfile.readFile(__dirname + '/' + DB_FILE_NAME) as
|
|
37
|
+
Promise<IDatabase>;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* Update the file.
|
|
41
42
|
*/
|
|
42
|
-
function saveDb(db:
|
|
43
|
+
function saveDb(db: IDatabase): Promise<void> {
|
|
43
44
|
return jsonfile.writeFile((__dirname + '/' + DB_FILE_NAME), db);
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -97,7 +97,7 @@ async function deleteAllUsers(): Promise<void> {
|
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* Insert multiple users. Can't do multiple at once cause using a plain file
|
|
100
|
-
* for
|
|
100
|
+
* for now.
|
|
101
101
|
*/
|
|
102
102
|
async function insertMult(
|
|
103
103
|
users: IUser[] | readonly IUser[],
|
|
@@ -128,3 +128,4 @@ export default {
|
|
|
128
128
|
deleteAllUsers,
|
|
129
129
|
insertMult,
|
|
130
130
|
} as const;
|
|
131
|
+
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"users":[{"id":366115170645,"name":"Sean Maxwell","email":"smaxwell@example.com","created":"2024-03-22T05:14:36.252Z"},{"id":310946254456,"name":"John Smith","email":"john.smith@example.com","created":"2024-03-22T05:20:55.079Z"},{"id":143027113460,"name":"Gordan Freeman","email":"nova@prospect.com","created":"2024-03-22T05:42:18.895Z"}]}
|
|
1
|
+
{"users":[{"id":366115170645,"name":"Sean Maxwell","email":"smaxwell@example.com","created":"2024-03-22T05:14:36.252Z"},{"id":310946254456,"name":"John Smith","email":"john.smith@example.com","created":"2024-03-22T05:20:55.079Z"},{"id":143027113460,"name":"Gordan Freeman","email":"nova@prospect.com","created":"2024-03-22T05:42:18.895Z"}]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"users":[{"id":
|
|
1
|
+
{"users":[{"id":521361725286,"name":"Bill","created":"2025-12-08T06:23:31.377Z","email":"sean.maxwell@gmail.com"},{"id":728107143962,"name":"John Smith","created":"2025-12-08T06:23:31.377Z","email":"john.smith@gmail.com"},{"id":704840128955,"name":"Gordan Freeman","created":"2025-12-08T06:23:31.377Z","email":"gordan.freeman@gmail.com"}]}
|