@cley_faye/boilerplate 3.21.2 → 4.0.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 (44) hide show
  1. package/README.md +7 -220
  2. package/bin/serve_spa.js +0 -1
  3. package/lib/bin/serve_spa.js +67 -39
  4. package/lib/express/middlewares/singlepageapp.d.ts +2 -2
  5. package/lib/express/middlewares/singlepageapp.js +20 -13
  6. package/lib/grunt/args.d.ts +14 -42
  7. package/lib/grunt/args.js +27 -41
  8. package/lib/grunt/reactapp/copy.d.ts +8 -34
  9. package/lib/grunt/reactapp/copy.js +47 -49
  10. package/lib/grunt/reactapp/image.d.ts +8 -23
  11. package/lib/grunt/reactapp/image.js +45 -42
  12. package/lib/grunt/reactapp/pug.d.ts +8 -30
  13. package/lib/grunt/reactapp/pug.js +49 -50
  14. package/lib/grunt/reactapp/sass.d.ts +8 -29
  15. package/lib/grunt/reactapp/sass.js +48 -43
  16. package/lib/grunt/reactapp/util.d.ts +5 -9
  17. package/lib/grunt/reactapp/util.js +12 -15
  18. package/lib/grunt/reactapp/webpack.d.ts +10 -81
  19. package/lib/grunt/reactapp/webpack.js +72 -132
  20. package/lib/grunt/reactapp.d.ts +22 -65
  21. package/lib/grunt/reactapp.js +70 -93
  22. package/lib/grunt/util.d.ts +4 -7
  23. package/lib/grunt/util.js +5 -8
  24. package/lib/grunt.d.ts +2 -3
  25. package/lib/grunt.js +5 -5
  26. package/lib/util.js +5 -4
  27. package/package.json +24 -36
  28. package/grunt.js +0 -3
  29. package/lib/express/autoclose.d.ts +0 -17
  30. package/lib/express/autoclose.js +0 -76
  31. package/lib/express/logger.d.ts +0 -25
  32. package/lib/express/logger.js +0 -132
  33. package/lib/express/middlewares/bodylogger.d.ts +0 -9
  34. package/lib/express/middlewares/bodylogger.js +0 -90
  35. package/lib/express/pipelinebuilder.d.ts +0 -115
  36. package/lib/express/pipelinebuilder.js +0 -288
  37. package/lib/express/unprocessableentityerror.d.ts +0 -8
  38. package/lib/express/unprocessableentityerror.js +0 -57
  39. package/lib/express.d.ts +0 -158
  40. package/lib/express.js +0 -218
  41. package/lib/repl.d.ts +0 -27
  42. package/lib/repl.js +0 -68
  43. package/lib/winston.d.ts +0 -38
  44. package/lib/winston.js +0 -224
