@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
@@ -25,35 +25,62 @@
25
25
  *
26
26
  */
27
27
  "use strict";
28
- var __importDefault = (this && this.__importDefault) || function (mod) {
29
- return (mod && mod.__esModule) ? mod : { "default": mod };
30
- };
28
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
29
+ if (k2 === undefined) k2 = k;
30
+ var desc = Object.getOwnPropertyDescriptor(m, k);
31
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
32
+ desc = { enumerable: true, get: function() { return m[k]; } };
33
+ }
34
+ Object.defineProperty(o, k2, desc);
35
+ }) : (function(o, m, k, k2) {
36
+ if (k2 === undefined) k2 = k;
37
+ o[k2] = m[k];
38
+ }));
39
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
40
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
41
+ }) : function(o, v) {
42
+ o["default"] = v;
43
+ });
44
+ var __importStar = (this && this.__importStar) || (function () {
45
+ var ownKeys = function(o) {
46
+ ownKeys = Object.getOwnPropertyNames || function (o) {
47
+ var ar = [];
48
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
49
+ return ar;
50
+ };
51
+ return ownKeys(o);
52
+ };
53
+ return function (mod) {
54
+ if (mod && mod.__esModule) return mod;
55
+ var result = {};
56
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
57
+ __setModuleDefault(result, mod);
58
+ return result;
59
+ };
60
+ })();
31
61
  Object.defineProperty(exports, "__esModule", { value: true });
32
62
  exports.handle = exports.webpackLoadersDefault = void 0;
33
- const path_1 = require("path");
34
63
  const node_fs_1 = require("node:fs");
35
- const eslint_webpack_plugin_1 = __importDefault(require("eslint-webpack-plugin"));
64
+ const path_1 = require("path");
36
65
  const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
37
- const util_js_1 = require("./util.js");
66
+ const util = __importStar(require("./util.js"));
38
67
  const defaultCoreJS = 3;
39
- const eslintPlugin = () => new eslint_webpack_plugin_1.default({ cache: true });
40
68
  const defaultLoadersDefine = (options) => [
41
69
  "transform-define",
42
70
  {
43
71
  // eslint-disable-next-line @typescript-eslint/naming-convention
44
- "process.env.BUILD_TYPE": options.development
45
- ? "development"
46
- : "production",
72
+ "process.env.BUILD_TYPE": options.development ? "development" : "production",
47
73
  ...options.defines,
48
74
  },
49
75
  ];
50
76
  const defaultLoadersPresetEnv = (options) => [
51
77
  "@babel/preset-env",
52
78
  {
53
- targets: (options.babel?.targets) ?? "> 2% and not dead, last 2 safari version, last 2 firefox version, last 2 chrome version, last 2 edge version, Firefox ESR",
54
- useBuiltIns: "usage",
55
- corejs: (options.babel?.corejs) ?? defaultCoreJS,
79
+ corejs: options.babel?.corejs ?? defaultCoreJS,
56
80
  modules: false,
81
+ targets: options.babel?.targets ??
82
+ "> 2% and not dead, last 2 safari version, last 2 firefox version, last 2 chrome version, last 2 edge version, Firefox ESR",
83
+ useBuiltIns: "usage",
57
84
  },
58
85
  ];
