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
@@ -0,0 +1,322 @@
1
+ /**
2
+ * NOTE: These functions were copied from here:
3
+ * https://github.com/seanpmaxwell/ts-validators/blob/master/src/validators.ts
4
+ */
5
+
6
+ /* eslint-disable max-len */
7
+
8
+
9
+ // **** Types **** //
10
+
11
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
12
+ type TFunc = (...args: any[]) => any;
13
+ type TBasicObj = Record<string, unknown>;
14
+ type TEnum = Record<string, string | number>;
15
+
16
+ // Add modifiers
17
+ type AddNull<T, N> = (N extends true ? T | null : T);
18
+ type AddNullables<T, O, N> = (O extends true ? AddNull<T, N> | undefined : AddNull<T, N>);
19
+ type AddMods<T, O, N, A> = A extends true ? AddNullables<T[], O, N> : AddNullables<T, O, N>;
20
+ export type TValidateWithTransform<T> = (arg: unknown, cb?: (arg: T) => void) => arg is T;
21
+
22
+
23
+ // **** Functions **** //
24
+
25
+ // Nullables
26
+ export const isUndef = ((arg: unknown): arg is undefined => arg === undefined);
27
+ export const isNull = ((arg: unknown): arg is null => arg === null);
28
+
29
+ // Base types
30
+ export const isStr = _checkType<string>('string');
31
+ export const isNum = _checkType<number>('number');
32
+ export const isBool = _checkType<boolean>('boolean');
33
+ export const isObj = _checkType<object>('object');
34
+
35
+ // Misc
36
+ export const parseObj = <U extends TSchema>(arg: U, onError?: TParseOnError<false>) =>
37
+ _parseObj<U, false, false, false>(arg, false, false, false, onError);
38
+ export const isEnumVal = <T>(arg: T) => _isEnumValBase<T, false, false>(arg, false, false);
39
+
40
+ // Util
41
+ export const transform = _transform;
42
+ export const safeJsonParse = _safeJsonParse;
43
+
44
+
45
+ // **** Helpers **** //
46
+
47
+ /**
48
+ * Check if unknown is a valid enum object.
49
+ * NOTE: this does not work for mixed enums see: "eslint@typescript-eslint/no-mixed-enums"
50
+ */
51
+ function _isEnum(arg: unknown): arg is TEnum {
52
+ // Check is non-array object
53
+ if (!(isObj(arg) && !Array.isArray(arg))) {
54
+ return false;
55
+ }
56
+ // Check if string or number enum
57
+ const param = (arg as TBasicObj),
58
+ keys = Object.keys(param),
59
+ middle = Math.floor(keys.length / 2);
60
+ // ** String Enum ** //
61
+ if (!isNum(param[keys[middle]])) {
62
+ return _checkObjEntries(arg, (key, val) => {
63
+ return isStr(key) && isStr(val);
64
+ });
65
+ }
66
+ // ** Number Enum ** //
67
+ // Enum key length will always be even
68
+ if (keys.length % 2 !== 0) {
69
+ return false;
70
+ }
71
+ // Check key/values
72
+ for (let i = 0; i < middle; i++) {
73
+ const thisKey = keys[i],
74
+ thisVal = param[thisKey],
75
+ thatKey = keys[i + middle],
76
+ thatVal = param[thatKey];
77
+ if (!(thisVal === thatKey && thisKey === String(thatVal))) {
78
+ return false;
79
+ }
80
+ }
81
+ // Return
82
+ return true;
83
+ }
84
+
85
+ /**
86
+ * Check is value satisfies enum.
87
+ */
88
+ function _isEnumValBase<T,
89
+ O extends boolean,
90
+ N extends boolean
91
+ >(
92
+ enumArg: T,
93
+ optional: O,
94
+ nullable: N,
95
+ ): ((arg: unknown) => arg is AddNullables<T[keyof T], O, N>) {
96
+ // Check is enum
97
+ if (!_isEnum(enumArg)) {
98
+ throw Error('Item to check from must be an enum.');
99
+ }
100
+ // Get keys
101
+ let resp = Object.keys(enumArg).reduce((arr: unknown[], key) => {
102
+ if (!arr.includes(key)) {
103
+ arr.push(enumArg[key]);
104
+ }
105
+ return arr;
106
+ }, []);
107
+ // Check if string or number enum
108
+ if (isNum(enumArg[resp[0] as string])) {
109
+ resp = resp.map(item => enumArg[item as string]);
110
+ }
111
+ // Return validator function
112
+ return (arg: unknown): arg is AddNullables<T[keyof T], O, N> => {
113
+ if (isUndef(arg)) {
114
+ return !!optional;
115
+ }
116
+ if (isNull(arg)) {
117
+ return !!nullable;
118
+ }
119
+ return resp.some(val => arg === val);
120
+ };
121
+ }
122
+
123
+ /**
124
+ * Do a validator callback function for each object key/value pair.
125
+ */
126
+ function _checkObjEntries(
127
+ val: unknown,
128
+ cb: (key: string, val: unknown) => boolean,
129
+ ): val is NonNullable<object> {
130
+ if (isObj(val)) {
131
+ for (const entry of Object.entries(val)) {
132
+ if (!cb(entry[0], entry[1])) {
133
+ return false;
134
+ }
135
+ }
136
+ }
137
+ return true;
138
+ }
139
+
140
+ /**
141
+ * Wrapper to check basic type.
142
+ */
143
+ function _checkType<T>(type: string) {
144
+ return (arg: unknown): arg is T => {
145
+ return typeof arg === type && (type === 'object' ? (arg !== null) : true);
146
+ };
147
+ }
148
+
149
+ /**
150
+ * Transform a value before checking it.
151
+ */
152
+ function _transform<T>(
153
+ transFn: TFunc,
154
+ vldt: ((arg: unknown) => arg is T),
155
+ ): TValidateWithTransform<T> {
156
+ return (arg: unknown, cb?: (arg: T) => void): arg is T => {
157
+ if (arg !== undefined) {
158
+ arg = transFn(arg);
159
+ }
160
+ cb?.(arg as T);
161
+ return vldt(arg);
162
+ };
163
+ }
164
+
165
+ /**
166
+ * Safe JSON parse
167
+ */
168
+ function _safeJsonParse<T>(arg: unknown): T {
169
+ if (isStr(arg)) {
170
+ return JSON.parse(arg) as T;
171
+ } else {
172
+ throw Error('JSON parse argument must be a string');
173
+ }
174
+ }
175
+
176
+
177
+ // **** Parse Object **** //
178
+
179
+ export interface TSchema {
180
+ [key: string]: TValidateWithTransform<unknown> | TSchema;
181
+ }
182
+
183
+ type TInferParseRes<U, O, N, A, Schema = TInferParseResHelper<U>> = (
184
+ AddMods<Schema, O, N, A>
185
+ );
186
+
187
+ type TInferParseResHelper<U> = {
188
+ [K in keyof U]: (
189
+ U[K] extends TValidateWithTransform<infer X>
190
+ ? X
191
+ : U[K] extends TSchema
192
+ ? TInferParseResHelper<U[K]>
193
+ : never
194
+ );
195
+ };
196
+
197
+ type TParseOnError<A> = (
198
+ A extends true
199
+ ? ((property?: string, value?: unknown, index?: number, caughtErr?: unknown) => void)
200
+ : ((property?: string, value?: unknown, caughtErr?: unknown) => void)
201
+ );
202
+
203
+ /**
204
+ * validates an object schema, calls an error function is supplied one, returns
205
+ * "undefined" if the parse fails, and works recursively too.
206
+ */
207
+ function _parseObj<
208
+ U extends TSchema,
209
+ O extends boolean,
210
+ N extends boolean,
211
+ A extends boolean,
212
+ >(
213
+ schema: U,
214
+ optional: O,
215
+ nullable: N,
216
+ isArr: A,
217
+ onError?: TParseOnError<A>,
218
+ ) {
219
+ return (arg: unknown) => _parseObjCore(
220
+ !!optional,
221
+ !!nullable,
222
+ !!isArr,
223
+ schema,
224
+ arg,
225
+ onError,
226
+ ) as TInferParseRes<U, O, N, A>;
227
+ }
228
+
229
+ /**
230
+ * Validate the schema.
231
+ */
232
+ function _parseObjCore(
233
+ optional: boolean,
234
+ nullable: boolean,
235
+ isArr: boolean,
236
+ schema: TSchema,
237
+ arg: unknown,
238
+ onError?: TFunc,
239
+ ) {
240
+ // Check "undefined"
241
+ if (arg === undefined) {
242
+ if (!optional) {
243
+ onError?.('object value was undefined but not optional', arg);
244
+ return undefined;
245
+ }
246
+ }
247
+ // Check "null"
248
+ if (arg === null) {
249
+ if (!nullable) {
250
+ onError?.('object value was null but not nullable', arg);
251
+ return undefined;
252
+ }
253
+ return null;
254
+ }
255
+ // Check "array"
256
+ if (isArr) {
257
+ if (!Array.isArray(arg)) {
258
+ onError?.('object not an array', arg);
259
+ return null;
260
+ }
261
+ // Iterate array
262
+ const resp = [];
263
+ for (let i = 0; i < arg.length; i++) {
264
+ const item: unknown = arg[i];
265
+ const parsedItem = _parseObjCoreHelper(schema, item, (prop, val, caughtErr) => {
266
+ onError?.(prop, val, i, caughtErr);
267
+ });
268
+ if (parsedItem === undefined) {
269
+ return undefined;
270
+ } else {
271
+ resp.push(parsedItem);
272
+ }
273
+ }
274
+ return resp;
275
+ }
276
+ // Default
277
+ return _parseObjCoreHelper(schema, arg, onError);
278
+ }
279
+
280
+ /**
281
+ * Iterate an object, apply a validator function to to each property in an
282
+ * object using the schema.
283
+ */
284
+ function _parseObjCoreHelper(
285
+ schema: TSchema,
286
+ arg: unknown,
287
+ onError?: TParseOnError<false>,
288
+ ) {
289
+ if (!isObj(arg)) {
290
+ return;
291
+ }
292
+ const retVal: TBasicObj = {};
293
+ for (const key in schema) {
294
+ const schemaProp = schema[key];
295
+ let val = (arg as TBasicObj)[key];
296
+ // Nested object
297
+ if (typeof schemaProp === 'object') {
298
+ const childVal = _parseObjCoreHelper(schemaProp, val, onError);
299
+ if (childVal !== undefined) {
300
+ val = childVal;
301
+ } else {
302
+ return undefined;
303
+ }
304
+ // Run validator
305
+ } else if (typeof schemaProp === 'function') {
306
+ try {
307
+ if (!schemaProp(val, (tval: unknown) => val = tval)) {
308
+ return onError?.(key, val);
309
+ }
310
+ } catch (err) {
311
+ if (err instanceof Error) {
312
+ return onError?.(key, val, err.message);
313
+ } else {
314
+ return onError?.(key, val, err);
315
+ }
316
+ }
317
+ }
318
+ retVal[key] = val;
319
+ }
320
+ // Return
321
+ return retVal;
322
+ }
@@ -1,87 +1,36 @@
1
1
  {
2
2
  "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
-
5
- /* Basic Options */
6
- // "incremental": true, /* Enable incremental compilation */
7
- "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
8
- "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
9
- // "lib": [], /* Specify library files to be included in the compilation. */
10
- // "allowJs": true, /* Allow javascript files to be compiled. */
11
- // "checkJs": true, /* Report errors in .js files. */
12
- // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
13
- // "declaration": true, /* Generates corresponding '.d.ts' file. */
14
- // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
15
- // "sourceMap": true, /* Generates corresponding '.map' file. */
16
- // "outFile": "./", /* Concatenate and emit output to single file. */
17
- "outDir": "dist", /* Redirect output structure to the directory. */
18
- // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
19
- // "composite": true, /* Enable project compilation */
20
- // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
21
- // "removeComments": true, /* Do not emit comments to output. */
22
- // "noEmit": true, /* Do not emit outputs. */
23
- // "importHelpers": true, /* Import emit helpers from 'tslib'. */
24
- // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
25
- // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
26
-
27
- /* Strict Type-Checking Options */
28
- "strict": true, /* Enable all strict type-checking options. */
29
- // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
30
- // "strictNullChecks": true, /* Enable strict null checks. */
31
- // "strictFunctionTypes": true, /* Enable strict checking of function types. */
32
- // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
33
- // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
34
- // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
35
- // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
36
-
37
- /* Additional Checks */
38
- // "noUnusedLocals": true, /* Report errors on unused locals. */
39
- // "noUnusedParameters": true, /* Report errors on unused parameters. */
40
- // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
41
- // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
42
-
43
- /* Module Resolution Options */
44
- // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
45
- "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
46
- // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
47
- // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
48
- // "typeRoots": [], /* List of folders to include type definitions from. */
49
- // "types": [], /* Type declaration files to be included in compilation. */
50
- // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
51
- "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
52
- // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
53
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
54
-
55
- /* Source Map Options */
56
- // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
57
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58
- // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
59
- // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
60
-
61
- /* Experimental Options */
62
- // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
63
- // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
64
-
65
- /* Advanced Options */
66
- "skipLibCheck": true, /* Skip type checking of declaration files. */
67
- "forceConsistentCasingInFileNames": true, /* Disallow inconsistently-cased references to the same file. */
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": [
6
+ "ES2020"
7
+ ],
8
+ "strict": true,
9
+ "moduleResolution": "node",
10
+ "baseUrl": "./",
11
+ "esModuleInterop": true,
12
+ "skipLibCheck": true,
13
+ "forceConsistentCasingInFileNames": true,
68
14
  "paths": {
69
- "@src/*": [
70
- "src/*"
71
- ],
15
+ "@src/*": ["src/*"]
72
16
  },
