@cley_faye/boilerplate 3.3.1 → 3.4.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.
package/README.md CHANGED
@@ -79,7 +79,7 @@ example):
79
79
  const {
80
80
  reactApp,
81
81
  reactAppDynamicTasks,
82
- } = require("@cley_faye/boilerplate/grunt");
82
+ } = require("@cley_faye/boilerplate/grunt.js");
83
83
 
84
84
  module.exports = grunt => {
85
85
  const baseGruntConfig = {};
@@ -181,7 +181,7 @@ The example from before can become:
181
181
  const {
182
182
  reactApp,
183
183
  reactAppOptionsHelper,
184
- } = require("@cley_faye/boilerplate/grunt");
184
+ } = require("@cley_faye/boilerplate/grunt.js");
185
185
 
186
186
  module.exports = grunt => {
187
187
  const baseGruntConfig = {};
@@ -239,7 +239,7 @@ It provide basic type checking and inline help display for arguments passed to G
239
239
  Usage:
240
240
 
241
241
  ```JavaScript
242
- const {getOpts, OptType} = require("@cley_faye/boilerplate/grunt");
242
+ const {getOpts, OptType} = require("@cley_faye/boilerplate/grunt.js");
243
243
  module.exports = grunt => {
244
244
  const opts = getOpts(
245
245
  grunt,
@@ -289,7 +289,7 @@ Quick sample:
289
289
 
290
290
  ```JavaScript
291
291
  import express from "express";
292
- import {createPipeline} from "@cley_faye/boilerplate/lib/express";
292
+ import {createPipeline} from "@cley_faye/boilerplate/lib/express.js";
293
293
 
294
294
  const app = express();
295
295
  app.use(createPipeline({
@@ -371,7 +371,7 @@ root of the service, or an object with the following properties:
371
371
  #### Configuring the template engine
372
372
 
373
373
  ```JavaScript
374
- import {setViewEngine} from "@cley_faye/boilerplate/lib/express";
374
+ import {setViewEngine} from "@cley_faye/boilerplate/lib/express.js";
375
375
 
376
376
  const app = express();
377
377
  setViewEngine(app, "pug", "webres/views", {});
@@ -385,9 +385,9 @@ Once the express application is defined, it need to be started to serve files an
385
385
  A helper is provided to do so, using the `appStart()` function.
386
386
 
387
387
  ```JavaScript
388
- import consoleLogger from "@cley_faye/boilerplate/lib/winston";
389
- import app from "./app";
390
- import {appStart} from "@cley_faye/boilerplate/lib/express";
388
+ import {consoleLogger} from "@cley_faye/boilerplate/lib/winston.js";
389
+ import app from "./app.js";
390
+ import {appStart} from "@cley_faye/boilerplate/lib/express.js";
391
391
 
392
392
  appStart({
393
393
  app,
@@ -410,7 +410,7 @@ The function returns a promise that resolve with the actual port used for listen
410
410
  The server is automatically registered using the `autoclose` part to stop when a SIGINT signal is
411
411
  received.
412
412
  It is also possible to trigger a stop by calling the `closeServer()` function on
413
- `@cley_faye/boilerplate/lib/express/autoclose`.
413
+ `@cley_faye/boilerplate/lib/express/autoclose.js`.
414
414
  This feature only supports one server at a time.
415
415
 
416
416
  Console logging
@@ -418,7 +418,7 @@ Console logging
418
418
  For convenience, a winston logger using console as output is provided:
419
419
 
420
420
  ```JavaScript
421
- import consoleLogger from "@cley_faye/boilerplate/lib/winston";
421
+ import {consoleLogger} from "@cley_faye/boilerplate/lib/winston.js";
422
422
 
423
423
  consoleLogger.info("Log line");
424
424
  ```
@@ -436,3 +436,11 @@ configuration to `true`.
436
436
 
437
437
  For Express app, there is no particular things to take care, except that if you use a facility like
438
438
  `nodemon` you have to watch the TypeScript output instead of the actual source files.
439
+
440
+ REPL
441
+ ----
442
+ This library provides a function to start a simple REPL instance (using node's built-in repl module)
443
+ to provide access to JavaScript features.
444
+
445
+ Basic usage includes predefined behavior for providing a database object and a list of services.
446
+ The export is in `lib/repl.js`.
package/grunt.js CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is kept as an "old" require/modules file to make it easier to use
2
2
  // with Gruntfile
3
- module.exports = require("./lib/grunt");
3
+ module.exports = require("./lib/grunt.js");
@@ -1,7 +1,7 @@
1
1
  import express from "express";
2
2
  import { OptionsJson, OptionsUrlencoded, OptionsText, Options as OptionsRaw } from "body-parser";
3
- import { LoggerOptions, ErrorLoggerOptions } from "./logger.js";
4
3
  import winston from "winston";
4
+ import { LoggerOptions, ErrorLoggerOptions } from "./logger.js";
5
5
  export declare type LogFunction = (...args: Array<string | number | Record<string, unknown>>) => void;
6
6
  export interface MiddlewareOptions {
7
7
  urlencoded?: boolean | OptionsUrlencoded;
package/lib/express.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /// <reference types="express-serve-static-core" />
2
2
  /// <reference types="node" />
3
- import { PipelineSettings, LogFunction } from "./express/pipelinebuilder.js";
3
+ import { Server } from "net";
4
4
  import express from "express";
5
5
  import winston from "winston";
6
- import { Server } from "net";
6
+ import { PipelineSettings, LogFunction } from "./express/pipelinebuilder.js";
7
7
  /** Create the full processing pipeline for an Express server
8
8
  *
9
9
  * This function creates a pipeline this way:
@@ -1,6 +1,6 @@
1
- import { GruntConfig } from "./util.js";
2
1
  import { BaseOptions } from "../util.js";
3
2
  import { HandlerFunctionResult } from "../reactapp.js";
3
+ import { GruntConfig } from "./util.js";
4
4
  export interface CopyOptions extends BaseOptions {
5
5
  options?: Record<string, unknown>;
6
6
  excludedExtensions?: Array<string>;
@@ -1,6 +1,6 @@
1
- import { GruntConfig } from "./util.js";
2
1
  import { BaseOptions } from "../util.js";
3
2
  import { HandlerFunctionResult } from "../reactapp.js";
3
+ import { GruntConfig } from "./util.js";
4
4
  export interface ImageOptions extends BaseOptions {
5
5
  options?: Record<string, unknown>;
6
6
  sourcePath?: string;
@@ -1,6 +1,6 @@
1
- import { GruntConfig } from "./util.js";
2
1
  import { BaseOptions } from "../util.js";
3
2
  import { HandlerFunctionResult } from "../reactapp.js";
3
+ import { GruntConfig } from "./util.js";
4
4
  export declare type DynamicDataFunc = () => Promise<Record<string, unknown>>;
5
5
  export interface PugOptions extends BaseOptions {
6
6
  options?: Record<string, unknown>;
@@ -1,6 +1,6 @@
1
- import { GruntConfig } from "./util.js";
2
1
  import { BaseOptions } from "../util.js";
3
2
  import { HandlerFunctionResult } from "../reactapp.js";
3
+ import { GruntConfig } from "./util.js";
4
4
  interface SassOptionsOptions {
5
5
  implementation?: Record<string, unknown>;
6
6
  }
@@ -1,6 +1,6 @@
1
- import { GruntConfig } from "./util.js";
2
1
  import { BaseOptions } from "../util.js";
3
2
  import { HandlerFunctionResult } from "../reactapp.js";
3
+ import { GruntConfig } from "./util.js";
4
4
  export interface WebpackLoadersOptions {
5
5
  development?: boolean;
6
6
  defines?: Record<string, string>;
@@ -31,9 +31,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
31
31
  Object.defineProperty(exports, "__esModule", { value: true });
32
32
  exports.handle = exports.webpackLoadersDefault = void 0;
33
33
  const path_1 = require("path");
34
- const util_js_1 = require("./util.js");
35
34
  const eslint_webpack_plugin_1 = __importDefault(require("eslint-webpack-plugin"));
36
35
  const resolve_typescript_plugin_1 = __importDefault(require("resolve-typescript-plugin"));
36
+ const util_js_1 = require("./util.js");
37
37
  const defaultCoreJS = 3;
38
38
  const eslintPlugin = () => new eslint_webpack_plugin_1.default({ cache: true });
39
39
  const defaultLoadersDefine = (options) => [
@@ -241,7 +241,7 @@ const handle = (gruntConfig, targetName, webpackOptions) => {
241
241
  babel: { plugins: webpackOptions.babelPlugins },
242
242
  typescript: webpackOptions.typescript,
243
243
  });
244
- const resolve = computeWebpackResolve(webpackOptions);
244
+ const webpackResolve = computeWebpackResolve(webpackOptions);
245
245
  const webpackConfig = {
246
246
  mode: webpackOptions.mode,
247
247
  devtool: webpackOptions.mode === "development" ? "eval-source-map" : false,
@@ -253,7 +253,7 @@ const handle = (gruntConfig, targetName, webpackOptions) => {
253
253
  eslintPlugin(),
254
254
  ...webpackOptions.plugins ?? [],
255
255
  ],
256
- resolve,
256
+ resolve: webpackResolve,
257
257
  };
258
258
  // Special case: I'm not sure I can move options in the task-specific part of
259
259
  // the configuration, so I add it at the toplevel of the "webpack" task.
package/lib/repl.d.ts ADDED
@@ -0,0 +1,27 @@
1
+ /** Function called when the REPL is closed */
2
+ export declare type ReplCloseFunc = () => void;
3
+ /** Mimic the required elements from a db object */
4
+ interface DBLikeObject {
5
+ /** db object can have a reference to an initialized sequelize instance */
6
+ sequelize?: {
7
+ /** Sequelize instance should have a close() method */
8
+ close?: () => void;
9
+ };
10
+ }
11
+ interface ReplArgs {
12
+ /** Display a service name in the prompt */
13
+ serviceName: string;
14
+ /**
15
+ * A DB object. If it exposes a db.sequelize.close() function, it will be called when the REPL is
16
+ * closed.
17
+ */
18
+ db?: DBLikeObject;
19
+ srv?: Record<string, unknown>;
20
+ /** Extra properties to attach to the REPL context */
21
+ extraContext?: Record<string, unknown>;
22
+ onClose?: ReplCloseFunc;
23
+ historyFile?: string;
24
+ }
25
+ /** Start the REPL prompt */
26
+ export declare const startRepl: ({ serviceName, db, srv, extraContext, onClose, historyFile, }: ReplArgs) => void;
27
+ export {};
package/lib/repl.js ADDED
@@ -0,0 +1,68 @@
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.startRepl = void 0;
33
+ const repl_1 = __importDefault(require("repl"));
34
+ const setupContext = (r, db, srv, extraContext) => {
35
+ const doContextSetup = () => {
36
+ Object.assign(r.context, {
37
+ ...extraContext,
38
+ db,
39
+ srv,
40
+ });
41
+ };
42
+ doContextSetup();
43
+ r.on("reset", doContextSetup);
44
+ };
45
+ /** Configure action when the REPL is closed */
46
+ const setupClose = (r, db, onClose) => {
47
+ if (!db && !onClose)
48
+ return;
49
+ r.on("exit", () => {
50
+ if (db?.sequelize?.close) {
51
+ db.sequelize.close();
52
+ }
53
+ if (onClose) {
54
+ onClose();
55
+ }
56
+ });
57
+ };
58
+ /** Start the REPL prompt */
59
+ const startRepl = ({ serviceName = "", db, srv, extraContext, onClose, historyFile = ".node_repl_history", }) => {
60
+ const r = repl_1.default.start({
61
+ prompt: `${serviceName}> `,
62
+ breakEvalOnSigint: true,
63
+ });
64
+ setupContext(r, db, srv, extraContext);
65
+ setupClose(r, db, onClose);
66
+ r.setupHistory(historyFile, () => { });
67
+ };
68
+ exports.startRepl = startRepl;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cley_faye/boilerplate",
3
- "version": "3.3.1",
3
+ "version": "3.4.1",
4
4
  "description": "Boilerplate code generator for generic projects",
5
5
  "repository": {
6
6
  "type": "git",
@@ -17,15 +17,16 @@
17
17
  },
18
18
  "homepage": "https://github.com/CleyFaye/boilerplate#readme",
19
19
  "devDependencies": {
20
- "@keeex/eslint-config": "^1.5.9",
20
+ "@keeex/eslint-config": "^1.7.0",
21
21
  "@types/express": "^4.17.11",
22
22
  "@types/grunt": "^0.4.25",
23
23
  "@types/http-errors": "^1.8.0",
24
24
  "@types/node": "^16.0.0",
25
25
  "@typescript-eslint/eslint-plugin": "^5.3.1",
26
26
  "@typescript-eslint/parser": "^5.3.1",
27
- "eslint": "^7.20.0",
28
- "eslint-plugin-promise": "^5.1.1",
27
+ "eslint": "^8.7.0",
28
+ "eslint-plugin-import": "^2.25.4",
29
+ "eslint-plugin-promise": "^6.0.0",
29
30
  "eslint-webpack-plugin": "^3.0.1",
30
31
  "express-winston": "^4.0.5",
31
32
  "grunt": "^1.4.1",
@@ -33,6 +34,7 @@
33
34
  "grunt-contrib-clean": "^2.0.0",
34
35
  "grunt-run": "^0.8.1",
35
36
  "load-grunt-tasks": "^5.1.0",
37
+ "logform": "^2.3.2",
36
38
  "typescript": "^4.1.5",
37
39
  "winston": "^3.3.3"
38
40
  },