@tscircuit/cli 0.0.255 → 0.0.257
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bun.lockb +0 -0
- package/cli/lib/cmd-fns/export-pnp-csv.ts +32 -0
- package/cli/lib/cmd-fns/index.ts +1 -0
- package/cli/lib/get-program.ts +11 -0
- package/cli/tests/export-pnp-csv.test.ts +24 -0
- package/dist/cli.js +77 -54
- package/package.json +2 -2
package/bun.lockb
CHANGED
|
Binary file
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod"
|
|
2
|
+
import { exportPnpCsvToBuffer } from "../export-fns/export-pnp-csv"
|
|
3
|
+
import { AppContext } from "../util/app-context"
|
|
4
|
+
import fs from "fs/promises"
|
|
5
|
+
import kleur from "kleur"
|
|
6
|
+
|
|
7
|
+
export const exportPnpCsv = async (ctx: AppContext, args: any) => {
|
|
8
|
+
const params = z
|
|
9
|
+
.object({
|
|
10
|
+
file: z.string().optional(),
|
|
11
|
+
input: z.string().optional(),
|
|
12
|
+
export: z.string().optional(),
|
|
13
|
+
outputfile: z.string().optional().default("pnp.csv"),
|
|
14
|
+
})
|
|
15
|
+
.refine((data) => data.file || data.input, {
|
|
16
|
+
message: "Either 'file' or 'input' must be provided",
|
|
17
|
+
})
|
|
18
|
+
.parse(args)
|
|
19
|
+
|
|
20
|
+
const inputFile = params.input || params.file
|
|
21
|
+
|
|
22
|
+
const pnpCsvBuffer = await exportPnpCsvToBuffer(
|
|
23
|
+
{
|
|
24
|
+
example_file_path: inputFile!,
|
|
25
|
+
export_name: params.export,
|
|
26
|
+
},
|
|
27
|
+
ctx,
|
|
28
|
+
)
|
|
29
|
+
console.log(kleur.gray(`[writing to ${params.outputfile}]...`))
|
|
30
|
+
await fs.writeFile(params.outputfile, pnpCsvBuffer)
|
|
31
|
+
console.log(kleur.green(`Pnp CSV file exported to ${params.outputfile}`))
|
|
32
|
+
}
|
package/cli/lib/cmd-fns/index.ts
CHANGED
|
@@ -38,6 +38,7 @@ export { configClear } from "./config-clear"
|
|
|
38
38
|
export { openCmd as open } from "./open"
|
|
39
39
|
export { versionCmd as version } from "./version"
|
|
40
40
|
export { exportGerbersCmd as exportGerbers } from "./export-gerbers"
|
|
41
|
+
export { exportPnpCsv } from "./export-pnp-csv"
|
|
41
42
|
export { exportKicadPcb } from "./export-kicad-pcb"
|
|
42
43
|
export { devServerFulfillExportRequests } from "./dev-server-fulfill-export-requests"
|
|
43
44
|
export { lintCmd as lint } from "./lint"
|
package/cli/lib/get-program.ts
CHANGED
|
@@ -304,6 +304,17 @@ export const getProgram = (ctx: AppContext) => {
|
|
|
304
304
|
.option("--outputfile <outputfile>", "Output file name", "output.kicad_pcb")
|
|
305
305
|
.action((args) => CMDFN.exportKicadPcb(ctx, args))
|
|
306
306
|
|
|
307
|
+
exportCmd
|
|
308
|
+
.command("pnp_csv")
|
|
309
|
+
.description("Export Plug n Play CSV file from an example file")
|
|
310
|
+
.option("--input <input>", "Input example file")
|
|
311
|
+
.option(
|
|
312
|
+
"--export <export_name>",
|
|
313
|
+
"Name of export to soupify, if not specified, soupify the default/only export",
|
|
314
|
+
)
|
|
315
|
+
.option("--outputfile <outputfile>", "Output file name", "pnp.csv")
|
|
316
|
+
.action((args) => CMDFN.exportPnpCsv(ctx, args))
|
|
317
|
+
|
|
307
318
|
cmd
|
|
308
319
|
.command("soupify")
|
|
309
320
|
.description("Convert an example file to tscircuit soup")
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { test, expect } from "bun:test"
|
|
2
|
+
import { $ } from "bun"
|
|
3
|
+
import { temporaryDirectory } from "tempy"
|
|
4
|
+
import { join } from "path/posix"
|
|
5
|
+
import { existsSync, readFileSync } from "fs"
|
|
6
|
+
|
|
7
|
+
test("tsci export pnp_csv --input example-project/examples/macrokeypad.tsx", async () => {
|
|
8
|
+
const tempDir = temporaryDirectory()
|
|
9
|
+
const pnpCsvPath = join(tempDir, "pnp.csv")
|
|
10
|
+
const { stdout, stderr } =
|
|
11
|
+
await $`bun cli/cli.ts export pnp_csv --input example-project/examples/macrokeypad.tsx --outputfile ${pnpCsvPath} --no-color`
|
|
12
|
+
|
|
13
|
+
expect(stderr.toString()).toBe("")
|
|
14
|
+
expect(stdout.toString()).toContain("pnp.csv")
|
|
15
|
+
|
|
16
|
+
expect(existsSync(pnpCsvPath)).toBe(true)
|
|
17
|
+
|
|
18
|
+
const pnpCsvContent = readFileSync(pnpCsvPath, "utf-8")
|
|
19
|
+
expect(pnpCsvContent).toContain("Designator")
|
|
20
|
+
expect(pnpCsvContent).toContain("Mid X")
|
|
21
|
+
expect(pnpCsvContent).toContain("Mid Y")
|
|
22
|
+
expect(pnpCsvContent).toContain("Layer")
|
|
23
|
+
expect(pnpCsvContent).toContain("Rotation")
|
|
24
|
+
})
|