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 #217 from qalbun-salim/feat/cmd-pnp-csv
- Loading branch information
Showing
4 changed files
with
68 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,32 @@ | ||
import { z } from "zod" | ||
import { exportPnpCsvToBuffer } from "../export-fns/export-pnp-csv" | ||
import { AppContext } from "../util/app-context" | ||
import fs from "fs/promises" | ||
import kleur from "kleur" | ||
|
||
export const exportPnpCsv = async (ctx: AppContext, args: any) => { | ||
const params = z | ||
.object({ | ||
file: z.string().optional(), | ||
input: z.string().optional(), | ||
export: z.string().optional(), | ||
outputfile: z.string().optional().default("pnp.csv"), | ||
}) | ||
.refine((data) => data.file || data.input, { | ||
message: "Either 'file' or 'input' must be provided", | ||
}) | ||
.parse(args) | ||
|
||
const inputFile = params.input || params.file | ||
|
||
const pnpCsvBuffer = await exportPnpCsvToBuffer( | ||
{ | ||
example_file_path: inputFile!, | ||
export_name: params.export, | ||
}, | ||
ctx, | ||
) | ||
console.log(kleur.gray(`[writing to ${params.outputfile}]...`)) | ||
await fs.writeFile(params.outputfile, pnpCsvBuffer) | ||
console.log(kleur.green(`Pnp CSV file exported to ${params.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
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,24 @@ | ||
import { test, expect } from "bun:test" | ||
import { $ } from "bun" | ||
import { temporaryDirectory } from "tempy" | ||
import { join } from "path/posix" | ||
import { existsSync, readFileSync } from "fs" | ||
|
||
test("tsci export pnp_csv --input example-project/examples/macrokeypad.tsx", async () => { | ||
const tempDir = temporaryDirectory() | ||
const pnpCsvPath = join(tempDir, "pnp.csv") | ||
const { stdout, stderr } = | ||
await $`bun cli/cli.ts export pnp_csv --input example-project/examples/macrokeypad.tsx --outputfile ${pnpCsvPath} --no-color` | ||
|
||
expect(stderr.toString()).toBe("") | ||
expect(stdout.toString()).toContain("pnp.csv") | ||
|
||
expect(existsSync(pnpCsvPath)).toBe(true) | ||
|
||
const pnpCsvContent = readFileSync(pnpCsvPath, "utf-8") | ||
expect(pnpCsvContent).toContain("Designator") | ||
expect(pnpCsvContent).toContain("Mid X") | ||
expect(pnpCsvContent).toContain("Mid Y") | ||
expect(pnpCsvContent).toContain("Layer") | ||
expect(pnpCsvContent).toContain("Rotation") | ||
}) |