This repository has been archived by the owner on Jan 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement command function to generate jlcpcb component
- Loading branch information
1 parent
bc1f627
commit a9b89fb
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters