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.
Files changed (93) hide show
  1. package/README.md +24 -33
  2. package/lib/cli.js +5 -25
  3. package/lib/express-generator-typescript.js +11 -19
  4. package/lib/project-files/README.md +18 -1
  5. package/lib/{project-files-auth/env/development.env → project-files/config/.env.development} +0 -9
  6. package/lib/project-files/config/.env.production +14 -0
  7. package/lib/project-files/{env/test.env → config/.env.test} +0 -10
  8. package/lib/project-files/config.js +18 -0
  9. package/lib/project-files/config.ts +22 -0
  10. package/lib/project-files/eslint.config.ts +96 -0
  11. package/lib/project-files/gitignore +2 -0
  12. package/lib/project-files/package.json +16 -9
  13. package/lib/project-files/scripts/build.ts +4 -0
  14. package/lib/project-files/spec/support/Paths.ts +1 -6
  15. package/lib/project-files/spec/support/apiCb.ts +18 -6
  16. package/lib/project-files/spec/tests/users.spec.ts +28 -33
  17. package/lib/project-files/spec/types/misc.ts +7 -6
  18. package/lib/project-files/spec/types/supertest/index.d.ts +2 -2
  19. package/lib/project-files/src/common/Env.ts +10 -0
  20. package/lib/project-files/src/common/route-errors.ts +41 -0
  21. package/lib/project-files/src/index.ts +3 -3
  22. package/lib/project-files/src/models/User.ts +9 -57
  23. package/lib/project-files/src/repos/MockOrm.ts +0 -2
  24. package/lib/project-files/src/repos/database.json +1 -1
  25. package/lib/project-files/src/routes/UserRoutes.ts +14 -5
  26. package/lib/project-files/src/{common → routes/common}/Paths.ts +0 -4
  27. package/lib/project-files/src/routes/common/index.ts +37 -0
  28. package/lib/project-files/src/routes/index.ts +1 -1
  29. package/lib/project-files/src/server.ts +7 -9
  30. package/lib/project-files/src/services/UserService.ts +1 -1
  31. package/lib/project-files/src/util/misc.ts +0 -16
  32. package/lib/project-files/src/util/schema.ts +11 -0
  33. package/lib/project-files/src/util/validators.ts +322 -0
  34. package/lib/project-files/tsconfig.json +20 -71
  35. package/lib/project-files/tsconfig.prod.json +22 -2
  36. package/package.json +1 -1
  37. package/lib/project-files/env/development.env +0 -24
  38. package/lib/project-files/env/production.env +0 -25
  39. package/lib/project-files/eslint.config.mjs +0 -58
  40. package/lib/project-files/preload.js +0 -23
  41. package/lib/project-files/src/common/EnvVars.ts +0 -24
  42. package/lib/project-files/src/common/classes.ts +0 -32
  43. package/lib/project-files/src/common/misc.ts +0 -5
  44. package/lib/project-files/src/routes/common/check.ts +0 -143
  45. package/lib/project-files/src/routes/common/types.ts +0 -8
  46. package/lib/project-files-auth/README.md +0 -35
  47. package/lib/project-files-auth/env/production.env +0 -25
  48. package/lib/project-files-auth/env/test.env +0 -24
  49. package/lib/project-files-auth/eslint.config.mjs +0 -58
  50. package/lib/project-files-auth/gitignore +0 -3
  51. package/lib/project-files-auth/package.json +0 -60
  52. package/lib/project-files-auth/preload.js +0 -23
  53. package/lib/project-files-auth/scripts/build.ts +0 -62
  54. package/lib/project-files-auth/spec/index.ts +0 -46
  55. package/lib/project-files-auth/spec/support/Paths.ts +0 -10
  56. package/lib/project-files-auth/spec/support/apiCb.ts +0 -76
  57. package/lib/project-files-auth/spec/support/jasmine.json +0 -11
  58. package/lib/project-files-auth/spec/support/login.ts +0 -42
  59. package/lib/project-files-auth/spec/tests/auth.spec.ts +0 -115
  60. package/lib/project-files-auth/spec/tests/users.spec.ts +0 -190
  61. package/lib/project-files-auth/spec/types/misc.ts +0 -12
  62. package/lib/project-files-auth/spec/types/supertest/index.d.ts +0 -14
  63. package/lib/project-files-auth/src/common/EnvVars.ts +0 -24
  64. package/lib/project-files-auth/src/common/HttpStatusCodes.ts +0 -386
  65. package/lib/project-files-auth/src/common/Paths.ts +0 -20
  66. package/lib/project-files-auth/src/common/classes.ts +0 -31
  67. package/lib/project-files-auth/src/index.ts +0 -12
  68. package/lib/project-files-auth/src/models/User.ts +0 -89
  69. package/lib/project-files-auth/src/public/scripts/http.js +0 -26
  70. package/lib/project-files-auth/src/public/scripts/login.js +0 -15
  71. package/lib/project-files-auth/src/public/scripts/users.js +0 -138
  72. package/lib/project-files-auth/src/public/stylesheets/login.css +0 -24
  73. package/lib/project-files-auth/src/public/stylesheets/users.css +0 -43
  74. package/lib/project-files-auth/src/repos/MockOrm.ts +0 -42
  75. package/lib/project-files-auth/src/repos/UserRepo.ts +0 -93
  76. package/lib/project-files-auth/src/repos/database.json +0 -1
  77. package/lib/project-files-auth/src/routes/AuthRoutes.ts +0 -42
  78. package/lib/project-files-auth/src/routes/UserRoutes.ts +0 -55
  79. package/lib/project-files-auth/src/routes/common/check.ts +0 -143
  80. package/lib/project-files-auth/src/routes/common/types.ts +0 -22
  81. package/lib/project-files-auth/src/routes/index.ts +0 -43
  82. package/lib/project-files-auth/src/routes/middleware/adminMw.ts +0 -47
  83. package/lib/project-files-auth/src/server.ts +0 -91
  84. package/lib/project-files-auth/src/services/AuthService.ts +0 -57
  85. package/lib/project-files-auth/src/services/UserService.ts +0 -59
  86. package/lib/project-files-auth/src/util/PwdUtil.ts +0 -39
  87. package/lib/project-files-auth/src/util/SessionUtil.ts +0 -94
  88. package/lib/project-files-auth/src/util/misc.ts +0 -22
  89. package/lib/project-files-auth/src/views/login.html +0 -58
  90. package/lib/project-files-auth/src/views/users.html +0 -140
  91. package/lib/project-files-auth/tsconfig.json +0 -87
  92. package/lib/project-files-auth/tsconfig.prod.json +0 -12
  93. /package/lib/{project-files-auth/src/common/misc.ts → project-files/src/common/constants.ts} +0 -0
package/README.md CHANGED
@@ -9,39 +9,29 @@
9
9
 
10
10
  ## What is it?
11
11
 
12
- Creates a new express application similar to the _express-generator_ module. Except this new
13
- application is configured to use TypeScript instead of plain JavaScript.
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.
14
13
 
15
14
  This project complies with Typescript best practices listed <a href="https://github.com/seanpmaxwell/Typescript-Best-Practices/blob/main/README.md">here</a>.
16
15
 
17
16
 
18
17
  ## Why express-generator-typescript?
19
18
 
20
- NodeJS is great for the rapid development of web-projects, but is often neglected because of the lack of
21
- type safety. TypeScript solves this issue and (along with its linter file) can even make your code
22
- more robust than some other static languages like Java.
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.
23
20
 
24
- There are some other tools out there to generate express apps with TypeScript such as
25
- _express-generator-ts_, but these either haven't been updated in a while or install a lot of junk
26
- in your project (such as an ORM).
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).
27
22
 
28
- Due to the heavy use of single-page-applications, no view-engine is configured by default. Express is
29
- only setup with the minimal settings for calling APIs and serving an index.html file. All the tools you
30
- need to run for development (while restarting on changes), building, testing, and running for production
31
- are packaged with this library.
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.
32
24
 
33
- In addition, relative paths are also setup, so you don't have to go through the trouble of installing
34
- and configuring _tsconfig-paths_ and _module-alias_. Just make sure to update `paths` in _tsconfig.json_
35
- and `_moduleAliases` in _preload.js_ if you want to add/edit the relative paths.
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.
36
26
 
37
27
 
38
28
  ## Sample-project
39
29
 
40
- When you run _express-generator-typescript_, it sets up a simple application with routes for
41
- adding, updating, deleting, and fetching user objects. This is just to demonstrate how routing is done
42
- with express.
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.
43
31
 
