sable 0.5.14 → 0.5.15
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/cli.d.ts +2 -0
- package/lib/cli.js +46 -0
- package/lib/index.d.ts +6 -6
- package/lib/index.js +9 -9
- package/package.json +12 -9
- package/bin/sable +0 -28
package/lib/cli.d.ts
ADDED
package/lib/cli.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const commander_1 = require("commander");
|
|
5
|
+
const middleware_static_livereload_1 = require("middleware-static-livereload");
|
|
6
|
+
const index_1 = require("./index");
|
|
7
|
+
const { version } = require("../package.json");
|
|
8
|
+
const program = new commander_1.Command()
|
|
9
|
+
.version(version)
|
|
10
|
+
.description("Starts a HTTP server for development")
|
|
11
|
+
.usage("[options] <documentRoot ...>")
|
|
12
|
+
.option("-p, --port <n>", "A port number for HTTP, HTTPS (4000)", Number.parseInt)
|
|
13
|
+
.option("-h, --host <s>", "Hostname")
|
|
14
|
+
.option("-v, --verbose", "Enable verbose logging")
|
|
15
|
+
.option("--noWatch", "Disable watching")
|
|
16
|
+
.option("-i, --index <s>", "A filename of index (index.html)")
|
|
17
|
+
.action(async ({ noWatch, port, host, verbose = false, index, }, { args: documentRoot }) => {
|
|
18
|
+
if (documentRoot.length === 0) {
|
|
19
|
+
documentRoot.push(process.cwd());
|
|
20
|
+
}
|
|
21
|
+
const options = {
|
|
22
|
+
watch: !noWatch,
|
|
23
|
+
documentRoot,
|
|
24
|
+
logLevel: verbose ? middleware_static_livereload_1.LogLevel.debug : middleware_static_livereload_1.LogLevel.info,
|
|
25
|
+
};
|
|
26
|
+
if (Array.isArray(port)) {
|
|
27
|
+
options.port = port[0];
|
|
28
|
+
}
|
|
29
|
+
else if (port) {
|
|
30
|
+
options.port = port;
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(host)) {
|
|
33
|
+
options.host = host[0];
|
|
34
|
+
}
|
|
35
|
+
else if (host) {
|
|
36
|
+
options.host = host;
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(index)) {
|
|
39
|
+
options.index = index[0];
|
|
40
|
+
}
|
|
41
|
+
else if (index) {
|
|
42
|
+
options.index = index;
|
|
43
|
+
}
|
|
44
|
+
await (0, index_1.startServer)(options);
|
|
45
|
+
});
|
|
46
|
+
program.parse();
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import * as http from
|
|
2
|
-
import * as
|
|
3
|
-
import * as staticLivereload from
|
|
4
|
-
export { LogLevel } from
|
|
5
|
-
export interface SableOptions extends staticLivereload.
|
|
1
|
+
import * as http from "http";
|
|
2
|
+
import type * as Connect 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
6
|
port?: number;
|
|
7
7
|
host?: string;
|
|
8
|
-
middlewares?: Array<
|
|
8
|
+
middlewares?: Array<Connect.HandleFunction>;
|
|
9
9
|
}
|
|
10
10
|
export declare const startServer: (options?: SableOptions) => Promise<http.Server>;
|
package/lib/index.js
CHANGED
|
@@ -2,31 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.startServer = exports.LogLevel = void 0;
|
|
4
4
|
const http = require("http");
|
|
5
|
-
const connect = require("connect");
|
|
6
5
|
const staticLivereload = require("middleware-static-livereload");
|
|
7
6
|
var middleware_static_livereload_1 = require("middleware-static-livereload");
|
|
8
7
|
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return middleware_static_livereload_1.LogLevel; } });
|
|
9
8
|
const startServer = async (options = {}) => {
|
|
10
|
-
const app = connect();
|
|
11
|
-
for (const middleware of
|
|
9
|
+
const app = require("connect")();
|
|
10
|
+
for (const middleware of options.middlewares || []) {
|
|
12
11
|
app.use(middleware);
|
|
13
12
|
}
|
|
14
13
|
app.use(staticLivereload.middleware(options));
|
|
15
14
|
const server = http.createServer(app);
|
|
16
15
|
return await new Promise((resolve, reject) => {
|
|
17
|
-
server.once(
|
|
16
|
+
server.once("listening", () => {
|
|
18
17
|
const addressInfo = server.address();
|
|
19
|
-
if (addressInfo && typeof addressInfo ===
|
|
18
|
+
if (addressInfo && typeof addressInfo === "object") {
|
|
20
19
|
const { address, family, port } = addressInfo;
|
|
21
|
-
const portSuffix = port === 80 ?
|
|
22
|
-
const hostname = options.host ||
|
|
20
|
+
const portSuffix = port === 80 ? "" : `:${port}`;
|
|
21
|
+
const hostname = options.host ||
|
|
22
|
+
(portSuffix && family === "IPv6" ? `[${address}]` : address);
|
|
23
23
|
process.stdout.write(`http://${hostname}${portSuffix}\n`);
|
|
24
24
|
}
|
|
25
25
|
resolve(server);
|
|
26
26
|
});
|
|
27
27
|
const listen = (port, host) => {
|
|
28
|
-
server.once(
|
|
29
|
-
if (error.code ===
|
|
28
|
+
server.once("error", (error) => {
|
|
29
|
+
if (error.code === "EADDRINUSE") {
|
|
30
30
|
listen(port + 1, host);
|
|
31
31
|
}
|
|
32
32
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sable",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.15",
|
|
4
4
|
"description": "Starts a server and a file watcher",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Kei Ito",
|
|
@@ -9,27 +9,30 @@
|
|
|
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
|
+
"type": "commonjs",
|
|
15
16
|
"main": "./lib/index.js",
|
|
16
17
|
"bin": {
|
|
17
|
-
"sable": "./
|
|
18
|
+
"sable": "./lib/cli.js"
|
|
18
19
|
},
|
|
19
20
|
"files": [
|
|
20
21
|
"lib"
|
|
21
22
|
],
|
|
22
23
|
"scripts": {
|
|
23
|
-
"lint": "
|
|
24
|
-
"build": "
|
|
25
|
-
"
|
|
24
|
+
"lint": "npx @biomejs/biome lint",
|
|
25
|
+
"build": "run-s build:*",
|
|
26
|
+
"build:tsc": "tsc",
|
|
27
|
+
"build:chmod": "chmod +x lib/cli.js",
|
|
28
|
+
"test": "node --test test/index.mjs",
|
|
26
29
|
"version": "run-s version:changelog version:add",
|
|
27
|
-
"version:changelog": "
|
|
30
|
+
"version:changelog": "nlib-changelog --output CHANGELOG.md",
|
|
28
31
|
"version:add": "git add ."
|
|
29
32
|
},
|
|
30
33
|
"dependencies": {
|
|
31
|
-
"commander": "
|
|
34
|
+
"commander": "12.1.0",
|
|
32
35
|
"connect": "3.7.0",
|
|
33
|
-
"middleware-static-livereload": "1.
|
|
36
|
+
"middleware-static-livereload": "1.3.0"
|
|
34
37
|
}
|
|
35
38
|
}
|
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
|
-
});
|