express-generator-typescript 2.0.2 → 2.0.3
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.
|
@@ -13,14 +13,27 @@ const fs = require('fs');
|
|
|
13
13
|
|
|
14
14
|
// **** Variables **** //
|
|
15
15
|
|
|
16
|
+
// Misc
|
|
16
17
|
const prjFolder = './project-files';
|
|
17
18
|
|
|
19
|
+
// ncp options
|
|
18
20
|
const ncpOpts = {
|
|
19
21
|
filter: (fileName) => {
|
|
20
22
|
return !(fileName === 'package-lock.json' || fileName === 'node_modules');
|
|
21
23
|
},
|
|
22
24
|
};
|
|
23
25
|
|
|
26
|
+
// Project-folder dependencies
|
|
27
|
+
const dependencies = 'express dotenv http-status-codes morgan cookie-parser jet-logger ' +
|
|
28
|
+
'module-alias command-line-args express-async-errors helmet jsonfile bcrypt jsonwebtoken';
|
|
29
|
+
|
|
30
|
+
// Project-folder development dependencies
|
|
31
|
+
const devDependencies = 'ts-node typescript nodemon find jasmine supertest ' +
|
|
32
|
+
'@types/node @types/express @types/jasmine @types/find @types/morgan @types/cookie-parser ' +
|
|
33
|
+
'@types/supertest fs-extra tsconfig-paths @types/jsonfile @types/command-line-args ' +
|
|
34
|
+
'@typescript-eslint/eslint-plugin @typescript-eslint/parser eslint @types/fs-extra ' +
|
|
35
|
+
'@types/bcrypt @types/jsonwebtoken eslint-plugin-node';
|
|
36
|
+
|
|
24
37
|
|
|
25
38
|
// **** Functions **** //
|
|
26
39
|
|
|
@@ -32,8 +45,7 @@ async function expressGenTs(destination, useYarn) {
|
|
|
32
45
|
await copyProjectFiles(destination);
|
|
33
46
|
updatePackageJson(destination);
|
|
34
47
|
await renameGitigoreFile(destination);
|
|
35
|
-
|
|
36
|
-
downloadNodeModules(destination, depStrings, useYarn);
|
|
48
|
+
downloadNodeModules(destination, useYarn);
|
|
37
49
|
} catch (err) {
|
|
38
50
|
console.error(err);
|
|
39
51
|
}
|
|
@@ -75,36 +87,19 @@ function renameGitigoreFile(destination) {
|
|
|
75
87
|
});
|
|
76
88
|
}
|
|
77
89
|
|
|
78
|
-
/**
|
|
79
|
-
* Setup dependency strings. This way gets you the latest version of everything.
|
|
80
|
-
*/
|
|
81
|
-
function getDepStrings() {
|
|
82
|
-
let dependencies = 'express dotenv http-status-codes morgan cookie-parser jet-logger ' +
|
|
83
|
-
'module-alias command-line-args express-async-errors helmet jsonfile bcrypt ' +
|
|
84
|
-
'jsonwebtoken';
|
|
85
|
-
let devDependencies = 'ts-node typescript nodemon find jasmine supertest ' +
|
|
86
|
-
'@types/node @types/express @types/jasmine @types/find @types/morgan ' +
|
|
87
|
-
'@types/cookie-parser @types/supertest fs-extra tsconfig-paths @types/jsonfile ' +
|
|
88
|
-
'@types/command-line-args @typescript-eslint/eslint-plugin @typescript-eslint/parser ' +
|
|
89
|
-
'eslint @types/fs-extra @types/bcrypt @types/jsonwebtoken ' +
|
|
90
|
-
'eslint-plugin-node';
|
|
91
|
-
// Return
|
|
92
|
-
return { dependencies, devDependencies };
|
|
93
|
-
}
|
|
94
|
-
|
|
95
90
|
/**
|
|
96
91
|
* Download the dependencies.
|
|
97
92
|
*/
|
|
98
|
-
function downloadNodeModules(destination,
|
|
93
|
+
function downloadNodeModules(destination, useYarn) {
|
|
99
94
|
const options = {cwd: destination};
|
|
100
95
|
let downloadLibCmd;
|
|
101
96
|
let downloadDepCmd;
|
|
102
97
|
if (useYarn) {
|
|
103
|
-
downloadLibCmd = 'yarn add ' +
|
|
104
|
-
downloadDepCmd = 'yarn add ' +
|
|
98
|
+
downloadLibCmd = 'yarn add ' + dependencies;
|
|
99
|
+
downloadDepCmd = 'yarn add ' + devDependencies + ' -D';
|
|
105
100
|
} else {
|
|
106
|
-
downloadLibCmd = 'npm i -s ' +
|
|
107
|
-
downloadDepCmd = 'npm i -D ' +
|
|
101
|
+
downloadLibCmd = 'npm i -s ' + dependencies;
|
|
102
|
+
downloadDepCmd = 'npm i -D ' + devDependencies;
|
|
108
103
|
}
|
|
109
104
|
childProcess.execSync(downloadLibCmd, options);
|
|
110
105
|
childProcess.execSync(downloadDepCmd, options);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import StatusCodes from 'http-status-codes';
|
|
2
2
|
import { Request, Response, NextFunction } from 'express';
|
|
3
|
+
import { JwtPayload } from 'jsonwebtoken';
|
|
3
4
|
|
|
4
5
|
import { IUser, UserRoles } from '@models/user-model';
|
|
5
6
|
import envVars from 'src/shared/env-vars';
|
|
6
7
|
import jwtUtil from '@util/jwt-util';
|
|
7
|
-
import { JwtPayload } from 'jsonwebtoken';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
// **** Variables **** //
|
|
@@ -38,7 +38,7 @@ export async function adminMw(req: Request, res: Response, next: NextFunction) {
|
|
|
38
38
|
}
|
|
39
39
|
// Make sure user role is an admin
|
|
40
40
|
const clientData = await jwtUtil.decode<ISessionUser>(jwt);
|
|
41
|
-
if (clientData.role === UserRoles.Admin) {
|
|
41
|
+
if (typeof clientData === 'object' && clientData.role === UserRoles.Admin) {
|
|
42
42
|
res.locals.sessionUser = clientData;
|
|
43
43
|
next();
|
|
44
44
|
} else {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import jsonwebtoken from 'jsonwebtoken';
|
|
1
|
+
import jsonwebtoken, { JwtPayload } from 'jsonwebtoken';
|
|
2
2
|
import envVars from '../shared/env-vars';
|
|
3
3
|
|
|
4
4
|
|
|
@@ -21,9 +21,9 @@ const options = {
|
|
|
21
21
|
* Encrypt data and return jwt.
|
|
22
22
|
*/
|
|
23
23
|
function sign(data: string | object | Buffer): Promise<string> {
|
|
24
|
-
return new Promise((
|
|
24
|
+
return new Promise((res, rej) => {
|
|
25
25
|
jsonwebtoken.sign(data, envVars.jwt.secret, options, (err, token) => {
|
|
26
|
-
return err ?
|
|
26
|
+
return err ? rej(err) : res(token || '');
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
29
|
}
|
|
@@ -31,7 +31,7 @@ function sign(data: string | object | Buffer): Promise<string> {
|
|
|
31
31
|
/**
|
|
32
32
|
* Decrypt JWT and extract client data.
|
|
33
33
|
*/
|
|
34
|
-
function decode<T>(jwt: string): Promise<T> {
|
|
34
|
+
async function decode<T extends JwtPayload>(jwt: string): Promise<string | undefined | T> {
|
|
35
35
|
return new Promise((res, rej) => {
|
|
36
36
|
jsonwebtoken.verify(jwt, envVars.jwt.secret, (err, decoded) => {
|
|
37
37
|
return err ? rej(errors.validation) : res(decoded as T);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.3",
|
|
4
4
|
"description": "Generate new Express applications similar to express-generate which but sets it up to use TypeScript instead",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"express-generator-typescript": "node bin/cli.js",
|