44
- If you want a fully-secure application, you can pass the `--with-auth` option and you will have an application which requires you to login before calling APIs on user objects. The app is configured with production quality client-side security and uses signed-cookies and jsonwebtokens to store user-session data. If you're new to web-development and still learning about securing websites, I highly encourage to use this option.
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>.
45
35
 
46
36
 
47
37
  ## Installation
@@ -55,9 +45,7 @@ $ npm install -g express-generator-typescript
55
45
 
56
46
  ## Quick Start
57
47
 
58
- The quickest way to get started is use npx and pass in the name of the project you want to create.
59
- If you don't specify a project name, the default _express-gen-ts_ will be used instead. If you
60
- want to use `yarn` instead of `npm`, pass the option `--use-yarn`.
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`.
61
49
 
62
50
  Create the app:<br/>
63
51
  With no options: `$ npx express-generator-typescript`<br/>
@@ -73,28 +61,31 @@ $ cd "project name" && npm run dev
73
61
 
74
62
  ## Available commands for the server.
75
63
 
76
- - Run the server in development mode: `npm run dev`.
77
- - Run all unit-tests: `npm test`.
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`.
78
66
  - Run a single unit-test: `npm test -- --testFile="name of test file" (i.e. --testFile=Users)`.
79
67
  - Check for linting errors: `npm run lint`.
80
68
  - Build the project for production: `npm run build`.
81
69
  - Run the production build: `npm start`.
70
+ - Check for typescript errors: `npm run type-check"`.
82
71
 
83
72
 
84
73
  ## Debugging
85
74
 
86
- During development, _express-generator-typescript_ uses `nodemon` to restart the server when changes
87
- are detected. If you want to enable debugging for node, you'll need to modify the nodemon configurations.
88
- This is located under `nodemonConfig:` in `package.json` for the server and `./spec/nodemon.json` for
89
- unit-testing. For the `exec` property, replace `ts-node` with `node --inspect -r ts-node/register`.
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
+
90
77
 
78
+ ## Note for VSCode users
91
79
 
92
- ## Note for windows users
80
+ In order to use eslint as a typescript file with VSCode, you need to add a setting to your eslint options. At the root of your project, add a `.vscode/settings.json` file (if you don't have one already) and add the option `unstable_ts_config`:
81
+
82
+ ```typescript
83
+ "eslint.options": {
84
+ "flags": ["unstable_ts_config"]
85
+ }
86
+ ```
87
+ <br/>
93
88
 
94
- If you are on Windows, the `bcrypt` module tends to be fussy. To use this module on Windows you
95
- need to make sure you have the node Windows build tools installed. I don't want to post instructions
96
- because they might change frequently. I would search the Microsoft docs on how to setup Node for Windows.
97
- To be able to debug in VSCODE on windows I also had to install the `node-gyp` module globally as well.
98
89
 
99
90
  Happy web deving :)
100
91
 
package/lib/cli.js CHANGED
@@ -1,22 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- /**
4
- * Create new express-generator-typescript project.
5
- *
6
- * created by Sean Maxwell, 5/31/2019
7
- */
3
+ const path = require('path'),
4
+ expressGenTs = require('../lib/express-generator-typescript');
8
5
 
9
- const path = require('path');
10
- const expressGenTs = require('../lib/express-generator-typescript');
11
6
 
7
+ // **** Run Script **** //
12
8
 
13
- // **** Start **** //
14
-
9
+ // Init
15
10
  console.log('Setting up new Express/TypeScript project...');
16
-
17
-
18
- // **** Process Options **** //
19
-
20
11
  const args = process.argv.slice(2);
21
12
 
22
13
  // Setup use yarn
@@ -27,14 +18,6 @@ if (useYarnIdx > -1) {
27
18
  args.splice(useYarnIdx, 1);
28
19
  }
29
20
 
30
- // Setup include authentication
31
- let withAuth = false;
32
- const withAuthIdx = args.indexOf('--with-auth');
33
- if (withAuthIdx > -1) {
34
- withAuth = true;
35
- args.splice(withAuthIdx, 1);
36
- }
37
-
38
21
  // Setup destination
39
22
  let destination = 'express-gen-ts';
