Skip to content

Commit

Permalink
Merge pull request #8 from tscircuit/usage
Browse files Browse the repository at this point in the history
Major Refactor, improve code separation, add tests, add build, release, add stringification, add README usage examples
  • Loading branch information
seveibar authored Oct 30, 2024
2 parents 3a82e99 + 65d7338 commit efab340
Show file tree
Hide file tree
Showing 24 changed files with 1,493 additions and 1,087 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/bun-formatcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
name: Format Check

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

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

steps:
- uses: actions/checkout@v3

- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: bun install

- name: Run format check
run: bun run format:check
24 changes: 24 additions & 0 deletions .github/workflows/bun-pver-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
name: Publish to npm
on:
push:
branches:
- main
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- uses: actions/setup-node@v3
with:
node-version: 20
registry-url: https://registry.npmjs.org/
- run: npm install -g pver
- run: bun install --frozen-lockfile
- run: pver release
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
25 changes: 25 additions & 0 deletions .github/workflows/bun-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
name: Bun Test

on:
pull_request:

jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 5

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: bun install

- name: Run tests
run: bun test
26 changes: 26 additions & 0 deletions .github/workflows/bun-typecheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Created using @tscircuit/plop (npm install -g @tscircuit/plop)
name: Type Check

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

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

steps:
- uses: actions/checkout@v3

- name: Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install dependencies
run: bun i

- name: Run type check
run: bunx tsc --noEmit
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,6 @@ dist

# Finder (MacOS) folder config
.DS_Store
.aider*

.vscode
101 changes: 100 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,102 @@
# dsn-converter

Convert to and frmo DSN to tscircuit components or circuit JSON
A TypeScript library for converting between DSN files and Circuit JSON format.

## Overview

dsn-converter is a powerful tool that enables bidirectional conversion between Specctr DSN format and Circuit JSON. This makes it possible to:

- Parse Specctra DSN files into a workable JSON format
- Convert Circuit JSON back into KiCad-compatible DSN files
- Visualize PCB designs using SVG rendering

## Installation

```bash
# Using bun
bun add dsn-converter

# Using npm
npm install dsn-converter
```

## Usage

### Converting DSN to Circuit JSON

```typescript
import { parseDsnToCircuitJson } from "dsn-converter"

const dsnContent = await Bun.file("your-design.dsn").text()

const circuitJson = parseDsnToCircuitJson(dsnContent)

await Bun.write("output.circuit.json", JSON.stringify(circuitJson, null, 2))
```

### Converting Circuit JSON to DSN

```typescript
import { circuitJsonToDsnString } from "dsn-converter"

const dsnString = circuitJsonToDsnString(circuitJson)

await Bun.write("output.dsn", dsnString)
```

## Features

- **Complete DSN Support**: Handles all major DSN file components including:

- Component placement
- PCB layers
- Traces and wiring
- Padstacks and SMT pads
- Net definitions
- Board boundaries

- **Accurate Conversions**: Maintains precise measurements and positions during conversion

- **Type Safety**: Full TypeScript support with comprehensive type definitions

## Data Structure

### DSN Format

The DSN format is represented as a structured JSON with the following main sections:

- `parser`: Contains file metadata
- `resolution`: Defines measurement units
- `structure`: Describes board layers and rules
- `placement`: Component positions
- `library`: Component and padstack definitions
- `network`: Net connections
- `wiring`: Trace routing

### Circuit JSON

The Circuit JSON format includes:

- PCB traces
- SMT pads
- Component definitions
- Layer information
- Routing data

## Development

```bash
# Install dependencies
bun install

# Run tests
bun test

# Run specific test file
bun test tests/dsn-pcb/parse-dsn-pcb.test.ts
```

## Acknowledgments

- Built with [Bun](https://bun.sh)
- Uses [tscircuit](https://github.com/tscircuit/tscircuit)
7 changes: 6 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://biomejs.dev/schemas/1.7.3/schema.json",
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
"organizeImports": {
"enabled": true
},
Expand Down Expand Up @@ -28,7 +28,12 @@
"suspicious": {
"noExplicitAny": "off"
},
"complexity": {
"noForEach": "off"
},
"style": {
"noUnusedTemplateLiteral": "off",
"noUselessElse": "off",
"noNonNullAssertion": "off",
"useNumberNamespace": "off",
"useFilenamingConvention": {
Expand Down
Binary file modified bun.lockb
Binary file not shown.
Loading

0 comments on commit efab340

Please sign in to comment.