express-generator-typescript 2.4.25 → 2.5.1
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.md +24 -33
- package/lib/cli.js +5 -25
- package/lib/express-generator-typescript.js +11 -19
- package/lib/project-files/README.md +18 -1
- package/lib/{project-files-auth/env/development.env → project-files/config/.env.development} +0 -9
- package/lib/project-files/config/.env.production +14 -0
- package/lib/project-files/{env/test.env → config/.env.test} +0 -10
- package/lib/project-files/config.js +18 -0
- package/lib/project-files/config.ts +22 -0
- package/lib/project-files/eslint.config.ts +96 -0
- package/lib/project-files/gitignore +2 -0
- package/lib/project-files/package.json +16 -9
- package/lib/project-files/scripts/build.ts +4 -0
- package/lib/project-files/spec/support/Paths.ts +1 -6
- package/lib/project-files/spec/support/apiCb.ts +18 -6
- package/lib/project-files/spec/tests/users.spec.ts +28 -33
- package/lib/project-files/spec/types/misc.ts +7 -6
- package/lib/project-files/spec/types/supertest/index.d.ts +2 -2
- package/lib/project-files/src/common/Env.ts +10 -0
- package/lib/project-files/src/common/route-errors.ts +41 -0
- package/lib/project-files/src/index.ts +3 -3
- package/lib/project-files/src/models/User.ts +9 -57
- package/lib/project-files/src/repos/MockOrm.ts +0 -2
- package/lib/project-files/src/repos/database.json +1 -1
- package/lib/project-files/src/routes/UserRoutes.ts +14 -5
- package/lib/project-files/src/{common → routes/common}/Paths.ts +0 -4
- package/lib/project-files/src/routes/common/index.ts +37 -0
- package/lib/project-files/src/routes/index.ts +1 -1
- package/lib/project-files/src/server.ts +7 -9
- package/lib/project-files/src/services/UserService.ts +1 -1
- package/lib/project-files/src/util/misc.ts +0 -16
- package/lib/project-files/src/util/schema.ts +11 -0
- package/lib/project-files/src/util/validators.ts +322 -0
- package/lib/project-files/tsconfig.json +20 -71
- package/lib/project-files/tsconfig.prod.json +22 -2
- package/package.json +1 -1
- package/lib/project-files/env/development.env +0 -24
- package/lib/project-files/env/production.env +0 -25
- package/lib/project-files/eslint.config.mjs +0 -58
- package/lib/project-files/preload.js +0 -23
- package/lib/project-files/src/common/EnvVars.ts +0 -24
- package/lib/project-files/src/common/classes.ts +0 -32
- package/lib/project-files/src/common/misc.ts +0 -5
- package/lib/project-files/src/routes/common/check.ts +0 -143
- package/lib/project-files/src/routes/common/types.ts +0 -8
- package/lib/project-files-auth/README.md +0 -35
- package/lib/project-files-auth/env/production.env +0 -25
- package/lib/project-files-auth/env/test.env +0 -24
- package/lib/project-files-auth/eslint.config.mjs +0 -58
- package/lib/project-files-auth/gitignore +0 -3
- package/lib/project-files-auth/package.json +0 -60
- package/lib/project-files-auth/preload.js +0 -23
- package/lib/project-files-auth/scripts/build.ts +0 -62
- package/lib/project-files-auth/spec/index.ts +0 -46
- package/lib/project-files-auth/spec/support/Paths.ts +0 -10
- package/lib/project-files-auth/spec/support/apiCb.ts +0 -76
- package/lib/project-files-auth/spec/support/jasmine.json +0 -11
- package/lib/project-files-auth/spec/support/login.ts +0 -42
- package/lib/project-files-auth/spec/tests/auth.spec.ts +0 -115
- package/lib/project-files-auth/spec/tests/users.spec.ts +0 -190
- package/lib/project-files-auth/spec/types/misc.ts +0 -12
- package/lib/project-files-auth/spec/types/supertest/index.d.ts +0 -14
- package/lib/project-files-auth/src/common/EnvVars.ts +0 -24
- package/lib/project-files-auth/src/common/HttpStatusCodes.ts +0 -386
- package/lib/project-files-auth/src/common/Paths.ts +0 -20
- package/lib/project-files-auth/src/common/classes.ts +0 -31
- package/lib/project-files-auth/src/index.ts +0 -12
- package/lib/project-files-auth/src/models/User.ts +0 -89
- package/lib/project-files-auth/src/public/scripts/http.js +0 -26
- package/lib/project-files-auth/src/public/scripts/login.js +0 -15
- package/lib/project-files-auth/src/public/scripts/users.js +0 -138
- package/lib/project-files-auth/src/public/stylesheets/login.css +0 -24
- package/lib/project-files-auth/src/public/stylesheets/users.css +0 -43
- package/lib/project-files-auth/src/repos/MockOrm.ts +0 -42
- package/lib/project-files-auth/src/repos/UserRepo.ts +0 -93
- package/lib/project-files-auth/src/repos/database.json +0 -1
- package/lib/project-files-auth/src/routes/AuthRoutes.ts +0 -42
- package/lib/project-files-auth/src/routes/UserRoutes.ts +0 -55
- package/lib/project-files-auth/src/routes/common/check.ts +0 -143
- package/lib/project-files-auth/src/routes/common/types.ts +0 -22
- package/lib/project-files-auth/src/routes/index.ts +0 -43
- package/lib/project-files-auth/src/routes/middleware/adminMw.ts +0 -47
- package/lib/project-files-auth/src/server.ts +0 -91
- package/lib/project-files-auth/src/services/AuthService.ts +0 -57
- package/lib/project-files-auth/src/services/UserService.ts +0 -59
- package/lib/project-files-auth/src/util/PwdUtil.ts +0 -39
- package/lib/project-files-auth/src/util/SessionUtil.ts +0 -94
- package/lib/project-files-auth/src/util/misc.ts +0 -22
- package/lib/project-files-auth/src/views/login.html +0 -58
- package/lib/project-files-auth/src/views/users.html +0 -140
- package/lib/project-files-auth/tsconfig.json +0 -87
- package/lib/project-files-auth/tsconfig.prod.json +0 -12
- /package/lib/{project-files-auth/src/common/misc.ts → project-files/src/common/constants.ts} +0 -0
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { ValidationErr } from '@src/common/classes';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type TReqObj = Record<string, unknown>;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Check that param/s is a string
|
|
9
|
-
*/
|
|
10
|
-
function isStr(reqObj: TReqObj, params: string): string;
|
|
11
|
-
function isStr(reqObj: TReqObj, params: readonly string[]): string[];
|
|
12
|
-
function isStr(
|
|
13
|
-
reqObj: TReqObj,
|
|
14
|
-
params: string | readonly string[],
|
|
15
|
-
): string | string[] {
|
|
16
|
-
return _checkWrapper(reqObj, params, _checkStr);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Check validator for string
|
|
21
|
-
*/
|
|
22
|
-
function _checkStr(val: unknown): string | undefined {
|
|
23
|
-
if (!!val && typeof val === 'string') {
|
|
24
|
-
return val;
|
|
25
|
-
} else {
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Check that param/s is a number.
|
|
32
|
-
*/
|
|
33
|
-
function isNum(reqObj: TReqObj, params: string): number;
|
|
34
|
-
function isNum(reqObj: TReqObj, params: readonly string[]): number[];
|
|
35
|
-
function isNum(
|
|
36
|
-
reqObj: TReqObj,
|
|
37
|
-
params: string | readonly string[],
|
|
38
|
-
): number | number[] {
|
|
39
|
-
return _checkWrapper(reqObj, params, _checkNum);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Check validator for string
|
|
44
|
-
*/
|
|
45
|
-
function _checkNum(val: unknown): number | undefined {
|
|
46
|
-
const valF = Number(val);
|
|
47
|
-
if (!isNaN(valF)) {
|
|
48
|
-
return valF;
|
|
49
|
-
} else {
|
|
50
|
-
return undefined;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Check that param/s is a number
|
|
56
|
-
*/
|
|
57
|
-
function isBool(reqObj: TReqObj, params: string): boolean;
|
|
58
|
-
function isBool(reqObj: TReqObj, params: readonly string[]): boolean[];
|
|
59
|
-
function isBool(
|
|
60
|
-
reqObj: TReqObj,
|
|
61
|
-
params: string | readonly string[],
|
|
62
|
-
): boolean | boolean[] {
|
|
63
|
-
return _checkWrapper(reqObj, params, _checkBool);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Check validator for string
|
|
68
|
-
*/
|
|
69
|
-
function _checkBool(val: unknown): boolean | undefined {
|
|
70
|
-
if (typeof val === 'boolean') {
|
|
71
|
-
return val;
|
|
72
|
-
} else if (typeof val === 'string') {
|
|
73
|
-
val = val.toLowerCase();
|
|
74
|
-
if (val === 'true') {
|
|
75
|
-
return true;
|
|
76
|
-
} else if (val === 'false') {
|
|
77
|
-
return false;
|
|
78
|
-
} else {
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
81
|
-
} else {
|
|
82
|
-
return undefined;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Check that param satisfies the validator function.
|
|
88
|
-
*/
|
|
89
|
-
function isValid<T>(
|
|
90
|
-
reqObj: TReqObj,
|
|
91
|
-
param: string,
|
|
92
|
-
validatorFn: (param: unknown) => param is T,
|
|
93
|
-
): T {
|
|
94
|
-
const val = reqObj[param];
|
|
95
|
-
if (validatorFn(val)) {
|
|
96
|
-
return val;
|
|
97
|
-
} else {
|
|
98
|
-
throw new ValidationErr(param);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// **** Shared Helpers **** //
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Do stuff based on whether or not params is an array
|
|
107
|
-
*/
|
|
108
|
-
function _checkWrapper<T>(
|
|
109
|
-
reqObj: TReqObj,
|
|
110
|
-
params: string | readonly string[],
|
|
111
|
-
checkFn: (val: unknown) => T | undefined,
|
|
112
|
-
): T | T[] {
|
|
113
|
-
// If is array
|
|
114
|
-
if (params instanceof Array) {
|
|
115
|
-
const retVal: T[] = [];
|
|
116
|
-
for (const param of params) {
|
|
117
|
-
const val = checkFn(reqObj[param]);
|
|
118
|
-
if (val !== undefined) {
|
|
119
|
-
retVal.push(val);
|
|
120
|
-
} else {
|
|
121
|
-
throw new ValidationErr(param);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return retVal;
|
|
125
|
-
}
|
|
126
|
-
// If not an array
|
|
127
|
-
const val = checkFn(reqObj[params]);
|
|
128
|
-
if (val !== undefined) {
|
|
129
|
-
return val;
|
|
130
|
-
}
|
|
131
|
-
// Throw error
|
|
132
|
-
throw new ValidationErr(params);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// **** Export Default **** //
|
|
137
|
-
|
|
138
|
-
export default {
|
|
139
|
-
isStr,
|
|
140
|
-
isNum,
|
|
141
|
-
isBool,
|
|
142
|
-
isValid,
|
|
143
|
-
} as const;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
## About
|
|
2
|
-
|
|
3
|
-
This project was created with [express-generator-typescript](https://github.com/seanpmaxwell/express-generator-typescript).
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
## Available Scripts
|
|
7
|
-
|
|
8
|
-
### `npm run dev` or `npm run dev:hot` (hot reloading)
|
|
9
|
-
|
|
10
|
-
Run the server in development mode.
|
|
11
|
-
|
|
12
|
-
### `npm test` or `npm run test:hot` (hot reloading)
|
|
13
|
-
|
|
14
|
-
Run all unit-tests.
|
|
15
|
-
|
|
16
|
-
### `npm test -- "name of test file" (i.e. Users).`
|
|
17
|
-
|
|
18
|
-
Run a single unit-test.
|
|
19
|
-
|
|
20
|
-
### `npm run lint`
|
|
21
|
-
|
|
22
|
-
Check for linting errors.
|
|
23
|
-
|
|
24
|
-
### `npm run build`
|
|
25
|
-
|
|
26
|
-
Build the project for production.
|
|
27
|
-
|
|
28
|
-
### `npm start`
|
|
29
|
-
|
|
30
|
-
Run the production build (Must be built first).
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
## Additional Notes
|
|
34
|
-
|
|
35
|
-
- If `npm run dev` gives you issues with bcrypt on MacOS you may need to run: `npm rebuild bcrypt --build-from-source`.
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
## Environment ##
|
|
2
|
-
NODE_ENV=production
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Server ##
|
|
6
|
-
PORT=8081
|
|
7
|
-
HOST=localhost
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## Setup jet-logger ##
|
|
11
|
-
JET_LOGGER_MODE=FILE
|
|
12
|
-
JET_LOGGER_FILEPATH=jet-logger.log
|
|
13
|
-
JET_LOGGER_TIMESTAMP=TRUE
|
|
14
|
-
JET_LOGGER_FORMAT=LINE
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
## Authentication ##
|
|
18
|
-
# SECURE_COOKIE 'false' here for demo-ing. But ideally should be true.
|
|
19
|
-
COOKIE_DOMAIN=localhost
|
|
20
|
-
COOKIE_PATH=/
|
|
21
|
-
SECURE_COOKIE=false
|
|
22
|
-
JWT_SECRET=xxxxxxxxxxxxxx
|
|
23
|
-
COOKIE_SECRET=xxxxxxxxxxxxxx
|
|
24
|
-
# expires in 3 days
|
|
25
|
-
COOKIE_EXP=259200000
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
## Environment ##
|
|
2
|
-
NODE_ENV=test
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Server ##
|
|
6
|
-
PORT=4000
|
|
7
|
-
HOST=localhost
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
## Setup jet-logger ##
|
|
11
|
-
JET_LOGGER_MODE=CONSOLE
|
|
12
|
-
JET_LOGGER_FILEPATH=jet-logger.log
|
|
13
|
-
JET_LOGGER_TIMESTAMP=TRUE
|
|
14
|
-
JET_LOGGER_FORMAT=LINE
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
## Authentication ##
|
|
18
|
-
COOKIE_DOMAIN=localhost
|
|
19
|
-
COOKIE_PATH=/
|
|
20
|
-
SECURE_COOKIE=false
|
|
21
|
-
JWT_SECRET=xxxxxxxxxxxxxx
|
|
22
|
-
COOKIE_SECRET=xxxxxxxxxxxxxx
|
|
23
|
-
# expires in 3 days
|
|
24
|
-
COOKIE_EXP=259200000
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import eslint from '@eslint/js';
|
|
2
|
-
import tseslint from 'typescript-eslint';
|
|
3
|
-
import stylisticTs from '@stylistic/eslint-plugin-ts';
|
|
4
|
-
import nodePlugin from 'eslint-plugin-n';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export default tseslint.config(
|
|
8
|
-
eslint.configs.recommended,
|
|
9
|
-
nodePlugin.configs['flat/recommended-script'],
|
|
10
|
-
...tseslint.configs.strictTypeChecked,
|
|
11
|
-
...tseslint.configs.stylisticTypeChecked,
|
|
12
|
-
{
|
|
13
|
-
ignores: [
|
|
14
|
-
'**/node_modules/*',
|
|
15
|
-
'**/*.mjs',
|
|
16
|
-
'**/*.js',
|
|
17
|
-
],
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
languageOptions: {
|
|
21
|
-
parserOptions: {
|
|
22
|
-
project: './tsconfig.json',
|
|
23
|
-
warnOnUnsupportedTypeScriptVersion: false,
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
plugins: {
|
|
29
|
-
'@stylistic/ts': stylisticTs,
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
{ files: ['**/*.ts'] },
|
|
33
|
-
{
|
|
34
|
-
rules: {
|
|
35
|
-
'@typescript-eslint/explicit-member-accessibility': 'warn',
|
|
36
|
-
'@typescript-eslint/no-misused-promises': 0,
|
|
37
|
-
'@typescript-eslint/no-floating-promises': 0,
|
|
38
|
-
'@typescript-eslint/no-confusing-void-expression': 0,
|
|
39
|
-
'@typescript-eslint/no-unnecessary-condition': 0,
|
|
40
|
-
'@typescript-eslint/restrict-template-expressions': [ 'error', { allowNumber: true }],
|
|
41
|
-
'max-len': [
|
|
42
|
-
'warn',
|
|
43
|
-
{
|
|
44
|
-
'code': 80
|
|
45
|
-
}
|
|
46
|
-
],
|
|
47
|
-
'@stylistic/ts/semi': ['warn'],
|
|
48
|
-
'comma-dangle': ['warn', 'always-multiline'],
|
|
49
|
-
'no-console': 1,
|
|
50
|
-
'no-extra-boolean-cast': 0,
|
|
51
|
-
'indent': ['warn', 2],
|
|
52
|
-
'quotes': ['warn', 'single'],
|
|
53
|
-
'n/no-process-env': 1,
|
|
54
|
-
'n/no-missing-import': 0,
|
|
55
|
-
'n/no-unpublished-import': 0
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
)
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "express-typescript-example",
|
|
3
|
-
"version": "0.0.0",
|
|
4
|
-
"scripts": {
|
|
5
|
-
"build": "npx ts-node ./scripts/build.ts",
|
|
6
|
-
"dev": "NODE_ENV=development npx ts-node ./src",
|
|
7
|
-
"dev:hot": "nodemon --exec \"npm run dev\" --watch ./src -e ts",
|
|
8
|
-
"lint": "npx eslint ./src",
|
|
9
|
-
"lint:tests": "npx eslint ./spec",
|
|
10
|
-
"start": "NODE_ENV=production node -r ./preload.js ./dist",
|
|
11
|
-
"test": "NODE_ENV=test npx ts-node ./spec",
|
|
12
|
-
"test:hot": "nodemon --exec \"npm run test\" --watch ./src --watch ./spec -e ts"
|
|
13
|
-
},
|
|
14
|
-
"engines": {
|
|
15
|
-
"node": ">=16.0.0"
|
|
16
|
-
},
|
|
17
|
-
"dependencies": {
|
|
18
|
-
"bcrypt": "^5.0.1",
|
|
19
|
-
"cookie-parser": "^1.4.6",
|
|
20
|
-
"dotenv": "^16.0.2",
|
|
21
|
-
"express": "^4.18.1",
|
|
22
|
-
"express-async-errors": "^3.1.1",
|
|
23
|
-
"helmet": "^6.0.0",
|
|
24
|
-
"inserturlparams": "^1.0.1",
|
|
25
|
-
"jet-logger": "^1.3.1",
|
|
26
|
-
"jet-paths": "^1.0.5",
|
|
27
|
-
"jsonfile": "^6.1.0",
|
|
28
|
-
"jsonwebtoken": "^8.5.1",
|
|
29
|
-
"module-alias": "^2.2.2",
|
|
30
|
-
"moment": "^2.30.1",
|
|
31
|
-
"morgan": "^1.10.0"
|
|
32
|
-
},
|
|
33
|
-
"devDependencies": {
|
|
34
|
-
"@types/bcrypt": "^5.0.0",
|
|
35
|
-
"@eslint/js": "^9.11.1",
|
|
36
|
-
"@stylistic/eslint-plugin-ts": "^2.8.0",
|
|
37
|
-
"@types/cookie-parser": "^1.4.3",
|
|
38
|
-
"@types/eslint__js": "^8.42.3",
|
|
39
|
-
"@types/express": "^4.17.13",
|
|
40
|
-
"@types/find": "^0.2.1",
|
|
41
|
-
"@types/fs-extra": "^9.0.13",
|
|
42
|
-
"@types/jasmine": "^4.3.0",
|
|
43
|
-
"@types/jsonfile": "^6.1.0",
|
|
44
|
-
"@types/jsonwebtoken": "^8.5.9",
|
|
45
|
-
"@types/morgan": "^1.9.3",
|
|
46
|
-
"@types/node": "^18.7.14",
|
|
47
|
-
"@types/supertest": "^6.0.2",
|
|
48
|
-
"eslint": "^9.11.1",
|
|
49
|
-
"eslint-plugin-n": "^17.10.3",
|
|
50
|
-
"find": "^0.3.0",
|
|
51
|
-
"fs-extra": "^10.1.0",
|
|
52
|
-
"jasmine": "^4.3.0",
|
|
53
|
-
"nodemon": "^2.0.19",
|
|
54
|
-
"supertest": "^6.3.4",
|
|
55
|
-
"ts-node": "^10.9.1",
|
|
56
|
-
"tsconfig-paths": "^4.1.0",
|
|
57
|
-
"typescript": "^5.6.2",
|
|
58
|
-
"typescript-eslint": "^8.8.0"
|
|
59
|
-
}
|
|
60
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
|
|
3
|
-
const dotenv = require('dotenv');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const moduleAlias = require('module-alias');
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// Check the env
|
|
9
|
-
const NODE_ENV = (process.env.NODE_ENV || 'development');
|
|
10
|
-
|
|
11
|
-
// Configure "dotenv"
|
|
12
|
-
const result2 = dotenv.config({
|
|
13
|
-
path: path.join(__dirname, `./env/${NODE_ENV}.env`),
|
|
14
|
-
});
|
|
15
|
-
if (result2.error) {
|
|
16
|
-
throw result2.error;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// Configure module-alias
|
|
20
|
-
if (NODE_ENV === 'production') {
|
|
21
|
-
moduleAlias.addAlias('@src', __dirname + '/dist');
|
|
22
|
-
}
|
|
23
|
-
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import fs from 'fs-extra';
|
|
2
|
-
import logger from 'jet-logger';
|
|
3
|
-
import childProcess from 'child_process';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Start
|
|
8
|
-
*/
|
|
9
|
-
(async () => {
|
|
10
|
-
try {
|
|
11
|
-
// Remove current build
|
|
12
|
-
await remove('./dist/');
|
|
13
|
-
await exec('npm run lint', './');
|
|
14
|
-
await exec('tsc --build tsconfig.prod.json', './');
|
|
15
|
-
// Copy
|
|
16
|
-
await copy('./src/public', './dist/public');
|
|
17
|
-
await copy('./src/views', './dist/views');
|
|
18
|
-
} catch (err) {
|
|
19
|
-
logger.err(err);
|
|
20
|
-
// eslint-disable-next-line n/no-process-exit
|
|
21
|
-
process.exit(1);
|
|
22
|
-
}
|
|
23
|
-
})();
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Remove file
|
|
27
|
-
*/
|
|
28
|
-
function remove(loc: string): Promise<void> {
|
|
29
|
-
return new Promise((res, rej) => {
|
|
30
|
-
return fs.remove(loc, err => {
|
|
31
|
-
return (!!err ? rej(err) : res());
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Copy file.
|
|
38
|
-
*/
|
|
39
|
-
function copy(src: string, dest: string): Promise<void> {
|
|
40
|
-
return new Promise((res, rej) => {
|
|
41
|
-
return fs.copy(src, dest, err => {
|
|
42
|
-
return (!!err ? rej(err) : res());
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Do command line command.
|
|
49
|
-
*/
|
|
50
|
-
function exec(cmd: string, loc: string): Promise<void> {
|
|
51
|
-
return new Promise((res, rej) => {
|
|
52
|
-
return childProcess.exec(cmd, {cwd: loc}, (err, stdout, stderr) => {
|
|
53
|
-
if (!!stdout) {
|
|
54
|
-
logger.info(stdout);
|
|
55
|
-
}
|
|
56
|
-
if (!!stderr) {
|
|
57
|
-
logger.warn(stderr);
|
|
58
|
-
}
|
|
59
|
-
return (!!err ? rej(err) : res());
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import find from 'find';
|
|
2
|
-
import Jasmine from 'jasmine';
|
|
3
|
-
import logger from 'jet-logger';
|
|
4
|
-
import { argv } from 'process';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// Init Jasmine
|
|
8
|
-
const jasmine = new Jasmine();
|
|
9
|
-
jasmine.exitOnCompletion = false;
|
|
10
|
-
|
|
11
|
-
// Set location of test files
|
|
12
|
-
jasmine.loadConfig({
|
|
13
|
-
random: true,
|
|
14
|
-
spec_dir: 'spec',
|
|
15
|
-
spec_files: [
|
|
16
|
-
'./tests/**/*.spec.ts',
|
|
17
|
-
],
|
|
18
|
-
stopSpecOnExpectationFailure: false,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
// Run all or a single unit-test
|
|
22
|
-
let execResp: Promise<jasmine.JasmineDoneInfo> | undefined;
|
|
23
|
-
if (!!argv[2]) {
|
|
24
|
-
const testFile = argv[2];
|
|
25
|
-
find.file(testFile + '.spec.ts', './spec', (files: string[]) => {
|
|
26
|
-
if (files.length === 1) {
|
|
27
|
-
jasmine.execute([files[0]]);
|
|
28
|
-
} else {
|
|
29
|
-
logger.err('Test file not found!');
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
} else {
|
|
33
|
-
execResp = jasmine.execute();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Wait for tests to finish
|
|
37
|
-
(async () => {
|
|
38
|
-
if (!!execResp) {
|
|
39
|
-
const info = await execResp;
|
|
40
|
-
if (info.overallStatus === 'passed') {
|
|
41
|
-
logger.info('All tests have passed :)');
|
|
42
|
-
} else {
|
|
43
|
-
logger.err('At least one test has failed :(');
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
})();
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { CallbackHandler } from 'supertest';
|
|
2
|
-
import moment from 'moment';
|
|
3
|
-
import logger from 'jet-logger';
|
|
4
|
-
|
|
5
|
-
import { TApiCb, TRes } from 'spec/types/misc';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* API callback function.
|
|
10
|
-
*/
|
|
11
|
-
function apiCb(
|
|
12
|
-
cb: TApiCb,
|
|
13
|
-
dateParam = 'created',
|
|
14
|
-
printErr?: boolean,
|
|
15
|
-
): CallbackHandler {
|
|
16
|
-
return (err: Error, res: TRes) => {
|
|
17
|
-
if (printErr) {
|
|
18
|
-
logger.err(err);
|
|
19
|
-
}
|
|
20
|
-
_strToDate(res.body, dateParam);
|
|
21
|
-
return cb(res);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* When date objects get sent through supertest they are converted to
|
|
27
|
-
* iso-strings. This will cause "toEqual()"" tests to fail, so we need to
|
|
28
|
-
* convert them back to Date objects.
|
|
29
|
-
*/
|
|
30
|
-
function _strToDate(
|
|
31
|
-
param: unknown,
|
|
32
|
-
prop: string,
|
|
33
|
-
): void {
|
|
34
|
-
return _iterate(param, prop);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Interate object recursively and convert string-dates to "Date" objects.
|
|
39
|
-
*/
|
|
40
|
-
function _iterate(param: unknown, prop: string): void {
|
|
41
|
-
if (!param || typeof param !== 'object') {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const paramF = param as Record<string, unknown>;
|
|
45
|
-
// For Arrays
|
|
46
|
-
if (Array.isArray(paramF)) {
|
|
47
|
-
for (const item of paramF) {
|
|
48
|
-
_iterate(item, prop);
|
|
49
|
-
}
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
// Check valid string or Date object. If undefined just skip
|
|
53
|
-
const val = paramF[prop];
|
|
54
|
-
if (
|
|
55
|
-
(typeof val !== 'undefined') &&
|
|
56
|
-
!((typeof val === 'string') || (val instanceof Date)) &&
|
|
57
|
-
!moment(val as string | Date).isValid()
|
|
58
|
-
) {
|
|
59
|
-
throw new Error('Property must be a valid date-string or Date() object');
|
|
60
|
-
}
|
|
61
|
-
// Convert and iterate
|
|
62
|
-
if (typeof val !== 'undefined') {
|
|
63
|
-
paramF[prop] = new Date(val as string | Date);
|
|
64
|
-
}
|
|
65
|
-
for (const key in paramF) {
|
|
66
|
-
const oval = paramF[key];
|
|
67
|
-
if (typeof oval === 'object' && key !== prop) {
|
|
68
|
-
_iterate(oval, prop);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// **** Export default **** //
|
|
75
|
-
|
|
76
|
-
export default apiCb;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Test, Response } from 'supertest';
|
|
2
|
-
import TestAgent from 'supertest/lib/agent';
|
|
3
|
-
|
|
4
|
-
import User, { UserRoles } from '@src/models/User';
|
|
5
|
-
import UserRepo from '@src/repos/UserRepo';
|
|
6
|
-
import PwdUtil from '@src/util/PwdUtil';
|
|
7
|
-
|
|
8
|
-
import Paths from './Paths';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// Login Credentials
|
|
12
|
-
const LoginCreds = {
|
|
13
|
-
email: 'jsmith@gmail.com',
|
|
14
|
-
password: 'Password@1',
|
|
15
|
-
} as const;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Login a user.
|
|
19
|
-
*/
|
|
20
|
-
function login(beforeAgent: TestAgent<Test>, done: (arg: string) => void) {
|
|
21
|
-
// Setup dummy data
|
|
22
|
-
const role = UserRoles.Admin,
|
|
23
|
-
pwdHash = PwdUtil.hashSync(LoginCreds.password),
|
|
24
|
-
loginUser = User.new('john smith', LoginCreds.email, new Date(), role,
|
|
25
|
-
pwdHash);
|
|
26
|
-
// Add spy
|
|
27
|
-
spyOn(UserRepo, 'getOne').and.resolveTo(loginUser);
|
|
28
|
-
// Call Login API
|
|
29
|
-
beforeAgent
|
|
30
|
-
.post(Paths.Auth.Login)
|
|
31
|
-
.type('form')
|
|
32
|
-
.send(LoginCreds)
|
|
33
|
-
.end((_: Error, res: Response) => {
|
|
34
|
-
const cookie = res.headers['set-cookie'][0];
|
|
35
|
-
return done(cookie);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// **** Export default **** //
|
|
41
|
-
|
|
42
|
-
export default login;
|