Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ src/generated/
.DS_Store
*.log
.env*
lib/
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,28 @@ Open `http://127.0.0.1:3000`.

## Command line

Install the `decoder` command from npm (Node.js 22.12 or newer):

```sh
npm run decoder -- init example.decoder.json "Example system"
npm run decoder -- validate example.decoder.json
npm run decoder -- preview example.decoder.json
npm run decoder -- render example.decoder.json plate.svg patent
npm run decoder -- package example.decoder.json exhibit.html
npm install -g primitive-decoder
```

```sh
decoder init example.decoder.json "Example system"
decoder validate example.decoder.json
decoder preview example.decoder.json
decoder render example.decoder.json plate.svg patent
decoder package example.decoder.json exhibit.html
```

Or run it once without installing: `npx primitive-decoder validate example.decoder.json`. In a checkout of this repository, use `npm run decoder -- <command>`.

The same engine is available as a library:

```js
import { DecoderSDK } from 'primitive-decoder';

const report = new DecoderSDK().validate(project);
```

`package` writes one self-contained HTML file: the same renderer and simulation as the Studio, the project data, and a vector fallback plate for devices without WebGL. It makes no network requests.
Expand Down
43 changes: 25 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 42 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
{
"name": "primitive-decoder",
"version": "0.1.0",
"private": true,
"description": "Local-first procedural system visualisation engine",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "https://github.com/Primitivelabai/decoder.git"
},
"homepage": "https://primitivelabai.github.io/decoder/",
"bugs": "https://github.com/Primitivelabai/decoder/issues",
"keywords": [
"3d",
"visualisation",
"diagram",
"exploded-view",
"technical-illustration",
"three",
"cli"
],
"type": "module",
"bin": {
"decoder": "lib/cli.js"
},
"exports": {
".": {
"types": "./lib/types/sdk/index.d.ts",
"import": "./lib/index.js"
},
"./package.json": "./package.json"
},
"types": "./lib/types/sdk/index.d.ts",
"files": [
"lib",
"skills",
"THIRD_PARTY_NOTICES.md"
],
"engines": {
"node": ">=22.12"
},
Expand All @@ -31,32 +57,35 @@
"pretest": "npm run bundle:standalone",
"predecoder": "npm run bundle:standalone",
"preverify:exports": "npm run bundle:standalone",
"prelint": "npm run bundle:standalone"
"prelint": "npm run bundle:standalone",
"build:package": "npm run bundle:standalone && node scripts/build-package.mjs",
"prepack": "npm run build:package",
"prepublishOnly": "npm run check"
},
"dependencies": {
"@fontsource/geist": "^5.3.0",
"@fontsource/geist-mono": "^5.3.0",
"@fontsource/space-grotesk": "^5.3.0",
"@types/three": "^0.187.0",
"ajv": "^8.20.0",
"lucide-react": "^0.546.0",
"react": "^19.0.1",
"react-dom": "^19.0.1",
"three": "^0.187.0",
"three-bvh-csg": "^0.0.19",
"three-gpu-pathtracer": "^0.0.28",
"three-mesh-bvh": "^0.10.0"
"three": "^0.187.0"
},
"devDependencies": {
"@fontsource/geist": "^5.3.0",
"@fontsource/geist-mono": "^5.3.0",
"@fontsource/space-grotesk": "^5.3.0",
"@tailwindcss/vite": "^4.3.3",
"@types/node": "^22.14.0",
"@types/react": "^19.3.0",
"@types/react-dom": "^19.3.0",
"@types/three": "^0.187.0",
"@vitejs/plugin-react": "^6.1.1",
"esbuild": "^0.28.0",
"lucide-react": "^0.546.0",
"playwright": "^1.65.0",
"prettier": "^3.10.1",
"react": "^19.0.1",
"react-dom": "^19.0.1",
"tailwindcss": "^4.3.3",
"three-bvh-csg": "^0.0.19",
"three-gpu-pathtracer": "^0.0.28",
"three-mesh-bvh": "^0.10.0",
"tsx": "^4.21.0",
"typescript": "^7.0.2",
"vite": "^8.3.0"
Expand Down
59 changes: 59 additions & 0 deletions scripts/build-package.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Builds the npm package: the SDK and the `decoder` command as ES modules in lib/,
// with type declarations for the SDK.
//
// Runtime dependencies stay external. The three.js add-ons (three-bvh-csg and friends)
// are bundled from their ES module builds, because Node would otherwise load their
// CommonJS builds and with them a second copy of three.
import { build } from 'esbuild';
import { execFileSync } from 'node:child_process';
import { existsSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
import { dirname, join, resolve } from 'node:path';

const pkg = JSON.parse(readFileSync('package.json', 'utf8'));
const external = Object.keys(pkg.dependencies ?? {}).flatMap((name) => [name, `${name}/*`]);

rmSync('lib', { recursive: true, force: true });

await build({
entryPoints: { index: 'src/sdk/index.ts', cli: 'cli/decoder.ts' },
outdir: 'lib',
bundle: true,
splitting: true,
format: 'esm',
platform: 'node',
target: 'node22',
mainFields: ['module', 'main'],
external,
chunkNames: 'chunks/[name]-[hash]',
legalComments: 'inline',
logLevel: 'warning',
});

execFileSync(process.execPath, ['node_modules/typescript/bin/tsc', '-p', 'tsconfig.package.json'], {
stdio: 'inherit',
});

// Node's ES module resolution needs explicit extensions in relative imports,
// including the ones inside declaration files.
const relativeImport = /(from\s+|import\s*\(\s*)(['"])(\.{1,2}\/[^'"]+)\2/g;
for (const file of walk('lib/types')) {
if (!file.endsWith('.d.ts')) continue;
const source = readFileSync(file, 'utf8');
const fixed = source.replace(relativeImport, (match, lead, quote, specifier) => {
const target = resolve(dirname(file), specifier);
if (existsSync(`${target}.d.ts`)) return `${lead}${quote}${specifier}.js${quote}`;
if (existsSync(join(target, 'index.d.ts'))) return `${lead}${quote}${specifier}/index.js${quote}`;
return match;
});
if (fixed !== source) writeFileSync(file, fixed);
}

console.log('Package built in lib/');

function* walk(dir) {
for (const name of readdirSync(dir)) {
const path = join(dir, name);
if (statSync(path).isDirectory()) yield* walk(path);
else yield path;
}
}
13 changes: 13 additions & 0 deletions tsconfig.package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"declaration": true,
"emitDeclarationOnly": true,
"allowImportingTsExtensions": false,
"rootDir": "./src",
"outDir": "./lib/types",
"types": []
},
"include": ["src/sdk/index.ts"]
}
Loading