@t8/serve 0.1.38 → 0.1.39

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Simple static file server + bundler, primarily for demo apps and tests, manual or automated
4
4
 
5
- ## Use cases
5
+ Use cases:
6
6
 
7
7
  - Use the CLI-based server to launch a demo or test app with a single CLI command.
8
8
  - Use the code-based setup to launch an own server from multiple tests, each with its own app.
@@ -12,19 +12,29 @@ Simple static file server + bundler, primarily for demo apps and tests, manual o
12
12
  ```sh
13
13
  npx @t8/serve [url|port] [*] [app_dir] [...assets_dirs] [-b [bundle_input_path] [bundle_output_path] [bundle_output_dir]] [--watch] [--minify]
14
14
  # * = SPA mode: serve all unmatched paths as "/"
15
+ ```
16
+
17
+ Examples:
15
18
 
19
+ ```sh
16
20
  npx @t8/serve 3000 app
17
- npx @t8/serve 3000 app -b
18
- npx @t8/serve 3000 * app
21
+ # - serve files from './app' at 'localhost:3000'
22
+
19
23
  npx @t8/serve 3000 * app -b
20
- npx @t8/serve 3000 app public dist
21
- npx @t8/serve 127.0.0.1:3000 app public dist
22
- npx @t8/serve 3000 app public dist -b
23
- npx @t8/serve 3000 app public dist -b src/index.ts
24
+ # - bundle './app/index.ts' to './app/dist/index.js' [-b]
25
+ # - serve files from './app' at 'localhost:3000' in the SPA mode [*] (handling all unmatched paths as "/")
26
+
27
+ npx @t8/serve 3000 * app -b src/index.ts
28
+ # - bundle './app/src/index.ts' to './app/dist/index.js'
29
+ # - serve files from './app' at 'localhost:3000' in the SPA mode
30
+
31
+ npx @t8/serve 127.0.0.1:3000 app public dist -b
32
+ # - bundle './app/index.ts' to './app/dist/index.js'
33
+ # - serve files from './app/public' and './app/dist' at '127.0.0.1:3000'
24
34
  ```
25
35
 
26
36
  <details>
27
- <summary>Example 1 (flat)</summary>
37
+ <summary>Example with Playwright #1 (flat)</summary>
28
38
 
29
39
  ```
30
40
  // package.json
@@ -47,7 +57,6 @@ npm run play
47
57
  ```
48
58
 
49
59
  ```
50
- // With Playwright:
51
60
  // playwright.config.ts
52
61
  ...
53
62
  use: {
@@ -62,7 +71,7 @@ webServer: {
62
71
  </details>
63
72
 
64
73
  <details>
65
- <summary>Example 2 (nested)</summary>
74
+ <summary>Example with Playwright #2 (nested)</summary>
66
75
 
67
76
  ```
68
77
  // package.json
@@ -87,7 +96,6 @@ npm run play
87
96
  ```
88
97
 
89
98
  ```
90
- // With Playwright:
91
99
  // playwright.config.ts
92
100
  ...
93
101
  use: {
@@ -102,7 +110,7 @@ webServer: {
102
110
  </details>
103
111
 
104
112
  <details>
105
- <summary>Example 3 (index.html)</summary>
113
+ <summary>Example with the watch mode</summary>
106
114
 
107
115
  ```
108
116
  /app
@@ -137,9 +145,10 @@ import { serve } from "@t8/serve";
137
145
 
138
146
  // Start
139
147
  let server = await serve({
140
- port: 3000,
148
+ host: "localhost", // default
149
+ port: 3000, // default
141
150
  path: "app",
142
- bundle: true, // or input path, or `{ input, output, dir }`
151
+ bundle: true, // or input path, or { input, output, dir }
143
152
  spa: true,
144
153
  });
145
154
 
@@ -148,7 +157,7 @@ server.close();
148
157
  ```
149
158
 
150
159
  <details>
151
- <summary>Example 1 (flat)</summary>
160
+ <summary>Example with Playwright 1 (flat)</summary>
152
161
 
153
162
  ```
154
163
  /playground
@@ -182,7 +191,7 @@ test.afterAll(() => {
182
191
  </details>
183
192
 
184
193
  <details>
185
- <summary>Example 2 (nested)</summary>
194
+ <summary>Example with Playwright 2 (nested)</summary>
186
195
 
187
196
  ```
188
197
  /tests/x
@@ -220,7 +229,7 @@ test.afterAll(() => {
220
229
  </details>
221
230
 
222
231
  <details>
223
- <summary>Example 3 (simple API)</summary>
232
+ <summary>Example with an API mock</summary>
224
233
 
225
234
  ```ts
226
235
  import { serve } from "@t8/serve";
package/dist/index.cjs CHANGED
@@ -90,6 +90,13 @@ const mimeTypes = {
90
90
  md: "text/markdown"
91
91
  };
92
92
 
93
+ /**
94
+ * Starts a static server as configured by the `config` parameter and
95
+ * returns the `Server` object.
96
+ *
97
+ * Bundles the code before starting the server, if configured with
98
+ * `config.bundle` to do so.
99
+ */
93
100
  async function serve(config = {}) {
94
101
  let stop = await bundle(config);
95
102
  return new Promise((resolve) => {
package/dist/index.d.ts CHANGED
@@ -68,6 +68,13 @@ type Config = {
68
68
  };
69
69
 
70
70
  type Server = ReturnType<typeof createServer>;
71
+ /**
72
+ * Starts a static server as configured by the `config` parameter and
73
+ * returns the `Server` object.
74
+ *
75
+ * Bundles the code before starting the server, if configured with
76
+ * `config.bundle` to do so.
77
+ */
71
78
  declare function serve(config?: Config): Promise<Server>;
72
79
 
73
80
  export { BundleConfig, Config, Server, serve };
package/dist/index.mjs CHANGED
@@ -90,6 +90,13 @@ const mimeTypes = {
90
90
  md: "text/markdown"
91
91
  };
92
92
 
93
+ /**
94
+ * Starts a static server as configured by the `config` parameter and
95
+ * returns the `Server` object.
96
+ *
97
+ * Bundles the code before starting the server, if configured with
98
+ * `config.bundle` to do so.
99
+ */
93
100
  async function serve(config = {}) {
94
101
  let stop = await bundle(config);
95
102
  return new Promise((resolve) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/serve",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "description": "Simple static file server + bundler, primarily for demo apps and tests, manual or automated",
5
5
  "keywords": [
6
6
  "node",
@@ -9,7 +9,7 @@
9
9
  "bundler"
10
10
  ],
11
11
  "bin": {
12
- "serve": "dist/run.mjs"
12
+ "serve": "./dist/run.mjs"
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",
package/src/serve.ts CHANGED
@@ -9,6 +9,13 @@ import { mimeTypes } from "./mimeTypes.ts";
9
9
 
10
10
  export type Server = ReturnType<typeof createServer>;
11
11
 
12
+ /**
13
+ * Starts a static server as configured by the `config` parameter and
14
+ * returns the `Server` object.
15
+ *
16
+ * Bundles the code before starting the server, if configured with
17
+ * `config.bundle` to do so.
18
+ */
12
19
  export async function serve(config: Config = {}): Promise<Server> {
13
20
  let stop = await bundle(config);
14
21