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.
Merge pull request #119 from tscircuit/feat/render-image-cmd
feat: new `render` image command added
- Loading branch information
Showing
5 changed files
with
351 additions
and
43 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
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,45 @@ | ||
import { circuitToPng } from "circuit-to-png" | ||
import fs from "fs" | ||
import { soupify } from "lib/soupify" | ||
import type { AppContext } from "lib/util/app-context" | ||
import path from "path" | ||
|
||
export const renderCmd = async ( | ||
ctx: AppContext, | ||
args: { | ||
input: string | ||
pcb?: boolean | ||
schematic?: boolean | ||
output?: string | ||
type?: string | ||
}, | ||
) => { | ||
const inputFile = path.resolve(args.input) | ||
let outputFile = args.output | ||
const outputType = | ||
args.type || path.extname(args.output || "").slice(1) || "png" | ||
|
||
if (!outputFile) { | ||
const inputBase = path.basename(inputFile, path.extname(inputFile)) | ||
outputFile = `${inputBase}.${outputType}` | ||
} | ||
|
||
if (!args.pcb && !args.schematic) { | ||
console.error("Error: You must specify either --pcb or --schematic") | ||
process.exit(1) | ||
} | ||
|
||
const viewType = args.pcb ? "pcb" : "schematic" | ||
|
||
console.log(`Rendering ${viewType} view of ${inputFile} to ${outputFile}`) | ||
const soup = await soupify( | ||
{ | ||
filePath: inputFile, | ||
}, | ||
ctx, | ||
) | ||
|
||
const soupBuffer = circuitToPng(soup, viewType) | ||
|
||
fs.writeFileSync(outputFile, soupBuffer) | ||
} |
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
Oops, something went wrong.