@t8/serve 0.1.6 → 0.1.8
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/dist/index.js +5 -5
- package/dist/run.cjs +10 -7
- package/dist/run.mjs +10 -7
- package/package.json +1 -1
- package/src/getFilePath.ts +5 -8
- package/src/run.ts +5 -2
package/dist/index.js
CHANGED
|
@@ -46,14 +46,14 @@ async function isValidFilePath(filePath, dirPath) {
|
|
|
46
46
|
|
|
47
47
|
// src/getFilePath.ts
|
|
48
48
|
var cwd = process.cwd();
|
|
49
|
-
async function getFilePath(
|
|
50
|
-
let
|
|
49
|
+
async function getFilePath(url = "", { path = "", dirs = [], spa }) {
|
|
50
|
+
let urlPath = url.replace(/[?#].*$/, "");
|
|
51
51
|
for (let dir of dirs.length === 0 ? [""] : dirs) {
|
|
52
52
|
let dirPath = (0, import_node_path.join)(cwd, path, dir);
|
|
53
|
-
let filePath = (0, import_node_path.join)(dirPath,
|
|
54
|
-
if (!
|
|
53
|
+
let filePath = (0, import_node_path.join)(dirPath, urlPath);
|
|
54
|
+
if (!urlPath.endsWith("/") && await isValidFilePath(filePath, dirPath))
|
|
55
55
|
return filePath;
|
|
56
|
-
filePath = (0, import_node_path.join)(dirPath,
|
|
56
|
+
filePath = (0, import_node_path.join)(dirPath, spa ? "" : urlPath, "index.html");
|
|
57
57
|
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
58
58
|
}
|
|
59
59
|
}
|
package/dist/run.cjs
CHANGED
|
@@ -29,14 +29,14 @@ async function isValidFilePath(filePath, dirPath) {
|
|
|
29
29
|
|
|
30
30
|
// src/getFilePath.ts
|
|
31
31
|
var cwd = process.cwd();
|
|
32
|
-
async function getFilePath(
|
|
33
|
-
let
|
|
32
|
+
async function getFilePath(url = "", { path = "", dirs = [], spa }) {
|
|
33
|
+
let urlPath = url.replace(/[?#].*$/, "");
|
|
34
34
|
for (let dir of dirs.length === 0 ? [""] : dirs) {
|
|
35
35
|
let dirPath = (0, import_node_path.join)(cwd, path, dir);
|
|
36
|
-
let filePath = (0, import_node_path.join)(dirPath,
|
|
37
|
-
if (!
|
|
36
|
+
let filePath = (0, import_node_path.join)(dirPath, urlPath);
|
|
37
|
+
if (!urlPath.endsWith("/") && await isValidFilePath(filePath, dirPath))
|
|
38
38
|
return filePath;
|
|
39
|
-
filePath = (0, import_node_path.join)(dirPath,
|
|
39
|
+
filePath = (0, import_node_path.join)(dirPath, spa ? "" : urlPath, "index.html");
|
|
40
40
|
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
41
41
|
}
|
|
42
42
|
}
|
|
@@ -91,14 +91,17 @@ function serve(config = {}) {
|
|
|
91
91
|
var exec = (0, import_node_util.promisify)(import_node_child_process.exec);
|
|
92
92
|
async function run() {
|
|
93
93
|
let [url, ...args] = process.argv.slice(2);
|
|
94
|
-
let buildFlagIndex = args.indexOf("-b");
|
|
95
94
|
let spa = false;
|
|
96
95
|
if (args[0] === "*") {
|
|
97
96
|
spa = true;
|
|
98
97
|
args.shift();
|
|
99
98
|
}
|
|
99
|
+
let buildFlagIndex = args.indexOf("-b");
|
|
100
100
|
let path = args[0];
|
|
101
|
-
let dirs =
|
|
101
|
+
let dirs = args.slice(
|
|
102
|
+
1,
|
|
103
|
+
buildFlagIndex === -1 ? args.length : buildFlagIndex
|
|
104
|
+
);
|
|
102
105
|
if (buildFlagIndex !== -1) {
|
|
103
106
|
let inputFile = (0, import_node_path3.join)(path, args[buildFlagIndex + 1] ?? "index.ts");
|
|
104
107
|
let outputFile = (0, import_node_path3.join)(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
|
package/dist/run.mjs
CHANGED
|
@@ -28,14 +28,14 @@ async function isValidFilePath(filePath, dirPath) {
|
|
|
28
28
|
|
|
29
29
|
// src/getFilePath.ts
|
|
30
30
|
var cwd = process.cwd();
|
|
31
|
-
async function getFilePath(
|
|
32
|
-
let
|
|
31
|
+
async function getFilePath(url = "", { path = "", dirs = [], spa }) {
|
|
32
|
+
let urlPath = url.replace(/[?#].*$/, "");
|
|
33
33
|
for (let dir of dirs.length === 0 ? [""] : dirs) {
|
|
34
34
|
let dirPath = join(cwd, path, dir);
|
|
35
|
-
let filePath = join(dirPath,
|
|
36
|
-
if (!
|
|
35
|
+
let filePath = join(dirPath, urlPath);
|
|
36
|
+
if (!urlPath.endsWith("/") && await isValidFilePath(filePath, dirPath))
|
|
37
37
|
return filePath;
|
|
38
|
-
filePath = join(dirPath,
|
|
38
|
+
filePath = join(dirPath, spa ? "" : urlPath, "index.html");
|
|
39
39
|
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
@@ -90,14 +90,17 @@ function serve(config = {}) {
|
|
|
90
90
|
var exec = promisify(originalExec);
|
|
91
91
|
async function run() {
|
|
92
92
|
let [url, ...args] = process.argv.slice(2);
|
|
93
|
-
let buildFlagIndex = args.indexOf("-b");
|
|
94
93
|
let spa = false;
|
|
95
94
|
if (args[0] === "*") {
|
|
96
95
|
spa = true;
|
|
97
96
|
args.shift();
|
|
98
97
|
}
|
|
98
|
+
let buildFlagIndex = args.indexOf("-b");
|
|
99
99
|
let path = args[0];
|
|
100
|
-
let dirs =
|
|
100
|
+
let dirs = args.slice(
|
|
101
|
+
1,
|
|
102
|
+
buildFlagIndex === -1 ? args.length : buildFlagIndex
|
|
103
|
+
);
|
|
101
104
|
if (buildFlagIndex !== -1) {
|
|
102
105
|
let inputFile = join2(path, args[buildFlagIndex + 1] ?? "index.ts");
|
|
103
106
|
let outputFile = join2(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
|
package/package.json
CHANGED
package/src/getFilePath.ts
CHANGED
|
@@ -5,22 +5,19 @@ import { isValidFilePath } from "./isValidFilePath";
|
|
|
5
5
|
const cwd = process.cwd();
|
|
6
6
|
|
|
7
7
|
export async function getFilePath(
|
|
8
|
-
|
|
8
|
+
url = "",
|
|
9
9
|
{ path = "", dirs = [], spa }: Config,
|
|
10
10
|
) {
|
|
11
|
-
let
|
|
11
|
+
let urlPath = url.replace(/[?#].*$/, "");
|
|
12
12
|
|
|
13
13
|
for (let dir of dirs.length === 0 ? [""] : dirs) {
|
|
14
14
|
let dirPath = join(cwd, path, dir);
|
|
15
|
-
let filePath = join(dirPath,
|
|
15
|
+
let filePath = join(dirPath, urlPath);
|
|
16
16
|
|
|
17
|
-
if (
|
|
18
|
-
!effectiveURLPath.endsWith("/") &&
|
|
19
|
-
(await isValidFilePath(filePath, dirPath))
|
|
20
|
-
)
|
|
17
|
+
if (!urlPath.endsWith("/") && (await isValidFilePath(filePath, dirPath)))
|
|
21
18
|
return filePath;
|
|
22
19
|
|
|
23
|
-
filePath = join(dirPath,
|
|
20
|
+
filePath = join(dirPath, spa ? "" : urlPath, "index.html");
|
|
24
21
|
|
|
25
22
|
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
26
23
|
}
|
package/src/run.ts
CHANGED
|
@@ -9,7 +9,6 @@ const exec = promisify(originalExec);
|
|
|
9
9
|
|
|
10
10
|
async function run() {
|
|
11
11
|
let [url, ...args] = process.argv.slice(2);
|
|
12
|
-
let buildFlagIndex = args.indexOf("-b");
|
|
13
12
|
let spa = false;
|
|
14
13
|
|
|
15
14
|
if (args[0] === "*") {
|
|
@@ -17,8 +16,12 @@ async function run() {
|
|
|
17
16
|
args.shift();
|
|
18
17
|
}
|
|
19
18
|
|
|
19
|
+
let buildFlagIndex = args.indexOf("-b");
|
|
20
20
|
let path = args[0];
|
|
21
|
-
let dirs =
|
|
21
|
+
let dirs = args.slice(
|
|
22
|
+
1,
|
|
23
|
+
buildFlagIndex === -1 ? args.length : buildFlagIndex,
|
|
24
|
+
);
|
|
22
25
|
|
|
23
26
|
if (buildFlagIndex !== -1) {
|
|
24
27
|
let inputFile = join(path, args[buildFlagIndex + 1] ?? "index.ts");
|