Skip to content

Commit

Permalink
Merge pull request #66 from tscircuit/add-spn
Browse files Browse the repository at this point in the history
add supplierPartNumbers prop
  • Loading branch information
seveibar authored Oct 15, 2024
2 parents 48b64bd + 7a8f650 commit 531d25a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
19 changes: 12 additions & 7 deletions lib/convert-to-typescript-component/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ export const convertBetterEasyToTsx = async ({

// Derive pinLabels from easyeda json
const pinLabels: Record<string, string> = {}
betterEasy.dataStr.shape
.filter((shape) => shape.type === "PIN")
.forEach((pin) => {
const isPinLabelNumeric = /^\d+$/.test(pin.label)
const label = isPinLabelNumeric ? `pin${pin.label}` : pin.label
for (const shape of betterEasy.dataStr.shape) {
if (shape.type === "PIN") {
const isPinLabelNumeric = /^\d+$/.test(shape.label)
const label = isPinLabelNumeric ? `pin${shape.label}` : shape.label

pinLabels[pin.pinNumber.toString()] = label
})
pinLabels[shape.pinNumber.toString()] = label
}
}

// Derive schPinArrangement from easyeda json
const pins = betterEasy.dataStr.shape.filter((shape) => shape.type === "PIN")
Expand Down Expand Up @@ -69,12 +69,17 @@ export const convertBetterEasyToTsx = async ({
}
}

const supplierPartNumbers: Record<string, string[]> = {
lcsc: [betterEasy.lcsc.number],
}

return soupTypescriptComponentTemplate({
componentName: pn,
pinLabels,
schPinArrangement,
objUrl: modelObjUrl,
circuitJson,
supplierPartNumbers,
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface Params {
schPinArrangement: ChipProps["schPortArrangement"]
objUrl?: string
circuitJson: AnyCircuitElement[]
supplierPartNumbers: Record<string, string[]>
}

export const soupTypescriptComponentTemplate = ({
Expand All @@ -19,6 +20,7 @@ export const soupTypescriptComponentTemplate = ({
schPinArrangement,
objUrl,
circuitJson,
supplierPartNumbers,
}: Params) => {
const footprintTsx = generateFootprintTsx(circuitJson)
return `
Expand All @@ -36,7 +38,6 @@ export const ${componentName} = (props: Props) => {
return (
<chip
{...props}
footprint={${footprintTsx}}
${
objUrl
? `cadModel={{
Expand All @@ -49,6 +50,8 @@ export const ${componentName} = (props: Props) => {
pinLabels={pinLabels}
schPinSpacing={0.75}
schPortArrangement={${JSON.stringify(schPinArrangement, null, " ")}}
supplierPartNumbers={${JSON.stringify(supplierPartNumbers, null, " ")}}
footprint={${footprintTsx}}
/>
)
}
Expand Down

0 comments on commit 531d25a

Please sign in to comment.