create-rulecad 0.3.9 → 0.3.12

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/index.mjs CHANGED
@@ -11,7 +11,8 @@ import readline from 'node:readline/promises';
11
11
  import { fileURLToPath } from 'node:url';
12
12
 
13
13
  const args = process.argv.slice(2), install = !args.includes('--no-install');
14
- const dir = path.resolve(args.find((a) => !a.startsWith('--')) || 'my-designs'), name = path.basename(dir);
14
+ // The folder is the argument that isn't an option, or --share's value
15
+ const dir = path.resolve(args.find((a, i) => !a.startsWith('--') && args[i - 1] !== '--share') || 'my-designs'), name = path.basename(dir);
15
16
  if (fs.existsSync(dir) && fs.readdirSync(dir).length) { console.error(`${dir} isn't empty: name a new folder (npm create rulecad my-designs)`); process.exit(1); }
16
17
 
17
18
  const TEMPLATE = fileURLToPath(new URL('./template/', import.meta.url));
@@ -19,10 +20,14 @@ fs.cpSync(TEMPLATE, dir, { recursive: true });
19
20
  fs.renameSync(path.join(dir, 'gitignore'), path.join(dir, '.gitignore')); // npm drops files named .gitignore from packages
20
21
  const readme = path.join(dir, 'README.md');
21
22
  fs.writeFileSync(readme, fs.readFileSync(readme, 'utf8').replaceAll('NAME', name));
23
+ // The cad command a new workspace gets. Before 1.0 a caret covers one minor version only, so this follows
24
+ // @rulecad/cad's minor (the test fails when it falls behind, and a new workspace would get an old cad).
25
+ const CAD = '^0.7.0';
22
26
  // $RULECAD_LOCAL: a rulecad checkout to use instead of npm (to try unpublished changes)
23
- const from = (pkg) => (process.env.RULECAD_LOCAL ? `file:${path.join(path.resolve(process.env.RULECAD_LOCAL), 'packages', pkg)}` : '^0.4.0');
27
+ const from = (pkg) => (process.env.RULECAD_LOCAL ? `file:${path.join(path.resolve(process.env.RULECAD_LOCAL), 'packages', pkg)}` : CAD);
24
28
  fs.writeFileSync(path.join(dir, 'package.json'), `${JSON.stringify({
25
- name, private: true, type: 'module',
29
+ name: name.toLowerCase().replace(/[^a-z0-9._~-]+/g, '-').replace(/^[._-]+|-+$/g, '') || 'my-designs', // a name npm takes, whatever the folder is called
30
+ private: true, type: 'module',
26
31
  scripts: { check: 'cad check home/soap-tray' },
27
32
  dependencies: { '@rulecad/cad': from('cad'), '@jscad/modeling': '^2.12.0' },
28
33
  }, null, 2)}\n`);
@@ -30,8 +35,8 @@ fs.writeFileSync(path.join(dir, 'package.json'), `${JSON.stringify({
30
35
  console.log(`made ${path.relative(process.cwd(), dir) || '.'}: a soap tray to start from, in projects/home`);
31
36
 
32
37
  // How models are shared: short links need somewhere to keep the model (a secret Gist); long links carry it
33
- let share = args.includes('--share') ? args[args.indexOf('--share') + 1] : null;
34
- if (share && !['gist', 'long'].includes(share)) { console.error(`--share is gist or long (got "${share}")`); process.exit(1); }
38
+ let share = args.includes('--share') ? args[args.indexOf('--share') + 1] || '' : null;
39
+ if (share !== null && !['gist', 'long'].includes(share)) { console.error(`--share is gist or long (got "${share}")`); process.exit(1); }
35
40
  if (!share && process.stdin.isTTY && process.stdout.isTTY) {
36
41
  const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
37
42
  const a = await rl.question('\nModel links: short ones are easy to paste into chat, but each model you share is stored in a secret\nGitHub Gist (needs the gh command, signed in). Long ones carry the model and upload nothing. Short links? [y/N] ');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-rulecad",
3
- "version": "0.3.9",
3
+ "version": "0.3.12",
4
4
  "description": "Start a rulecad project: npm create rulecad my-designs. A workspace with a soap tray to start from, ready to check, preview, export and share.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -44,10 +44,15 @@ variable says which rule it comes from. Follow these steps; they're what makes a
44
44
  - Holes and slots get the printer's hole compensation; parts that slide together get its fit clearance. Chamfer
45
45
  bottom edges.
46
46
  - An overhang warning means supports: say so in `orientation`, or change the shape or orientation.
47
+ - A part that moves by bending (a spring, a snap, a hinge with no pin) is a flexure from `v.flexures`: drawn flat, so it
48
+ bends within its layers; give its thickness in whole lines (`x1c.line`), and check its strain at the travel against
49
+ the material's limit with `v.flexures.printable`. PLA creeps held bent and fatigues; PETG or nylon for springs.
47
50
  - Use the print-aware features in `v.shapes` before drawing your own: `countersink`, `teardropHole`, `nutPocket`,
48
51
  `crushRibs`, `wallOpening` print without supports as drawn. Use `v.ops.union/subtract/intersect` for booleans: the
49
52
  workspace can switch them to Manifold (faster, watertight) without touching the design.
50
- - Designs run sandboxed: they may import only `@jscad/modeling`, `@rulecad/shapes` and files in their project.
53
+ - Designs run sandboxed: they may import only `@jscad/modeling`, `@rulecad/shapes`, `@rulecad/flexures` and files in
54
+ their project, and can't write files or start programs. To see a value while designing, `console.log` it: it comes
55
+ out with the command's output. A misspelt `v.name` stops the build and says which name was meant.
51
56
  - Something printed under the part and removed afterwards is a named `support` part (`return { cap, pillar }`, both
52
57
  described in the .json's `parts`), not part of the shape. Look at `cad preview --explode` too.
53
58
 
@@ -90,6 +95,9 @@ variable says which rule it comes from. Follow these steps; they're what makes a
90
95
  `"overhang"` to the way up it will print, so the result needs no supports, and give horizontal bosses and holes a
91
96
  `teardrop` (`"down"`, `"up"`). Draw the part as it prints; if that isn't the problem's frame, give its `analysis` a
92
97
  `rotate` and `move` back. Build with `v.shapes.optimisedSolid(...)` and `"engine": "manifold"`; look at the four views.
98
+ The result is made printable before it's drawn (hanging cells emptied, tips lifted, loose bits dropped), but a kept
99
+ region is never emptied: if `cad optimise` says part of one has nothing holding it up, give the part more material
100
+ to stand it on, or keep less. `cad check` tests the part for one piece and nothing starting in mid-air.
93
101
  - Before reporting numbers for a final shape, verify them: give the `analysis` a smaller `cell` (solids: about a
94
102
  third of the problem's) and check the stiffness has settled (`fea.settled`). Report the verified numbers, the safety
95
103
  factor, and where the peak stress is.