brep-io-kernel 1.0.104 → 1.0.106
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 -22
- package/bin/brep-io-kernel.js +259 -0
- package/dist-kernel/brep-kernel.js +34064 -33482
- package/dist-kernel/help/CONTRIBUTING.html +514 -0
- package/dist-kernel/help/HOME.png +0 -0
- package/dist-kernel/help/LICENSE.html +514 -0
- package/dist-kernel/help/MODELING.png +0 -0
- package/dist-kernel/help/PMI.png +0 -0
- package/dist-kernel/help/SKETCH.png +0 -0
- package/dist-kernel/help/api-examples.html +514 -0
- package/dist-kernel/help/assembly-constraints__Coincident_Constraint_dialog.png +0 -0
- package/dist-kernel/help/assembly-constraints___Angle_Constraint_dialog.png +0 -0
- package/dist-kernel/help/assembly-constraints___Distance_Constraint_dialog.png +0 -0
- package/dist-kernel/help/assembly-constraints___Fixed_Constraint_dialog.png +0 -0
- package/dist-kernel/help/assembly-constraints___Parallel_Constraint_dialog.png +0 -0
- package/dist-kernel/help/assembly-constraints___Touch_Align_Constraint_dialog.png +0 -0
- package/dist-kernel/help/assembly-constraints__angle-constraint.html +514 -0
- package/dist-kernel/help/assembly-constraints__coincident-constraint.html +514 -0
- package/dist-kernel/help/assembly-constraints__distance-constraint.html +514 -0
- package/dist-kernel/help/assembly-constraints__fixed-constraint.html +514 -0
- package/dist-kernel/help/assembly-constraints__parallel-constraint.html +514 -0
- package/dist-kernel/help/assembly-constraints__solver.html +514 -0
- package/dist-kernel/help/assembly-constraints__touch-align-constraint.html +514 -0
- package/dist-kernel/help/brep-api.html +529 -0
- package/dist-kernel/help/brep-kernel.html +524 -0
- package/dist-kernel/help/brep-model.html +514 -0
- package/dist-kernel/help/cad-embed.html +566 -0
- package/dist-kernel/help/cylindrical-face-radius-embedding.html +556 -0
- package/dist-kernel/help/developer-index.html +514 -0
- package/dist-kernel/help/dialog-screenshots.html +514 -0
- package/dist-kernel/help/extruded-sketch-radius-embedding.html +602 -0
- package/dist-kernel/help/features__Assembly_Component_dialog.png +0 -0
- package/dist-kernel/help/features__Boolean_dialog.png +0 -0
- package/dist-kernel/help/features__Chamfer_dialog.png +0 -0
- package/dist-kernel/help/features__Collapse_Edge_dialog.png +0 -0
- package/dist-kernel/help/features__Datium_dialog.png +0 -0
- package/dist-kernel/help/features__Edge_smooth_dialog.png +0 -0
- package/dist-kernel/help/features__Extrude_dialog.png +0 -0
- package/dist-kernel/help/features__Fillet_dialog.png +0 -0
- package/dist-kernel/help/features__Helix_dialog.png +0 -0
- package/dist-kernel/help/features__Hole_dialog.png +0 -0
- package/dist-kernel/help/features__Image_Heightmap_Solid_dialog.png +0 -0
- package/dist-kernel/help/features__Image_to_Face_dialog.png +0 -0
- package/dist-kernel/help/features__Import_3D_Model_dialog.png +0 -0
- package/dist-kernel/help/features__Loft_dialog.png +0 -0
- package/dist-kernel/help/features__Mirror_dialog.png +0 -0
- package/dist-kernel/help/features__Offset_Face_dialog.png +0 -0
- package/dist-kernel/help/features__Offset_Shell_dialog.png +0 -0
- package/dist-kernel/help/features__Overlap_Cleanup_dialog.png +0 -0
- package/dist-kernel/help/features__Pattern_Linear_dialog.png +0 -0
- package/dist-kernel/help/features__Pattern_Radial_dialog.png +0 -0
- package/dist-kernel/help/features__Pattern_dialog.png +0 -0
- package/dist-kernel/help/features__Plane_dialog.png +0 -0
- package/dist-kernel/help/features__Primitive_Cone_dialog.png +0 -0
- package/dist-kernel/help/features__Primitive_Cube_dialog.png +0 -0
- package/dist-kernel/help/features__Primitive_Cylinder_dialog.png +0 -0
- package/dist-kernel/help/features__Primitive_Pyramid_dialog.png +0 -0
- package/dist-kernel/help/features__Primitive_Sphere_dialog.png +0 -0
- package/dist-kernel/help/features__Primitive_Torus_dialog.png +0 -0
- package/dist-kernel/help/features__Remesh_dialog.png +0 -0
- package/dist-kernel/help/features__Revolve_dialog.png +0 -0
- package/dist-kernel/help/features__Sheet_Metal_Contour_Flange_dialog.png +0 -0
- package/dist-kernel/help/features__Sheet_Metal_Cutout_dialog.png +0 -0
- package/dist-kernel/help/features__Sheet_Metal_Flange_dialog.png +0 -0
- package/dist-kernel/help/features__Sheet_Metal_Hem_dialog.png +0 -0
- package/dist-kernel/help/features__Sheet_Metal_Tab_dialog.png +0 -0
- package/dist-kernel/help/features__Sketch_dialog.png +0 -0
- package/dist-kernel/help/features__Spline_dialog.png +0 -0
- package/dist-kernel/help/features__Sweep_dialog.png +0 -0
- package/dist-kernel/help/features__Text_to_Face_dialog.png +0 -0
- package/dist-kernel/help/features__Transform_dialog.png +0 -0
- package/dist-kernel/help/features__Tube_dialog.png +0 -0
- package/dist-kernel/help/features__assembly-component.html +514 -0
- package/dist-kernel/help/features__boolean.html +514 -0
- package/dist-kernel/help/features__chamfer.html +514 -0
- package/dist-kernel/help/features__datium.html +514 -0
- package/dist-kernel/help/features__datum.html +514 -0
- package/dist-kernel/help/features__extrude.html +514 -0
- package/dist-kernel/help/features__fillet.html +514 -0
- package/dist-kernel/help/features__helix.html +514 -0
- package/dist-kernel/help/features__hole.html +514 -0
- package/dist-kernel/help/features__image-heightmap-solid.html +514 -0
- package/dist-kernel/help/features__image-to-face-2D_dialog.png +0 -0
- package/dist-kernel/help/features__image-to-face-3D_dialog.png +0 -0
- package/dist-kernel/help/features__image-to-face.html +514 -0
- package/dist-kernel/help/features__import-3d-model.html +514 -0
- package/dist-kernel/help/features__index.html +514 -0
- package/dist-kernel/help/features__loft.html +514 -0
- package/dist-kernel/help/features__mirror.html +514 -0
- package/dist-kernel/help/features__offset-shell.html +514 -0
- package/dist-kernel/help/features__pattern-linear.html +514 -0
- package/dist-kernel/help/features__pattern-radial.html +514 -0
- package/dist-kernel/help/features__pattern.html +514 -0
- package/dist-kernel/help/features__plane.html +514 -0
- package/dist-kernel/help/features__primitive-cone.html +514 -0
- package/dist-kernel/help/features__primitive-cube.html +514 -0
- package/dist-kernel/help/features__primitive-cylinder.html +514 -0
- package/dist-kernel/help/features__primitive-pyramid.html +514 -0
- package/dist-kernel/help/features__primitive-sphere.html +514 -0
- package/dist-kernel/help/features__primitive-torus.html +514 -0
- package/dist-kernel/help/features__remesh.html +514 -0
- package/dist-kernel/help/features__revolve.html +514 -0
- package/dist-kernel/help/features__sheet-metal-contour-flange.html +514 -0
- package/dist-kernel/help/features__sheet-metal-flange.html +514 -0
- package/dist-kernel/help/features__sheet-metal-tab.html +514 -0
- package/dist-kernel/help/features__sketch.html +514 -0
- package/dist-kernel/help/features__spline.html +514 -0
- package/dist-kernel/help/features__sweep.html +514 -0
- package/dist-kernel/help/features__text-to-face.html +514 -0
- package/dist-kernel/help/features__transform.html +514 -0
- package/dist-kernel/help/features__tube.html +514 -0
- package/dist-kernel/help/file-formats.html +514 -0
- package/dist-kernel/help/fonts-licenses.html +4753 -0
- package/dist-kernel/help/getting-started.html +514 -0
- package/dist-kernel/help/github-repo-storage.html +514 -0
- package/dist-kernel/help/highlights.html +514 -0
- package/dist-kernel/help/history-systems.html +514 -0
- package/dist-kernel/help/how-it-works.html +514 -0
- package/dist-kernel/help/index.html +914 -0
- package/dist-kernel/help/input-params-schema.html +629 -0
- package/dist-kernel/help/inspector-improvements.html +514 -0
- package/dist-kernel/help/inspector.html +514 -0
- package/dist-kernel/help/modes__modeling.html +514 -0
- package/dist-kernel/help/modes__pmi.html +514 -0
- package/dist-kernel/help/modes__sketch.html +514 -0
- package/dist-kernel/help/part-history.html +548 -0
- package/dist-kernel/help/plugins.html +514 -0
- package/dist-kernel/help/pmi-annotations__Angle_Dimension_dialog.png +0 -0
- package/dist-kernel/help/pmi-annotations__Explode_Body_dialog.png +0 -0
- package/dist-kernel/help/pmi-annotations__Hole_Callout_dialog.png +0 -0
- package/dist-kernel/help/pmi-annotations__Leader_dialog.png +0 -0
- package/dist-kernel/help/pmi-annotations__Linear_Dimension_dialog.png +0 -0
- package/dist-kernel/help/pmi-annotations__Note_dialog.png +0 -0
- package/dist-kernel/help/pmi-annotations__Radial_Dimension_dialog.png +0 -0
- package/dist-kernel/help/pmi-annotations__angle-dimension.html +514 -0
- package/dist-kernel/help/pmi-annotations__explode-body.html +514 -0
- package/dist-kernel/help/pmi-annotations__hole-callout.html +514 -0
- package/dist-kernel/help/pmi-annotations__index.html +514 -0
- package/dist-kernel/help/pmi-annotations__leader.html +514 -0
- package/dist-kernel/help/pmi-annotations__linear-dimension.html +514 -0
- package/dist-kernel/help/pmi-annotations__note.html +514 -0
- package/dist-kernel/help/pmi-annotations__radial-dimension.html +514 -0
- package/dist-kernel/help/search-index.json +518 -0
- package/dist-kernel/help/simplified-radial-dimensions.html +564 -0
- package/dist-kernel/help/sketch-solver-2d.html +597 -0
- package/dist-kernel/help/sketcher2d-embed.html +595 -0
- package/dist-kernel/help/solid-methods.html +645 -0
- package/dist-kernel/help/table-of-contents.html +605 -0
- package/dist-kernel/help/ui-overview.html +514 -0
- package/dist-kernel/help/whats-new.html +514 -0
- package/package.json +12 -15
- package/src/BREP/SolidMethods/fillet.js +244 -52
- package/src/BREP/fillets/fillet.js +1 -1
- package/src/PartHistory.js +28 -3
- package/src/UI/MainToolbar.js +1 -1
- package/src/UI/SelectionFilter.js +7 -3
- package/src/UI/toolbarButtons/zoomToFitButton.js +1 -2
- package/src/features/edgeSmooth/EdgeSmoothFeature.js +32 -33
- package/src/features/edgeSmooth/edgeCurveFit.js +95 -0
- package/src/features/edgeSmooth/vertexTargetConstraints.js +212 -0
- package/src/features/fillet/FilletFeature.js +1 -1
- package/src/generated/licenseBundle.js +1 -1
- package/src/tests/test_edge_smooth_curve_fit.js +113 -0
- package/src/tests/test_fillet_nonClosed.js +6 -0
- package/src/tests/test_history_expand_does_not_dirty.js +42 -0
- package/src/tests/tests.js +6 -0
package/README.md
CHANGED
|
@@ -4,12 +4,13 @@
|
|
|
4
4
|
A feature-based modeling playground experimenting with BREP-style workflows on top of triangle meshes. It combines robust manifold CSG (via the [Manifold](https://github.com/elalish/manifold/) library) with a simple face and edge representation, a history pipeline, and Three.js visualization. Import meshes (STL), repair and group them into faces, then perform boolean operations, fillets, chamfers, sweeps, lofts, and more.
|
|
5
5
|
|
|
6
6
|
This project is actively evolving; expect rough edges while APIs settle.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
[
|
|
9
|
+
[](docs/modes/modeling.md)
|
|
10
|
+
[](docs/modes/sketch.md)
|
|
11
|
+
[](docs/modes/pmi.md)
|
|
12
|
+
[](docs/features/image-to-face.md)
|
|
13
|
+
[](docs/features/image-to-face.md)
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
## Documentation Map
|
|
@@ -18,28 +19,12 @@ This project is actively evolving; expect rough edges while APIs settle.
|
|
|
18
19
|
- [What's New](docs/whats-new.md)
|
|
19
20
|
- [Getting Started](docs/getting-started.md)
|
|
20
21
|
- [Developer Docs Index](docs/developer-index.md)
|
|
21
|
-
- [API Examples (Live Demos)](docs/api-examples.md)
|
|
22
|
-
- [UI Overview (Browser)](docs/ui-overview.md)
|
|
23
|
-
- [How It Works](docs/how-it-works.md)
|
|
24
|
-
- [History Systems](docs/history-systems.md)
|
|
25
|
-
- [Input Params Schema](docs/input-params-schema.md)
|
|
26
|
-
- [BREP Model and Classes](docs/brep-model.md)
|
|
27
|
-
- [BREP API (BREP.js exports)](docs/brep-api.md)
|
|
28
|
-
- [BREP Kernel (core classes & helpers)](docs/brep-kernel.md)
|
|
29
|
-
- [2D Sketch Solver (standalone)](docs/sketch-solver-2d.md)
|
|
30
|
-
- [Embeddable CAD App](docs/cad-embed.md)
|
|
31
22
|
- [File Formats: Import and Export](docs/file-formats.md)
|
|
32
23
|
- [Plugins and Examples](docs/plugins.md)
|
|
33
24
|
- [Recent Inspector Improvements](docs/inspector-improvements.md)
|
|
34
25
|
- [Inspector](docs/inspector.md)
|
|
35
26
|
|
|
36
27
|
|
|
37
|
-
|
|
38
|
-
## Dialog Screenshots
|
|
39
|
-
|
|
40
|
-
See [Dialog Screenshots](docs/dialog-screenshots.md) for the capture helpers, output locations, and configuration options.
|
|
41
|
-
|
|
42
|
-
|
|
43
28
|
## Run Local Dev Environment
|
|
44
29
|
```
|
|
45
30
|
# clone repo and cd to the folder
|
|
@@ -139,6 +124,9 @@ configuration.
|
|
|
139
124
|
|
|
140
125
|
- Install:
|
|
141
126
|
- `pnpm add brep-io-kernel`
|
|
127
|
+
- CLI helper (no install):
|
|
128
|
+
- `npx brep-io-kernel` (starts a local server for bundled docs/assets)
|
|
129
|
+
- `npx brep-io-kernel --port 8080`
|
|
142
130
|
- Import (ESM):
|
|
143
131
|
- `import { BREP, PartHistory } from 'brep-io-kernel';`
|
|
144
132
|
- `import { AssemblyConstraintHistory, AssemblyConstraintRegistry } from 'brep-io-kernel';`
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { createReadStream, existsSync, readFileSync, statSync } from "node:fs";
|
|
4
|
+
import { createServer } from "node:http";
|
|
5
|
+
import {
|
|
6
|
+
dirname,
|
|
7
|
+
extname,
|
|
8
|
+
isAbsolute,
|
|
9
|
+
relative,
|
|
10
|
+
resolve,
|
|
11
|
+
} from "node:path";
|
|
12
|
+
import { fileURLToPath } from "node:url";
|
|
13
|
+
|
|
14
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
const packageRoot = resolve(here, "..");
|
|
16
|
+
const packageJsonPath = resolve(packageRoot, "package.json");
|
|
17
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
18
|
+
|
|
19
|
+
const args = process.argv.slice(2);
|
|
20
|
+
|
|
21
|
+
const defaults = {
|
|
22
|
+
host: "127.0.0.1",
|
|
23
|
+
port: 4173,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const contentTypeByExt = {
|
|
27
|
+
".css": "text/css; charset=utf-8",
|
|
28
|
+
".gif": "image/gif",
|
|
29
|
+
".htm": "text/html; charset=utf-8",
|
|
30
|
+
".html": "text/html; charset=utf-8",
|
|
31
|
+
".ico": "image/x-icon",
|
|
32
|
+
".jpg": "image/jpeg",
|
|
33
|
+
".jpeg": "image/jpeg",
|
|
34
|
+
".js": "text/javascript; charset=utf-8",
|
|
35
|
+
".json": "application/json; charset=utf-8",
|
|
36
|
+
".map": "application/json; charset=utf-8",
|
|
37
|
+
".mjs": "text/javascript; charset=utf-8",
|
|
38
|
+
".otf": "font/otf",
|
|
39
|
+
".png": "image/png",
|
|
40
|
+
".svg": "image/svg+xml",
|
|
41
|
+
".txt": "text/plain; charset=utf-8",
|
|
42
|
+
".ttf": "font/ttf",
|
|
43
|
+
".wasm": "application/wasm",
|
|
44
|
+
".woff": "font/woff",
|
|
45
|
+
".woff2": "font/woff2",
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
function printHelp() {
|
|
49
|
+
console.log(`${packageJson.name} ${packageJson.version}`);
|
|
50
|
+
console.log("");
|
|
51
|
+
console.log("Usage:");
|
|
52
|
+
console.log(" npx brep-io-kernel [--host HOST] [--port PORT]");
|
|
53
|
+
console.log(" npx brep-io-kernel [--help] [--version] [--example]");
|
|
54
|
+
console.log("");
|
|
55
|
+
console.log("Options:");
|
|
56
|
+
console.log(" -h, --help Show this help message.");
|
|
57
|
+
console.log(" -v, --version Print the installed package version.");
|
|
58
|
+
console.log(" --example Print a minimal Node.js usage example.");
|
|
59
|
+
console.log(` --host HOST Bind host (default: ${defaults.host}).`);
|
|
60
|
+
console.log(` -p, --port N Bind port (default: ${defaults.port}).`);
|
|
61
|
+
console.log("");
|
|
62
|
+
console.log(
|
|
63
|
+
"No arguments starts a local static server for bundled docs/assets."
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function printExample() {
|
|
68
|
+
console.log("import { BREP, PartHistory } from 'brep-io-kernel';");
|
|
69
|
+
console.log("");
|
|
70
|
+
console.log("const partHistory = new PartHistory();");
|
|
71
|
+
console.log("// Use BREP + PartHistory APIs here.");
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function fail(message) {
|
|
75
|
+
console.error(message);
|
|
76
|
+
process.exit(1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function parseArgs(argv) {
|
|
80
|
+
const out = {
|
|
81
|
+
help: false,
|
|
82
|
+
version: false,
|
|
83
|
+
example: false,
|
|
84
|
+
host: defaults.host,
|
|
85
|
+
port: defaults.port,
|
|
86
|
+
unknown: [],
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
90
|
+
const arg = argv[i];
|
|
91
|
+
if (arg === "-h" || arg === "--help") {
|
|
92
|
+
out.help = true;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (arg === "-v" || arg === "--version") {
|
|
96
|
+
out.version = true;
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (arg === "--example") {
|
|
100
|
+
out.example = true;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (arg === "--host") {
|
|
104
|
+
const value = argv[i + 1];
|
|
105
|
+
if (!value || value.startsWith("-")) {
|
|
106
|
+
out.unknown.push(arg);
|
|
107
|
+
} else {
|
|
108
|
+
out.host = value;
|
|
109
|
+
i += 1;
|
|
110
|
+
}
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (arg.startsWith("--host=")) {
|
|
114
|
+
out.host = arg.slice("--host=".length);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (arg === "-p" || arg === "--port") {
|
|
118
|
+
const value = argv[i + 1];
|
|
119
|
+
if (!value || value.startsWith("-")) {
|
|
120
|
+
out.unknown.push(arg);
|
|
121
|
+
} else {
|
|
122
|
+
out.port = Number(value);
|
|
123
|
+
i += 1;
|
|
124
|
+
}
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (arg.startsWith("--port=")) {
|
|
128
|
+
out.port = Number(arg.slice("--port=".length));
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
out.unknown.push(arg);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return out;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function findLandingPath(rootDir) {
|
|
138
|
+
const candidates = [
|
|
139
|
+
"/help/index.html",
|
|
140
|
+
"/node.html",
|
|
141
|
+
];
|
|
142
|
+
for (const candidate of candidates) {
|
|
143
|
+
const absolute = resolve(rootDir, `.${candidate}`);
|
|
144
|
+
if (existsSync(absolute)) return candidate;
|
|
145
|
+
}
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function safeResolveRequest(rootDir, pathname, landingPath) {
|
|
150
|
+
let requestPath = pathname || "/";
|
|
151
|
+
if (requestPath === "/") requestPath = landingPath;
|
|
152
|
+
if (requestPath.endsWith("/")) requestPath = `${requestPath}index.html`;
|
|
153
|
+
|
|
154
|
+
const candidate = resolve(rootDir, `.${requestPath}`);
|
|
155
|
+
const rel = relative(rootDir, candidate);
|
|
156
|
+
if (!rel || rel.startsWith("..") || isAbsolute(rel)) {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
return candidate;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function openStreamResponse(res, filePath) {
|
|
163
|
+
const ext = extname(filePath).toLowerCase();
|
|
164
|
+
const contentType =
|
|
165
|
+
contentTypeByExt[ext] || "application/octet-stream";
|
|
166
|
+
res.writeHead(200, { "content-type": contentType });
|
|
167
|
+
const stream = createReadStream(filePath);
|
|
168
|
+
stream.on("error", () => {
|
|
169
|
+
if (!res.headersSent) {
|
|
170
|
+
res.writeHead(500, { "content-type": "text/plain; charset=utf-8" });
|
|
171
|
+
}
|
|
172
|
+
res.end("Internal server error.");
|
|
173
|
+
});
|
|
174
|
+
stream.pipe(res);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function startStaticServer({ host, port }) {
|
|
178
|
+
if (!host) fail("Invalid host value.");
|
|
179
|
+
if (!Number.isInteger(port) || port <= 0 || port > 65535) {
|
|
180
|
+
fail("Invalid port. Use an integer between 1 and 65535.");
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const rootDir = resolve(packageRoot, "dist-kernel");
|
|
184
|
+
if (!existsSync(rootDir)) {
|
|
185
|
+
fail(`Missing dist-kernel at: ${rootDir}`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const landingPath = findLandingPath(rootDir);
|
|
189
|
+
if (!landingPath) {
|
|
190
|
+
fail(`No landing page found in: ${rootDir}`);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const server = createServer((req, res) => {
|
|
194
|
+
try {
|
|
195
|
+
const reqUrl = new URL(req.url || "/", "http://localhost");
|
|
196
|
+
const filePath = safeResolveRequest(rootDir, reqUrl.pathname, landingPath);
|
|
197
|
+
if (!filePath || !existsSync(filePath)) {
|
|
198
|
+
res.writeHead(404, { "content-type": "text/plain; charset=utf-8" });
|
|
199
|
+
res.end("Not found.");
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const fileStat = statSync(filePath);
|
|
203
|
+
if (!fileStat.isFile()) {
|
|
204
|
+
res.writeHead(404, { "content-type": "text/plain; charset=utf-8" });
|
|
205
|
+
res.end("Not found.");
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
openStreamResponse(res, filePath);
|
|
209
|
+
} catch (error) {
|
|
210
|
+
res.writeHead(500, { "content-type": "text/plain; charset=utf-8" });
|
|
211
|
+
res.end("Internal server error.");
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
server.on("error", (error) => {
|
|
216
|
+
const message = error && error.code === "EADDRINUSE"
|
|
217
|
+
? `Port ${port} is already in use.`
|
|
218
|
+
: `Server error: ${error?.message || String(error)}`;
|
|
219
|
+
fail(message);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
server.listen(port, host, () => {
|
|
223
|
+
const displayHost = host.includes(":") ? `[${host}]` : host;
|
|
224
|
+
const baseUrl = `http://${displayHost}:${port}`;
|
|
225
|
+
console.log(`${packageJson.name} ${packageJson.version}`);
|
|
226
|
+
console.log(`Serving: ${rootDir}`);
|
|
227
|
+
console.log(`Open: ${baseUrl}${landingPath}`);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
const shutdown = () => {
|
|
231
|
+
server.close(() => process.exit(0));
|
|
232
|
+
};
|
|
233
|
+
process.on("SIGINT", shutdown);
|
|
234
|
+
process.on("SIGTERM", shutdown);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const parsed = parseArgs(args);
|
|
238
|
+
if (parsed.unknown.length) {
|
|
239
|
+
console.error(`Unknown argument(s): ${parsed.unknown.join(" ")}`);
|
|
240
|
+
console.error("Run `npx brep-io-kernel --help` for usage.");
|
|
241
|
+
process.exit(1);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (parsed.version) {
|
|
245
|
+
console.log(packageJson.version);
|
|
246
|
+
process.exit(0);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (parsed.example) {
|
|
250
|
+
printExample();
|
|
251
|
+
process.exit(0);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
if (parsed.help) {
|
|
255
|
+
printHelp();
|
|
256
|
+
process.exit(0);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
startStaticServer({ host: parsed.host, port: parsed.port });
|