@cley_faye/boilerplate 3.21.3 → 4.0.2
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 +7 -219
- package/bin/serve_spa.js +0 -1
- package/lib/bin/serve_spa.js +67 -39
- package/lib/express/middlewares/singlepageapp.d.ts +2 -2
- package/lib/express/middlewares/singlepageapp.js +20 -13
- package/lib/grunt/args.d.ts +14 -42
- package/lib/grunt/args.js +27 -41
- package/lib/grunt/reactapp/copy.d.ts +8 -34
- package/lib/grunt/reactapp/copy.js +47 -49
- package/lib/grunt/reactapp/image.d.ts +8 -23
- package/lib/grunt/reactapp/image.js +45 -42
- package/lib/grunt/reactapp/pug.d.ts +8 -30
- package/lib/grunt/reactapp/pug.js +49 -50
- package/lib/grunt/reactapp/sass.d.ts +8 -29
- package/lib/grunt/reactapp/sass.js +48 -43
- package/lib/grunt/reactapp/util.d.ts +5 -9
- package/lib/grunt/reactapp/util.js +12 -15
- package/lib/grunt/reactapp/webpack.d.ts +9 -80
- package/lib/grunt/reactapp/webpack.js +71 -125
- package/lib/grunt/reactapp.d.ts +22 -64
- package/lib/grunt/reactapp.js +70 -93
- package/lib/grunt/util.d.ts +4 -7
- package/lib/grunt/util.js +5 -8
- package/lib/grunt.d.ts +2 -3
- package/lib/grunt.js +5 -5
- package/lib/util.js +5 -4
- package/package.json +23 -30
- package/grunt.js +0 -3
- package/lib/express/autoclose.d.ts +0 -17
- package/lib/express/autoclose.js +0 -76
- package/lib/express/logger.d.ts +0 -25
- package/lib/express/logger.js +0 -132
- package/lib/express/middlewares/bodylogger.d.ts +0 -9
- package/lib/express/middlewares/bodylogger.js +0 -90
- package/lib/express/pipelinebuilder.d.ts +0 -115
- package/lib/express/pipelinebuilder.js +0 -288
- package/lib/express/unprocessableentityerror.d.ts +0 -8
- package/lib/express/unprocessableentityerror.js +0 -57
- package/lib/express.d.ts +0 -156
- package/lib/express.js +0 -218
- package/lib/repl.d.ts +0 -27
- package/lib/repl.js +0 -68
- package/lib/winston.d.ts +0 -38
- package/lib/winston.js +0 -224
package/README.md
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
Some
|
|
1
|
+
Some webapp boilerplate
|
|
2
2
|
===============================
|
|
3
|
-
This repository is a small set of functions to help setting up simple webapps/Express services.
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
Note: this is legacy stuff. Low maintenance (well, lower than before). We moved toward better
|
|
5
|
+
options, that directly embeds most of the work with tsc, babel and webpack.
|
|
6
|
+
|
|
7
|
+
This repository is a small set of functions to help setting up simple webapps.
|
|
8
|
+
|
|
9
|
+
It provides Grunt tasks to transpile a webapp so it can work in most browsers.
|
|
7
10
|
|
|
8
11
|
These tools allows some level of configuration, but most default options expects a specific
|
|
9
12
|
directory layout for your project.
|
|
@@ -13,8 +16,6 @@ This is not a "starter project" but an actual dependency to keep in your project
|
|
|
13
16
|
Install it using
|
|
14
17
|
|
|
15
18
|
```shell
|
|
16
|
-
npm install @cley_faye/boilerplate
|
|
17
|
-
// alternatively, if you don't run an express server and only build a webapp offline
|
|
18
19
|
npm install -D @cley_faye/boilerplate
|
|
19
20
|
```
|
|
20
21
|
|
|
@@ -45,12 +46,6 @@ For webapp building:
|
|
|
45
46
|
- grunt
|
|
46
47
|
- ts-loader (for supporting TypeScript import in webpack/babel)
|
|
47
48
|
|
|
48
|
-
For express:
|
|
49
|
-
|
|
50
|
-
- express
|
|
51
|
-
- winston
|
|
52
|
-
- express-winston
|
|
53
|
-
|
|
54
49
|
Peer dependencies are used to limit major version mismatch.
|
|
55
50
|
|
|
56
51
|
Webapp side
|
|
@@ -280,195 +275,6 @@ All names provided in the config are converted to kebab-case for the command lin
|
|
|
280
275
|
If `--help` is passed to the command line, an additional help message will be displayed on the
|
|
281
276
|
output, using the provided descriptions if available.
|
|
282
277
|
|
|
283
|
-
Express application definition
|
|
284
|
-
------------------------------
|
|
285
|
-
The express helper actually provide a single place to configure most of the express pipeline with
|
|
286
|
-
some generic options and generic-ish way to provide routes.
|
|
287
|
-
|
|
288
|
-
It is limited to a very simple set of features but avoid having to retype them all the time.
|
|
289
|
-
Some standard security features are not defined here; my personal usecases usually involves having a
|
|
290
|
-
secure webserver in front that takes care of most headers.
|
|
291
|
-
|
|
292
|
-
Default settings operate using winston for logging.
|
|
293
|
-
|
|
294
|
-
To define your express app, you can call `createPipeline()`.
|
|
295
|
-
|
|
296
|
-
Quick sample:
|
|
297
|
-
|
|
298
|
-
```JavaScript
|
|
299
|
-
import express from "express";
|
|
300
|
-
import {createPipeline} from "@cley_faye/boilerplate/lib/express.js";
|
|
301
|
-
|
|
302
|
-
const app = express();
|
|
303
|
-
app.use(createPipeline({
|
|
304
|
-
topLevels: [],
|
|
305
|
-
routes: [],
|
|
306
|
-
statics: [],
|
|
307
|
-
postStatics: [],
|
|
308
|
-
errorHandlers: [],
|
|
309
|
-
options: {
|
|
310
|
-
log: {},
|
|
311
|
-
middleware: {},
|
|
312
|
-
defaultErrorHandler: true,
|
|
313
|
-
}
|
|
314
|
-
}));
|
|
315
|
-
|
|
316
|
-
export default app;
|
|
317
|
-
```
|
|
318
|
-
|
|
319
|
-
This will not serve anything by default, but display most top-level options that can be provided at
|
|
320
|
-
this point.
|
|
321
|
-
|
|
322
|
-
### Options
|
|
323
|
-
The log options can be used to control the express server logging behavior.
|
|
324
|
-
It supports the following properties:
|
|
325
|
-
|
|
326
|
-
- route: log all route called. Can be either a boolean or an express-winston configuration.
|
|
327
|
-
In the later case, all properties are accepted except the winston instance, which is set
|
|
328
|
-
separately.
|
|
329
|
-
More details in the "custom logging" section below.
|
|
330
|
-
- error: log all errors. Accept a boolean, or an object with the "collapseNodeModules" boolean
|
|
331
|
-
property.
|
|
332
|
-
- logger: an instance of a winston logger.
|
|
333
|
-
- timestamp: set to true to prepend a timestamp to each log line
|
|
334
|
-
- ignoredRoutes: array of path to not log
|
|
335
|
-
|
|
336
|
-
Note that if `route` is a full object, some of the other proprties might be ignored.
|
|
337
|
-
|
|
338
|
-
The middleware options allow enabling/disabling common middlewares.
|
|
339
|
-
Currently only support a few builtin middlewares from express:
|
|
340
|
-
|
|
341
|
-
- `json`, to enable auto-parsing of json body.
|
|
342
|
-
- `urlencoded`, to parse parameters from the query string
|
|
343
|
-
- `text`, to populate body with the raw request as a string
|
|
344
|
-
- `raw`, to populate body with the raw request content
|
|
345
|
-
|
|
346
|
-
Each of these options accept either `true` (to use their default behavior) or an object with their
|
|
347
|
-
configuration as specified in the ExpressJS manual.
|
|
348
|
-
|
|
349
|
-
The `defaultErrorHandler` property enable a final error handler.
|
|
350
|
-
It's behavior is to intercept errors/exceptions and return them as a reply.
|
|
351
|
-
If the error is a proper error object (from `http-errors`), it will return the message (if expose is
|
|
352
|
-
true) and the statusCode.
|
|
353
|
-
If the request declares that it can accept json, the error is sent back as a json object with
|
|
354
|
-
`statusCode` and `message`.
|
|
355
|
-
Otherwise the message is sent as a plaintext reply.
|
|
356
|
-
|
|
357
|
-
### Defining routes
|
|
358
|
-
`topLevels`, `routes` and `postStatics` are arrays of handlers.
|
|
359
|
-
Each handler can be either another Router (for route composition), a simple handler without route
|
|
360
|
-
specification (a simple `req, res, next` function), or a complete route definition in the form of an
|
|
361
|
-
object with the following properties:
|
|
362
|
-
|
|
363
|
-
- route: the route to handle
|
|
364
|
-
- handler: the route handler (or an array, or a Router)
|
|
365
|
-
- method: the method this route should handle. Defaults to "get".
|
|
366
|
-
|
|
367
|
-
### Defining error handlers
|
|
368
|
-
The `errorHandlers` property accept an array of functions that follow the express "error handler"
|
|
369
|
-
kind of functions (four parameters: `err`, `req`, `res` and `next`).
|
|
370
|
-
If provided, and if the default error handler is set, they will be called before it.
|
|
371
|
-
|
|
372
|
-
### Providing statics
|
|
373
|
-
To serve static files, the `statics` property can be used.
|
|
374
|
-
It's an array of either directly the path to a directory, in which case it will be served at the
|
|
375
|
-
root of the service, or an object with the following properties:
|
|
376
|
-
|
|
377
|
-
- root: The directory where the static files are
|
|
378
|
-
- options: The options to pass to express static handler
|
|
379
|
-
- route: The route under which the static files will be served
|
|
380
|
-
|
|
381
|
-
### Custom logging
|
|
382
|
-
The default configuration (by setting `options.log.route: true`) allows some level of customization
|
|
383
|
-
of the actual logged data.
|
|
384
|
-
If a custom object is passed instead of `true`, the following will not automatically apply.
|
|
385
|
-
|
|
386
|
-
By default, all body content is logged.
|
|
387
|
-
To finely tune what body elements are logged on each route the `bodyLogger()` middleware can be
|
|
388
|
-
used.
|
|
389
|
-
It takes two parameters, the first one is an array of properties that *should* be logged, the second
|
|
390
|
-
one can be a custom object or a function returning a custom object with extra properties to log.
|
|
391
|
-
|
|
392
|
-
For example, for a login route, you might want to hide the provided password but still get some info
|
|
393
|
-
(note: this is an example, in practice you probably shouldn't care about this)
|
|
394
|
-
|
|
395
|
-
```JavaScript
|
|
396
|
-
router.post(
|
|
397
|
-
"/login",
|
|
398
|
-
bodyLogger(
|
|
399
|
-
["login"],
|
|
400
|
-
req => ({
|
|
401
|
-
passwordLength: req.body.password.length,
|
|
402
|
-
}),
|
|
403
|
-
),
|
|
404
|
-
processLogin,
|
|
405
|
-
);
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
In addition to excluding properties from the body of a request and adding custom properties, it can
|
|
409
|
-
be useful to always identify a request coming from a logged-in user.
|
|
410
|
-
|
|
411
|
-
You can provide a `authFromReq` property to the `options.log` configuration.
|
|
412
|
-
It should be a function that receive `req` as its argument and returns a string identifying the
|
|
413
|
-
logged-in user.
|
|
414
|
-
(this only work with the default log handler; if you define anything in `route` you can set this in
|
|
415
|
-
`dynamicMeta()`)
|
|
416
|
-
|
|
417
|
-
### Configuring global aspects of an Express App
|
|
418
|
-
|
|
419
|
-
#### Configuring the template engine
|
|
420
|
-
|
|
421
|
-
```JavaScript
|
|
422
|
-
import {setViewEngine} from "@cley_faye/boilerplate/lib/express.js";
|
|
423
|
-
|
|
424
|
-
const app = express();
|
|
425
|
-
setViewEngine(app, "pug", "webres/views", {});
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
The last parameter is optional; if provided it will define values available to the template engine.
|
|
429
|
-
|
|
430
|
-
Running Express application
|
|
431
|
-
---------------------------
|
|
432
|
-
Once the express application is defined, it need to be started to serve files and resources.
|
|
433
|
-
A helper is provided to do so, using the `appStart()` function.
|
|
434
|
-
|
|
435
|
-
```JavaScript
|
|
436
|
-
import {consoleLogger} from "@cley_faye/boilerplate/lib/winston.js";
|
|
437
|
-
import app from "./app.js";
|
|
438
|
-
import {appStart} from "@cley_faye/boilerplate/lib/express.js";
|
|
439
|
-
|
|
440
|
-
appStart({
|
|
441
|
-
app,
|
|
442
|
-
listenInterface: false,
|
|
443
|
-
port: 3000,
|
|
444
|
-
shutdownFunction: () => {;},
|
|
445
|
-
logger: consoleLogger,
|
|
446
|
-
noReady: false,
|
|
447
|
-
}).then(({port, server}) => {;});
|
|
448
|
-
```
|
|
449
|
-
|
|
450
|
-
The settings are:
|
|
451
|
-
|
|
452
|
-
- listenInterface: listen only to localhost or not. Can also be used to specify the address of an
|
|
453
|
-
interface to bind to.
|
|
454
|
-
- port: port to listen to. Can be 0 to use a random available port
|
|
455
|
-
- shutdownFunction: a function to call after the server stop listening
|
|
456
|
-
- logger: a winston logger to log that the server started listening
|
|
457
|
-
- noReady: if true, does not call `process.send("ready");` (used by PM2)
|
|
458
|
-
|
|
459
|
-
The shutdown function can return a promise, and if it returns/resolve with `true` the process is
|
|
460
|
-
left alive.
|
|
461
|
-
Otherwise `process.exit()` is called after `shutdownFunction()` resolves/returns.
|
|
462
|
-
|
|
463
|
-
The `appStart()` function returns a promise that resolve with the actual port used for listening
|
|
464
|
-
when the server is started.
|
|
465
|
-
|
|
466
|
-
The server is automatically registered using the `autoclose` part to stop when a SIGINT signal is
|
|
467
|
-
received.
|
|
468
|
-
It is also possible to trigger a stop by calling the `closeServer()` function on
|
|
469
|
-
`@cley_faye/boilerplate/lib/express/autoclose.js`.
|
|
470
|
-
This feature only supports one server at a time.
|
|
471
|
-
|
|
472
278
|
Extra middleware
|
|
473
279
|
----------------
|
|
474
280
|
|
|
@@ -497,16 +303,6 @@ A convenience command is available as "serve_spa" to be called from the command
|
|
|
497
303
|
It is possible to pass it some parameters; run it with `--help` for more informations.
|
|
498
304
|
To use this tool, `minimist` must be installed in addition to express dependencies.
|
|
499
305
|
|
|
500
|
-
Console logging
|
|
501
|
-
---------------
|
|
502
|
-
For convenience, a winston logger using console as output is provided:
|
|
503
|
-
|
|
504
|
-
```JavaScript
|
|
505
|
-
import {consoleLogger} from "@cley_faye/boilerplate/lib/winston.js";
|
|
506
|
-
|
|
507
|
-
consoleLogger.info("Log line");
|
|
508
|
-
```
|
|
509
|
-
|
|
510
306
|
Using TypeScript
|
|
511
307
|
-----------------
|
|
512
308
|
Typical use of TypeScript implies converting `.ts` file to `.js`.
|
|
@@ -522,11 +318,3 @@ If a `tsconfig-tsloader.json` file exists at the root of the project, it will be
|
|
|
522
318
|
|
|
523
319
|
For Express app, there is no particular things to take care, except that if you use a facility like
|
|
524
320
|
`nodemon` you have to watch the TypeScript output instead of the actual source files.
|
|
525
|
-
|
|
526
|
-
REPL
|
|
527
|
-
----
|
|
528
|
-
This library provides a function to start a simple REPL instance (using node's built-in repl module)
|
|
529
|
-
to provide access to JavaScript features.
|
|
530
|
-
|
|
531
|
-
Basic usage includes predefined behavior for providing a database object and a list of services.
|
|
532
|
-
The export is in `lib/repl.js`.
|
package/bin/serve_spa.js
CHANGED
package/lib/bin/serve_spa.js
CHANGED
|
@@ -41,33 +41,42 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
41
41
|
}) : function(o, v) {
|
|
42
42
|
o["default"] = v;
|
|
43
43
|
});
|
|
44
|
-
var __importStar = (this && this.__importStar) || function (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
};
|
|
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
|
+
})();
|
|
51
61
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
52
62
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
53
63
|
};
|
|
54
64
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
/* eslint-disable no-console */
|
|
66
|
+
const fs = __importStar(require("node:fs"));
|
|
55
67
|
const path = __importStar(require("node:path"));
|
|
56
|
-
const node_fs_1 = require("node:fs");
|
|
57
68
|
const express_1 = __importDefault(require("express"));
|
|
58
69
|
const minimist_1 = __importDefault(require("minimist"));
|
|
59
70
|
const singlepageapp_js_1 = require("../express/middlewares/singlepageapp.js");
|
|
60
|
-
const express_js_1 = require("../express.js");
|
|
61
|
-
const winston_js_1 = require("../winston.js");
|
|
62
71
|
const ARGV_START_OFFSET = 2;
|
|
63
|
-
const { port, root, index, help, staticlist, static: staticDirs } = (0, minimist_1.default)(process.argv.slice(ARGV_START_OFFSET));
|
|
72
|
+
const { port, root, index, help, staticlist, static: staticDirs, } = (0, minimist_1.default)(process.argv.slice(ARGV_START_OFFSET));
|
|
64
73
|
const DEFAULT_PORT = 3000;
|
|
65
74
|
const DEFAULT_PATH = path.join("dist", "webapp");
|
|
66
75
|
const DEFAULT_INDEX = "index.html";
|
|
67
76
|
const DEFAULT_STATICFILE = "spa_static.config";
|
|
68
77
|
const DEFAULT_STATIC = ["js", "css", "img"];
|
|
69
78
|
if (help) {
|
|
70
|
-
|
|
79
|
+
console.log(`
|
|
71
80
|
Usage:
|
|
72
81
|
|
|
73
82
|
serve_spa \\
|
|
@@ -84,7 +93,6 @@ It defaults to ${JSON.stringify(DEFAULT_STATIC)}.
|
|
|
84
93
|
The staticfile value is a text file with one static directory line.
|
|
85
94
|
If present, they are merged with the CLI arguments.
|
|
86
95
|
`.trim());
|
|
87
|
-
// eslint-disable-next-line no-process-exit
|
|
88
96
|
process.exit(0);
|
|
89
97
|
}
|
|
90
98
|
const getPort = () => port ?? DEFAULT_PORT;
|
|
@@ -93,37 +101,57 @@ const getStatic = () => {
|
|
|
93
101
|
if (staticDirs)
|
|
94
102
|
result.push(...(Array.isArray(staticDirs) ? staticDirs : [staticDirs]));
|
|
95
103
|
if (staticlist) {
|
|
96
|
-
for (const staticsrc of
|
|
97
|
-
if (!
|
|
104
|
+
for (const staticsrc of Array.isArray(staticlist) ? staticlist : [staticlist]) {
|
|
105
|
+
if (!fs.existsSync(staticsrc))
|
|
98
106
|
continue;
|
|
99
|
-
result.push(...
|
|
107
|
+
result.push(...fs
|
|
108
|
+
.readFileSync(staticsrc, "utf8")
|
|
100
109
|
.split("\n")
|
|
101
|
-
.filter(c => c));
|
|
110
|
+
.filter((c) => c));
|
|
102
111
|
}
|
|
103
112
|
}
|
|
104
113
|
return result.length > 0 ? result : undefined;
|
|
105
114
|
};
|
|
106
115
|
const app = (0, express_1.default)();
|
|
107
|
-
app.use((
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
log: {
|
|
116
|
-
route: true,
|
|
117
|
-
error: true,
|
|
118
|
-
logger: winston_js_1.consoleLogger,
|
|
119
|
-
},
|
|
120
|
-
},
|
|
116
|
+
app.use((req, res, next) => {
|
|
117
|
+
console.log(`${Date.now()} - ${req.method} ${req.url}`);
|
|
118
|
+
next();
|
|
119
|
+
});
|
|
120
|
+
app.use((0, singlepageapp_js_1.singlePageApp)({
|
|
121
|
+
htmlFile: index,
|
|
122
|
+
rootDir: root ?? "dist/webapp",
|
|
123
|
+
staticRootDirectories: getStatic(),
|
|
121
124
|
}));
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
let server = null;
|
|
126
|
+
const maxSignals = 5;
|
|
127
|
+
let signalsReceived = 0;
|
|
128
|
+
const signalHandler = (signal) => {
|
|
129
|
+
if (!server) {
|
|
130
|
+
console.log(`Received ${signal}, but server not started; exiting`);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
133
|
+
if (signalsReceived === 0) {
|
|
134
|
+
signalsReceived = 1;
|
|
135
|
+
console.log(`Received ${signal}, stopping server`);
|
|
136
|
+
server.close();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (signalsReceived < maxSignals) {
|
|
140
|
+
++signalsReceived;
|
|
141
|
+
console.log(`Received ${signal}, ${signalsReceived} / ${maxSignals}`);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
console.log(`Received final ${signal}, exiting`);
|
|
145
|
+
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
|
|
146
|
+
process.exit(2);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
process.on("SIGINT", () => {
|
|
150
|
+
signalHandler("SIGINT");
|
|
151
|
+
});
|
|
152
|
+
process.on("SIGTERM", () => {
|
|
153
|
+
signalHandler("SIGTERM");
|
|
154
|
+
});
|
|
155
|
+
server = app.listen(getPort(), () => {
|
|
156
|
+
console.log(`Server listening on port ${port}`);
|
|
157
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as express from "express";
|
|
2
2
|
interface SinglePageAppConfig {
|
|
3
3
|
/** Path to the file to serve for the whole application
|
|
4
4
|
*
|
|
@@ -37,5 +37,5 @@ interface SinglePageAppConfig {
|
|
|
37
37
|
* someRouter.use("/app", singlePageApp({rootDir: "dist/webapp"});
|
|
38
38
|
* ```
|
|
39
39
|
*/
|
|
40
|
-
export declare const singlePageApp: (config: SinglePageAppConfig) => Array<RequestHandler>;
|
|
40
|
+
export declare const singlePageApp: (config: SinglePageAppConfig) => Array<express.RequestHandler>;
|
|
41
41
|
export {};
|
|
@@ -41,20 +41,27 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
41
41
|
}) : function(o, v) {
|
|
42
42
|
o["default"] = v;
|
|
43
43
|
});
|
|
44
|
-
var __importStar = (this && this.__importStar) || function (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
+
})();
|
|
54
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
62
|
exports.singlePageApp = void 0;
|
|
56
63
|
const path = __importStar(require("node:path"));
|
|
57
|
-
const
|
|
64
|
+
const express = __importStar(require("express"));
|
|
58
65
|
/** Serve a single page webapp using a modern browser URL router
|
|
59
66
|
*
|
|
60
67
|
* This will serve all requests from the router using the provided index.html file, except for files
|
|
@@ -75,7 +82,7 @@ const express_1 = __importDefault(require("express"));
|
|
|
75
82
|
const singlePageApp = (config) => {
|
|
76
83
|
const rootDir = path.resolve(config.rootDir);
|
|
77
84
|
const htmlFile = config.htmlFile ?? "index.html";
|
|
78
|
-
const staticDirs = (config.staticRootDirectories ?? ["js", "css", "img"]).map(c => `/${c}`);
|
|
85
|
+
const staticDirs = (config.staticRootDirectories ?? ["js", "css", "img"]).map((c) => `/${c}`);
|
|
79
86
|
const appRoute = (req, res, next) => {
|
|
80
87
|
for (const candidates of staticDirs)
|
|
81
88
|
if (req.url.startsWith(candidates))
|
|
@@ -85,7 +92,7 @@ const singlePageApp = (config) => {
|
|
|
85
92
|
return next(err);
|
|
86
93
|
});
|
|
87
94
|
};
|
|
88
|
-
const staticRoute =
|
|
95
|
+
const staticRoute = express.static(rootDir);
|
|
89
96
|
return [appRoute, staticRoute];
|
|
90
97
|
};
|
|
91
98
|
exports.singlePageApp = singlePageApp;
|
package/lib/grunt/args.d.ts
CHANGED
|
@@ -3,72 +3,44 @@ export declare enum OptType {
|
|
|
3
3
|
NUMBER = "number",
|
|
4
4
|
BOOLEAN = "boolean"
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
7
|
-
* Possible value type for options from command line
|
|
8
|
-
*/
|
|
6
|
+
/** Possible value type for options from command line */
|
|
9
7
|
export type OptValue = string | number | boolean;
|
|
10
|
-
/**
|
|
11
|
-
* List of all configured options
|
|
12
|
-
*/
|
|
8
|
+
/** List of all configured options */
|
|
13
9
|
export type Opts = Record<string, OptValue>;
|
|
14
|
-
/**
|
|
15
|
-
* Raw value type from command line
|
|
16
|
-
*/
|
|
10
|
+
/** Raw value type from command line */
|
|
17
11
|
export type RawOptValue = undefined | boolean | string;
|
|
18
|
-
/**
|
|
19
|
-
* Interface to an option provider (usually Grunt itself)
|
|
20
|
-
*/
|
|
12
|
+
/** Interface to an option provider (usually Grunt itself) */
|
|
21
13
|
export interface OptionsProvider {
|
|
22
|
-
/**
|
|
23
|
-
* Return the value of an option from its key
|
|
24
|
-
*/
|
|
14
|
+
/** Return the value of an option from its key */
|
|
25
15
|
option: (key: string) => RawOptValue;
|
|
26
16
|
}
|
|
27
|
-
/**
|
|
28
|
-
* Expected option from command line
|
|
29
|
-
*/
|
|
17
|
+
/** Expected option from command line */
|
|
30
18
|
interface OptionDefinitionBase {
|
|
31
|
-
/**
|
|
32
|
-
* Description for --help
|
|
33
|
-
*/
|
|
19
|
+
/** Description for --help */
|
|
34
20
|
description?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Value type. Default to STRING.
|
|
37
|
-
*/
|
|
21
|
+
/** Value type. Default to STRING. */
|
|
38
22
|
type?: OptType;
|
|
39
23
|
}
|
|
40
|
-
/**
|
|
41
|
-
* String option from command line
|
|
42
|
-
*/
|
|
24
|
+
/** String option from command line */
|
|
43
25
|
export interface OptionDefinitionString extends OptionDefinitionBase {
|
|
44
26
|
type: OptType.STRING;
|
|
45
27
|
defaultValue?: string;
|
|
46
28
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Number option from command line
|
|
49
|
-
*/
|
|
29
|
+
/** Number option from command line */
|
|
50
30
|
export interface OptionDefinitionNumber extends OptionDefinitionBase {
|
|
51
31
|
type: OptType.NUMBER;
|
|
52
32
|
defaultValue?: number;
|
|
53
33
|
}
|
|
54
|
-
/**
|
|
55
|
-
* Boolean option from command line
|
|
56
|
-
*/
|
|
34
|
+
/** Boolean option from command line */
|
|
57
35
|
export interface OptionDefinitionBoolean extends OptionDefinitionBase {
|
|
58
36
|
type: OptType.BOOLEAN;
|
|
59
37
|
defaultValue?: boolean;
|
|
60
38
|
}
|
|
61
|
-
/**
|
|
62
|
-
* All possible option definition types
|
|
63
|
-
*/
|
|
39
|
+
/** All possible option definition types */
|
|
64
40
|
export type OptionDefinition = OptionDefinitionString | OptionDefinitionNumber | OptionDefinitionBoolean;
|
|
65
|
-
/**
|
|
66
|
-
* Expected options from command line
|
|
67
|
-
*/
|
|
41
|
+
/** Expected options from command line */
|
|
68
42
|
export type ConfigDefinition = Record<string, OptionDefinition>;
|
|
69
|
-
/**
|
|
70
|
-
* Display help to the user
|
|
71
|
-
*/
|
|
43
|
+
/** Display help to the user */
|
|
72
44
|
export declare const displayHelp: (configDef: ConfigDefinition) => void;
|
|
73
45
|
/**
|
|
74
46
|
* Construct the full config object from command line values.
|