@cley_faye/boilerplate 3.19.0 → 3.20.0
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/lib/bin/serve_spa.js +20 -4
- package/package.json +1 -1
package/lib/bin/serve_spa.js
CHANGED
|
@@ -53,16 +53,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
53
53
|
};
|
|
54
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
55
|
const path = __importStar(require("node:path"));
|
|
56
|
+
const node_fs_1 = require("node:fs");
|
|
56
57
|
const express_1 = __importDefault(require("express"));
|
|
57
58
|
const minimist_1 = __importDefault(require("minimist"));
|
|
58
59
|
const singlepageapp_js_1 = require("../express/middlewares/singlepageapp.js");
|
|
59
60
|
const express_js_1 = require("../express.js");
|
|
60
61
|
const winston_js_1 = require("../winston.js");
|
|
61
62
|
const ARGV_START_OFFSET = 2;
|
|
62
|
-
const { port, root, index, help, static: staticDirs } = (0, minimist_1.default)(process.argv.slice(ARGV_START_OFFSET));
|
|
63
|
+
const { port, root, index, help, staticlist, static: staticDirs } = (0, minimist_1.default)(process.argv.slice(ARGV_START_OFFSET));
|
|
63
64
|
const DEFAULT_PORT = 3000;
|
|
64
65
|
const DEFAULT_PATH = path.join("dist", "webapp");
|
|
65
66
|
const DEFAULT_INDEX = "index.html";
|
|
67
|
+
const DEFAULT_STATICFILE = "spa_static.config";
|
|
66
68
|
const DEFAULT_STATIC = ["js", "css", "img"];
|
|
67
69
|
if (help) {
|
|
68
70
|
winston_js_1.consoleLogger.info(`
|
|
@@ -72,20 +74,34 @@ serve_spa \\
|
|
|
72
74
|
[--port=${DEFAULT_PORT}] \\
|
|
73
75
|
[--root=${DEFAULT_PATH}] \\
|
|
74
76
|
[--index=${DEFAULT_INDEX}] \\
|
|
77
|
+
[--staticlist=${DEFAULT_STATICFILE}] \\
|
|
75
78
|
[--static=js…] \\
|
|
76
79
|
[--help]
|
|
77
80
|
|
|
78
81
|
The --static argument can be repeated to add more directories to it.
|
|
79
82
|
It defaults to ${JSON.stringify(DEFAULT_STATIC)}.
|
|
83
|
+
|
|
84
|
+
The staticfile value is a text file with one static directory line.
|
|
85
|
+
If present, they are merged with the CLI arguments.
|
|
80
86
|
`.trim());
|
|
81
87
|
// eslint-disable-next-line no-process-exit
|
|
82
88
|
process.exit(0);
|
|
83
89
|
}
|
|
84
90
|
const getPort = () => port ?? DEFAULT_PORT;
|
|
85
91
|
const getStatic = () => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
const result = [];
|
|
93
|
+
if (staticDirs)
|
|
94
|
+
result.push(...(Array.isArray(staticDirs) ? staticDirs : [staticDirs]));
|
|
95
|
+
if (staticlist) {
|
|
96
|
+
for (const staticsrc of (Array.isArray(staticlist) ? staticlist : [staticlist])) {
|
|
97
|
+
if (!(0, node_fs_1.existsSync)(staticsrc))
|
|
98
|
+
continue;
|
|
99
|
+
result.push(...(0, node_fs_1.readFileSync)(staticsrc, "utf8")
|
|
100
|
+
.split("\n")
|
|
101
|
+
.filter(c => c));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return result.length > 0 ? result : undefined;
|
|
89
105
|
};
|
|
90
106
|
const app = (0, express_1.default)();
|
|
91
107
|
app.use((0, express_js_1.createPipeline)({
|