@t8/serve 0.1.1 → 0.1.2

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/run.cjs CHANGED
@@ -1,6 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
 
4
+ // src/run.ts
5
+ var import_node_child_process = require("node:child_process");
6
+ var import_node_path3 = require("node:path");
7
+ var import_node_util = require("node:util");
8
+
4
9
  // src/serve.ts
5
10
  var import_node_fs = require("node:fs");
6
11
  var import_node_http = require("node:http");
@@ -79,9 +84,21 @@ function serve(config = {}) {
79
84
  }
80
85
 
81
86
  // src/run.ts
82
- var args = process.argv.slice(2);
83
- serve({
84
- url: args[0],
85
- path: args[1],
86
- dirs: args.slice(2)
87
- });
87
+ var exec = (0, import_node_util.promisify)(import_node_child_process.exec);
88
+ async function run() {
89
+ let [url, path = "", ...args] = process.argv.slice(2);
90
+ let buildFlagIndex = args.indexOf("-b");
91
+ if (buildFlagIndex !== -1) {
92
+ let inputFile = (0, import_node_path3.join)(path, args[buildFlagIndex + 1] ?? "index.ts");
93
+ let outputFile = (0, import_node_path3.join)(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
94
+ await exec(
95
+ `npx esbuild ${inputFile} --outfile=${outputFile} --bundle --platform=neutral --log-level=warning`
96
+ );
97
+ }
98
+ serve({
99
+ url,
100
+ path,
101
+ dirs: buildFlagIndex === -1 ? args : args.slice(0, buildFlagIndex)
102
+ });
103
+ }
104
+ run();
package/dist/run.mjs CHANGED
@@ -1,5 +1,10 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ // src/run.ts
4
+ import { exec as originalExec } from "node:child_process";
5
+ import { join as join2 } from "node:path";
6
+ import { promisify } from "node:util";
7
+
3
8
  // src/serve.ts
4
9
  import { createReadStream } from "node:fs";
5
10
  import { createServer } from "node:http";
@@ -78,9 +83,21 @@ function serve(config = {}) {
78
83
  }
79
84
 
80
85
  // src/run.ts
81
- var args = process.argv.slice(2);
82
- serve({
83
- url: args[0],
84
- path: args[1],
85
- dirs: args.slice(2)
86
- });
86
+ var exec = promisify(originalExec);
87
+ async function run() {
88
+ let [url, path = "", ...args] = process.argv.slice(2);
89
+ let buildFlagIndex = args.indexOf("-b");
90
+ if (buildFlagIndex !== -1) {
91
+ let inputFile = join2(path, args[buildFlagIndex + 1] ?? "index.ts");
92
+ let outputFile = join2(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
93
+ await exec(
94
+ `npx esbuild ${inputFile} --outfile=${outputFile} --bundle --platform=neutral --log-level=warning`
95
+ );
96
+ }
97
+ serve({
98
+ url,
99
+ path,
100
+ dirs: buildFlagIndex === -1 ? args : args.slice(0, buildFlagIndex)
101
+ });
102
+ }
103
+ run();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t8/serve",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "node",
package/src/run.ts CHANGED
@@ -1,15 +1,36 @@
1
1
  #!/usr/bin/env node
2
+ import { exec as originalExec } from "node:child_process";
3
+ import { join } from "node:path";
4
+ import { promisify } from "node:util";
2
5
  import { serve } from "./serve";
3
6
 
4
- let args = process.argv.slice(2);
7
+ const exec = promisify(originalExec);
5
8
 
6
9
  /**
7
10
  * @example
8
11
  * serve 3000 app public dist
9
12
  * serve 127.0.0.1:3000 app public dist
13
+ * serve 3000 app public dist -b
14
+ * serve 3000 app public dist -b src/index.ts
10
15
  */
11
- serve({
12
- url: args[0],
13
- path: args[1],
14
- dirs: args.slice(2),
15
- });
16
+ async function run() {
17
+ let [url, path = "", ...args] = process.argv.slice(2);
18
+ let buildFlagIndex = args.indexOf("-b");
19
+
20
+ if (buildFlagIndex !== -1) {
21
+ let inputFile = join(path, args[buildFlagIndex + 1] ?? "index.ts");
22
+ let outputFile = join(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
23
+
24
+ await exec(
25
+ `npx esbuild ${inputFile} --outfile=${outputFile} --bundle --platform=neutral --log-level=warning`,
26
+ );
27
+ }
28
+
29
+ serve({
30
+ url,
31
+ path,
32
+ dirs: buildFlagIndex === -1 ? args : args.slice(0, buildFlagIndex),
33
+ });
34
+ }
35
+
36
+ run();