Replace Makefile w/ something that reads the libs metadata

Fixes #122
This commit is contained in:
Jonathan Hornung 2025-08-15 08:57:49 +02:00
commit b8d8f545b0
5 changed files with 616 additions and 301 deletions

View file

@ -36,7 +36,7 @@ Licenses: see [LICENSES](./LICENSE).
- Animation rendering (And other formats than STL)
- [x] Compress URL fragment
- [x] Mobile (iOS) editing support: switch to https://www.npmjs.com/package/react-codemirror ?
- [ ] Replace Makefile w/ something that reads the libs metadata
- [x] Replace Makefile w/ something that reads the libs metadata
- [ ] Merge modifiers rendering code to openscad
- Model /home fs in shared state. have two clear paths: /libraries for builtins, and /home for user data. State pointing to /libraries paths needs not store the data except if there's overrides (flagged as modifications in the file picker)
- Drag and drop of files (SCAD, STL, etc) and Zip archives. For assets, auto insert the corresponding import.
@ -49,10 +49,12 @@ Licenses: see [LICENSES](./LICENSE).
## Building
Prerequisites:
* wget
* GNU make
* wget or curl
* Node.js (>=18.12.0)
* npm
* Docker able to run amd64 containers. If running on a different platform (including Silicon Mac), you can add support for amd64 images through QEMU with:
* git
* zip
* Docker able to run amd64 containers (only needed if building WASM from source). If running on a different platform (including Silicon Mac), you can add support for amd64 images through QEMU with:
```bash
docker run --privileged --rm tonistiigi/binfmt --install all
@ -61,27 +63,26 @@ Prerequisites:
Local dev:
```bash
make public
npm run build:libs # Download WASM and build all OpenSCAD libraries
npm install
npm start
npm run start
# http://localhost:4000/
```
Local prod (test both the different inlining and serving under a prefix):
```bash
make public
npm run build:libs # Download WASM and build all OpenSCAD libraries
npm install
npm run start:prod
npm run start:production
# http://localhost:3000/dist/
```
Deployment (edit "homepage" in `package.json` to match your deployment root!):
```bash
make public
npm run build:all # Build libraries and compile the application
npm install
NODE_ENV=production npm run build
rm -fR ../ochafik.github.io/openscad2 && cp -R dist ../ochafik.github.io/openscad2
# Now commit and push changes, wait for site update and enjoy!
@ -104,24 +105,45 @@ rm -fR ../ochafik.github.io/openscad2 && cp -R dist ../ochafik.github.io/opensca
- Build WASM binary (add `WASM_BUILD=Debug` argument if you'd like to debug any cryptic crashes):
```bash
make wasm
npm run build:libs:wasm
```
- Then continue the build:
```bash
make public
npm start
npm run build:libs
npm run start
```
## Adding OpenSCAD libraries
You'll need to update 3 files (search for BOSL2 for an example):
- [Makefile](./Makefile): to pull the library's code (optionally alias some files for easier imports) and package it as a `.zip` archive
- [libs-config.json](./libs-config.json): to add the library's metadata including repository URL, branch, and files to include/exclude in the zip archive
- [src/fs/zip-archives.ts](./src/fs/zip-archives.ts): to use the `.zip` archive in the UI (both for file explorer and automatic imports mounting)
- [LICENSE.md](./LICENSE.md): most libraries require proper disclosure of their usage and of their license. If a license is unique, paste it in full, otherwise, link to one of the standard ones already there.
### Library Configuration Format
In `libs-config.json`, add an entry like this:
```json
{
"name": "LibraryName",
"repo": "https://github.com/user/repo.git",
"branch": "main",
"zipIncludes": ["*.scad", "LICENSE", "examples"],
"zipExcludes": ["**/tests/**"],
"workingDir": "."
}
```
Available build commands:
- `npm run build:libs` - Build all libraries
- `npm run build:libs:clean` - Clean all build artifacts
- `npm run build:libs:wasm` - Download/build just the WASM binary
- `npm run build:libs:fonts` - Download/build just the fonts
Send us a PR, then once it's merged request an update to the hosted https://ochafik.com/openscad2 demo.