@t8/serve 0.1.5 → 0.1.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/README.md +4 -1
- package/dist/index.js +6 -4
- package/dist/run.cjs +19 -6
- package/dist/run.mjs +19 -6
- package/package.json +1 -1
- package/src/Config.ts +1 -0
- package/src/getFilePath.ts +11 -5
- package/src/run.ts +15 -2
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
|
}
|
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
|
}
|
|
@@ -88,8 +90,18 @@ function serve(config = {}) {
|
|
|
88
90
|
// src/run.ts
|
|
89
91
|
var exec = (0, import_node_util.promisify)(import_node_child_process.exec);
|
|
90
92
|
async function run() {
|
|
91
|
-
let [url,
|
|
93
|
+
let [url, ...args] = process.argv.slice(2);
|
|
94
|
+
let spa = false;
|
|
95
|
+
if (args[0] === "*") {
|
|
96
|
+
spa = true;
|
|
97
|
+
args.shift();
|
|
98
|
+
}
|
|
92
99
|
let buildFlagIndex = args.indexOf("-b");
|
|
100
|
+
let path = args[0];
|
|
101
|
+
let dirs = args.slice(
|
|
102
|
+
1,
|
|
103
|
+
buildFlagIndex === -1 ? args.length : buildFlagIndex
|
|
104
|
+
);
|
|
93
105
|
if (buildFlagIndex !== -1) {
|
|
94
106
|
let inputFile = (0, import_node_path3.join)(path, args[buildFlagIndex + 1] ?? "index.ts");
|
|
95
107
|
let outputFile = (0, import_node_path3.join)(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
|
|
@@ -101,7 +113,8 @@ async function run() {
|
|
|
101
113
|
serve({
|
|
102
114
|
url,
|
|
103
115
|
path,
|
|
104
|
-
dirs
|
|
116
|
+
dirs,
|
|
117
|
+
spa
|
|
105
118
|
});
|
|
106
119
|
}
|
|
107
120
|
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
|
}
|
|
@@ -87,8 +89,18 @@ function serve(config = {}) {
|
|
|
87
89
|
// src/run.ts
|
|
88
90
|
var exec = promisify(originalExec);
|
|
89
91
|
async function run() {
|
|
90
|
-
let [url,
|
|
92
|
+
let [url, ...args] = process.argv.slice(2);
|
|
93
|
+
let spa = false;
|
|
94
|
+
if (args[0] === "*") {
|
|
95
|
+
spa = true;
|
|
96
|
+
args.shift();
|
|
97
|
+
}
|
|
91
98
|
let buildFlagIndex = args.indexOf("-b");
|
|
99
|
+
let path = args[0];
|
|
100
|
+
let dirs = args.slice(
|
|
101
|
+
1,
|
|
102
|
+
buildFlagIndex === -1 ? args.length : buildFlagIndex
|
|
103
|
+
);
|
|
92
104
|
if (buildFlagIndex !== -1) {
|
|
93
105
|
let inputFile = join2(path, args[buildFlagIndex + 1] ?? "index.ts");
|
|
94
106
|
let outputFile = join2(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
|
|
@@ -100,7 +112,8 @@ async function run() {
|
|
|
100
112
|
serve({
|
|
101
113
|
url,
|
|
102
114
|
path,
|
|
103
|
-
dirs
|
|
115
|
+
dirs,
|
|
116
|
+
spa
|
|
104
117
|
});
|
|
105
118
|
}
|
|
106
119
|
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,20 @@ 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
|
+
let spa = false;
|
|
13
|
+
|
|
14
|
+
if (args[0] === "*") {
|
|
15
|
+
spa = true;
|
|
16
|
+
args.shift();
|
|
17
|
+
}
|
|
18
|
+
|
|
12
19
|
let buildFlagIndex = args.indexOf("-b");
|
|
20
|
+
let path = args[0];
|
|
21
|
+
let dirs = args.slice(
|
|
22
|
+
1,
|
|
23
|
+
buildFlagIndex === -1 ? args.length : buildFlagIndex,
|
|
24
|
+
);
|
|
13
25
|
|
|
14
26
|
if (buildFlagIndex !== -1) {
|
|
15
27
|
let inputFile = join(path, args[buildFlagIndex + 1] ?? "index.ts");
|
|
@@ -24,7 +36,8 @@ async function run() {
|
|
|
24
36
|
serve({
|
|
25
37
|
url,
|
|
26
38
|
path,
|
|
27
|
-
dirs
|
|
39
|
+
dirs,
|
|
40
|
+
spa,
|
|
28
41
|
});
|
|
29
42
|
}
|
|
30
43
|
|