-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce CLI, fix slot issues from experiments w/ jlcpcb
- Loading branch information
Showing
5 changed files
with
81 additions
and
2 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 |
---|---|---|
|
@@ -184,3 +184,5 @@ gerber-output | |
gerber-output.zip | ||
.aider* | ||
*.diff.png | ||
|
||
tmp* |
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,71 @@ | ||
#!/usr/bin/env node | ||
|
||
import { program } from "commander" | ||
import { readFile, writeFile } from "node:fs/promises" | ||
import { createWriteStream } from "node:fs" | ||
import { resolve, dirname, basename } from "node:path" | ||
import { fileURLToPath } from "node:url" | ||
import archiver from "archiver" | ||
import { convertSoupToGerberCommands, stringifyGerberCommandLayers } from "./" | ||
import { convertSoupToExcellonDrillCommands, stringifyExcellonDrill } from "./" | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
|
||
program | ||
.name("circuit-to-gerber") | ||
.description("Convert circuit JSON files to Gerber/Excellon files") | ||
.argument("<input>", "Input circuit JSON file (*.circuit.json)") | ||
.option( | ||
"-o, --output <file>", | ||
"Output ZIP file (defaults to input.gerbers.zip)", | ||
) | ||
.action(async (input, options) => { | ||
try { | ||
// Read and parse input JSON | ||
const circuitJson = JSON.parse(await readFile(input, "utf8")) | ||
|
||
// Convert to gerber commands | ||
const gerberCmds = convertSoupToGerberCommands(circuitJson) | ||
const excellonDrillCmds = convertSoupToExcellonDrillCommands({ | ||
circuitJson, | ||
is_plated: true, | ||
}) | ||
const excellonDrillUnplatedCmds = convertSoupToExcellonDrillCommands({ | ||
circuitJson, | ||
is_plated: false, | ||
}) | ||
|
||
// Stringify all outputs | ||
const gerberOutput = stringifyGerberCommandLayers(gerberCmds) | ||
const excellonDrillOutput = stringifyExcellonDrill(excellonDrillCmds) | ||
const excellonDrillUnplatedOutput = stringifyExcellonDrill( | ||
excellonDrillUnplatedCmds, | ||
) | ||
|
||
// Create output ZIP file | ||
const outputPath = | ||
options.output || input.replace(".circuit.json", ".gerbers.zip") | ||
const output = createWriteStream(outputPath) | ||
const archive = archiver("zip", { zlib: { level: 9 } }) | ||
|
||
archive.pipe(output) | ||
|
||
// Add all gerber files to ZIP | ||
for (const [filename, content] of Object.entries(gerberOutput)) { | ||
archive.append(content, { name: `${filename}.gbr` }) | ||
} | ||
|
||
// Add drill files | ||
archive.append(excellonDrillOutput, { name: "plated.drl" }) | ||
archive.append(excellonDrillUnplatedOutput, { name: "unplated.drl" }) | ||
|
||
await archive.finalize() | ||
|
||
console.log(`Created ${outputPath}`) | ||
} catch (err) { | ||
console.error("Error:", (err as Error).message) | ||
process.exit(1) | ||
} | ||
}) | ||
|
||
program.parse() |
2 changes: 1 addition & 1 deletion
2
src/gerber/convert-soup-to-gerber-commands/getCommandHeaders.ts
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