59
86
  const defaultLoadersReact = (options) => [
@@ -62,49 +89,20 @@ const defaultLoadersReact = (options) => [
62
89
  ];
63
90
  /** Build the default webpack loaders list.
64
91
  *
65
- * Uses babel and eslint. Some options can be customized here.
66
- *
67
- * @param [options]
68
- * @param [options.development]
69
- * true for development-friendly options, false for production options
70
- *
71
- * @param [options.defines]
72
- * List of defines to set using Babel transform-define
73
- *
74
- * @param [options.babel]
75
- * @param [options.babel.corejs]
76
- * Version of core-js to use (default to 3)
77
- *
78
- * @param [options.babel.targets]
79
- * Browser targets (default to "> 2% and not dead, last 2 safari version, last 2 firefox version,
80
- * last 2 chrome version, last 2 edge version, Firefox ESR")
81
- *
82
- * @param [options.babel.plugins]
83
- * Plugins to add to babel
84
- *
85
- * @param [options.typescript]
86
- * Add support for importing .ts and .tsx files
92
+ * Uses babel. Some options can be customized here.
87
93
  */
88
94
  const webpackLoadersDefault = (options) => {
89
- const allFilesCheck = options.typescript
90
- ? /.(?:js|ts|tsx)$/u
91
- : /.js$/u;
95
+ const allFilesCheck = options.typescript ? /.(?:js|ts|tsx)$/u : /.js$/u;
92
96
  const res = [
93
97
  {
94
- test: allFilesCheck,
95
98
  exclude: /node_modules/u,
99
+ test: allFilesCheck,
96
100
  use: {
97
101
  loader: "babel-loader",
98
102
  options: {
99
103
  cacheDirectory: true,
100
- presets: [
101
- defaultLoadersPresetEnv(options),
102
- defaultLoadersReact(options),
103
- ],
104
- plugins: [
105
- defaultLoadersDefine(options),
106
- ...(options.babel?.plugins ?? []),
107
- ],
104
+ plugins: [defaultLoadersDefine(options), ...(options.babel?.plugins ?? [])],
105
+ presets: [defaultLoadersPresetEnv(options), defaultLoadersReact(options)],
108
106
  },
109
107
  },
110
108
  },
@@ -112,24 +110,26 @@ const webpackLoadersDefault = (options) => {
112
110
  if (options.typescript) {
113
111
  const alternativeConfig = "tsconfig-tsloader.json";
114
112
  const tsLoader = (0, node_fs_1.existsSync)(alternativeConfig)
115
- ? [{
113
+ ? [
114
+ {
116
115
  loader: "ts-loader",
117
116
  options: { configFile: alternativeConfig },
118
- }]
117
+ },
118
+ ]
119
119
  : "ts-loader";
120
120
  res.push({
121
+ exclude: /node_modules/u,
121
122
  test: /.(?:ts|tsx)$/u,
122
123
  use: tsLoader,
123
- exclude: /node_modules/u,
124
124
  });
125
125
  }
126
126
  return res;
127
127
  };
128
128
  exports.webpackLoadersDefault = webpackLoadersDefault;
129
129
  const computeWebpackOutput = (webpackOptions, targetName) => webpackOptions.output ?? {
130
- path: (0, path_1.resolve)("dist", targetName, "js"),
131
- filename: "[name].js",
132
130
  chunkFilename: "[name]-[fullhash].js",
131
+ filename: "[name].js",
132
+ path: (0, path_1.resolve)("dist", targetName, "js"),
133
133
  };
134
134
  const lastNamePosition = 2;
135
135
  const getHandledFiles = (webpackEntry) => Object.keys(webpackEntry).reduce((acc, cur) => {
@@ -160,135 +160,75 @@ const getWatchTasks = (webpackOptions, targetName) => {
160
160
  return [];
161
161
  };
162
162
  const registerTasks = (gruntConfig, targetName, webpackConfig) => {
163
- (0, util_js_1.insertTask)(gruntConfig, "webpack", `${targetName}_watch`, {
163
+ util.insertTask(gruntConfig, "webpack", `${targetName}_watch`, {
164
164
  ...webpackConfig,
165
165
  watch: true,
166
166
  });
167
- return [
168
- (0, util_js_1.insertTask)(gruntConfig, "webpack", targetName, webpackConfig),
169
- ];
167
+ return [util.insertTask(gruntConfig, "webpack", targetName, webpackConfig)];
170
168
  };
171
169
  const computeWebpackResolve = (webpackOptions) => {
172
170
  const res = { ...webpackOptions.resolve };
173
171
  if (webpackOptions.typescript) {
174
- if (res.extensionAlias === undefined) {
175
- res.extensionAlias = {};
176
- }
172
+ res.extensionAlias ?? (res.extensionAlias = {});
177
173
  res.extensionAlias[".js"] = [".ts", ".tsx", ".js", ".jsx"];
178
174
  res.extensionAlias[".mjs"] = [".mts", ".mtsx", ".mjs", ".mjsx"];
179
175
  }
180
176
  return res;
181
177
  };
182
178
  const getWebpackPlugins = (webpackOptions) => {
183
- const plugins = [
184
- eslintPlugin(),
185
- ...webpackOptions.plugins ?? [],
186
- ];
179
+ const plugins = [...(webpackOptions.plugins ?? [])];
187
180
  if (webpackOptions.generateReport) {
188
181
  plugins.push(new webpack_bundle_analyzer_1.BundleAnalyzerPlugin({
189
182
  analyzerMode: "static",
190
- reportFilename: (0, path_1.join)(process.cwd(), "bundle_report.html"),
191
183
  openAnalyzer: false,
184
+ reportFilename: (0, path_1.join)(process.cwd(), "bundle_report.html"),
192
185
  }));
193
186
  }
194
187
  return plugins;
195
188
  };
196
189
  /** Add a webpack task for the reactApp recipe
197
190
  *
198
- * @param gruntConfig
199
- * Grunt configuration to add the task to
200
- *
201
- * @param targetName
202
- * Name of the target for the image minification task.
203
- *
204
- * @param webpackOptions
205
- * Options for the webpack task configuration.
206
- *
207
- * @param [webpackOptions.options]
208
- * Options for webpack
209
- *
210
- * @param [webpackOptions.entry]
211
- * List of entrypoints.
212
- * Defaults to {targetName: "webres/<targetName>/js/loader.js"}
213
- *
214
- * @param [webpackOptions.externals]
215
- * List of external libraries.
216
- * Defaults to {}.
217
- *
218
- * @param [webpackOptions.output]
219
- * Configure webpack output location and name.
220
- * Defaults to {path: "dist/<targetName>/js", filename: "[name].js"}
221
- *
222
- * @param [webpackOptions.output.path]
223
- * Path to put the compiled files into.
224
- * It is possible to pass a completely different object as webpackOptions.output
225
- * than expected, it will be handed to webpack as-is.
226
- *
227
- * @param [webpackOptions.output.filename]
228
- * Template for output filename.
229
- * It is possible to pass a completely different object as webpackOptions.output
230
- * than expected, it will be handed to webpack as-is.
231
- *
232
- * @param [webpackOptions.loaders]
233
- * Configuration for webpack loaders. See webpack doc about module.rules.
234
- * Defaults to using babel with React configuration and eslint.
235
- * To customize the default behavior build an object with
236
- * webpackLoadersDefault().
237
- *
238
- * @param [webpackOptions.plugins]
239
- * Configuration for webpack plugins. See webpack doc about plugins.
191
+ * @param gruntConfig - Grunt configuration to add the task to
240
192
  *
241
- * @param [webpackOptions.babelPlugins]
242
- * List of extra babel plugins.
193
+ * @param targetName - Name of the target for the image minification task.
243
194
  *
244
- * @param [webpackOptions.mode]
245
- * Build mode. "development", "production" or "none".
246
- * Defaults to "development"
195
+ * @param webpackOptions - Options for the webpack task configuration.
247
196
  *
248
- * @param [webpackOptions.generateReport]
249
- * Generate a bundle report HTML file.
250
- *
251
- * @param [webpackOptions.typescript]
252
- * Allow loading typescript source for webpack/babel.
253
- *
254
- * @return
197
+ * @returns
255
198
  * List of tasks added.
256
199
  * This function add "webpack:<targetName>".
257
200
  */
258
201
  const handle = (gruntConfig, targetName, webpackOptions) => {
259
- const webpackEntry = webpackOptions.entry
260
- ?? { [targetName]: (0, path_1.join)("webres", targetName, "js", "loader.js") };
202
+ const webpackEntry = webpackOptions.entry ?? {
203
+ [targetName]: (0, path_1.join)("webres", targetName, "js", "loader.js"),
204
+ };
261
205
  const handledFiles = getHandledFiles(webpackEntry);
262
206
  const webpackOutput = computeWebpackOutput(webpackOptions, targetName);
263
- const webpackLoaders = webpackOptions.loaders
264
- ?? (0, exports.webpackLoadersDefault)({
265
- development: webpackOptions.mode === "development",
266
- defines: webpackOptions.defines,
207
+ const webpackLoaders = webpackOptions.loaders ??
208
+ (0, exports.webpackLoadersDefault)({
267
209
  babel: { plugins: webpackOptions.babelPlugins },
210
+ defines: webpackOptions.defines,
211
+ development: webpackOptions.mode === "development",
268
212
  typescript: webpackOptions.typescript,
269
213
  });
270
214
  const webpackResolve = computeWebpackResolve(webpackOptions);
271
215
  const webpackConfig = {
272
- mode: webpackOptions.mode,
273
216
  devtool: webpackOptions.mode === "development" ? "eval-source-map" : false,
274
217
  entry: webpackEntry,
275
- output: webpackOutput,
276
218
  externals: webpackOptions.externals,
219
+ mode: webpackOptions.mode,
277
220
  module: { rules: webpackLoaders },
221
+ output: webpackOutput,
278
222
  plugins: getWebpackPlugins(webpackOptions),
279
223
  resolve: webpackResolve,
280
224
  };
281
225
  // Special case: I'm not sure I can move options in the task-specific part of
282
226
  // the configuration, so I add it at the toplevel of the "webpack" task.
283
227
  if (webpackOptions.options) {
284
- (0, util_js_1.insertTask)(gruntConfig, "webpack", "options", webpackOptions.options);
228
+ util.insertTask(gruntConfig, "webpack", "options", webpackOptions.options);
285
229
  }
286
230
  const requiredTasks = registerTasks(gruntConfig, targetName, webpackConfig);
287
231
  const watchTasks = getWatchTasks(webpackOptions, targetName);
288
- return {
289
- requiredTasks,
290
- handledFiles,
291
- watchTasks,
292
- };
232
+ return { handledFiles, requiredTasks, watchTasks, };
293
233
  };
294
234
  exports.handle = handle;
@@ -1,11 +1,10 @@
1
- /// <reference types="grunt" />
2
- import { BaseOptions } from "./util.js";
3
- import { PugOptions } from "./reactapp/pug.js";
4
- import { ImageOptions } from "./reactapp/image.js";
5
- import { WebpackOptions } from "./reactapp/webpack.js";
6
- import { SassOptions } from "./reactapp/sass.js";
7
- import { CopyOptions } from "./reactapp/copy.js";
8
- import { GruntConfig } from "./reactapp/util.js";
1
+ import * as reactAppCopy from "./reactapp/copy.js";
2
+ import * as reactAppImage from "./reactapp/image.js";
3
+ import * as reactAppPug from "./reactapp/pug.js";
4
+ import * as reactAppSass from "./reactapp/sass.js";
5
+ import * as reactAppUtil from "./reactapp/util.js";
6
+ import * as reactAppWebpack from "./reactapp/webpack.js";
7
+ import * as util from "./util.js";
9
8
  export declare enum HandlerType {
10
9
  PUG = "pug",
11
10
  IMAGE = "image",
@@ -14,11 +13,11 @@ export declare enum HandlerType {
14
13
  COPY = "copy"
15
14
  }
16
15
  export interface ReactAppOptions {
17
- [HandlerType.PUG]?: PugOptions;
18
- [HandlerType.IMAGE]?: ImageOptions;
19
- [HandlerType.WEBPACK]?: WebpackOptions;
20
- [HandlerType.SASS]?: SassOptions;
21
- [HandlerType.COPY]?: CopyOptions;
16
+ [HandlerType.PUG]?: reactAppPug.PugOptions;
17
+ [HandlerType.IMAGE]?: reactAppImage.ImageOptions;
18
+ [HandlerType.WEBPACK]?: reactAppWebpack.WebpackOptions;
19
+ [HandlerType.SASS]?: reactAppSass.SassOptions;
20
+ [HandlerType.COPY]?: reactAppCopy.CopyOptions;
22
21
  watch?: number | boolean;
23
22
  }
24
23
  export interface WatchTaskDef {
@@ -31,7 +30,7 @@ export interface HandlerFunctionResult {
31
30
  handledFiles: Array<string>;
32
31
  watchTasks: Array<WatchTaskDef>;
33
32
  }
34
- export type HandlerFunction = (gruntConfig: GruntConfig, targetName: string, options: BaseOptions) => HandlerFunctionResult;
33
+ export type HandlerFunction = (gruntConfig: reactAppUtil.GruntConfig, targetName: string, options: util.BaseOptions) => HandlerFunctionResult;
35
34
  /** Insert necessary build step for a React/Web app.
36
35
  *
37
36
  * This function will add the following Grunt tasks:
@@ -42,73 +41,31 @@ export type HandlerFunction = (gruntConfig: GruntConfig, targetName: string, opt
42
41
  * - "sass:<targetName>": compile sass/scss files
43
42
  * - "copy:<targetName>": copy files not handled in other tasks
44
43
  *
45
- * @param gruntConfig
46
- * The Grunt configuration with other tasks, before it is passed to
44
+ * @param gruntConfig - The Grunt configuration with other tasks, before it is passed to
47
45
  * grunt.initConfig()
48
46
  *
49
- * @param [targetName]
50
- * Name for the various targets added to Grunt. Defaults to "reactApp"
47
+ * @param targetName - Name for the various targets added to Grunt. Defaults to "reactApp"
51
48
  *
52
- * @param [options]
53
- * Options to control the extra tasks
49
+ * @param options - Options to control the extra tasks
54
50
  *
55
- * @param [options.pug]
56
- * Options for the pug task. See pug.js for details.
57
- *
58
- * @param [options.pug.disabled]
59
- * Do not generate pug task
60
- *
61
- * @param [options.image]
62
- * Options for the image task. See image.js for details.
63
- *
64
- * @param [options.image.disabled]
65
- * Do not generate image task
66
- *
67
- * @param [options.webpack]
68
- * Options for the webpack task. See webpack.js for details.
69
- *
70
- * @param [options.webpack.disabled]
71
- * Do not generate webpack task
72
- *
73
- * @param [options.sass]
74
- * Options for the sass task. See sass.js for details.
75
- *
76
- * @param [options.sass.disabled]
77
- * Do not generate sass task
78
- *
79
- * @param [options.copy]
80
- * Optiosn for the copy task. See copy.js for details.
81
- *
82
- * @param [options.copy.disabled]
83
- * Do not generate copy task
84
- *
85
- * @return
51
+ * @returns
86
52
  * List of tasks to build the application
87
53
  */
88
- export declare const reactApp: (gruntConfig: GruntConfig, targetName?: string, options?: ReactAppOptions) => Array<string>;
54
+ export declare const reactApp: (gruntConfig: reactAppUtil.GruntConfig, targetName?: string, options?: ReactAppOptions) => Array<string>;
89
55
  export interface HelperOptions {
90
56
  production?: boolean;
91
57
  watch?: boolean | number;
92
58
  }
93
59
  /** Helper for common options shared across multiple tasks.
94
60
  *
95
- * @param [helperOptions]
96
- * Options shared by multiple tasks
97
- *
98
- * @param [helperOptions.production]
99
- * Make a production build.
100
- * - set outputStyle and sourceMap for sass
101
- * - set pretty for pug
102
- * - add a "productionBuild" property in pug data
103
- * - set mode for webpack
61
+ * @param helperOptions - Options shared by multiple tasks
104
62
  *
105
- * @param [options]
106
- * Initial options for reactApp().
63
+ * @param options - Initial options for reactApp().
107
64
  * This object will be copied and required parameters will be added by this
108
65
  * function.
109
66
  * Modified object are also duplicated, so no original data is modified.
110
67
  *
111
- * @return
68
+ * @returns
112
69
  * A configuration object for reactApp().
113
70
  */
114
71
  export declare const reactAppOptionsHelper: (helperOptions: HelperOptions, options: ReactAppOptions) => ReactAppOptions;
@@ -117,4 +74,4 @@ export declare const reactAppOptionsHelper: (helperOptions: HelperOptions, optio
117
74
  *
118
75
  * Must be called before any other `grunt.registerTask()`
119
76
  */
120
- export declare const reactAppDynamicTasks: (grunt: grunt.task.CommonTaskModule, gruntConfig: GruntConfig) => void;
77
+ export declare const reactAppDynamicTasks: (grunt: grunt.task.CommonTaskModule, gruntConfig: reactAppUtil.GruntConfig) => void;