sable 0.5.14 → 0.5.16
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/cjs/cli.cjs +117 -0
- package/cjs/index.cjs +72 -0
- package/esm/cli.mjs +93 -0
- package/esm/index.mjs +41 -0
- package/package.json +22 -10
- package/types/cli.d.ts +2 -0
- package/types/index.d.ts +10 -0
- package/bin/sable +0 -28
- package/lib/index.d.ts +0 -10
- package/lib/index.js +0 -41
package/cjs/cli.cjs
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/cli.ts
|
|
27
|
+
var import_node_fs = require("node:fs");
|
|
28
|
+
var import_node_path = require("node:path");
|
|
29
|
+
var import_commander = require("commander");
|
|
30
|
+
var import_middleware_static_livereload2 = require("middleware-static-livereload");
|
|
31
|
+
|
|
32
|
+
// src/index.ts
|
|
33
|
+
var http = __toESM(require("node:http"), 1);
|
|
34
|
+
var import_connect = __toESM(require("connect"), 1);
|
|
35
|
+
var staticLivereload = __toESM(require("middleware-static-livereload"), 1);
|
|
36
|
+
var import_middleware_static_livereload = require("middleware-static-livereload");
|
|
37
|
+
var startServer = async (options2 = {}) => {
|
|
38
|
+
const app = (0, import_connect.default)();
|
|
39
|
+
for (const middleware2 of options2.middlewares || []) {
|
|
40
|
+
app.use(middleware2);
|
|
41
|
+
}
|
|
42
|
+
app.use(staticLivereload.middleware(options2));
|
|
43
|
+
const server = http.createServer(app);
|
|
44
|
+
return await new Promise((resolve, reject) => {
|
|
45
|
+
server.once("listening", () => {
|
|
46
|
+
const addressInfo = server.address();
|
|
47
|
+
if (addressInfo && typeof addressInfo === "object") {
|
|
48
|
+
const { address, family, port: port2 } = addressInfo;
|
|
49
|
+
const portSuffix = port2 === 80 ? "" : `:${port2}`;
|
|
50
|
+
const hostname = options2.host || (portSuffix && family === "IPv6" ? `[${address}]` : address);
|
|
51
|
+
process.stdout.write(`http://${hostname}${portSuffix}
|
|
52
|
+
`);
|
|
53
|
+
}
|
|
54
|
+
resolve(server);
|
|
55
|
+
});
|
|
56
|
+
const listen = (port2, host2) => {
|
|
57
|
+
server.once("error", (error) => {
|
|
58
|
+
if (error.code === "EADDRINUSE") {
|
|
59
|
+
listen(port2 + 1, host2);
|
|
60
|
+
} else {
|
|
61
|
+
reject(error);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
server.listen(port2, host2);
|
|
65
|
+
};
|
|
66
|
+
listen(options2.port || 4e3, options2.host);
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/cli.ts
|
|
71
|
+
var import_meta = {};
|
|
72
|
+
var packageJsonPath = typeof __dirname !== "undefined" ? (0, import_node_path.join)(__dirname, "../package.json") : typeof import_meta !== "undefined" ? new URL("../package.json", import_meta.url) : void 0;
|
|
73
|
+
if (!packageJsonPath) {
|
|
74
|
+
throw new Error("Unable to resolve path to package.json");
|
|
75
|
+
}
|
|
76
|
+
var { version } = JSON.parse((0, import_node_fs.readFileSync)(packageJsonPath, "utf8"));
|
|
77
|
+
var program = new import_commander.Command().version(version).description("Starts a HTTP server for development").option(
|
|
78
|
+
"-p, --port <n>",
|
|
79
|
+
"A port number for HTTP, HTTPS (4000)",
|
|
80
|
+
Number.parseInt
|
|
81
|
+
).option("-h, --host <s>", "Hostname").option("-v, --verbose", "Enable verbose logging").option("--noWatch", "Disable watching").option("-i, --index <s>", "A filename of index (index.html)").argument("[documentRoot...]", "Paths to serve");
|
|
82
|
+
program.parse();
|
|
83
|
+
var {
|
|
84
|
+
noWatch,
|
|
85
|
+
port,
|
|
86
|
+
host,
|
|
87
|
+
verbose = false,
|
|
88
|
+
index
|
|
89
|
+
} = program.opts();
|
|
90
|
+
var documentRoot = program.args;
|
|
91
|
+
if (documentRoot.length === 0) {
|
|
92
|
+
documentRoot.push(process.cwd());
|
|
93
|
+
}
|
|
94
|
+
var options = {
|
|
95
|
+
watch: !noWatch,
|
|
96
|
+
documentRoot,
|
|
97
|
+
logLevel: verbose ? import_middleware_static_livereload2.LogLevel.debug : import_middleware_static_livereload2.LogLevel.info
|
|
98
|
+
};
|
|
99
|
+
if (Array.isArray(port)) {
|
|
100
|
+
options.port = port[0];
|
|
101
|
+
} else if (port) {
|
|
102
|
+
options.port = port;
|
|
103
|
+
}
|
|
104
|
+
if (Array.isArray(host)) {
|
|
105
|
+
options.host = host[0];
|
|
106
|
+
} else if (host) {
|
|
107
|
+
options.host = host;
|
|
108
|
+
}
|
|
109
|
+
if (Array.isArray(index)) {
|
|
110
|
+
options.index = index[0];
|
|
111
|
+
} else if (index) {
|
|
112
|
+
options.index = index;
|
|
113
|
+
}
|
|
114
|
+
startServer(options).catch((error) => {
|
|
115
|
+
console.error(error);
|
|
116
|
+
process.exit(1);
|
|
117
|
+
});
|
package/cjs/index.cjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
LogLevel: () => import_middleware_static_livereload.LogLevel,
|
|
34
|
+
startServer: () => startServer
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
37
|
+
var http = __toESM(require("node:http"), 1);
|
|
38
|
+
var import_connect = __toESM(require("connect"), 1);
|
|
39
|
+
var staticLivereload = __toESM(require("middleware-static-livereload"), 1);
|
|
40
|
+
var import_middleware_static_livereload = require("middleware-static-livereload");
|
|
41
|
+
var startServer = async (options = {}) => {
|
|
42
|
+
const app = (0, import_connect.default)();
|
|
43
|
+
for (const middleware2 of options.middlewares || []) {
|
|
44
|
+
app.use(middleware2);
|
|
45
|
+
}
|
|
46
|
+
app.use(staticLivereload.middleware(options));
|
|
47
|
+
const server = http.createServer(app);
|
|
48
|
+
return await new Promise((resolve, reject) => {
|
|
49
|
+
server.once("listening", () => {
|
|
50
|
+
const addressInfo = server.address();
|
|
51
|
+
if (addressInfo && typeof addressInfo === "object") {
|
|
52
|
+
const { address, family, port } = addressInfo;
|
|
53
|
+
const portSuffix = port === 80 ? "" : `:${port}`;
|
|
54
|
+
const hostname = options.host || (portSuffix && family === "IPv6" ? `[${address}]` : address);
|
|
55
|
+
process.stdout.write(`http://${hostname}${portSuffix}
|
|
56
|
+
`);
|
|
57
|
+
}
|
|
58
|
+
resolve(server);
|
|
59
|
+
});
|
|
60
|
+
const listen = (port, host) => {
|
|
61
|
+
server.once("error", (error) => {
|
|
62
|
+
if (error.code === "EADDRINUSE") {
|
|
63
|
+
listen(port + 1, host);
|
|
64
|
+
} else {
|
|
65
|
+
reject(error);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
server.listen(port, host);
|
|
69
|
+
};
|
|
70
|
+
listen(options.port || 4e3, options.host);
|
|
71
|
+
});
|
|
72
|
+
};
|
package/esm/cli.mjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/cli.ts
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { Command } from "commander";
|
|
7
|
+
import { LogLevel as LogLevel2 } from "middleware-static-livereload";
|
|
8
|
+
|
|
9
|
+
// src/index.ts
|
|
10
|
+
import * as http from "node:http";
|
|
11
|
+
import connect from "connect";
|
|
12
|
+
import * as staticLivereload from "middleware-static-livereload";
|
|
13
|
+
import { LogLevel } from "middleware-static-livereload";
|
|
14
|
+
var startServer = async (options2 = {}) => {
|
|
15
|
+
const app = connect();
|
|
16
|
+
for (const middleware2 of options2.middlewares || []) {
|
|
17
|
+
app.use(middleware2);
|
|
18
|
+
}
|
|
19
|
+
app.use(staticLivereload.middleware(options2));
|
|
20
|
+
const server = http.createServer(app);
|
|
21
|
+
return await new Promise((resolve, reject) => {
|
|
22
|
+
server.once("listening", () => {
|
|
23
|
+
const addressInfo = server.address();
|
|
24
|
+
if (addressInfo && typeof addressInfo === "object") {
|
|
25
|
+
const { address, family, port: port2 } = addressInfo;
|
|
26
|
+
const portSuffix = port2 === 80 ? "" : `:${port2}`;
|
|
27
|
+
const hostname = options2.host || (portSuffix && family === "IPv6" ? `[${address}]` : address);
|
|
28
|
+
process.stdout.write(`http://${hostname}${portSuffix}
|
|
29
|
+
`);
|
|
30
|
+
}
|
|
31
|
+
resolve(server);
|
|
32
|
+
});
|
|
33
|
+
const listen = (port2, host2) => {
|
|
34
|
+
server.once("error", (error) => {
|
|
35
|
+
if (error.code === "EADDRINUSE") {
|
|
36
|
+
listen(port2 + 1, host2);
|
|
37
|
+
} else {
|
|
38
|
+
reject(error);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
server.listen(port2, host2);
|
|
42
|
+
};
|
|
43
|
+
listen(options2.port || 4e3, options2.host);
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// src/cli.ts
|
|
48
|
+
var packageJsonPath = typeof __dirname !== "undefined" ? join(__dirname, "../package.json") : typeof import.meta !== "undefined" ? new URL("../package.json", import.meta.url) : void 0;
|
|
49
|
+
if (!packageJsonPath) {
|
|
50
|
+
throw new Error("Unable to resolve path to package.json");
|
|
51
|
+
}
|
|
52
|
+
var { version } = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
53
|
+
var program = new Command().version(version).description("Starts a HTTP server for development").option(
|
|
54
|
+
"-p, --port <n>",
|
|
55
|
+
"A port number for HTTP, HTTPS (4000)",
|
|
56
|
+
Number.parseInt
|
|
57
|
+
).option("-h, --host <s>", "Hostname").option("-v, --verbose", "Enable verbose logging").option("--noWatch", "Disable watching").option("-i, --index <s>", "A filename of index (index.html)").argument("[documentRoot...]", "Paths to serve");
|
|
58
|
+
program.parse();
|
|
59
|
+
var {
|
|
60
|
+
noWatch,
|
|
61
|
+
port,
|
|
62
|
+
host,
|
|
63
|
+
verbose = false,
|
|
64
|
+
index
|
|
65
|
+
} = program.opts();
|
|
66
|
+
var documentRoot = program.args;
|
|
67
|
+
if (documentRoot.length === 0) {
|
|
68
|
+
documentRoot.push(process.cwd());
|
|
69
|
+
}
|
|
70
|
+
var options = {
|
|
71
|
+
watch: !noWatch,
|
|
72
|
+
documentRoot,
|
|
73
|
+
logLevel: verbose ? LogLevel2.debug : LogLevel2.info
|
|
74
|
+
};
|
|
75
|
+
if (Array.isArray(port)) {
|
|
76
|
+
options.port = port[0];
|
|
77
|
+
} else if (port) {
|
|
78
|
+
options.port = port;
|
|
79
|
+
}
|
|
80
|
+
if (Array.isArray(host)) {
|
|
81
|
+
options.host = host[0];
|
|
82
|
+
} else if (host) {
|
|
83
|
+
options.host = host;
|
|
84
|
+
}
|
|
85
|
+
if (Array.isArray(index)) {
|
|
86
|
+
options.index = index[0];
|
|
87
|
+
} else if (index) {
|
|
88
|
+
options.index = index;
|
|
89
|
+
}
|
|
90
|
+
startServer(options).catch((error) => {
|
|
91
|
+
console.error(error);
|
|
92
|
+
process.exit(1);
|
|
93
|
+
});
|
package/esm/index.mjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import * as http from "node:http";
|
|
3
|
+
import connect from "connect";
|
|
4
|
+
import * as staticLivereload from "middleware-static-livereload";
|
|
5
|
+
import { LogLevel } from "middleware-static-livereload";
|
|
6
|
+
var startServer = async (options = {}) => {
|
|
7
|
+
const app = connect();
|
|
8
|
+
for (const middleware2 of options.middlewares || []) {
|
|
9
|
+
app.use(middleware2);
|
|
10
|
+
}
|
|
11
|
+
app.use(staticLivereload.middleware(options));
|
|
12
|
+
const server = http.createServer(app);
|
|
13
|
+
return await new Promise((resolve, reject) => {
|
|
14
|
+
server.once("listening", () => {
|
|
15
|
+
const addressInfo = server.address();
|
|
16
|
+
if (addressInfo && typeof addressInfo === "object") {
|
|
17
|
+
const { address, family, port } = addressInfo;
|
|
18
|
+
const portSuffix = port === 80 ? "" : `:${port}`;
|
|
19
|
+
const hostname = options.host || (portSuffix && family === "IPv6" ? `[${address}]` : address);
|
|
20
|
+
process.stdout.write(`http://${hostname}${portSuffix}
|
|
21
|
+
`);
|
|
22
|
+
}
|
|
23
|
+
resolve(server);
|
|
24
|
+
});
|
|
25
|
+
const listen = (port, host) => {
|
|
26
|
+
server.once("error", (error) => {
|
|
27
|
+
if (error.code === "EADDRINUSE") {
|
|
28
|
+
listen(port + 1, host);
|
|
29
|
+
} else {
|
|
30
|
+
reject(error);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
server.listen(port, host);
|
|
34
|
+
};
|
|
35
|
+
listen(options.port || 4e3, options.host);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
LogLevel,
|
|
40
|
+
startServer
|
|
41
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sable",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.16",
|
|
4
4
|
"description": "Starts a server and a file watcher",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Kei Ito",
|
|
@@ -9,27 +9,39 @@
|
|
|
9
9
|
},
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"engines": {
|
|
12
|
-
"node": ">=
|
|
12
|
+
"node": ">=14"
|
|
13
13
|
},
|
|
14
14
|
"repository": "https://github.com/gjbkz/sable",
|
|
15
|
-
"
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "./esm/index.mjs",
|
|
16
17
|
"bin": {
|
|
17
|
-
"sable": "./
|
|
18
|
+
"sable": "./esm/cli.mjs"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./types/index.d.ts",
|
|
23
|
+
"import": "./esm/index.mjs",
|
|
24
|
+
"require": "./cjs/index.cjs"
|
|
25
|
+
}
|
|
18
26
|
},
|
|
19
27
|
"files": [
|
|
20
|
-
"
|
|
28
|
+
"esm",
|
|
29
|
+
"cjs",
|
|
30
|
+
"types"
|
|
21
31
|
],
|
|
22
32
|
"scripts": {
|
|
23
|
-
"lint": "
|
|
24
|
-
"build": "
|
|
25
|
-
"
|
|
33
|
+
"lint": "npx @biomejs/biome lint",
|
|
34
|
+
"build": "run-s build:*",
|
|
35
|
+
"build:typedef": "tsc --project tsconfig.typedef.json",
|
|
36
|
+
"build:code": "node build.ts",
|
|
37
|
+
"test": "node --test test/index.mjs",
|
|
26
38
|
"version": "run-s version:changelog version:add",
|
|
27
39
|
"version:changelog": "npx @nlib/changelog --output CHANGELOG.md",
|
|
28
40
|
"version:add": "git add ."
|
|
29
41
|
},
|
|
30
42
|
"dependencies": {
|
|
31
|
-
"commander": "
|
|
43
|
+
"commander": "14.0.1",
|
|
32
44
|
"connect": "3.7.0",
|
|
33
|
-
"middleware-static-livereload": "1.
|
|
45
|
+
"middleware-static-livereload": "1.4.3"
|
|
34
46
|
}
|
|
35
47
|
}
|
package/types/cli.d.ts
ADDED
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as http from "node:http";
|
|
2
|
+
import { type HandleFunction } from "connect";
|
|
3
|
+
import * as staticLivereload from "middleware-static-livereload";
|
|
4
|
+
export { LogLevel } from "middleware-static-livereload";
|
|
5
|
+
export interface SableOptions extends Partial<staticLivereload.MiddlewareOptions> {
|
|
6
|
+
port?: number;
|
|
7
|
+
host?: string;
|
|
8
|
+
middlewares?: Array<HandleFunction>;
|
|
9
|
+
}
|
|
10
|
+
export declare const startServer: (options?: SableOptions) => Promise<http.Server>;
|
package/bin/sable
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const console = require('console');
|
|
3
|
-
const {Command} = require('commander');
|
|
4
|
-
const {startServer} = require('..');
|
|
5
|
-
const packageJSON = require('../package.json');
|
|
6
|
-
|
|
7
|
-
const program = new Command()
|
|
8
|
-
.version(packageJSON.version)
|
|
9
|
-
.description('Starts a HTTP server for development')
|
|
10
|
-
.usage('[options] <documentRoot ...>')
|
|
11
|
-
.option('-p, --port <n>', 'A port number for HTTP, HTTPS (4000)', parseInt)
|
|
12
|
-
.option('-h, --host <s>', 'Hostname')
|
|
13
|
-
.option('--noWatch', 'Disable watching')
|
|
14
|
-
.option('-i, --index <s>', 'A filename of index (index.html)')
|
|
15
|
-
.parse(process.argv);
|
|
16
|
-
|
|
17
|
-
if (program.noWatch) {
|
|
18
|
-
program.watch = false;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
startServer({
|
|
22
|
-
...program.opts(),
|
|
23
|
-
documentRoot: 0 < program.args.length ? program.args : [process.cwd()],
|
|
24
|
-
})
|
|
25
|
-
.catch((error) => {
|
|
26
|
-
console.error(error);
|
|
27
|
-
process.exit(1);
|
|
28
|
-
});
|
package/lib/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as http from 'http';
|
|
2
|
-
import * as connect from 'connect';
|
|
3
|
-
import * as staticLivereload from 'middleware-static-livereload';
|
|
4
|
-
export { LogLevel } from 'middleware-static-livereload';
|
|
5
|
-
export interface SableOptions extends staticLivereload.Options {
|
|
6
|
-
port?: number;
|
|
7
|
-
host?: string;
|
|
8
|
-
middlewares?: Array<connect.HandleFunction>;
|
|
9
|
-
}
|
|
10
|
-
export declare const startServer: (options?: SableOptions) => Promise<http.Server>;
|
package/lib/index.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.startServer = exports.LogLevel = void 0;
|
|
4
|
-
const http = require("http");
|
|
5
|
-
const connect = require("connect");
|
|
6
|
-
const staticLivereload = require("middleware-static-livereload");
|
|
7
|
-
var middleware_static_livereload_1 = require("middleware-static-livereload");
|
|
8
|
-
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return middleware_static_livereload_1.LogLevel; } });
|
|
9
|
-
const startServer = async (options = {}) => {
|
|
10
|
-
const app = connect();
|
|
11
|
-
for (const middleware of (options.middlewares || [])) {
|
|
12
|
-
app.use(middleware);
|
|
13
|
-
}
|
|
14
|
-
app.use(staticLivereload.middleware(options));
|
|
15
|
-
const server = http.createServer(app);
|
|
16
|
-
return await new Promise((resolve, reject) => {
|
|
17
|
-
server.once('listening', () => {
|
|
18
|
-
const addressInfo = server.address();
|
|
19
|
-
if (addressInfo && typeof addressInfo === 'object') {
|
|
20
|
-
const { address, family, port } = addressInfo;
|
|
21
|
-
const portSuffix = port === 80 ? '' : `:${port}`;
|
|
22
|
-
const hostname = options.host || (portSuffix && family === 'IPv6' ? `[${address}]` : address);
|
|
23
|
-
process.stdout.write(`http://${hostname}${portSuffix}\n`);
|
|
24
|
-
}
|
|
25
|
-
resolve(server);
|
|
26
|
-
});
|
|
27
|
-
const listen = (port, host) => {
|
|
28
|
-
server.once('error', (error) => {
|
|
29
|
-
if (error.code === 'EADDRINUSE') {
|
|
30
|
-
listen(port + 1, host);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
reject(error);
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
server.listen(port, host);
|
|
37
|
-
};
|
|
38
|
-
listen(options.port || 4000, options.host);
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
exports.startServer = startServer;
|