Skip to content

Commit aea74b5

Browse files
authored
Correct CLI and add tests. (#1425)
1 parent b51858f commit aea74b5

File tree

5 files changed

+51
-4
lines changed

5 files changed

+51
-4
lines changed

bindings/wasm/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ lib/*.d.ts
77
lib/*.d.ts.map
88
dist/
99
coverage/
10+
test/results

bindings/wasm/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Please see our usage [examples](https://github.com/elalish/manifold/tree/master/
3434

3535
## Command Line Interface
3636

37-
ManifoldCAD now has a [command line interface](./bin/manifold-cad). It can be run directly as `./bin/manifold-cad`, or via npx: `npx manifold-cad`.
37+
ManifoldCAD has a [command line interface](./bin/manifold-cad). It can be run directly as `./bin/manifold-cad`. It can also be run via `npx`. If Manifold is not already present, use `npx manifold-3d manifold-cad` or `npx manifold-3d`. If Manifold is already installed, `npx manifold-cad` will suffice.
3838

3939
```
4040
Usage: manifold-cad [options] <infile.js> <outfile>

bindings/wasm/bin/manifold-cad

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ import {extname} from 'node:path';
1818

1919
import {Command} from 'commander';
2020

21-
import {bundleFile} from '../lib/bundle.js';
21+
import {bundleFile} from '../lib/bundler.js';
2222
import {Export3MF} from '../lib/export-3mf.js';
2323
import {ExportGLTF} from '../lib/export-gltf.js';
2424
import * as worker from '../lib/worker.js';
25-
import {BundlerError,EvaluatorError} from '../lib/error.js';
2625

2726
const exporters = [
2827
new Export3MF(),

bindings/wasm/lib/bundler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ export const esbuildManifoldPlugin = (options: BundlerOptions = {}):
100100
(async () => {
101101
const {resolve, dirname} = await import('node:path');
102102
const {fileURLToPath} = await import('node:url');
103-
const dir = __dirname ?? import.meta?.dirname ??
103+
const dir = ('string' == typeof __dirname && __dirname) ||
104+
('string' == typeof import.meta?.dirname && import.meta.dirname) ||
104105
dirname(fileURLToPath(import.meta.url));
105106
manifoldCADExportPath = resolve(dir, './manifoldCAD.ts');
106107
})();

bindings/wasm/test/cli.test.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright 2025 The Manifold Authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import {exec as execSync} from 'child_process';
16+
import {glob} from 'glob';
17+
import * as fs from 'node:fs/promises';
18+
import * as path from 'path';
19+
import {promisify} from 'util';
20+
import {beforeAll, expect, suite, test} from 'vitest';
21+
22+
const exec = promisify(execSync);
23+
24+
const resultPath = path.resolve(import.meta.dirname, './results/cli/')
25+
26+
beforeAll(async () => {
27+
await fs.mkdir(resultPath, {recursive: true});
28+
});
29+
30+
const execCLI =
31+
async (infile: string, outfile: string = `${resultPath}/${infile}.glb`) => {
32+
const cmd = [
33+
'../bin/manifold-cad', `"./fixtures/${infile}"`, `"${outfile}"`
34+
].join(' ');
35+
return await exec(cmd, {cwd: import.meta.dirname});
36+
};
37+
38+
suite('When executed, the CLI will', () => {
39+
test('Successfully build a known-good model', async () => {
40+
await expect(execCLI('unitSphere.mjs')).resolves.toBeDefined();
41+
});
42+
43+
test('Fail to build a known-bad model', async () => {
44+
await expect(execCLI('unitSphereNoManifoldImport.mjs')).rejects.toThrow();
45+
});
46+
});

0 commit comments

Comments
 (0)