sable 0.5.9 → 0.5.13
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 → README.md} +1 -3
- package/bin/sable +6 -3
- package/lib/index.d.ts +2 -2
- package/lib/index.js +8 -9
- package/package.json +12 -76
- package/CHANGELOG.md +0 -249
- package/src/index.ts +0 -60
package/{readme.md → README.md}
RENAMED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# Sable
|
|
2
2
|
|
|
3
|
-
[](https://travis-ci.com/kei-ito/sable)
|
|
5
|
-
[](https://ci.appveyor.com/project/kei-ito/sable/branch/master)
|
|
3
|
+
[](https://github.com/kei-ito/sable/actions/workflows/test.yml)
|
|
6
4
|
[](https://codecov.io/gh/kei-ito/sable)
|
|
7
5
|
|
|
8
6
|
Starts a server for development.
|
package/bin/sable
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const console = require('console');
|
|
3
|
-
const
|
|
3
|
+
const {Command} = require('commander');
|
|
4
4
|
const {startServer} = require('..');
|
|
5
5
|
const packageJSON = require('../package.json');
|
|
6
6
|
|
|
7
|
-
program
|
|
7
|
+
const program = new Command()
|
|
8
8
|
.version(packageJSON.version)
|
|
9
9
|
.description('Starts a HTTP server for development')
|
|
10
10
|
.usage('[options] <documentRoot ...>')
|
|
@@ -18,7 +18,10 @@ if (program.noWatch) {
|
|
|
18
18
|
program.watch = false;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
startServer(
|
|
21
|
+
startServer({
|
|
22
|
+
...program.opts(),
|
|
23
|
+
documentRoot: 0 < program.args.length ? program.args : [process.cwd()],
|
|
24
|
+
})
|
|
22
25
|
.catch((error) => {
|
|
23
26
|
console.error(error);
|
|
24
27
|
process.exit(1);
|
package/lib/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ import * as http from 'http';
|
|
|
2
2
|
import * as connect from 'connect';
|
|
3
3
|
import * as staticLivereload from 'middleware-static-livereload';
|
|
4
4
|
export { LogLevel } from 'middleware-static-livereload';
|
|
5
|
-
export interface
|
|
5
|
+
export interface SableOptions extends staticLivereload.Options {
|
|
6
6
|
port?: number;
|
|
7
7
|
host?: string;
|
|
8
8
|
middlewares?: Array<connect.HandleFunction>;
|
|
9
9
|
}
|
|
10
|
-
export declare const startServer: (options?:
|
|
10
|
+
export declare const startServer: (options?: SableOptions) => Promise<http.Server>;
|
package/lib/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.startServer = void 0;
|
|
3
|
+
exports.startServer = exports.LogLevel = void 0;
|
|
4
4
|
const http = require("http");
|
|
5
5
|
const connect = require("connect");
|
|
6
6
|
const staticLivereload = require("middleware-static-livereload");
|
|
7
7
|
var middleware_static_livereload_1 = require("middleware-static-livereload");
|
|
8
8
|
Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return middleware_static_livereload_1.LogLevel; } });
|
|
9
|
-
|
|
9
|
+
const startServer = async (options = {}) => {
|
|
10
10
|
const app = connect();
|
|
11
11
|
for (const middleware of (options.middlewares || [])) {
|
|
12
12
|
app.use(middleware);
|
|
13
13
|
}
|
|
14
14
|
app.use(staticLivereload.middleware(options));
|
|
15
15
|
const server = http.createServer(app);
|
|
16
|
-
await new Promise((resolve, reject) => {
|
|
16
|
+
return await new Promise((resolve, reject) => {
|
|
17
17
|
server.once('listening', () => {
|
|
18
18
|
const addressInfo = server.address();
|
|
19
19
|
if (addressInfo && typeof addressInfo === 'object') {
|
|
@@ -25,18 +25,17 @@ exports.startServer = async (options = {}) => {
|
|
|
25
25
|
resolve(server);
|
|
26
26
|
});
|
|
27
27
|
const listen = (port, host) => {
|
|
28
|
-
server
|
|
29
|
-
.once('error', (error) => {
|
|
28
|
+
server.once('error', (error) => {
|
|
30
29
|
if (error.code === 'EADDRINUSE') {
|
|
31
30
|
listen(port + 1, host);
|
|
32
31
|
}
|
|
33
32
|
else {
|
|
34
33
|
reject(error);
|
|
35
34
|
}
|
|
36
|
-
})
|
|
37
|
-
|
|
35
|
+
});
|
|
36
|
+
server.listen(port, host);
|
|
38
37
|
};
|
|
39
38
|
listen(options.port || 4000, options.host);
|
|
40
39
|
});
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
};
|
|
41
|
+
exports.startServer = startServer;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sable",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.13",
|
|
4
4
|
"description": "Starts a server and a file watcher",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Kei Ito",
|
|
@@ -9,91 +9,27 @@
|
|
|
9
9
|
},
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"engines": {
|
|
12
|
-
"node": ">=
|
|
12
|
+
"node": ">=12"
|
|
13
13
|
},
|
|
14
14
|
"repository": "kei-ito/sable",
|
|
15
15
|
"main": "./lib/index.js",
|
|
16
16
|
"bin": {
|
|
17
17
|
"sable": "./bin/sable"
|
|
18
18
|
},
|
|
19
|
+
"files": [
|
|
20
|
+
"lib"
|
|
21
|
+
],
|
|
19
22
|
"scripts": {
|
|
20
23
|
"lint": "eslint --ext .ts src",
|
|
21
|
-
"build": "tsc",
|
|
22
|
-
"test": "ava
|
|
23
|
-
"version:changelog": "conventional-changelog --preset angular --infile CHANGELOG.md --same-file --release-count 0",
|
|
24
|
-
"version:add": "git add .",
|
|
24
|
+
"build": "tsc --project tsconfig.build.json",
|
|
25
|
+
"test": "ava",
|
|
25
26
|
"version": "run-s version:changelog version:add",
|
|
26
|
-
"
|
|
27
|
+
"version:changelog": "npx @nlib/changelog --output CHANGELOG.md",
|
|
28
|
+
"version:add": "git add ."
|
|
27
29
|
},
|
|
28
30
|
"dependencies": {
|
|
29
|
-
"
|
|
30
|
-
"commander": "^5.0.0",
|
|
31
|
+
"commander": "8.3.0",
|
|
31
32
|
"connect": "3.7.0",
|
|
32
|
-
"middleware-static-livereload": "
|
|
33
|
-
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"@commitlint/cli": "^9.0.1",
|
|
36
|
-
"@commitlint/config-conventional": "9.0.1",
|
|
37
|
-
"@nlib/lint": "^3.17.2",
|
|
38
|
-
"@nlib/remove-sourcemap": "^3.17.2",
|
|
39
|
-
"@types/node": "^14.0.14",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "^3.4.0",
|
|
41
|
-
"@typescript-eslint/parser": "^3.4.0",
|
|
42
|
-
"ava": "3.9.0",
|
|
43
|
-
"chokidar": "^3.4.0",
|
|
44
|
-
"conventional-changelog-cli": "^2.0.34",
|
|
45
|
-
"eslint": "7.3.1",
|
|
46
|
-
"husky": "^4.2.5",
|
|
47
|
-
"lint-staged": "^10.2.11",
|
|
48
|
-
"npm-run-all": "4.1.5",
|
|
49
|
-
"ts-node": "^8.10.2",
|
|
50
|
-
"typescript": "^3.9.5"
|
|
51
|
-
},
|
|
52
|
-
"eslintConfig": {
|
|
53
|
-
"extends": "./node_modules/@nlib/lint/.eslintrc.json",
|
|
54
|
-
"env": {
|
|
55
|
-
"es6": true,
|
|
56
|
-
"node": true
|
|
57
|
-
},
|
|
58
|
-
"globals": {
|
|
59
|
-
"URL": false
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
"ava": {
|
|
63
|
-
"extensions": [
|
|
64
|
-
"ts",
|
|
65
|
-
"js"
|
|
66
|
-
],
|
|
67
|
-
"require": [
|
|
68
|
-
"ts-node/register"
|
|
69
|
-
]
|
|
70
|
-
},
|
|
71
|
-
"commitlint": {
|
|
72
|
-
"extends": [
|
|
73
|
-
"@commitlint/config-conventional"
|
|
74
|
-
]
|
|
75
|
-
},
|
|
76
|
-
"husky": {
|
|
77
|
-
"hooks": {
|
|
78
|
-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
79
|
-
"pre-commit": "lint-staged"
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
"lint-staged": {
|
|
83
|
-
"*.js": [
|
|
84
|
-
"eslint"
|
|
85
|
-
]
|
|
86
|
-
},
|
|
87
|
-
"renovate": {
|
|
88
|
-
"extends": [
|
|
89
|
-
":ignoreModulesAndTests",
|
|
90
|
-
":unpublishSafe",
|
|
91
|
-
":semanticPrefixChore",
|
|
92
|
-
":prNotPending",
|
|
93
|
-
":prConcurrentLimit10",
|
|
94
|
-
":prHourlyLimitNone",
|
|
95
|
-
":label(dependencies)",
|
|
96
|
-
":automergeMinor"
|
|
97
|
-
]
|
|
33
|
+
"middleware-static-livereload": "1.2.21"
|
|
98
34
|
}
|
|
99
|
-
}
|
|
35
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
## [0.5.9](https://github.com/kei-ito/sable/compare/v0.5.8...v0.5.9) (2020-06-26)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## [0.5.8](https://github.com/kei-ito/sable/compare/v0.5.7...v0.5.8) (2020-06-22)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## [0.5.7](https://github.com/kei-ito/sable/compare/v0.5.6...v0.5.7) (2019-12-09)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
## [0.5.6](https://github.com/kei-ito/sable/compare/v0.5.5...v0.5.6) (2019-12-09)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
## [0.5.5](https://github.com/kei-ito/sable/compare/v0.5.4...v0.5.5) (2019-12-08)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
## [0.5.4](https://github.com/kei-ito/sable/compare/v0.5.3...v0.5.4) (2019-11-15)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
## [0.5.3](https://github.com/kei-ito/sable/compare/v0.5.2...v0.5.3) (2019-08-23)
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
## [0.5.2](https://github.com/kei-ito/sable/compare/v0.5.1...v0.5.2) (2019-06-27)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
### Features
|
|
33
|
-
|
|
34
|
-
* add middlewares ([30874fb](https://github.com/kei-ito/sable/commit/30874fbb0479e536775bc79acaf74fcc8b476196))
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
## [0.5.1](https://github.com/kei-ito/sable/compare/v0.5.0...v0.5.1) (2019-06-27)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### Features
|
|
42
|
-
|
|
43
|
-
* support all options ([8a6abf7](https://github.com/kei-ito/sable/commit/8a6abf7c7ea7dc6f1be458a0914ebe600a83c5b1))
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
# [0.5.0](https://github.com/kei-ito/sable/compare/v0.4.6...v0.5.0) (2019-06-11)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
### Features
|
|
51
|
-
|
|
52
|
-
* use connect ([#42](https://github.com/kei-ito/sable/issues/42)) ([95c2e9a](https://github.com/kei-ito/sable/commit/95c2e9a3b81cc487dce3d8cc7d612d1958742819))
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
## [0.4.6](https://github.com/kei-ito/sable/compare/v0.4.5...v0.4.6) (2018-11-28)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
## [0.4.5](https://github.com/kei-ito/sable/compare/v0.4.4...v0.4.5) (2018-10-19)
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
## [0.4.4](https://github.com/kei-ito/sable/compare/v0.4.3...v0.4.4) (2018-10-18)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
## [0.4.3](https://github.com/kei-ito/sable/compare/v0.4.2...v0.4.3) (2018-08-22)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
## [0.4.2](https://github.com/kei-ito/sable/compare/v0.4.1...v0.4.2) (2018-08-22)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
## [0.4.1](https://github.com/kei-ito/sable/compare/v0.4.0...v0.4.1) (2018-08-16)
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
# [0.4.0](https://github.com/kei-ito/sable/compare/v0.3.1...v0.4.0) (2018-08-09)
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
### Bug Fixes
|
|
84
|
-
|
|
85
|
-
* **package:** update ws to version 6.0.0 ([43f23d3](https://github.com/kei-ito/sable/commit/43f23d3b8d7b147005aa6eb42fbd42fb81e3ac74))
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
## [0.3.1](https://github.com/kei-ito/sable/compare/v0.3.0...v0.3.1) (2018-07-18)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
# [0.3.0](https://github.com/kei-ito/sable/compare/v0.2.15...v0.3.0) (2018-07-18)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
## [0.2.15](https://github.com/kei-ito/sable/compare/v0.2.14...v0.2.15) (2018-04-03)
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
## [0.2.14](https://github.com/kei-ito/sable/compare/v0.2.13...v0.2.14) (2018-03-15)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
## [0.2.13](https://github.com/kei-ito/sable/compare/v0.2.12...v0.2.13) (2018-01-22)
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
## [0.2.12](https://github.com/kei-ito/sable/compare/v0.2.11...v0.2.12) (2018-01-22)
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
## [0.2.11](https://github.com/kei-ito/sable/compare/v0.2.10...v0.2.11) (2018-01-09)
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
## [0.2.10](https://github.com/kei-ito/sable/compare/v0.2.9...v0.2.10) (2017-12-27)
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
## [0.2.9](https://github.com/kei-ito/sable/compare/v0.2.8...v0.2.9) (2017-12-22)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
## [0.2.8](https://github.com/kei-ito/sable/compare/v0.2.7...v0.2.8) (2017-12-22)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
## [0.2.7](https://github.com/kei-ito/sable/compare/v0.2.6...v0.2.7) (2017-12-22)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
## [0.2.6](https://github.com/kei-ito/sable/compare/v0.2.5...v0.2.6) (2017-12-22)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
## [0.2.5](https://github.com/kei-ito/sable/compare/v0.2.4...v0.2.5) (2017-12-22)
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
## [0.2.4](https://github.com/kei-ito/sable/compare/v0.2.3...v0.2.4) (2017-12-21)
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
## [0.2.3](https://github.com/kei-ito/sable/compare/v0.2.2...v0.2.3) (2017-12-12)
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
## [0.2.2](https://github.com/kei-ito/sable/compare/v0.2.1...v0.2.2) (2017-12-07)
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
## [0.2.1](https://github.com/kei-ito/sable/compare/v0.2.0...v0.2.1) (2017-12-07)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
# [0.2.0](https://github.com/kei-ito/sable/compare/v0.1.7...v0.2.0) (2017-12-06)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
### Reverts
|
|
161
|
-
|
|
162
|
-
* Revert "0.2.0" ([b42bc83](https://github.com/kei-ito/sable/commit/b42bc8356762131a8050b05e844fccfc168e2274))
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
## [0.1.7](https://github.com/kei-ito/sable/compare/v0.1.6...v0.1.7) (2017-07-28)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
## [0.1.6](https://github.com/kei-ito/sable/compare/v0.1.5...v0.1.6) (2017-06-30)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
## [0.1.5](https://github.com/kei-ito/sable/compare/v0.1.4...v0.1.5) (2017-06-30)
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
## [0.1.4](https://github.com/kei-ito/sable/compare/v0.1.3...v0.1.4) (2017-06-30)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
## [0.1.3](https://github.com/kei-ito/sable/compare/v0.1.2...v0.1.3) (2017-06-15)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
## [0.1.2](https://github.com/kei-ito/sable/compare/v0.1.1...v0.1.2) (2017-05-24)
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
## [0.1.1](https://github.com/kei-ito/sable/compare/v0.1.0...v0.1.1) (2017-05-24)
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
# [0.1.0](https://github.com/kei-ito/sable/compare/v0.0.21...v0.1.0) (2017-05-06)
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
## [0.0.21](https://github.com/kei-ito/sable/compare/v0.0.20...v0.0.21) (2017-04-12)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
## [0.0.20](https://github.com/kei-ito/sable/compare/v0.0.19...v0.0.20) (2017-03-30)
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
## [0.0.19](https://github.com/kei-ito/sable/compare/v0.0.18...v0.0.19) (2017-03-27)
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
## [0.0.18](https://github.com/kei-ito/sable/compare/v0.0.17...v0.0.18) (2017-03-27)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
## [0.0.17](https://github.com/kei-ito/sable/compare/v0.0.16...v0.0.17) (2017-03-23)
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
## [0.0.16](https://github.com/kei-ito/sable/compare/v0.0.15...v0.0.16) (2017-03-23)
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
## [0.0.15](https://github.com/kei-ito/sable/compare/v0.0.14...v0.0.15) (2017-03-23)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
## [0.0.14](https://github.com/kei-ito/sable/compare/v0.0.13...v0.0.14) (2017-03-23)
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
## [0.0.13](https://github.com/kei-ito/sable/compare/v0.0.12...v0.0.13) (2017-03-23)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
## [0.0.12](https://github.com/kei-ito/sable/compare/v0.0.11...v0.0.12) (2017-03-22)
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
## [0.0.11](https://github.com/kei-ito/sable/compare/v0.0.10...v0.0.11) (2017-03-16)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
## [0.0.10](https://github.com/kei-ito/sable/compare/v0.0.9...v0.0.10) (2017-03-15)
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
## 0.0.9 (2017-03-15)
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
package/src/index.ts
DELETED
|
@@ -1,60 +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
|
-
|
|
6
|
-
export interface ISableOptions extends staticLivereload.IOptions {
|
|
7
|
-
/**
|
|
8
|
-
* The first argument of server.listen()
|
|
9
|
-
* https://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback
|
|
10
|
-
* @default 4000
|
|
11
|
-
*/
|
|
12
|
-
port?: number,
|
|
13
|
-
/**
|
|
14
|
-
* The second argument of server.listen()
|
|
15
|
-
* https://nodejs.org/api/net.html#net_server_listen_port_host_backlog_callback
|
|
16
|
-
* @default undefined
|
|
17
|
-
*/
|
|
18
|
-
host?: string,
|
|
19
|
-
/**
|
|
20
|
-
* A list of middlewares.
|
|
21
|
-
* @default []
|
|
22
|
-
*/
|
|
23
|
-
middlewares?: Array<connect.HandleFunction>,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const startServer = async (
|
|
27
|
-
options: ISableOptions = {},
|
|
28
|
-
): Promise<http.Server> => {
|
|
29
|
-
const app = connect();
|
|
30
|
-
for (const middleware of (options.middlewares || [])) {
|
|
31
|
-
app.use(middleware);
|
|
32
|
-
}
|
|
33
|
-
app.use(staticLivereload.middleware(options));
|
|
34
|
-
const server = http.createServer(app);
|
|
35
|
-
await new Promise<http.Server>((resolve, reject) => {
|
|
36
|
-
server.once('listening', () => {
|
|
37
|
-
const addressInfo = server.address();
|
|
38
|
-
if (addressInfo && typeof addressInfo === 'object') {
|
|
39
|
-
const {address, family, port} = addressInfo;
|
|
40
|
-
const portSuffix = port === 80 ? '' : `:${port}`;
|
|
41
|
-
const hostname = options.host || (portSuffix && family === 'IPv6' ? `[${address}]` : address);
|
|
42
|
-
process.stdout.write(`http://${hostname}${portSuffix}\n`);
|
|
43
|
-
}
|
|
44
|
-
resolve(server);
|
|
45
|
-
});
|
|
46
|
-
const listen = (port: number, host?: string) => {
|
|
47
|
-
server
|
|
48
|
-
.once('error', (error: Error & {code: string}) => {
|
|
49
|
-
if (error.code === 'EADDRINUSE') {
|
|
50
|
-
listen(port + 1, host);
|
|
51
|
-
} else {
|
|
52
|
-
reject(error);
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
.listen(port, host);
|
|
56
|
-
};
|
|
57
|
-
listen(options.port || 4000, options.host);
|
|
58
|
-
});
|
|
59
|
-
return server;
|
|
60
|
-
};
|