@t8/serve 0.1.5 → 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 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, urlPath);
53
- if (await isValidFilePath(filePath, dirPath)) return filePath;
54
- filePath = (0, import_node_path.join)(dirPath, urlPath, "index.html");
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, urlPath);
36
- if (await isValidFilePath(filePath, dirPath)) return filePath;
37
- filePath = (0, import_node_path.join)(dirPath, urlPath, "index.html");
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,15 @@ 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, path = "", ...args] = process.argv.slice(2);
93
+ let [url, ...args] = process.argv.slice(2);
92
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);
93
102
  if (buildFlagIndex !== -1) {
94
103
  let inputFile = (0, import_node_path3.join)(path, args[buildFlagIndex + 1] ?? "index.ts");
95
104
  let outputFile = (0, import_node_path3.join)(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
@@ -101,7 +110,8 @@ async function run() {
101
110
  serve({
102
111
  url,
103
112
  path,
104
- dirs: buildFlagIndex === -1 ? args : args.slice(0, buildFlagIndex)
113
+ dirs,
114
+ spa
105
115
  });
106
116
  }
107
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, urlPath);
35
- if (await isValidFilePath(filePath, dirPath)) return filePath;
36
- filePath = join(dirPath, urlPath, "index.html");
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,15 @@ function serve(config = {}) {
87
89
  // src/run.ts
88
90
  var exec = promisify(originalExec);
89
91
  async function run() {
90
- let [url, path = "", ...args] = process.argv.slice(2);
92
+ let [url, ...args] = process.argv.slice(2);
91
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);
92
101
  if (buildFlagIndex !== -1) {
93
102
  let inputFile = join2(path, args[buildFlagIndex + 1] ?? "index.ts");
94
103
  let outputFile = join2(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
@@ -100,7 +109,8 @@ async function run() {
100
109
  serve({
101
110
  url,
102
111
  path,
103
- dirs: buildFlagIndex === -1 ? args : args.slice(0, buildFlagIndex)
112
+ dirs,
113
+ spa
104
114
  });
105
115
  }
106
116
  run();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/serve",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "node",
package/src/Config.ts CHANGED
@@ -2,4 +2,5 @@ export type Config = {
2
2
  url?: string;
3
3
  path?: string;
4
4
  dirs?: string[];
5
+ spa?: boolean;
5
6
  };
@@ -5,16 +5,22 @@ import { isValidFilePath } from "./isValidFilePath";
5
5
  const cwd = process.cwd();
6
6
 
7
7
  export async function getFilePath(
8
- urlPath: string = "",
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, urlPath);
15
+ let filePath = join(dirPath, effectiveURLPath);
14
16
 
15
- if (await isValidFilePath(filePath, dirPath)) return filePath;
17
+ if (
18
+ !effectiveURLPath.endsWith("/") &&
19
+ (await isValidFilePath(filePath, dirPath))
20
+ )
21
+ return filePath;
16
22
 
17
- filePath = join(dirPath, urlPath, "index.html");
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, path = "", ...args] = process.argv.slice(2);
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: buildFlagIndex === -1 ? args : args.slice(0, buildFlagIndex),
36
+ dirs,
37
+ spa,
28
38
  });
29
39
  }
30
40