@t8/serve 0.1.2 → 0.1.4
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 +10 -0
- package/dist/index.js +5 -7
- package/dist/run.cjs +7 -7
- package/dist/run.mjs +8 -8
- package/package.json +36 -36
- package/src/getFilePath.ts +4 -6
- package/src/isValidFilePath.ts +2 -2
- package/src/run.ts +2 -7
package/README.md
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
```sh
|
|
2
|
+
npx @t8/serve [url|port] [app_dir] [...assets_dirs] [-b [bundle_input_path] [bundle_output_path]]
|
|
3
|
+
|
|
4
|
+
npx @t8/serve 3000 app
|
|
5
|
+
npx @t8/serve 3000 app -b
|
|
6
|
+
npx @t8/serve 3000 app public dist
|
|
7
|
+
npx @t8/serve 127.0.0.1:3000 app public dist
|
|
8
|
+
npx @t8/serve 3000 app public dist -b
|
|
9
|
+
npx @t8/serve 3000 app public dist -b src/index.ts
|
|
10
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -38,7 +38,7 @@ async function isValidFilePath(filePath, dirPath) {
|
|
|
38
38
|
if (!filePath.startsWith(dirPath)) return false;
|
|
39
39
|
try {
|
|
40
40
|
await (0, import_promises.access)(filePath);
|
|
41
|
-
return
|
|
41
|
+
return !(await (0, import_promises.lstat)(filePath)).isDirectory();
|
|
42
42
|
} catch {
|
|
43
43
|
return false;
|
|
44
44
|
}
|
|
@@ -46,15 +46,13 @@ 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 = [
|
|
50
|
-
for (let dir of dirs) {
|
|
49
|
+
async function getFilePath(urlPath = "", { path = "", dirs = [] }) {
|
|
50
|
+
for (let dir of dirs.length === 0 ? [""] : dirs) {
|
|
51
51
|
let dirPath = (0, import_node_path.join)(cwd, path, dir);
|
|
52
52
|
let filePath = (0, import_node_path.join)(dirPath, urlPath);
|
|
53
53
|
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
57
|
-
}
|
|
54
|
+
filePath = (0, import_node_path.join)(dirPath, urlPath, "index.html");
|
|
55
|
+
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
58
|
|
package/dist/run.cjs
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
// src/run.ts
|
|
5
5
|
var import_node_child_process = require("node:child_process");
|
|
6
|
+
var import_promises2 = require("node:fs/promises");
|
|
6
7
|
var import_node_path3 = require("node:path");
|
|
7
8
|
var import_node_util = require("node:util");
|
|
8
9
|
|
|
@@ -20,7 +21,7 @@ async function isValidFilePath(filePath, dirPath) {
|
|
|
20
21
|
if (!filePath.startsWith(dirPath)) return false;
|
|
21
22
|
try {
|
|
22
23
|
await (0, import_promises.access)(filePath);
|
|
23
|
-
return
|
|
24
|
+
return !(await (0, import_promises.lstat)(filePath)).isDirectory();
|
|
24
25
|
} catch {
|
|
25
26
|
return false;
|
|
26
27
|
}
|
|
@@ -28,15 +29,13 @@ async function isValidFilePath(filePath, dirPath) {
|
|
|
28
29
|
|
|
29
30
|
// src/getFilePath.ts
|
|
30
31
|
var cwd = process.cwd();
|
|
31
|
-
async function getFilePath(urlPath = "", { path = "", dirs = [
|
|
32
|
-
for (let dir of dirs) {
|
|
32
|
+
async function getFilePath(urlPath = "", { path = "", dirs = [] }) {
|
|
33
|
+
for (let dir of dirs.length === 0 ? [""] : dirs) {
|
|
33
34
|
let dirPath = (0, import_node_path.join)(cwd, path, dir);
|
|
34
35
|
let filePath = (0, import_node_path.join)(dirPath, urlPath);
|
|
35
36
|
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
39
|
-
}
|
|
37
|
+
filePath = (0, import_node_path.join)(dirPath, urlPath, "index.html");
|
|
38
|
+
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
41
|
|
|
@@ -91,6 +90,7 @@ async function run() {
|
|
|
91
90
|
if (buildFlagIndex !== -1) {
|
|
92
91
|
let inputFile = (0, import_node_path3.join)(path, args[buildFlagIndex + 1] ?? "index.ts");
|
|
93
92
|
let outputFile = (0, import_node_path3.join)(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
|
|
93
|
+
await (0, import_promises2.rm)((0, import_node_path3.join)(path, "dist"), { recursive: true, force: true });
|
|
94
94
|
await exec(
|
|
95
95
|
`npx esbuild ${inputFile} --outfile=${outputFile} --bundle --platform=neutral --log-level=warning`
|
|
96
96
|
);
|
package/dist/run.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
// src/run.ts
|
|
4
4
|
import { exec as originalExec } from "node:child_process";
|
|
5
|
+
import { rm } from "node:fs/promises";
|
|
5
6
|
import { join as join2 } from "node:path";
|
|
6
7
|
import { promisify } from "node:util";
|
|
7
8
|
|
|
@@ -14,12 +15,12 @@ import { extname } from "node:path";
|
|
|
14
15
|
import { join } from "node:path";
|
|
15
16
|
|
|
16
17
|
// src/isValidFilePath.ts
|
|
17
|
-
import { access } from "node:fs/promises";
|
|
18
|
+
import { access, lstat } from "node:fs/promises";
|
|
18
19
|
async function isValidFilePath(filePath, dirPath) {
|
|
19
20
|
if (!filePath.startsWith(dirPath)) return false;
|
|
20
21
|
try {
|
|
21
22
|
await access(filePath);
|
|
22
|
-
return
|
|
23
|
+
return !(await lstat(filePath)).isDirectory();
|
|
23
24
|
} catch {
|
|
24
25
|
return false;
|
|
25
26
|
}
|
|
@@ -27,15 +28,13 @@ async function isValidFilePath(filePath, dirPath) {
|
|
|
27
28
|
|
|
28
29
|
// src/getFilePath.ts
|
|
29
30
|
var cwd = process.cwd();
|
|
30
|
-
async function getFilePath(urlPath = "", { path = "", dirs = [
|
|
31
|
-
for (let dir of dirs) {
|
|
31
|
+
async function getFilePath(urlPath = "", { path = "", dirs = [] }) {
|
|
32
|
+
for (let dir of dirs.length === 0 ? [""] : dirs) {
|
|
32
33
|
let dirPath = join(cwd, path, dir);
|
|
33
34
|
let filePath = join(dirPath, urlPath);
|
|
34
35
|
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
38
|
-
}
|
|
36
|
+
filePath = join(dirPath, urlPath, "index.html");
|
|
37
|
+
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
|
|
@@ -90,6 +89,7 @@ async function run() {
|
|
|
90
89
|
if (buildFlagIndex !== -1) {
|
|
91
90
|
let inputFile = join2(path, args[buildFlagIndex + 1] ?? "index.ts");
|
|
92
91
|
let outputFile = join2(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
|
|
92
|
+
await rm(join2(path, "dist"), { recursive: true, force: true });
|
|
93
93
|
await exec(
|
|
94
94
|
`npx esbuild ${inputFile} --outfile=${outputFile} --bundle --platform=neutral --log-level=warning`
|
|
95
95
|
);
|
package/package.json
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@t8/serve",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"node",
|
|
7
|
-
"server",
|
|
8
|
-
"static"
|
|
9
|
-
],
|
|
10
|
-
"bin": {
|
|
11
|
-
"serve": "dist/run.mjs"
|
|
12
|
-
},
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/t8js/serve.git"
|
|
16
|
-
},
|
|
17
|
-
"license": "ISC",
|
|
18
|
-
"author": "axtk",
|
|
19
|
-
"type": "module",
|
|
20
|
-
"main": "dist/index.js",
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "npx npm-run-all clean -p compile compile-mjs-bin compile-cjs-bin",
|
|
23
|
-
"clean": "node -e \"require('node:fs').rmSync('dist', {force: true, recursive: true});\"",
|
|
24
|
-
"compile": "npx esbuild index.ts --bundle --outdir=dist --platform=node",
|
|
25
|
-
"compile-mjs-bin": "npx esbuild src/run.ts --bundle --outfile=dist/run.mjs --platform=node --format=esm",
|
|
26
|
-
"compile-cjs-bin": "npx esbuild src/run.ts --bundle --outfile=dist/run.cjs --platform=node --format=cjs",
|
|
27
|
-
"prepublishOnly": "npm run build",
|
|
28
|
-
"preversion": "npx npm-run-all typecheck shape build",
|
|
29
|
-
"shape": "npx codeshape",
|
|
30
|
-
"typecheck": "tsc --noEmit"
|
|
31
|
-
},
|
|
32
|
-
"devDependencies": {
|
|
33
|
-
"@types/node": "^24.5.2",
|
|
34
|
-
"typescript": "^5.9.2"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@t8/serve",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"node",
|
|
7
|
+
"server",
|
|
8
|
+
"static"
|
|
9
|
+
],
|
|
10
|
+
"bin": {
|
|
11
|
+
"serve": "dist/run.mjs"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/t8js/serve.git"
|
|
16
|
+
},
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"author": "axtk",
|
|
19
|
+
"type": "module",
|
|
20
|
+
"main": "dist/index.js",
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "npx npm-run-all clean -p compile compile-mjs-bin compile-cjs-bin",
|
|
23
|
+
"clean": "node -e \"require('node:fs').rmSync('dist', {force: true, recursive: true});\"",
|
|
24
|
+
"compile": "npx esbuild index.ts --bundle --outdir=dist --platform=node",
|
|
25
|
+
"compile-mjs-bin": "npx esbuild src/run.ts --bundle --outfile=dist/run.mjs --platform=node --format=esm",
|
|
26
|
+
"compile-cjs-bin": "npx esbuild src/run.ts --bundle --outfile=dist/run.cjs --platform=node --format=cjs",
|
|
27
|
+
"prepublishOnly": "npm run build",
|
|
28
|
+
"preversion": "npx npm-run-all typecheck shape build",
|
|
29
|
+
"shape": "npx codeshape",
|
|
30
|
+
"typecheck": "tsc --noEmit"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^24.5.2",
|
|
34
|
+
"typescript": "^5.9.2"
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/getFilePath.ts
CHANGED
|
@@ -6,18 +6,16 @@ const cwd = process.cwd();
|
|
|
6
6
|
|
|
7
7
|
export async function getFilePath(
|
|
8
8
|
urlPath: string = "",
|
|
9
|
-
{ path = "", dirs = [
|
|
9
|
+
{ path = "", dirs = [] }: Config,
|
|
10
10
|
) {
|
|
11
|
-
for (let dir of dirs) {
|
|
11
|
+
for (let dir of dirs.length === 0 ? [""] : dirs) {
|
|
12
12
|
let dirPath = join(cwd, path, dir);
|
|
13
13
|
let filePath = join(dirPath, urlPath);
|
|
14
14
|
|
|
15
15
|
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
filePath = join(dirPath, urlPath, "index.html");
|
|
17
|
+
filePath = join(dirPath, urlPath, "index.html");
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
}
|
|
19
|
+
if (await isValidFilePath(filePath, dirPath)) return filePath;
|
|
22
20
|
}
|
|
23
21
|
}
|
package/src/isValidFilePath.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { access } from "node:fs/promises";
|
|
1
|
+
import { access, lstat } from "node:fs/promises";
|
|
2
2
|
|
|
3
3
|
export async function isValidFilePath(filePath: string, dirPath: string) {
|
|
4
4
|
if (!filePath.startsWith(dirPath)) return false;
|
|
5
5
|
|
|
6
6
|
try {
|
|
7
7
|
await access(filePath);
|
|
8
|
-
return
|
|
8
|
+
return !(await lstat(filePath)).isDirectory();
|
|
9
9
|
} catch {
|
|
10
10
|
return false;
|
|
11
11
|
}
|
package/src/run.ts
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { exec as originalExec } from "node:child_process";
|
|
3
|
+
import { rm } from "node:fs/promises";
|
|
3
4
|
import { join } from "node:path";
|
|
4
5
|
import { promisify } from "node:util";
|
|
5
6
|
import { serve } from "./serve";
|
|
6
7
|
|
|
7
8
|
const exec = promisify(originalExec);
|
|
8
9
|
|
|
9
|
-
/**
|
|
10
|
-
* @example
|
|
11
|
-
* serve 3000 app public dist
|
|
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
|
|
15
|
-
*/
|
|
16
10
|
async function run() {
|
|
17
11
|
let [url, path = "", ...args] = process.argv.slice(2);
|
|
18
12
|
let buildFlagIndex = args.indexOf("-b");
|
|
@@ -21,6 +15,7 @@ async function run() {
|
|
|
21
15
|
let inputFile = join(path, args[buildFlagIndex + 1] ?? "index.ts");
|
|
22
16
|
let outputFile = join(path, "dist", args[buildFlagIndex + 2] ?? "index.js");
|
|
23
17
|
|
|
18
|
+
await rm(join(path, "dist"), { recursive: true, force: true });
|
|
24
19
|
await exec(
|
|
25
20
|
`npx esbuild ${inputFile} --outfile=${outputFile} --bundle --platform=neutral --log-level=warning`,
|
|
26
21
|
);
|