73
17
  "useUnknownInCatchVariables": false
74
18
  },
75
19
  "ts-node": {
76
- "require": ["tsconfig-paths/register", "./preload.js"]
20
+ "swc": true,
21
+ "require": [
22
+ "tsconfig-paths/register",
23
+ "./config.ts"
24
+ ],
77
25
  },
78
26
  "include": [
79
27
  "src/**/*.ts",
80
28
  "spec/**/*.ts",
29
+ "config.ts",
81
30
  "scripts",
82
- "preload.js"
31
+ "eslint.config.ts"
83
32
  ],
84
33
  "exclude": [
85
34
  "src/public/*"
86
35
  ]
87
- }
36
+ }
@@ -1,12 +1,32 @@
1
1
  {
2
- "extends": "./tsconfig.json",
3
2
  "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "commonjs",
5
+ "lib": [
6
+ "ES2020"
7
+ ],
8
+ "strict": true,
9
+ "moduleResolution": "node",
10
+ "baseUrl": "./",
11
+ "outDir": "temp",
12
+ "esModuleInterop": true,
13
+ "skipLibCheck": true,
14
+ "forceConsistentCasingInFileNames": true,
15
+ "paths": {
16
+ "@src/*": ["src/*"]
17
+ },
18
+ "useUnknownInCatchVariables": false,
4
19
  "sourceMap": false,
5
20
  "removeComments": true
6
21
  },
