express-generator-typescript 2.7.7 → 2.7.9
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 +1 -1
- package/lib/express-generator-typescript.js +1 -1
- package/lib/project-files/package.json +0 -1
- package/lib/project-files/src/common/util/validators.ts +2 -9
- package/lib/project-files/src/models/User.ts +6 -7
- package/lib/project-files/src/repos/database.test.json +1 -1
- package/lib/project-files/tests/users.test.ts +4 -9
- package/lib/project-files/vitest.config.mts +1 -1
- package/package.json +1 -1
- package/README-git +0 -79
- package/express-typescript.png +0 -0
- package/lib/project-files/src/public/scripts/http.js +0 -26
- package/lib/project-files/src/public/scripts/users.js +0 -141
- /package/lib/project-files/src/models/common/{types/index.ts → types.ts} +0 -0
- /package/lib/project-files/tests/{support → aux}/setup.ts +0 -0
- /package/lib/project-files/tests/common/{types/index.ts → types.ts} +0 -0
- /package/lib/project-files/tests/common/{util/index.ts → utils.ts} +0 -0
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
# express-generator-typescript
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Command line tool which generates production-ready express templates with TypeScript baked in. Spin up a web server in seconds that follows the [TypeScript best practices](https://github.com/seanpmaxwell/Typescript-Best-Practices/blob/main/README.md).
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
## Documenation
|
|
@@ -14,7 +14,7 @@ const PROJECT_FOLDER_PATH = './project-files';
|
|
|
14
14
|
|
|
15
15
|
// Project-folder dependencies
|
|
16
16
|
const DEPENDENCIES = 'express dotenv morgan cookie-parser jet-logger ' +
|
|
17
|
-
'module-alias helmet jsonfile
|
|
17
|
+
'module-alias helmet jsonfile jet-paths dayjs jet-env ' +
|
|
18
18
|
'jet-validators',
|
|
19
19
|
DEV_DEPENDENCIES = 'ts-node typescript nodemon find supertest vitest ' +
|
|
20
20
|
'@types/node @types/find @types/morgan @types/cookie-parser ' +
|
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isDate } from 'jet-validators';
|
|
2
2
|
import { transform } from 'jet-validators/utils';
|
|
3
3
|
|
|
4
4
|
/******************************************************************************
|
|
5
5
|
Functions
|
|
6
6
|
******************************************************************************/
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Database relational key.
|
|
10
|
-
*/
|
|
11
|
-
export function isRelationalKey(arg: unknown): arg is number {
|
|
12
|
-
return isNumber(arg) && arg >= -1;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
8
|
/**
|
|
16
9
|
* Convert to date object then check is a validate date.
|
|
17
10
|
*/
|
|
18
|
-
export const
|
|
11
|
+
export const transformIsDate = transform(
|
|
19
12
|
arg => new Date(arg as string),
|
|
20
13
|
arg => isDate(arg),
|
|
21
14
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { isString } from 'jet-validators';
|
|
1
|
+
import { isString, isUnsignedInteger } from 'jet-validators';
|
|
2
2
|
import { parseObject, TParseOnError } from 'jet-validators/utils';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { transformIsDate } from '@src/common/util/validators';
|
|
5
5
|
import { IModel } from './common/types';
|
|
6
6
|
|
|
7
7
|
/******************************************************************************
|
|
@@ -9,7 +9,7 @@ import { IModel } from './common/types';
|
|
|
9
9
|
******************************************************************************/
|
|
10
10
|
|
|
11
11
|
const DEFAULT_USER_VALS: IUser = {
|
|
12
|
-
id:
|
|
12
|
+
id: 0,
|
|
13
13
|
name: '',
|
|
14
14
|
created: new Date(),
|
|
15
15
|
email: '',
|
|
@@ -30,10 +30,10 @@ export interface IUser extends IModel {
|
|
|
30
30
|
|
|
31
31
|
// Initialize the "parseUser" function
|
|
32
32
|
const parseUser = parseObject<IUser>({
|
|
33
|
-
id:
|
|
33
|
+
id: isUnsignedInteger,
|
|
34
34
|
name: isString,
|
|
35
35
|
email: isString,
|
|
36
|
-
created:
|
|
36
|
+
created: transformIsDate,
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
/******************************************************************************
|
|
@@ -46,8 +46,7 @@ const parseUser = parseObject<IUser>({
|
|
|
46
46
|
function __new__(user?: Partial<IUser>): IUser {
|
|
47
47
|
const defaults = { ...DEFAULT_USER_VALS };
|
|
48
48
|
defaults.created = new Date();
|
|
49
|
-
|
|
50
|
-
return parseUser(retVal, errors => {
|
|
49
|
+
return parseUser({ ...defaults, ...user }, errors => {
|
|
51
50
|
throw new Error('Setup new user failed ' + JSON.stringify(errors, null, 2));
|
|
52
51
|
});
|
|
53
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"users":[{"id":
|
|
1
|
+
{"users":[{"id":345992854447,"name":"Bill","created":"2025-12-18T02:17:25.124Z","email":"sean.maxwell@gmail.com"},{"id":321485906005,"name":"John Smith","created":"2025-12-18T02:17:25.124Z","email":"john.smith@gmail.com"},{"id":70616376029,"name":"Gordan Freeman","created":"2025-12-18T02:17:25.124Z","email":"gordan.freeman@gmail.com"}]}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import insertUrlParams from 'inserturlparams';
|
|
2
|
-
|
|
3
1
|
import UserRepo from '@src/repos/UserRepo';
|
|
4
2
|
import User, { IUser } from '@src/models/User';
|
|
5
3
|
import { USER_NOT_FOUND_ERR } from '@src/services/UserService';
|
|
@@ -8,8 +6,8 @@ import HTTP_STATUS_CODES from '@src/common/constants/HTTP_STATUS_CODES';
|
|
|
8
6
|
import { ValidationError } from '@src/common/util/route-errors';
|
|
9
7
|
import { JET_PATHS as Paths } from '@src/common/constants/PATHS';
|
|
10
8
|
|
|
11
|
-
import { compareUserArrays, parseValidationError } from './common/
|
|
12
|
-
import { agent } from './
|
|
9
|
+
import { compareUserArrays, parseValidationError } from './common/utils';
|
|
10
|
+
import { agent } from './aux/setup';
|
|
13
11
|
import { TRes } from './common/types';
|
|
14
12
|
|
|
15
13
|
/******************************************************************************
|
|
@@ -115,14 +113,11 @@ describe('UserRouter', () => {
|
|
|
115
113
|
// Delete User
|
|
116
114
|
describe(`"DELETE:${Paths.Users.Delete()}"`, () => {
|
|
117
115
|
|
|
118
|
-
const getPath = (id: number) => insertUrlParams(Paths.Users.Delete({ id}),
|
|
119
|
-
{ id });
|
|
120
|
-
|
|
121
116
|
// Success
|
|
122
117
|
it(`should return a status code of "${HTTP_STATUS_CODES.Ok}" if the ` +
|
|
123
118
|
'request was successful.', async () => {
|
|
124
119
|
const id = dbUsers[0].id,
|
|
125
|
-
res = await agent.delete(
|
|
120
|
+
res = await agent.delete(Paths.Users.Delete(id));
|
|
126
121
|
expect(res.status).toBe(HTTP_STATUS_CODES.Ok);
|
|
127
122
|
});
|
|
128
123
|
|
|
@@ -130,7 +125,7 @@ describe('UserRouter', () => {
|
|
|
130
125
|
it('should return a JSON object with the error message of ' +
|
|
131
126
|
`"${USER_NOT_FOUND_ERR}" and a status code of ` +
|
|
132
127
|
`"${HTTP_STATUS_CODES.NotFound}" if the id was not found.`, async () => {
|
|
133
|
-
const res: TRes = await agent.delete(
|
|
128
|
+
const res: TRes = await agent.delete(Paths.Users.Delete(-1));
|
|
134
129
|
expect(res.status).toBe(HTTP_STATUS_CODES.NotFound);
|
|
135
130
|
expect(res.body.error).toBe(USER_NOT_FOUND_ERR);
|
|
136
131
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-generator-typescript",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.9",
|
|
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",
|
package/README-git
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<img alt="express-generator-typescript" src="https://github.com/seanpmaxwell/express-generator-typescript/raw/master/express-typescript.png" width="420">
|
|
3
|
-
</p>
|
|
4
|
-
|
|
5
|
-
<p align="center">
|
|
6
|
-
<a href="https://www.npmjs.com/package/express-generator-typescript"><img src="https://img.shields.io/npm/v/express-generator-typescript.svg?style=for-the-badge&logo=npm" alt="NPM Version"></a>
|
|
7
|
-
<a href="https://www.npmjs.com/package/express-generator-typescript"><img src="https://img.shields.io/npm/dm/express-generator-typescript.svg?style=for-the-badge" alt="NPM Downloads"></a>
|
|
8
|
-
<a href="https://www.npmjs.com/package/express-generator-typescript"><img src="https://img.shields.io/npm/l/express-generator-typescript.svg?style=for-the-badge" alt="License"></a>
|
|
9
|
-
</p>
|
|
10
|
-
|
|
11
|
-
# express-generator-typescript
|
|
12
|
-
|
|
13
|
-
Production-ready Express application scaffolding with TypeScript baked in. Generate a modern API starter in seconds that follows the [TypeScript best practices](https://github.com/seanpmaxwell/Typescript-Best-Practices/blob/main/README.md) used to build this tool.
|
|
14
|
-
|
|
15
|
-
## Overview
|
|
16
|
-
|
|
17
|
-
`express-generator-typescript` creates a new Express application similar to the classic `express-generator` package, but the generated project is fully wired for TypeScript from day one. You get strict typing, linting, hot reloading, production builds, testing utilities, and sane defaults that focus on APIs (no view engine or opinionated ORM). Path aliases are preconfigured through `tsconfig-paths` and `_moduleAliases`, so referencing modules stays clean even as the app grows.
|
|
18
|
-
|
|
19
|
-
## Features
|
|
20
|
-
|
|
21
|
-
- **TypeScript-first** – strict compiler settings, linting, and sensible tsconfig defaults ready to go.
|
|
22
|
-
- **API-centric** – no view engine or extra dependencies; ideal for SPAs, mobile backends, or services.
|
|
23
|
-
- **Productivity tooling** – includes nodemon, ts-node, hot reload scripts, Jest, ESLint, and production builds.
|
|
24
|
-
- **Path aliases** – aliases configured in `tsconfig.json` and `preload.js` so you can import modules cleanly.
|
|
25
|
-
- **Keeps dependencies lean** – no bundled ORM or UI layers; only the essentials for Express + TS development.
|
|
26
|
-
|
|
27
|
-
## Installation
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
npx express-generator-typescript
|
|
31
|
-
# or install globally
|
|
32
|
-
npm install -g express-generator-typescript
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Quick Start
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
# generate a project (defaults to express-gen-ts)
|
|
39
|
-
npx express-generator-typescript my-api
|
|
40
|
-
|
|
41
|
-
cd my-api
|
|
42
|
-
|
|
43
|
-
# start developing at http://localhost:3000
|
|
44
|
-
npm run dev
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
Use `--use-yarn` if you prefer Yarn over npm. If you omit the project name, the generator creates `express-gen-ts`.
|
|
48
|
-
|
|
49
|
-
## CLI Options
|
|
50
|
-
|
|
51
|
-
| Option | Description |
|
|
52
|
-
| ----------------- | --------------------------------------------------------------------------- |
|
|
53
|
-
| `project name` | Folder to create. Defaults to `express-gen-ts` if omitted. |
|
|
54
|
-
| `--use-yarn` | Installs dependencies with Yarn instead of npm. |
|
|
55
|
-
| `--version` | Prints the generator version. |
|
|
56
|
-
|
|
57
|
-
> The historical `--with-auth` switch was removed in v2.5+. For an auth-ready example see the [express-jsonwebtoken-demo](https://github.com/seanpmaxwell/express-jsonwebtoken-demo) project.
|
|
58
|
-
|
|
59
|
-
## Sample Project
|
|
60
|
-
|
|
61
|
-
The generated code includes CRUD routes for illustrative `User` resources to demonstrate controllers, services, and routing patterns in Express + TypeScript. Replace these samples with your own modules after scaffolding.
|
|
62
|
-
|
|
63
|
-
## Available Scripts
|
|
64
|
-
|
|
65
|
-
- `npm run dev` / `npm run dev:hot` – Run the server with live reload.
|
|
66
|
-
- `npm run test` / `npm run test:hot` – Execute all Jest tests, optionally with watch mode.
|
|
67
|
-
- `npm run test -- users.test.ts` – Target a single test file.
|
|
68
|
-
- `npm run lint` – Run ESLint checks.
|
|
69
|
-
- `npm run build` – Compile the project for production.
|
|
70
|
-
- `npm start` – Serve the built project.
|
|
71
|
-
- `npm run type-check` – Run the TypeScript compiler without emitting files.
|
|
72
|
-
|
|
73
|
-
## Debugging
|
|
74
|
-
|
|
75
|
-
Development uses `nodemon` so the server restarts when files change. To enable the Node.js inspector, edit `nodemonConfig` in `package.json` (and `spec/nodemon.json` for tests) and change the `exec` value from `ts-node` to `node --inspect -r ts-node/register`.
|
|
76
|
-
|
|
77
|
-
## License
|
|
78
|
-
|
|
79
|
-
[MIT](LICENSE)
|
package/express-typescript.png
DELETED
|
Binary file
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
var Http = (() => {
|
|
2
|
-
|
|
3
|
-
// Setup request for json
|
|
4
|
-
var getOptions = (verb, data) => {
|
|
5
|
-
var options = {
|
|
6
|
-
dataType: 'json',
|
|
7
|
-
method: verb,
|
|
8
|
-
headers: {
|
|
9
|
-
'Accept': 'application/json',
|
|
10
|
-
'Content-Type': 'application/json',
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
if (!!data) {
|
|
14
|
-
options.body = JSON.stringify(data);
|
|
15
|
-
}
|
|
16
|
-
return options;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// Set Http methods
|
|
20
|
-
return {
|
|
21
|
-
get: (path) => fetch(path, getOptions('GET')),
|
|
22
|
-
post: (path, data) => fetch(path, getOptions('POST', data)),
|
|
23
|
-
put: (path, data) => fetch(path, getOptions('PUT', data)),
|
|
24
|
-
delete: (path) => fetch(path, getOptions('DELETE')),
|
|
25
|
-
};
|
|
26
|
-
})();
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
|
|
3
|
-
/******************************************************************************
|
|
4
|
-
Constants
|
|
5
|
-
******************************************************************************/
|
|
6
|
-
|
|
7
|
-
const DateFormatter = new Intl.DateTimeFormat('en-US', {
|
|
8
|
-
year: 'numeric',
|
|
9
|
-
month: '2-digit',
|
|
10
|
-
day: '2-digit',
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const formatDate = (date) => DateFormatter.format(new Date(date));
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/******************************************************************************
|
|
17
|
-
Run
|
|
18
|
-
******************************************************************************/
|
|
19
|
-
|
|
20
|
-
// Start
|
|
21
|
-
displayUsers();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
/******************************************************************************
|
|
25
|
-
Functions
|
|
26
|
-
******************************************************************************/
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Call api
|
|
30
|
-
*/
|
|
31
|
-
function displayUsers() {
|
|
32
|
-
Http
|
|
33
|
-
.get('/api/users/all')
|
|
34
|
-
.then(resp => resp.json())
|
|
35
|
-
.then(resp => {
|
|
36
|
-
var allUsersTemplate = document.getElementById('all-users-template'),
|
|
37
|
-
allUsersTemplateHtml = allUsersTemplate.innerHTML,
|
|
38
|
-
template = Handlebars.compile(allUsersTemplateHtml);
|
|
39
|
-
var allUsersAnchor = document.getElementById('all-users-anchor');
|
|
40
|
-
allUsersAnchor.innerHTML = template({
|
|
41
|
-
users: resp.users.map(user => ({
|
|
42
|
-
...user,
|
|
43
|
-
createdFormatted: formatDate(user.created),
|
|
44
|
-
})),
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Setup event listener for button click
|
|
50
|
-
document.addEventListener('click', event => {
|
|
51
|
-
event.preventDefault();
|
|
52
|
-
var ele = event.target;
|
|
53
|
-
if (ele.matches('#add-user-btn')) {
|
|
54
|
-
addUser();
|
|
55
|
-
} else if (ele.matches('.edit-user-btn')) {
|
|
56
|
-
showEditView(ele.parentNode.parentNode);
|
|
57
|
-
} else if (ele.matches('.cancel-edit-btn')) {
|
|
58
|
-
cancelEdit(ele.parentNode.parentNode);
|
|
59
|
-
} else if (ele.matches('.submit-edit-btn')) {
|
|
60
|
-
submitEdit(ele);
|
|
61
|
-
} else if (ele.matches('.delete-user-btn')) {
|
|
62
|
-
deleteUser(ele);
|
|
63
|
-
}
|
|
64
|
-
}, false);
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Add a new user.
|
|
68
|
-
*/
|
|
69
|
-
function addUser() {
|
|
70
|
-
var nameInput = document.getElementById('name-input');
|
|
71
|
-
var emailInput = document.getElementById('email-input');
|
|
72
|
-
var data = {
|
|
73
|
-
user: {
|
|
74
|
-
id: -1,
|
|
75
|
-
name: nameInput.value,
|
|
76
|
-
email: emailInput.value,
|
|
77
|
-
created: new Date(),
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
// Call api
|
|
81
|
-
Http
|
|
82
|
-
.post('/api/users/add', data)
|
|
83
|
-
.then(() => {
|
|
84
|
-
nameInput.value = '';
|
|
85
|
-
emailInput.value = '';
|
|
86
|
-
displayUsers();
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Show edit view.
|
|
92
|
-
*/
|
|
93
|
-
function showEditView(userEle) {
|
|
94
|
-
var normalView = userEle.getElementsByClassName('normal-view')[0];
|
|
95
|
-
var editView = userEle.getElementsByClassName('edit-view')[0];
|
|
96
|
-
normalView.style.display = 'none';
|
|
97
|
-
editView.style.display = 'block';
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Cancel edit.
|
|
102
|
-
*/
|
|
103
|
-
function cancelEdit(userEle) {
|
|
104
|
-
var normalView = userEle.getElementsByClassName('normal-view')[0];
|
|
105
|
-
var editView = userEle.getElementsByClassName('edit-view')[0];
|
|
106
|
-
normalView.style.display = 'block';
|
|
107
|
-
editView.style.display = 'none';
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Submit edit.
|
|
112
|
-
*/
|
|
113
|
-
function submitEdit(ele) {
|
|
114
|
-
var userEle = ele.parentNode.parentNode;
|
|
115
|
-
var nameInput = userEle.getElementsByClassName('name-edit-input')[0];
|
|
116
|
-
var emailInput = userEle.getElementsByClassName('email-edit-input')[0];
|
|
117
|
-
var id = ele.getAttribute('data-user-id');
|
|
118
|
-
var created = ele.getAttribute('data-user-created');
|
|
119
|
-
console.log(ele, created)
|
|
120
|
-
var data = {
|
|
121
|
-
user: {
|
|
122
|
-
id: Number(id),
|
|
123
|
-
name: nameInput.value,
|
|
124
|
-
email: emailInput.value,
|
|
125
|
-
created: new Date(created),
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
Http
|
|
129
|
-
.put('/api/users/update', data)
|
|
130
|
-
.then(() => displayUsers());
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Delete a user
|
|
135
|
-
*/
|
|
136
|
-
function deleteUser(ele) {
|
|
137
|
-
var id = ele.getAttribute('data-user-id');
|
|
138
|
-
Http
|
|
139
|
-
.delete('/api/users/delete/' + id)
|
|
140
|
-
.then(() => displayUsers());
|
|
141
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|