express-generator-typescript 2.0.3 → 2.0.4
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/bin/cli.js +24 -23
- package/lib/cli.js +24 -22
- package/lib/project-files/src/routes/auth-router.ts +4 -4
- package/lib/project-files/src/routes/user-router.ts +6 -6
- package/lib/project-files/src/shared/types.ts +11 -3
- package/lib/project-files/src/types/express/index.d.ts +0 -9
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -10,26 +10,27 @@ const path = require('path');
|
|
|
10
10
|
const expressGenTs = require('../lib/express-generator-typescript');
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
destination =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
// Start
|
|
14
|
+
console.log('Setting up new Express/TypeScript project...');
|
|
15
|
+
|
|
16
|
+
// Setup use yarn
|
|
17
|
+
let useYarn = false;
|
|
18
|
+
const args = process.argv.slice(2);
|
|
19
|
+
let idx = -1;
|
|
20
|
+
idx = args.indexOf('--use-yarn');
|
|
21
|
+
if (idx > -1) {
|
|
22
|
+
useYarn = true;
|
|
23
|
+
args.splice(idx, 1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Setup destination
|
|
27
|
+
let destination = 'express-gen-ts';
|
|
28
|
+
if (args.length > 0) {
|
|
29
|
+
destination = args[0];
|
|
30
|
+
}
|
|
31
|
+
destination = path.join(process.cwd(), destination);
|
|
32
|
+
|
|
33
|
+
// Creating new project finished
|
|
34
|
+
expressGenTs(destination, useYarn).then(() => {
|
|
35
|
+
console.log('Project setup complete!');
|
|
36
|
+
});
|
package/lib/cli.js
CHANGED
|
@@ -10,25 +10,27 @@ const path = require('path');
|
|
|
10
10
|
const expressGenTs = require('../lib/express-generator-typescript');
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
destination =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
13
|
+
// Start
|
|
14
|
+
console.log('Setting up new Express/TypeScript project...');
|
|
15
|
+
|
|
16
|
+
// Setup use yarn
|
|
17
|
+
let useYarn = false;
|
|
18
|
+
const args = process.argv.slice(2);
|
|
19
|
+
let idx = -1;
|
|
20
|
+
idx = args.indexOf('--use-yarn');
|
|
21
|
+
if (idx > -1) {
|
|
22
|
+
useYarn = true;
|
|
23
|
+
args.splice(idx, 1);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Setup destination
|
|
27
|
+
let destination = 'express-gen-ts';
|
|
28
|
+
if (args.length > 0) {
|
|
29
|
+
destination = args[0];
|
|
30
|
+
}
|
|
31
|
+
destination = path.join(process.cwd(), destination);
|
|
32
|
+
|
|
33
|
+
// Creating new project finished
|
|
34
|
+
expressGenTs(destination, useYarn).then(() => {
|
|
35
|
+
console.log('Project setup complete!');
|
|
36
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Router } from 'express';
|
|
2
2
|
import StatusCodes from 'http-status-codes';
|
|
3
3
|
|
|
4
4
|
import authService from '@services/auth-service';
|
|
5
5
|
import { ParamMissingError } from '@shared/errors';
|
|
6
6
|
import envVars from 'src/shared/env-vars';
|
|
7
|
-
import { IReq } from '@shared/types';
|
|
7
|
+
import { IReq, IRes } from '@shared/types';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
// **** Types **** //
|
|
@@ -34,7 +34,7 @@ export const p = {
|
|
|
34
34
|
/**
|
|
35
35
|
* Login a user.
|
|
36
36
|
*/
|
|
37
|
-
router.post(p.login, async (req: IReq<ILoginReq>, res:
|
|
37
|
+
router.post(p.login, async (req: IReq<ILoginReq>, res: IRes) => {
|
|
38
38
|
const { email, password } = req.body;
|
|
39
39
|
if (!email || !password) {
|
|
40
40
|
throw new ParamMissingError();
|
|
@@ -50,7 +50,7 @@ router.post(p.login, async (req: IReq<ILoginReq>, res: Response) => {
|
|
|
50
50
|
/**
|
|
51
51
|
* Logout the user.
|
|
52
52
|
*/
|
|
53
|
-
router.get(p.logout, (_:
|
|
53
|
+
router.get(p.logout, (_: IReq, res: IRes) => {
|
|
54
54
|
const { key, options } = envVars.cookieProps;
|
|
55
55
|
res.clearCookie(key, options);
|
|
56
56
|
return res.status(OK).end();
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import StatusCodes from 'http-status-codes';
|
|
2
|
-
import {
|
|
2
|
+
import { Router } from 'express';
|
|
3
3
|
|
|
4
4
|
import userService from '@services/user-service';
|
|
5
5
|
import { ParamMissingError } from '@shared/errors';
|
|
6
6
|
import { IUser } from '@models/user-model';
|
|
7
|
-
import { IReq } from '@shared/types';
|
|
7
|
+
import { IReq, IRes } from '@shared/types';
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
// **** Variables **** //
|
|
@@ -27,7 +27,7 @@ export const p = {
|
|
|
27
27
|
/**
|
|
28
28
|
* Get all users.
|
|
29
29
|
*/
|
|
30
|
-
router.get(p.get, async (_:
|
|
30
|
+
router.get(p.get, async (_: IReq, res: IRes) => {
|
|
31
31
|
const users = await userService.getAll();
|
|
32
32
|
return res.status(OK).json({ users });
|
|
33
33
|
});
|
|
@@ -35,7 +35,7 @@ router.get(p.get, async (_: Request, res: Response) => {
|
|
|
35
35
|
/**
|
|
36
36
|
* Add one user.
|
|
37
37
|
*/
|
|
38
|
-
router.post(p.add, async (req: IReq<{user: IUser}>, res:
|
|
38
|
+
router.post(p.add, async (req: IReq<{user: IUser}>, res: IRes) => {
|
|
39
39
|
const { user } = req.body;
|
|
40
40
|
if (!user) {
|
|
41
41
|
throw new ParamMissingError();
|
|
@@ -47,7 +47,7 @@ router.post(p.add, async (req: IReq<{user: IUser}>, res: Response) => {
|
|
|
47
47
|
/**
|
|
48
48
|
* Update one user.
|
|
49
49
|
*/
|
|
50
|
-
router.put(p.update, async (req: IReq<{user: IUser}>, res:
|
|
50
|
+
router.put(p.update, async (req: IReq<{user: IUser}>, res: IRes) => {
|
|
51
51
|
const { user } = req.body;
|
|
52
52
|
if (!user) {
|
|
53
53
|
throw new ParamMissingError();
|
|
@@ -59,7 +59,7 @@ router.put(p.update, async (req: IReq<{user: IUser}>, res: Response) => {
|
|
|
59
59
|
/**
|
|
60
60
|
* Delete one user.
|
|
61
61
|
*/
|
|
62
|
-
router.delete(p.delete, async (req:
|
|
62
|
+
router.delete(p.delete, async (req: IReq, res: IRes) => {
|
|
63
63
|
const { id } = req.params;
|
|
64
64
|
if (!id) {
|
|
65
65
|
throw new ParamMissingError();
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import * as e from 'express';
|
|
2
2
|
import { Query } from 'express-serve-static-core';
|
|
3
3
|
|
|
4
|
+
import { ISessionUser } from '@routes/middleware';
|
|
4
5
|
|
|
5
|
-
// **** Generics for Request Object **** //
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
// **** Express **** //
|
|
8
|
+
|
|
9
|
+
export interface IReq<T = void> extends e.Request {
|
|
8
10
|
body: T;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
export interface IReqQuery<T extends Query, U = void> extends e.Request {
|
|
12
14
|
query: T;
|
|
13
15
|
body: U;
|
|
14
|
-
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface IRes extends e.Response {
|
|
19
|
+
locals: {
|
|
20
|
+
sessionUser: ISessionUser;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import 'express';
|
|
2
2
|
|
|
3
|
-
import { ISessionUser } from '@routes/middleware';
|
|
4
|
-
|
|
5
|
-
|
|
6
3
|
|
|
7
4
|
// **** Declaration Merging **** //
|
|
8
5
|
|
|
@@ -11,10 +8,4 @@ declare module 'express' {
|
|
|
11
8
|
export interface Request {
|
|
12
9
|
signedCookies: Record<string, string>;
|
|
13
10
|
}
|
|
14
|
-
|
|
15
|
-
export interface Response {
|
|
16
|
-
locals: {
|
|
17
|
-
sessionUser: ISessionUser;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
11
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
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",
|