@rulecad/cad 0.3.1 → 0.3.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.
Files changed (2) hide show
  1. package/bin/cad.mjs +9 -3
  2. package/package.json +2 -2
package/bin/cad.mjs CHANGED
@@ -12,7 +12,7 @@ import { git, tags, bump, bigger, newer, compare, snapshot, materialise, files,
12
12
  import { check } from '@rulecad/printcheck';
13
13
  import { preview } from '../lib/preview.mjs';
14
14
  import { isAssembly, buildAssembly, checkAssembly, shapes } from '../lib/assembly.mjs';
15
- import { fromParts, fromShapes, encode } from '@rulecad/model-link';
15
+ import { fromParts, fromShapes, encode, check as checkLink, expand } from '@rulecad/model-link';
16
16
  import { threemf, slotOf } from '../lib/threemf.mjs';
17
17
 
18
18
  // The project's filaments: { base: { slot: 1, … }, legend: { slot: 2, … } } in project.json
@@ -31,6 +31,12 @@ function filamentNotes(parts, fil) {
31
31
  const openInSlicer = (f) => (process.platform === 'darwin' ? execFileSync('open', ['-a', 'Bambu Studio', f])
32
32
  : execFileSync(process.platform === 'win32' ? 'explorer' : 'xdg-open', [f]));
33
33
  const VIEW = process.env.CAD_VIEW_URL || config.viewUrl;
34
+ // A link to the model page; one the page would turn away is an error here, not when someone opens it
35
+ async function linkTo(model) {
36
+ const errors = checkLink(model.shapes ? expand(model) : model);
37
+ if (errors.length) throw new Error(`no link: ${errors[0]}`);
38
+ return `${VIEW}#m=${await encode(model)}`;
39
+ }
34
40
 
35
41
  const HELP = `cad: JSCAD designs you can trace, check, share and print (rulecad)
36
42
 
@@ -278,7 +284,7 @@ async function assembly(cmd, ref) {
278
284
  return placed.place.map(([i, ...m], n) => { const p = placed.shapes[i].part; return { shape: i, role: p.role, label: p.object || p.label, slot: slotOf(fil, p.filament), triangles: tri(placed.shapes[i].triangles), matrix: m, name: s.parts[n].name }; });
279
285
  })() : []),
280
286
  };
281
- const url = `${VIEW}#m=${await encode(model)}`;
287
+ const url = await linkTo(model);
282
288
  return { view: url, stl: `${url}&get=stl`, '3mf': `${url}&get=3mf`, src: model.src, size: url.length, title, version: '' };
283
289
  };
284
290
  if (cmd === 'link') return await printLinks(await link());
@@ -309,7 +315,7 @@ async function links(d, b, set) {
309
315
  ...(b.circuit ? { views: await (await pcbEngine()).views(b.circuit) } : {}), // boards: the 2D board and schematic
310
316
  ...fromParts(b.parts.map((p) => ({ name: p.name, role: p.role, label: p.label, slot: slotOf(fil, p.filament), triangles: p.triangles.flatMap((t) => t.slice(1, -1).map((_, i) => [t[0], t[i + 1], t[i + 2]])) }))),
311
317
  };
312
- const url = `${VIEW}#m=${await encode(model)}`;
318
+ const url = await linkTo(model);
313
319
  return { view: url, stl: `${url}&get=stl`, '3mf': `${url}&get=3mf`, src, size: url.length, title: model.title, version };
314
320
  }
315
321
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/cad",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "The cad command: JSCAD designs from traceable rules, checked for printing and fit, versioned by what fits, shared as links and exported as Bambu 3MF.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -47,7 +47,7 @@
47
47
  "@rulecad/keyboard-layout": "^0.1.2",
48
48
  "@rulecad/printcheck": "^0.1.0",
49
49
  "@rulecad/fit": "^0.2.0",
50
- "@rulecad/model-link": "^0.1.2",
50
+ "@rulecad/model-link": "^0.1.4",
51
51
  "@rulecad/versions": "^0.1.0",
52
52
  "@rulecad/shapes": "^0.2.0",
53
53
  "@rulecad/rules": "^0.2.0",