40
23
  if (args.length > 0) {
@@ -42,10 +25,7 @@ if (args.length > 0) {
42
25
  }
43
26
  destination = path.join(process.cwd(), destination);
44
27
 
45
-
46
- // **** Call the generator script **** //
47
-
48
28
  // Creating new project finished
49
- expressGenTs(destination, useYarn, withAuth).then(() => {
29
+ expressGenTs(destination, useYarn).then(() => {
50
30
  console.log('Project setup complete!');
51
31
  });
@@ -8,20 +8,17 @@ const path = require('path'),
8
8
  // **** Variables **** //
9
9
 
10
10
  // Project folder paths
11
- const PROJECT_FOLDER_PATH = './project-files',
12
- PROJECT_FOLDER_PATH_AUTH = './project-files-auth';
11
+ const PROJECT_FOLDER_PATH = './project-files';
13
12
 
14
13
  // Project-folder dependencies
15
14
  const DEPENDENCIES = 'express dotenv morgan cookie-parser jet-logger ' +
16
15
  'module-alias express-async-errors helmet jsonfile inserturlparams ' +
17
- 'jet-paths moment ',
18
- DEPENDENCIES_AUTH = ' bcrypt jsonwebtoken',
16
+ 'jet-paths dayjs jet-schema jet-env ',
19
17
  DEV_DEPENDENCIES = 'ts-node typescript nodemon find jasmine supertest ' +
20
18
  '@types/node @types/express @types/jasmine @types/find @types/morgan ' +
21
- '@types/cookie-parser @types/supertest fs-extra tsconfig-paths ' +
22
- '@types/jsonfile @types/fs-extra ' +
23
- 'eslint @eslint/js @types/eslint__js typescript-eslint eslint-plugin-n @stylistic/eslint-plugin-ts',
24
- DEV_DEPENDENCIES_AUTH = ' @types/bcrypt @types/jsonwebtoken';
19
+ '@types/cookie-parser @types/supertest fs-extra tsconfig-paths jiti @swc/core ' +
20
+ '@types/jsonfile @types/fs-extra @types/module-alias @stylistic/eslint-plugin-js ' +
21
+ 'eslint @eslint/js @types/eslint__js typescript-eslint eslint-plugin-n @stylistic/eslint-plugin-ts';
25
22
 
26
23
  // "ncp" options
27
24
  const ncpOpts = {
@@ -36,12 +33,12 @@ const ncpOpts = {
36
33
  /**
37
34
  * Entry point
38
35
  */
39
- async function expressGenTs(destination, useYarn, withAuth) {
36
+ async function expressGenTs(destination, useYarn) {
40
37
  try {
41
- await copyProjectFiles(destination, withAuth);
38
+ await copyProjectFiles(destination);
42
39
  updatePackageJson(destination);
43
40
  await renameGitigoreFile(destination);
44
- downloadNodeModules(destination, useYarn, withAuth);
41
+ downloadNodeModules(destination, useYarn);
45
42
  } catch (err) {
46
43
  console.error(err);
47
44
  }
@@ -50,9 +47,8 @@ async function expressGenTs(destination, useYarn, withAuth) {
50
47
  /**
51
48
  * Copy project files
52
49
  */
53
- function copyProjectFiles(destination, withAuth) {
54
- const folder = (withAuth ? PROJECT_FOLDER_PATH_AUTH : PROJECT_FOLDER_PATH),
55
- source = path.join(__dirname, folder);
50
+ function copyProjectFiles(destination) {
51
+ const source = path.join(__dirname, PROJECT_FOLDER_PATH);
56
52
  return /** @type {Promise<void>} */(new Promise((res, rej) => {
57
53
  return ncp(source, destination, ncpOpts, (err) => {
58
54
  return (!!err ? rej(err) : res());
@@ -88,15 +84,11 @@ function renameGitigoreFile(destination) {
88
84
  /**
89
85
  * Download the dependencies.
90
86
  */
91
- function downloadNodeModules(destination, useYarn, withAuth) {
87
+ function downloadNodeModules(destination, useYarn) {
92
88
  const options = { cwd: destination };
93
89
  // Setup dependencies string
94
90
  let depStr = DEPENDENCIES,
95
91
  devDepStr = DEV_DEPENDENCIES;
96
- if (withAuth) {
97
- depStr += DEPENDENCIES_AUTH;
98
- devDepStr += DEV_DEPENDENCIES_AUTH;
99
- }
100
92
  // Setup download command
101
93
  let downloadLibCmd,
102
94
  downloadDepCmd;
@@ -5,31 +5,48 @@ This project was created with [express-generator-typescript](https://github.com/
5
5
 
6
6
  ## Available Scripts
7
7
 
8
+ ### `npm run clean-install`
9
+
10
+ Remove the existing `node_modules/` folder, `package-lock.json`, and reinstall all library modules.
11
+
12
+
8
13
  ### `npm run dev` or `npm run dev:hot` (hot reloading)
9
14
 
10
- Run the server in development mode.
15
+ Run the server in development mode.<br/>
16
+
17
+ **IMPORTANT** development mode uses `swc` for performance reasons which DOES NOT check for typescript errors. Run `npm run type-check` to check for type errors. NOTE: you should use your IDE to prevent most type errors.
18
+
11
19
 
12
20
  ### `npm test` or `npm run test:hot` (hot reloading)
13
21
 
14
22
  Run all unit-tests.
15
23
 
24
+
16
25
  ### `npm test -- "name of test file" (i.e. users).`
17
26
 
18
27
  Run a single unit-test.
19
28
 
29
+
20
30
  ### `npm run lint`
21
31
 
22
32
  Check for linting errors.
23
33
 
34
+
24
35
  ### `npm run build`
25
36
 
26
37
  Build the project for production.
27
38
 
39
+
28
40
  ### `npm start`
29
41
 
30
42
  Run the production build (Must be built first).
31
43
 
32
44
 
45
+ ### `npm run type-check`
46
+
47
+ Check for typescript errors.
48
+
49
+
33
50
  ## Additional Notes
34
51
 
35
52
  - If `npm run dev` gives you issues with bcrypt on MacOS you may need to run: `npm rebuild bcrypt --build-from-source`.
@@ -13,12 +13,3 @@ JET_LOGGER_FILEPATH=jet-logger.log
13
13
  JET_LOGGER_TIMESTAMP=TRUE
14
14
  JET_LOGGER_FORMAT=LINE
15
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
@@ -0,0 +1,14 @@
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
@@ -12,13 +12,3 @@ JET_LOGGER_MODE=CONSOLE
12
12
  JET_LOGGER_FILEPATH=jet-logger.log
13
13
  JET_LOGGER_TIMESTAMP=TRUE
14
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
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const dotenv_1 = __importDefault(require("dotenv"));
8
+ const module_alias_1 = __importDefault(require("module-alias"));
9
+ const NODE_ENV = (process.env.NODE_ENV ?? 'development');
10
+ const result2 = dotenv_1.default.config({
11
+ path: path_1.default.join(__dirname, `./config/.env.${NODE_ENV}`),
12
+ });
13
+ if (result2.error) {
14
+ throw result2.error;
15
+ }
16
+ if (__filename.endsWith('js')) {
17
+ module_alias_1.default.addAlias('@src', __dirname + '/dist');
18
+ }
@@ -0,0 +1,22 @@
1
+ /* eslint-disable n/no-process-env */
2
+
3
+ import path from 'path';
4
+ import dotenv from 'dotenv';
5
+ import moduleAlias from '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, `./config/.env.${NODE_ENV}`),
14
+ });
15
+ if (result2.error) {
16
+ throw result2.error;
17
+ }
18
+
19
+ // Configure moduleAlias
20
+ if (__filename.endsWith('js')) {
21
+ moduleAlias.addAlias('@src', __dirname + '/dist');
22
+ }
@@ -0,0 +1,96 @@
1
+ import eslint from '@eslint/js';
2
+ import tseslint from 'typescript-eslint';
3
+ import stylisticJs from '@stylistic/eslint-plugin-js';
4
+ import stylisticTs from '@stylistic/eslint-plugin-ts';
5
+ import nodePlugin from 'eslint-plugin-n';
6
+
7
+
8
+ export default tseslint.config(
9
+ eslint.configs.recommended,
10
+ nodePlugin.configs['flat/recommended-script'],
11
+ ...tseslint.configs.strictTypeChecked,
12
+ ...tseslint.configs.stylisticTypeChecked,
13
+ {
14
+ ignores: [
15
+ '**/node_modules/*',
16
+ '**/*.mjs',
17
+ '**/*.js',
18
+ ],
19
+ },
20
+ {
21
+ languageOptions: {
22
+ parserOptions: {
23
+ project: './tsconfig.json',
24
+ warnOnUnsupportedTypeScriptVersion: false,
25
+ },
26
+ },
27
+ },
28
+ {
29
+ plugins: {
30
+ '@stylistic/js': stylisticJs,
31
+ '@stylistic/ts': stylisticTs,
32
+ },
33
+ },
34
+ {
35
+ files: ['**/*.ts'],
36
+ },
37
+ {
38
+ rules: {
39
+ '@typescript-eslint/explicit-member-accessibility': 'warn',
40
+ '@typescript-eslint/no-misused-promises': 0,
41
+ '@typescript-eslint/no-floating-promises': 0,
42
+ '@typescript-eslint/no-confusing-void-expression': 0,
43
+ '@typescript-eslint/no-unnecessary-condition': 0,
44
+ '@typescript-eslint/restrict-template-expressions': [
45
+ 'error', { allowNumber: true },
46
+ ],
47
+ '@typescript-eslint/restrict-plus-operands': [
48
+ 'warn', { allowNumberAndString: true },
49
+ ],
50
+ '@typescript-eslint/no-unused-vars': 'warn',
51
+ '@typescript-eslint/no-unsafe-enum-comparison': 0,
52
+ '@typescript-eslint/no-unnecessary-type-parameters': 0,
53
+ '@stylistic/js/no-extra-semi': 'warn',
54
+ 'max-len': [
55
+ 'warn',
56
+ {
57
+ 'code': 80,
58
+ },
59
+ ],
60
+ '@stylistic/ts/semi': ['warn', 'always'],
61
+ '@stylistic/ts/member-delimiter-style': ['warn', {
62
+ 'multiline': {
63
+ 'delimiter': 'comma',
64
+ 'requireLast': true,
65
+ },
66
+ 'singleline': {
67
+ 'delimiter': 'comma',
68
+ 'requireLast': false,
69
+ },
70
+ 'overrides': {
71
+ 'interface': {
72
+ 'singleline': {
73
+ 'delimiter': 'semi',
74
+ 'requireLast': false,
75
+ },
76
+ 'multiline': {
77
+ 'delimiter': 'semi',
78
+ 'requireLast': true,
79
+ },
80
+ },
81
+ },
82
+ }],
83
+ '@typescript-eslint/no-non-null-assertion': 0,
84
+ '@typescript-eslint/no-unused-expressions': 'warn',
85
+ 'comma-dangle': ['warn', 'always-multiline'],
86
+ 'no-console': 1,
87
+ 'no-extra-boolean-cast': 0,
88
+ 'indent': ['warn', 2],
89
+ 'quotes': ['warn', 'single'],
90
+ 'n/no-process-env': 1,
91
+ 'n/no-missing-import': 0,
92
+ 'n/no-unpublished-import': 0,
93
+ 'prefer-const': 'warn',
94
+ },
95
+ },
96
+ );
@@ -1,3 +1,5 @@
1
1
  **/node_modules
2
2
  dist/
3
+ temp/
3
4
  **/**/*.log
5
+ config.js
@@ -2,35 +2,40 @@
2
2
  "name": "express-typescript-example",
3
3
  "version": "0.0.0",
4
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"
5
+ "build": "ts-node ./scripts/build.ts",
6
+ "clean-install": "rm -rf ./node_modules && rm -r package-lock.json && npm i",
7
+ "dev": "NODE_ENV=development ts-node ./src",
8
+ "dev:hot": "nodemon --exec \"npm run dev\" --watch ./src --ext .ts",
9
+ "lint": "eslint --flag unstable_ts_config",
10
+ "start": "NODE_ENV=production node -r ./config.js ./dist",
11
+ "test": "NODE_ENV=test ts-node ./spec",
12
+ "test:hot": "nodemon --exec \"npm run test\" --watch ./src --watch ./spec --ext .ts",
13
+ "type-check": "tsc --noEmit"
13
14
  },
14
15
  "engines": {
15
16
  "node": ">=16.0.0"
16
17
  },
17
18
  "dependencies": {
18
19
  "cookie-parser": "^1.4.6",
20
+ "dayjs": "^1.11.13",
19
21
  "dotenv": "^16.0.2",
20
22
  "express": "^4.18.1",
21
23
  "express-async-errors": "^3.1.1",
22
24
  "helmet": "^6.0.0",
23
25
  "inserturlparams": "^1.0.1",
26
+ "jet-env": "^1.1.4",
24
27
  "jet-logger": "^1.3.1",
25
28
  "jet-paths": "^1.0.5",
29
+ "jet-schema": "^1.4.2",
26
30
  "jsonfile": "^6.1.0",
27
31
  "module-alias": "^2.2.2",
28
- "moment": "^2.30.1",
29
32
  "morgan": "^1.10.0"
30
33
  },
31
34
  "devDependencies": {
32
35
  "@eslint/js": "^9.11.1",
36
+ "@stylistic/eslint-plugin-js": "^2.11.0",
33
37
  "@stylistic/eslint-plugin-ts": "^2.8.0",
38
+ "@swc/core": "^1.9.3",
34
39
  "@types/cookie-parser": "^1.4.3",
35
40
  "@types/eslint__js": "^8.42.3",
36
41
  "@types/express": "^4.17.13",
@@ -38,6 +43,7 @@
38
43
  "@types/fs-extra": "^9.0.13",
39
44
  "@types/jasmine": "^4.3.0",
40
45
  "@types/jsonfile": "^6.1.0",
46
+ "@types/module-alias": "^2.0.4",
41
47
  "@types/morgan": "^1.9.3",
42
48
  "@types/node": "^18.7.14",
43
49
  "@types/supertest": "^6.0.2",
@@ -46,6 +52,7 @@
46
52
  "find": "^0.3.0",
47
53
  "fs-extra": "^10.1.0",
48
54
  "jasmine": "^4.3.0",
55
+ "jiti": "^2.4.1",
49
56
  "nodemon": "^2.0.19",
50
57
  "supertest": "^6.3.4",
51
58
  "ts-node": "^10.9.1",
@@ -15,6 +15,10 @@ import childProcess from 'child_process';
15
15
  // Copy
16
16
  await copy('./src/public', './dist/public');
17
17
  await copy('./src/views', './dist/views');
18
+ await copy('./src/repos/database.json', './dist/repos/database.json');
19
+ await copy('./temp/config.js', './config.js');
20
+ await copy('./temp/src', './dist');
21
+ await remove('./temp/');
18
22
  } catch (err) {
19
23
  logger.err(err);
20
24
  // eslint-disable-next-line n/no-process-exit
@@ -1,10 +1,5 @@
1
- /**
2
- * Convert paths to full for testing.
3
- */
4
-
5
1
  import jetPaths from 'jet-paths';
6
-
7
- import Paths from '@src/common/Paths';
2
+ import Paths from '@src/routes/common/Paths';
8
3
 
9
4
 
10
5
  export default jetPaths(Paths);
@@ -1,5 +1,5 @@
1
1
  import { CallbackHandler } from 'supertest';
2
- import moment from 'moment';
2
+ import dayjs, { Dayjs } from 'dayjs';
3
3
  import logger from 'jet-logger';
4
4
 
5
5
  import { TApiCb, TRes } from 'spec/types/misc';
@@ -51,11 +51,7 @@ function _iterate(param: unknown, prop: string): void {
51
51
  }
52
52
  // Check valid string or Date object. If undefined just skip
53
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
- ) {
54
+ if (val !== undefined && !_isValidDate(val)) {
59
55
  throw new Error('Property must be a valid date-string or Date() object');
60
56
  }
61
57
  // Convert and iterate
@@ -70,6 +66,22 @@ function _iterate(param: unknown, prop: string): void {
70
66
  }
71
67
  }
72
68
 
69
+ /**
70
+ * Is date a valid date.
71
+ */
72
+ function _isValidDate(date: unknown): boolean {
73
+ if (
74
+ typeof date === 'string' ||
75
+ (date instanceof Date) ||
76
+ (date instanceof Dayjs) ||
77
+ typeof date === 'number'
78
+ ) {
79
+ return dayjs(date).isValid();
80
+ } else {
81
+ return false;
82
+ }
83
+ }
84
+
73
85
 
74
86
  // **** Export default **** //
75
87