Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
Implement command function to generate jlcpcb component
Browse files Browse the repository at this point in the history
  • Loading branch information
andrii-balitskyi committed Sep 26, 2024
1 parent bc1f627 commit a9b89fb
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
51 changes: 51 additions & 0 deletions cli/lib/cmd-fns/gen-jlcpcb-component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import path from "path"
import fs from "fs/promises"
import { spawn } from "bun"
import { AppContext } from "../util/app-context"

export const genJlcpcbComponent = async (
ctx: AppContext,
args: { partNumber: string },
) => {
const normalizedPartNumber = args.partNumber.toUpperCase()

const baseCommand = "easyeda"
const generatorExecutable = path.resolve(
ctx.cwd,
"node_modules/.bin",
process.platform === "win32" ? `${baseCommand}.cmd` : baseCommand,
)

const outputDir = path.resolve(ctx.cwd, "gen")
const outputFile = path.join(outputDir, `${normalizedPartNumber}.tsx`)

await fs.mkdir(outputDir, { recursive: true })

const cmd = [
generatorExecutable,
"convert",
"-i",
normalizedPartNumber,
"-o",
outputFile,
"-t",
"tsx",
]

const proc = spawn({
cmd,
stdout: "inherit",
stderr: "pipe",
})

const exitCode = await proc.exited

if (exitCode !== 0) {
const stderr = await new Response(proc.stderr).text()
throw new Error(
`JLCPCB component generation failed with exit code ${exitCode}: ${stderr}`,
)
}

console.log(`Generated JLCPCB component at: ${outputFile}`)
}
1 change: 1 addition & 0 deletions cli/lib/cmd-fns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ export { exportKicadPcb } from "./export-kicad-pcb"
export { devServerFulfillExportRequests } from "./dev-server-fulfill-export-requests"
export { lintCmd as lint } from "./lint"
export { renderCmd as render } from "./render"
export { genJlcpcbComponent } from "./gen-jlcpcb-component"

0 comments on commit a9b89fb

Please sign in to comment.