@t8/serve 0.1.4 → 0.1.6
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 +4 -1
- package/dist/index.js +10 -5
- package/dist/run.cjs +20 -7
- package/dist/run.mjs +20 -7
- package/package.json +1 -1
- package/src/Config.ts +1 -0
- package/src/getFilePath.ts +11 -5
- package/src/run.ts +12 -2
- package/src/serve.ts +6 -1
package/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
```sh
|
|
2
|
-
npx @t8/serve [url|port] [app_dir] [...assets_dirs] [-b [bundle_input_path] [bundle_output_path]]
|
|
2
|
+
npx @t8/serve [url|port] [*] [app_dir] [...assets_dirs] [-b [bundle_input_path] [bundle_output_path]]
|
|
3
|
+
# * = SPA mode: serve all paths as "/"
|
|
3
4
|
|
|
4
5
|
npx @t8/serve 3000 app
|
|
5
6
|
npx @t8/serve 3000 app -b
|
|
7
|
+
npx @t8/serve 3000 * app
|
|
8
|
+
npx @t8/serve 3000 * app -b
|
|
6
9
|
npx @t8/serve 3000 app public dist
|
|
7
10
|
npx @t8/serve 127.0.0.1:3000 app public dist
|
|
8
11
|
npx @t8/serve 3000 app public dist -b
|
package/dist/index.js
CHANGED
|
@@ -46,12 +46,14 @@ async function isValidFilePath(filePath, dirPath) {
|
|
|
46
46
|
|
|
47
47
|
// src/getFilePath.ts
|
|
48
48
|
var cwd = process.cwd();
|
|
49
|
-
async function getFilePath(urlPath = "", { path = "", dirs = [] }) {
|
|
49
|
+
async function getFilePath(urlPath = "", { path = "", dirs = [], spa }) {
|
|
50
|
+
let effectiveURLPath = spa ? "/" : urlPath.replace(/[?#].*$/, "");
|
|
50
51
|
for (let dir of dirs.length === 0 ? [""] : dirs) {
|
|
51
52
|
let dirPath = (0, import_node_path.join)(cwd, path, dir);
|
|
52
|
-
let filePath = (0, import_node_path.join)(dirPath,
|
|
53
|
-
if (await isValidFilePath(filePath, dirPath))
|
|
54
|
-
|
|
53
|
+
let filePath = (0, import_node_path.join)(dirPath, effectiveURLPath);
|
|
54
|
+
if (!effectiveURLPath.endsWith("/") && await isValidFilePath(filePath, dirPath))
|
|
55
|
+
return filePath;
|
|
56
|
+
filePath = (0, import_node_path.join)(dirPath, effectiveURLPath, "index.html");
|
|
55
57
|
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
56
58
|
}
|
|
57
59
|
}
|
|
@@ -95,7 +97,10 @@ function serve(config = {}) {
|
|
|
95
97
|
server.on("close", () => {
|
|
96
98
|
process.exit(0);
|
|
97
99
|
});
|
|
98
|
-
|
|
100
|
+
let serverPort = Number(port) || defaultPort;
|
|
101
|
+
let serverHost = host || defaultHost;
|
|
102
|
+
server.listen(serverPort, serverHost);
|
|
103
|
+
console.log(`Server running at http://${serverHost}:${serverPort}`);
|
|
99
104
|
return server;
|
|
100
105
|
}
|
|
101
106
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/run.cjs
CHANGED
|
@@ -29,12 +29,14 @@ async function isValidFilePath(filePath, dirPath) {
|
|
|
29
29
|
|
|
30
30
|
// src/getFilePath.ts
|
|
31
31
|
var cwd = process.cwd();
|
|
32
|
-
async function getFilePath(urlPath = "", { path = "", dirs = [] }) {
|
|
32
|
+
async function getFilePath(urlPath = "", { path = "", dirs = [], spa }) {
|
|
33
|
+
let effectiveURLPath = spa ? "/" : urlPath.replace(/[?#].*$/, "");
|
|
33
34
|
for (let dir of dirs.length === 0 ? [""] : dirs) {
|
|
34
35
|
let dirPath = (0, import_node_path.join)(cwd, path, dir);
|
|
35
|
-
let filePath = (0, import_node_path.join)(dirPath,
|
|
36
|
-
if (await isValidFilePath(filePath, dirPath))
|
|
37
|
-
|
|
36
|
+
let filePath = (0, import_node_path.join)(dirPath, effectiveURLPath);
|
|
37
|
+
if (!effectiveURLPath.endsWith("/") && await isValidFilePath(filePath, dirPath))
|
|
38
|
+
return filePath;
|
|
39
|
+
filePath = (0, import_node_path.join)(dirPath, effectiveURLPath, "index.html");
|
|
38
40
|
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
39
41
|
}
|
|
40
42
|
}
|
|
@@ -78,15 +80,25 @@ function serve(config = {}) {
|
|
|
78
80
|
server.on("close", () => {
|
|
79
81
|
process.exit(0);
|
|
80
82
|
});
|
|
81
|
-
|
|
83
|
+
let serverPort = Number(port) || defaultPort;
|
|
84
|
+
let serverHost = host || defaultHost;
|
|
85
|
+
server.listen(serverPort, serverHost);
|
|
86
|
+
console.log(`Server running at http://${serverHost}:${serverPort}`);
|
|
82
87
|
return server;
|
|
83
88
|
}
|
|
84
89
|
|
|
85
90
|
// src/run.ts
|
|
86
91
|
var exec = (0, import_node_util.promisify)(import_node_child_process.exec);
|
|
87
92
|
async function run() {
|
|
88
|
-
let [url,
|
|
93
|
+
let [url, ...args] = process.argv.slice(2);
|
|
89
94
|
let buildFlagIndex = args.indexOf("-b");
|
|
95
|
+
let spa = false;
|
|
96
|
+
if (args[0] === "*") {
|
|
97
|
+
spa = true;
|
|
98
|
+
args.shift();
|
|
99
|
+
}
|
|
100
|
+
let path = args[0];
|
|
101
|
+
let dirs = buildFlagIndex === -1 ? args : args.slice(0, buildFlagIndex);
|
|
90
102
|
if (buildFlagIndex !== -1) {
|
|
91
103
|
let inputFile = (0, import_node_path3.join)(path, args[buildFlagIndex + 1] ?? "index.ts");
|
|
92
104
|
let outputFile = (0, import_node_path3.join)(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
|
|
@@ -98,7 +110,8 @@ async function run() {
|
|
|
98
110
|
serve({
|
|
99
111
|
url,
|
|
100
112
|
path,
|
|
101
|
-
dirs
|
|
113
|
+
dirs,
|
|
114
|
+
spa
|
|
102
115
|
});
|
|
103
116
|
}
|
|
104
117
|
run();
|
package/dist/run.mjs
CHANGED
|
@@ -28,12 +28,14 @@ async function isValidFilePath(filePath, dirPath) {
|
|
|
28
28
|
|
|
29
29
|
// src/getFilePath.ts
|
|
30
30
|
var cwd = process.cwd();
|
|
31
|
-
async function getFilePath(urlPath = "", { path = "", dirs = [] }) {
|
|
31
|
+
async function getFilePath(urlPath = "", { path = "", dirs = [], spa }) {
|
|
32
|
+
let effectiveURLPath = spa ? "/" : urlPath.replace(/[?#].*$/, "");
|
|
32
33
|
for (let dir of dirs.length === 0 ? [""] : dirs) {
|
|
33
34
|
let dirPath = join(cwd, path, dir);
|
|
34
|
-
let filePath = join(dirPath,
|
|
35
|
-
if (await isValidFilePath(filePath, dirPath))
|
|
36
|
-
|
|
35
|
+
let filePath = join(dirPath, effectiveURLPath);
|
|
36
|
+
if (!effectiveURLPath.endsWith("/") && await isValidFilePath(filePath, dirPath))
|
|
37
|
+
return filePath;
|
|
38
|
+
filePath = join(dirPath, effectiveURLPath, "index.html");
|
|
37
39
|
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
38
40
|
}
|
|
39
41
|
}
|
|
@@ -77,15 +79,25 @@ function serve(config = {}) {
|
|
|
77
79
|
server.on("close", () => {
|
|
78
80
|
process.exit(0);
|
|
79
81
|
});
|
|
80
|
-
|
|
82
|
+
let serverPort = Number(port) || defaultPort;
|
|
83
|
+
let serverHost = host || defaultHost;
|
|
84
|
+
server.listen(serverPort, serverHost);
|
|
85
|
+
console.log(`Server running at http://${serverHost}:${serverPort}`);
|
|
81
86
|
return server;
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
// src/run.ts
|
|
85
90
|
var exec = promisify(originalExec);
|
|
86
91
|
async function run() {
|
|
87
|
-
let [url,
|
|
92
|
+
let [url, ...args] = process.argv.slice(2);
|
|
88
93
|
let buildFlagIndex = args.indexOf("-b");
|
|
94
|
+
let spa = false;
|
|
95
|
+
if (args[0] === "*") {
|
|
96
|
+
spa = true;
|
|
97
|
+
args.shift();
|
|
98
|
+
}
|
|
99
|
+
let path = args[0];
|
|
100
|
+
let dirs = buildFlagIndex === -1 ? args : args.slice(0, buildFlagIndex);
|
|
89
101
|
if (buildFlagIndex !== -1) {
|
|
90
102
|
let inputFile = join2(path, args[buildFlagIndex + 1] ?? "index.ts");
|
|
91
103
|
let outputFile = join2(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
|
|
@@ -97,7 +109,8 @@ async function run() {
|
|
|
97
109
|
serve({
|
|
98
110
|
url,
|
|
99
111
|
path,
|
|
100
|
-
dirs
|
|
112
|
+
dirs,
|
|
113
|
+
spa
|
|
101
114
|
});
|
|
102
115
|
}
|
|
103
116
|
run();
|
package/package.json
CHANGED
package/src/Config.ts
CHANGED
package/src/getFilePath.ts
CHANGED
|
@@ -5,16 +5,22 @@ import { isValidFilePath } from "./isValidFilePath";
|
|
|
5
5
|
const cwd = process.cwd();
|
|
6
6
|
|
|
7
7
|
export async function getFilePath(
|
|
8
|
-
urlPath
|
|
9
|
-
{ path = "", dirs = [] }: Config,
|
|
8
|
+
urlPath = "",
|
|
9
|
+
{ path = "", dirs = [], spa }: Config,
|
|
10
10
|
) {
|
|
11
|
+
let effectiveURLPath = spa ? "/" : urlPath.replace(/[?#].*$/, "");
|
|
12
|
+
|
|
11
13
|
for (let dir of dirs.length === 0 ? [""] : dirs) {
|
|
12
14
|
let dirPath = join(cwd, path, dir);
|
|
13
|
-
let filePath = join(dirPath,
|
|
15
|
+
let filePath = join(dirPath, effectiveURLPath);
|
|
14
16
|
|
|
15
|
-
if (
|
|
17
|
+
if (
|
|
18
|
+
!effectiveURLPath.endsWith("/") &&
|
|
19
|
+
(await isValidFilePath(filePath, dirPath))
|
|
20
|
+
)
|
|
21
|
+
return filePath;
|
|
16
22
|
|
|
17
|
-
filePath = join(dirPath,
|
|
23
|
+
filePath = join(dirPath, effectiveURLPath, "index.html");
|
|
18
24
|
|
|
19
25
|
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
20
26
|
}
|
package/src/run.ts
CHANGED
|
@@ -8,8 +8,17 @@ import { serve } from "./serve";
|
|
|
8
8
|
const exec = promisify(originalExec);
|
|
9
9
|
|
|
10
10
|
async function run() {
|
|
11
|
-
let [url,
|
|
11
|
+
let [url, ...args] = process.argv.slice(2);
|
|
12
12
|
let buildFlagIndex = args.indexOf("-b");
|
|
13
|
+
let spa = false;
|
|
14
|
+
|
|
15
|
+
if (args[0] === "*") {
|
|
16
|
+
spa = true;
|
|
17
|
+
args.shift();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let path = args[0];
|
|
21
|
+
let dirs = buildFlagIndex === -1 ? args : args.slice(0, buildFlagIndex);
|
|
13
22
|
|
|
14
23
|
if (buildFlagIndex !== -1) {
|
|
15
24
|
let inputFile = join(path, args[buildFlagIndex + 1] ?? "index.ts");
|
|
@@ -24,7 +33,8 @@ async function run() {
|
|
|
24
33
|
serve({
|
|
25
34
|
url,
|
|
26
35
|
path,
|
|
27
|
-
dirs
|
|
36
|
+
dirs,
|
|
37
|
+
spa,
|
|
28
38
|
});
|
|
29
39
|
}
|
|
30
40
|
|
package/src/serve.ts
CHANGED
|
@@ -37,7 +37,12 @@ export function serve(config: Config = {}) {
|
|
|
37
37
|
process.exit(0);
|
|
38
38
|
});
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
let serverPort = Number(port) || defaultPort;
|
|
41
|
+
let serverHost = host || defaultHost;
|
|
42
|
+
|
|
43
|
+
server.listen(serverPort, serverHost);
|
|
44
|
+
|
|
45
|
+
console.log(`Server running at http://${serverHost}:${serverPort}`);
|
|
41
46
|
|
|
42
47
|
return server;
|
|
43
48
|
}
|