package/lib/winston.js DELETED
@@ -1,224 +0,0 @@
1
- /**
2
- * @license
3
- * @preserve
4
- * MIT License
5
- *
6
- * Copyright (c) 2021 Gabriel Paul "Cley Faye" Risterucci
7
- *
8
- * Permission is hereby granted, free of charge, to any person obtaining a copy
9
- * of this software and associated documentation files (the "Software"), to deal
10
- * in the Software without restriction, including without limitation the rights
11
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
- * copies of the Software, and to permit persons to whom the Software is
13
- * furnished to do so, subject to the following conditions:
14
- *
15
- * The above copyright notice and this permission notice shall be included in all
16
- * copies or substantial portions of the Software.
17
- *
18
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
- * SOFTWARE.
25
- *
26
- */
27
- "use strict";
28
- var __importDefault = (this && this.__importDefault) || function (mod) {
29
- return (mod && mod.__esModule) ? mod : { "default": mod };
30
- };
31
- Object.defineProperty(exports, "__esModule", { value: true });
32
- exports.consoleLogger = exports.transports = exports.setConfig = exports.customFormat = exports.filterError = exports.prefixOutput = exports.filterStacktrace = void 0;
33
- const winston_1 = __importDefault(require("winston"));
34
- const unprocessableentityerror_js_1 = require("./express/unprocessableentityerror.js");
35
- const LOG_LEVEL_PADDING_SIZE = 10;
36
- const stackFilterRegex = /(?:at process|at runMicrotasks)/u;
37
- const isFiltered = (line, extraFilter) => {
38
- if (stackFilterRegex.exec(line))
39
- return true;
40
- if (extraFilter) {
41
- for (const filter of Array.isArray(extraFilter) ? extraFilter : [extraFilter]) {
42
- if (filter.exec(line))
43
- return true;
44
- }
45
- }
46
- return false;
47
- };
48
- /**
49
- * Collapse useless lines in stacktrace
50
- */
51
- const filterStacktrace = function* (message, extraFilter) {
52
- let inCollapse = false;
53
- const lines = message.split("\n");
54
- for (const line of lines) {
55
- if (isFiltered(line, extraFilter)) {
56
- if (!inCollapse) {
57
- inCollapse = true;
58
- yield "[...]";
59
- }
60
- }
61
- else {
62
- inCollapse = false;
63
- yield line;
64
- }
65
- }
66
- };
67
- exports.filterStacktrace = filterStacktrace;
68
- /**
69
- * Prefix all lines with the level and the timestamp if needed
70
- */
71
- const prefixOutput = (level, message, timestamp) => {
72
- const timestampPrefix = (timestamp ?? (level.toLowerCase() === "error"))
73
- ? `${new Date().toISOString()} `
74
- : "";
75
- const levelPrefix = `${level.toString().padStart(LOG_LEVEL_PADDING_SIZE)}: `;
76
- const levelEmpty = `${" ".repeat(LOG_LEVEL_PADDING_SIZE)} `;
77
- return message.split("\n").map((line, id) => `${timestampPrefix}${id === 0 ? levelPrefix : levelEmpty}${line}`)
78
- .join("\n");
79
- };
80
- exports.prefixOutput = prefixOutput;
81
- const logConfig = {
82
- timestamp: true,
83
- collapseNodeModules: true,
84
- collapseStacktrace: true,
85
- stacktraceFilter: undefined,
86
- };
87
- const indent = (msg, indentLevel) => {
88
- if (indentLevel === 0)
89
- return msg;
90
- const indentList = [];
91
- for (let i = 0; i < indentLevel;) {
92
- ++i;
93
- const str = `${i}|`;
94
- if (i < indentLevel) {
95
- indentList.push(" ".repeat(str.length));
96
- }
97
- else {
98
- indentList.push(str);
99
- }
100
- }
101
- const indentStr = indentList.join("");
102
- return msg.split("\n")
103
- .map(c => `${indentStr} ${c.trimEnd()}`)
104
- .join("\n");
105
- };
106
- /** Add context from axios */
107
- const addAxiosContent = (error) => {
108
- const res = [];
109
- if (error.request?._currentUrl) {
110
- res.push(`HTTP Request URL: ${error.request._currentUrl}`);
111
- }
112
- if (error.response?.data) {
113
- res.push("HTTP Response body:");
114
- if (typeof error.response.data === "string") {
115
- res.push(error.response.data);
116
- }
117
- else {
118
- try {
119
- res.push(JSON.stringify(error.response.data));
120
- }
121
- catch {
122
- res.push("<cannot output body>");
123
- }
124
- }
125
- }
126
- if (res.length === 0)
127
- return;
128
- return res.join("\n");
129
- };
130
- /** Add context from http-errors */
131
- const addHttpErrorContent = (error) => {
132
- if (error.statusCode === undefined)
133
- return;
134
- return `HttpError status: ${error.statusCode}`;
135
- };
136
- const getCause = (error) => {
137
- const cause = error.cause;
138
- if (cause === undefined)
139
- return;
140
- if (cause instanceof Error)
141
- return cause;
142
- try {
143
- return new Error(JSON.stringify(cause));
144
- }
145
- catch {
146
- return new Error("Unknown cause");
147
- }
148
- };
149
- /** Handle 422
150
- *
151
- * If return a string, do not process the error normally.
152
- */
153
- const process422Error = (error) => {
154
- const errorInfo = (0, unprocessableentityerror_js_1.get422Fields)(error);
155
- return errorInfo?.message;
156
- };
157
- /** Return a string with the full error and stacktrace, including causes */
158
- const filterError = (error, collapseStacktrace = true, extraFilter) => {
159
- const resultRows = [];
160
- const unprocessableCheck = process422Error(error);
161
- if (unprocessableCheck)
162
- return unprocessableCheck;
163
- let cursor = error;
164
- let indentLevel = 0;
165
- while (cursor) {
166
- if (indentLevel === 0) {
167
- resultRows.push(cursor.name);
168
- }
169
- else {
170
- resultRows.push(indent(`Caused by: ${cursor.name}`, indentLevel));
171
- }
172
- resultRows.push(indent(cursor.message, indentLevel));
173
- if (cursor.stack) {
174
- if (collapseStacktrace) {
175
- resultRows.push(indent([...(0, exports.filterStacktrace)(cursor.stack, extraFilter)].join("\n"), indentLevel));
176
- }
177
- else {
178
- resultRows.push(indent(cursor.stack, indentLevel));
179
- }
180
- }
181
- const axiosContent = addAxiosContent(cursor);
182
- if (axiosContent)
183
- resultRows.push(indent(axiosContent, indentLevel));
184
- const httpErrorsContent = addHttpErrorContent(cursor);
185
- if (httpErrorsContent)
186
- resultRows.push(indent(httpErrorsContent, indentLevel));
187
- cursor = getCause(cursor);
188
- ++indentLevel;
189
- }
190
- return resultRows.join("\n");
191
- };
192
- exports.filterError = filterError;
193
- const getErrorFromTransformable = (info) => {
194
- if (info instanceof Error)
195
- return info;
196
- if (info.meta) {
197
- const meta = info.meta;
198
- if (meta.error && meta.error instanceof Error)
199
- return meta.error;
200
- }
201
- };
202
- const customFormat = (timestamp, collapseStacktrace, stacktraceFilter) => winston_1.default.format.printf((info) => {
203
- const effectiveTimestamp = timestamp ?? logConfig.timestamp;
204
- const effectiveCollapse = collapseStacktrace
205
- ?? (logConfig.collapseNodeModules || logConfig.collapseStacktrace);
206
- const effectiveStacktraceFilter = stacktraceFilter ?? logConfig.stacktraceFilter;
207
- const error = getErrorFromTransformable(info);
208
- const message = error
209
- ? (0, exports.filterError)(error, effectiveCollapse, effectiveStacktraceFilter)
210
- : info.message.toString();
211
- return (0, exports.prefixOutput)(info.level, message, effectiveTimestamp);
212
- });
213
- exports.customFormat = customFormat;
214
- /** Edit the configuration applied to consoleLogger */
215
- const setConfig = (config) => {
216
- Object.assign(logConfig, config);
217
- };
218
- exports.setConfig = setConfig;
219
- exports.transports = [new winston_1.default.transports.Console()];
220
- exports.consoleLogger = winston_1.default.createLogger({
221
- level: "info",
222
- format: (0, exports.customFormat)(),
223
- transports: exports.transports,
224
- });