@lzwme/sserver 0.0.6 → 0.0.7
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/dist/cli.js +1 -0
- package/dist/config.d.ts +2 -0
- package/dist/static-server.js +33 -2
- package/package.json +11 -10
package/dist/cli.js
CHANGED
|
@@ -14,6 +14,7 @@ commander_1.program
|
|
|
14
14
|
.description(console_log_colors_1.color.yellow(pkg.description) + ` [version@${console_log_colors_1.color.cyanBright(pkg.version)}]`)
|
|
15
15
|
// .option('-c, --config-path [filepath]', `配置文件 ${color.yellow(config.configPath)} 的路径`)
|
|
16
16
|
.option('-d, --root-dir [dirpath]', '静态服务器的根目录路径')
|
|
17
|
+
.option('-a, --autoindex', '是否开启目录列表浏览')
|
|
17
18
|
.option('-p, --port [port]', '端口号')
|
|
18
19
|
.option('--host <hostname>', '域名。默认为 `localhost`')
|
|
19
20
|
.option('-H, --https', '启用 https 模式')
|
package/dist/config.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { type Options } from 'http-proxy-middleware';
|
|
|
6
6
|
import { type Response, type Express } from 'express';
|
|
7
7
|
import { type NLogger, type color } from '@lzwme/fe-utils';
|
|
8
8
|
export interface SSConfig {
|
|
9
|
+
/** 是否开启目录列表 */
|
|
10
|
+
autoindex?: boolean;
|
|
9
11
|
/** 自定义 app 应用逻辑 */
|
|
10
12
|
custom?(app: Express, config: SSConfig, logger: NLogger, c: typeof color): void;
|
|
11
13
|
/** host 地址。默认为 127.0.0.1 */
|
package/dist/static-server.js
CHANGED
|
@@ -6,15 +6,38 @@
|
|
|
6
6
|
* @LastEditTime: 2023-02-03 13:32:07
|
|
7
7
|
* @Description:
|
|
8
8
|
*/
|
|
9
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
12
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
13
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
14
|
+
}
|
|
15
|
+
Object.defineProperty(o, k2, desc);
|
|
16
|
+
}) : (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
o[k2] = m[k];
|
|
19
|
+
}));
|
|
20
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
21
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
22
|
+
}) : function(o, v) {
|
|
23
|
+
o["default"] = v;
|
|
24
|
+
});
|
|
25
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
26
|
+
if (mod && mod.__esModule) return mod;
|
|
27
|
+
var result = {};
|
|
28
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
29
|
+
__setModuleDefault(result, mod);
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
9
32
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
10
33
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
11
34
|
};
|
|
12
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
36
|
exports.initServer = void 0;
|
|
14
37
|
const node_https_1 = require("node:https");
|
|
38
|
+
const node_child_process_1 = require("node:child_process");
|
|
15
39
|
const console_log_colors_1 = require("console-log-colors");
|
|
16
40
|
const express_1 = __importDefault(require("express"));
|
|
17
|
-
const child_process_1 = require("child_process");
|
|
18
41
|
const fe_utils_1 = require("@lzwme/fe-utils");
|
|
19
42
|
const config_1 = require("./config");
|
|
20
43
|
const get_logger_1 = require("./get-logger");
|
|
@@ -46,6 +69,14 @@ async function initServer(c) {
|
|
|
46
69
|
}
|
|
47
70
|
},
|
|
48
71
|
}));
|
|
72
|
+
if (config.autoindex) {
|
|
73
|
+
// @ts-expect-error
|
|
74
|
+
const serveIndex = await Promise.resolve().then(() => __importStar(require('serve-index')));
|
|
75
|
+
app.use(serveIndex.default(rootDir, {
|
|
76
|
+
icons: true,
|
|
77
|
+
hidden: true,
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
49
80
|
const onListen = () => {
|
|
50
81
|
get_logger_1.logger.log(console_log_colors_1.color.green(`Runing at : `.padStart(15, ' ')), console_log_colors_1.color.cyanBright(url));
|
|
51
82
|
get_logger_1.logger.log(console_log_colors_1.color.green(`ROOT DIR : `.padStart(15, ' ')), console_log_colors_1.color.cyanBright(rootDir));
|
|
@@ -59,7 +90,7 @@ async function initServer(c) {
|
|
|
59
90
|
get_logger_1.logger.debug(config);
|
|
60
91
|
if (config.open) {
|
|
61
92
|
const openPageCmd = `${process.platform === 'win32' ? `start` : `open`} ${url}`;
|
|
62
|
-
(0,
|
|
93
|
+
(0, node_child_process_1.execSync)(openPageCmd);
|
|
63
94
|
}
|
|
64
95
|
return app;
|
|
65
96
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lzwme/sserver",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "一个基于 Node.js 的简易静态服务器,用于辅助开发调试随启随用",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -47,21 +47,22 @@
|
|
|
47
47
|
"release": "npm run build"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@lzwme/fe-utils": "^1.
|
|
51
|
-
"commander": "^10.0.
|
|
52
|
-
"console-log-colors": "^0.
|
|
50
|
+
"@lzwme/fe-utils": "^1.5.1",
|
|
51
|
+
"commander": "^10.0.1",
|
|
52
|
+
"console-log-colors": "^0.4.0",
|
|
53
53
|
"express": "^4.18.2",
|
|
54
54
|
"http-proxy-middleware": "^2.0.6",
|
|
55
|
-
"node-forge": "^1.3.1"
|
|
55
|
+
"node-forge": "^1.3.1",
|
|
56
|
+
"serve-index": "^1.9.1"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
|
-
"@lzwme/fed-lint-helper": "^2.2
|
|
59
|
-
"@types/express": "^4.17.
|
|
60
|
-
"@types/node": "^
|
|
61
|
-
"@types/node-forge": "^1.3.
|
|
59
|
+
"@lzwme/fed-lint-helper": "^2.3.2",
|
|
60
|
+
"@types/express": "^4.17.17",
|
|
61
|
+
"@types/node": "^20.3.1",
|
|
62
|
+
"@types/node-forge": "^1.3.2",
|
|
62
63
|
"husky": "^8.0.3",
|
|
63
64
|
"standard-version": "^9.5.0",
|
|
64
65
|
"ts-node": "^10.9.1",
|
|
65
|
-
"typescript": "^
|
|
66
|
+
"typescript": "^5.1.3"
|
|
66
67
|
}
|
|
67
68
|
}
|