Skip to content

Commit

Permalink
Add Support for Polygon, Add Typecheck and Formatcheck github workflo…
Browse files Browse the repository at this point in the history
…ws (#6)

* Add Support for Polygon, Add Typecheck and Formatcheck github workflows

* fix name inside typecheck yml
  • Loading branch information
seveibar authored Jul 8, 2024
1 parent f07c26e commit 756370a
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 7 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/formatcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Format Check

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
format-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: '22'

- name: Install dependencies
run: npm ci

- name: Run format check
run: npm run format:check
25 changes: 25 additions & 0 deletions .github/workflows/typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Type Check

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
type-check:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "22"

- name: Install dependencies
run: npm ci

- name: Run format check
run: npx tsc --noEmit
41 changes: 41 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"organizeImports": {
"enabled": true
},
"formatter": {
"enabled": true,
"indentStyle": "space"
},
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingCommas": "all",
"semicolons": "asNeeded",
"arrowParentheses": "always",
"bracketSpacing": true,
"bracketSameLine": false
}
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"suspicious": {
"noExplicitAny": "off"
},
"style": {
"noNonNullAssertion": "off",
"useFilenamingConvention": {
"level": "error",
"options": {
"strictCase": true,
"requireAscii": true,
"filenameCases": ["kebab-case", "export"]
}
}
}
}
}
}
18 changes: 18 additions & 0 deletions examples/polygon.fixture.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { JsCadFixture } from "../lib/components/jscad-fixture"
import { Polygon } from "../lib/jscad-fns/polygon"

export default () => (
<JsCadFixture wireframe>
<Polygon
points={[
[-2, -1],
[2, -1],
[2.5, 2],
[1, 1],
[0, 2],
[-1, 1],
[-2, 2],
]}
/>
</JsCadFixture>
)
31 changes: 25 additions & 6 deletions lib/create-host-config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import type ReactReconciler from "react-reconciler"
import type {
CuboidProps,
CylinderEllipticProps,
CylinderProps,
EllipsoidProps,
GeodesicSphereProps,
RoundedCuboidProps,
RoundedCylinderProps,
SphereProps,
TorusProps,
} from "./jscad-fns"
import type { JSCADModule, JSCADPrimitive } from "./jscad-primitives"
import type { PolygonProps } from "./jscad-fns/polygon"

export function createHostConfig(jscad: JSCADModule) {
const hostConfig: ReactReconciler.HostConfig<
string, // Type
Expand Down Expand Up @@ -79,6 +94,10 @@ export function createHostConfig(jscad: JSCADModule) {
radius: (props as TorusProps).radius,
tube: (props as TorusProps).tube,
})
case "jscadpolygon":
return jscad.primitives.polygon({
points: (props as PolygonProps).points,
})
default:
throw new Error(`Unknown element type: ${type}`)
}
Expand Down Expand Up @@ -134,7 +153,7 @@ export function createHostConfig(jscad: JSCADModule) {
prepareForCommit() {
return null
},
resetAfterCommit() { },
resetAfterCommit() {},
getPublicInstance(instance: JSCADPrimitive) {
return instance
},
Expand All @@ -147,18 +166,18 @@ export function createHostConfig(jscad: JSCADModule) {
shouldSetTextContent() {
return false
},
clearContainer() { },
clearContainer() {},
scheduleTimeout: setTimeout,
cancelTimeout: clearTimeout,
noTimeout: -1,
isPrimaryRenderer: true,
getCurrentEventPriority: () => 99,
getInstanceFromNode: () => null,
beforeActiveInstanceBlur: () => { },
afterActiveInstanceBlur: () => { },
prepareScopeUpdate: () => { },
beforeActiveInstanceBlur: () => {},
afterActiveInstanceBlur: () => {},
prepareScopeUpdate: () => {},
getInstanceFromScope: () => null,
detachDeletedInstance: () => { },
detachDeletedInstance: () => {},
}
return hostConfig
}
7 changes: 7 additions & 0 deletions lib/jscad-fns/polygon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type PolygonProps = {
points: [number, number][]
}

export function Polygon({ points }: PolygonProps) {
return <jscadpolygon points={points} />
}
4 changes: 4 additions & 0 deletions lib/jscad-primitives.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Define a type for the JSCAD module structure we expect
export interface JSCADModule {
primitives: {
polygon: (options: {
points: [number, number][]
}) => any
cube: (options: {
size: number | [number, number, number]
}) => any
Expand Down Expand Up @@ -50,6 +53,7 @@ export type JSCADPrimitive =
| ReturnType<JSCADModule["primitives"]["roundedCylinder"]>
| ReturnType<JSCADModule["primitives"]["cylinderElliptic"]>
| ReturnType<JSCADModule["primitives"]["torus"]>
| ReturnType<JSCADModule["primitives"]["polygon"]>
export type JSCADOperation =
| JSCADModule["booleans"]["union"]
| JSCADModule["booleans"]["subtract"]
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"scripts": {
"start": "cosmos",
"build": "cosmos-export",
"predeploy": "BUILD_FOR_GH_PAGES=1 npm run build"
"predeploy": "BUILD_FOR_GH_PAGES=1 npm run build",
"format": "biome format . --write",
"format:check": "biome format . --check"
},
"devDependencies": {
"@jscad/modeling": "^2.12.2",
Expand Down

0 comments on commit 756370a

Please sign in to comment.