Skip to content

Commit 4ef9807

Browse files
adjusted node examples
1 parent 9a6c45f commit 4ef9807

File tree

8 files changed

+81
-1824
lines changed

8 files changed

+81
-1824
lines changed

examples/node/basic/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
1-
import initOpenCascade from "@bitbybit-dev/occt/bitbybit-dev-occt/node.js";
1+
import { createRequire } from "module";
2+
import initOpenCascade from "@bitbybit-dev/occt/bitbybit-dev-occt/index.js";
23
import { OCCTWire } from "@bitbybit-dev/occt/lib/services/shapes/wire.js";
34
import { OccHelper } from "@bitbybit-dev/occt/lib/occ-helper.js";
45
import { VectorHelperService } from "@bitbybit-dev/occt/lib/api/vector-helper.service.js";
56
import { ShapesHelperService } from "@bitbybit-dev/occt/lib/api/shapes-helper.service.js";
67

8+
const require = createRequire(import.meta.url);
9+
710
async function run() {
811
console.log("initializing...");
9-
const occ = await initOpenCascade();
12+
13+
// For Node.js, we need to specify the path to the WASM file
14+
const wasmPath = require.resolve("@bitbybit-dev/occt/bitbybit-dev-occt/bitbybit-dev-occt.5e93f201.wasm");
15+
16+
const occ = await initOpenCascade({
17+
locateFile: (path: string) => {
18+
if (path.endsWith(".wasm")) {
19+
return wasmPath;
20+
}
21+
return path;
22+
}
23+
});
1024

1125
const vecHelper = new VectorHelperService();
1226
const shapesHelper = new ShapesHelperService();

examples/node/basic/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
"node": ">=20.19.4"
1616
},
1717
"dependencies": {
18-
"@bitbybit-dev/occt": "^1.0.0-rc.0"
18+
"@bitbybit-dev/occt": "^1.0.0"
1919
},
2020
"devDependencies": {
2121
"extensionless": "1.9.9",
2222
"concurrently": "^7.6.0",
2323
"nodemon": "^2.0.20",
24-
"typescript": "^4.9.4"
24+
"typescript": "~5.8.0"
2525
},
2626
"extensionless": {
2727
"lookFor": [

examples/node/basic/tsconfig.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
{
22
"compilerOptions": {
3-
"target": "es2016",
4-
"module": "nodenext",
3+
"target": "ES2022",
4+
"module": "NodeNext",
5+
"moduleResolution": "NodeNext",
56
"outDir": "./dist",
67
"esModuleInterop": true,
7-
"forceConsistentCasingInFileNames": true,
88
"strict": true,
9-
"skipLibCheck": true
9+
"skipLibCheck": true,
10+
"declaration": false,
11+
"sourceMap": true
1012
},
1113
"include": [
12-
"./"
14+
"./*.ts"
1315
]
1416
}
Lines changed: 20 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,34 @@
1-
import { MathBitByBit, Logic, Lists, TextBitByBit, Vector, Point, Transforms, Color, GeometryHelper, Line, Polyline } from "@bitbybit-dev/base";
2-
import { JSONBitByBit, CSVBitByBit, Verb } from "@bitbybit-dev/core";
3-
import { Jscad } from "@bitbybit-dev/jscad";
4-
import { ManifoldService } from "@bitbybit-dev/manifold";
5-
import { OCCTService, OccHelper, VectorHelperService, ShapesHelperService } from "@bitbybit-dev/occt";
6-
import Module from "manifold-3d";
7-
import { JSONPath } from "jsonpath-plus";
8-
import initOpenCascade from "@bitbybit-dev/occt/bitbybit-dev-occt/node.js";
9-
import * as vrb from "verb-nurbs-web";
1+
import { createRequire } from "module";
2+
import { OCCTService } from "@bitbybit-dev/occt/lib/occ-service.js";
3+
import { OccHelper } from "@bitbybit-dev/occt/lib/occ-helper.js";
4+
import { VectorHelperService } from "@bitbybit-dev/occt/lib/api/vector-helper.service.js";
5+
import { ShapesHelperService } from "@bitbybit-dev/occt/lib/api/shapes-helper.service.js";
6+
import initOpenCascade from "@bitbybit-dev/occt/bitbybit-dev-occt/index.js";
7+
8+
const require = createRequire(import.meta.url);
109

1110
export class BitByBitBase {
12-
public math: MathBitByBit;
13-
public logic: Logic;
14-
public lists: Lists;
15-
public json: JSONBitByBit;
16-
public csv: CSVBitByBit;
17-
public vector: Vector;
18-
public point: Point;
19-
public line: Line;
20-
public transforms: Transforms;
21-
public polyline: Polyline;
22-
public verb: Verb;
23-
public jscad: Jscad;
24-
public manifold: ManifoldService;
25-
public text: TextBitByBit;
26-
public occt: OCCTService;
27-
public color: Color;
11+
public occt!: OCCTService;
2812

2913
constructor() {
3014
}
3115

3216
async init() {
33-
const occ = await initOpenCascade();
34-
const s = await import("@bitbybit-dev/jscad/jscad-generated.js");
35-
const jscad = s.default();
36-
this.jscad = new Jscad(jscad);
37-
const wasm = await Module({
38-
locateFile: () => {
39-
return "./manifold-3-3-2.wasm";
40-
},
17+
// For Node.js, we need to specify the path to the WASM file
18+
const wasmPath = require.resolve("@bitbybit-dev/occt/bitbybit-dev-occt/bitbybit-dev-occt.5e93f201.wasm");
19+
20+
const occ = await initOpenCascade({
21+
locateFile: (path: string) => {
22+
if (path.endsWith(".wasm")) {
23+
return wasmPath;
24+
}
25+
return path;
26+
}
4127
});
42-
wasm.setup();
43-
this.manifold = new ManifoldService(wasm);
44-
const geometryHelper = new GeometryHelper();
45-
this.math = new MathBitByBit();
46-
this.lists = new Lists();
47-
this.vector = new Vector(this.math, geometryHelper);
48-
this.color = new Color(this.math);
49-
this.transforms = new Transforms(this.vector, this.math);
50-
this.point = new Point(geometryHelper, this.transforms, this.vector, this.lists);
51-
const verb = { geom: vrb.geom, core: vrb.core };
52-
this.verb = new Verb({ verb } as any, geometryHelper, this.math);
53-
this.line = new Line(this.vector, this.point, geometryHelper);
54-
this.polyline = new Polyline(this.vector, this.point, this.line, geometryHelper);
28+
5529
const vecHelper = new VectorHelperService();
5630
const shapesHelper = new ShapesHelperService();
5731
const occHelper = new OccHelper(vecHelper, shapesHelper, occ);
5832
this.occt = new OCCTService(occ, occHelper);
59-
this.logic = new Logic();
60-
this.json = new JSONBitByBit({ jsonpath: JSONPath } as any);
61-
this.csv = new CSVBitByBit();
62-
this.text = new TextBitByBit(this.point);
6333
}
6434
}

examples/node/express-app/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import express, { Express, Request, Response } from "express";
22
import dotenv from "dotenv";
3-
import { BitByBitBase } from "./bitbybit";
3+
import { BitByBitBase } from "./bitbybit.js";
44

55
const bitbybit = new BitByBitBase();
66

0 commit comments

Comments
 (0)