22
+ "include": [
23
+ "src/**/*.ts",
24
+ "config.ts"
25
+ ],
7
26
  "exclude": [
8
27
  "spec",
9
28
  "src/public/",
10
- "scripts"
29
+ "scripts",
30
+ "eslint.config.ts"
11
31
  ]
12
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "express-generator-typescript",
3
- "version": "2.4.25",
3
+ "version": "2.5.1",
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",
@@ -1,24 +0,0 @@
1
- ## Environment ##
2
- NODE_ENV=development
3
-
4
-
5
- ## Server ##
6
- PORT=3000
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,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,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,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,24 +0,0 @@
1
- /* eslint-disable n/no-process-env */
2
-
3
-
4
- export default {
5
- NodeEnv: (process.env.NODE_ENV ?? ''),
6
- Port: (process.env.PORT ?? 0),
7
- CookieProps: {
8
- Key: 'ExpressGeneratorTs',
9
- Secret: (process.env.COOKIE_SECRET ?? ''),
10
- // Casing to match express cookie options
11
- Options: {
12
- httpOnly: true,
13
- signed: true,
14
- path: (process.env.COOKIE_PATH ?? ''),
15
- maxAge: Number(process.env.COOKIE_EXP ?? 0),
16
- domain: (process.env.COOKIE_DOMAIN ?? ''),
17
- secure: (process.env.SECURE_COOKIE === 'true'),
18
- },
19
- },
20
- Jwt: {
21
- Secret: (process.env.JWT_SECRET ?? ''),
22
- Exp: (process.env.COOKIE_EXP ?? ''), // exp at the same time as the cookie
23
- },
24
- } as const;
@@ -1,32 +0,0 @@
1
- import HttpStatusCodes from '@src/common/HttpStatusCodes';
2
-
3
-
4
- /**
5
- * Error with status code and message.
6
- */
7
- export class RouteError extends Error {
8
-
9
- public status: HttpStatusCodes;
10
-
11
- public constructor(status: HttpStatusCodes, message: string) {
12
- super(message);
13
- this.status = status;
14
- }
15
- }
16
-
17
- /**
18
- * If route validation fails.
19
- */
20
- export class ValidationErr extends RouteError {
21
-
22
- public static MSG = 'The follow parameter were missing or invalid "';
23
-
24
- public constructor(paramName: string) {
25
- super(HttpStatusCodes.BAD_REQUEST, ValidationErr.GetMsg(paramName));
26
- }
27
-
28
- public static GetMsg(param: string) {
29
- return ValidationErr.MSG + param + '".';
30
- }
31
- }
32
-
@@ -1,5 +0,0 @@
1
- export enum NodeEnvs {
2
- Dev = 'development',
3
- Test = 'test',
4
- Production = 'production'
5
- }