@tscircuit/cli 0.0.57 → 0.0.58

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.
@@ -0,0 +1,60 @@
1
+ import { AppContext } from "../util/app-context"
2
+ import { z } from "zod"
3
+ import * as Path from "path"
4
+ import { unlink } from "node:fs/promises"
5
+ import { soupify } from "lib/soupify"
6
+ import * as fs from "fs"
7
+ import {
8
+ stringifyGerberCommandLayers,
9
+ convertSoupToGerberCommands,
10
+ } from "@tscircuit/builder"
11
+ import { zip } from "zip-a-folder"
12
+ import kleur from "kleur"
13
+ import archiver from "archiver"
14
+
15
+ export const exportGerbersCmd = async (ctx: AppContext, args: any) => {
16
+ const params = z
17
+ .object({
18
+ file: z.string(),
19
+ export: z.string().optional(),
20
+ outputfile: z.string().optional().default("gerbers.zip"),
21
+ })
22
+ .parse(args)
23
+
24
+ console.log(kleur.gray("[soupifying]..."))
25
+ const soup = await soupify(
26
+ {
27
+ filePath: params.file,
28
+ exportName: params.export,
29
+ },
30
+ ctx
31
+ )
32
+
33
+ console.log(kleur.gray("[soup to gerber json]..."))
34
+ const gerber_layer_cmds = convertSoupToGerberCommands(soup)
35
+
36
+ console.log(kleur.gray("[stringify gerber json]..."))
37
+ const gerber_file_contents = stringifyGerberCommandLayers(gerber_layer_cmds)
38
+
39
+ console.log(kleur.gray("[writing gerbers to tmp dir]..."))
40
+ const tempDir = Path.join(".tscircuit", "tmp-gerber-export")
41
+ await fs.mkdirSync(tempDir, { recursive: true })
42
+ for (const [fileName, fileContents] of Object.entries(gerber_file_contents)) {
43
+ const filePath = Path.join(tempDir, fileName)
44
+ await fs.writeFileSync(filePath, fileContents)
45
+ }
46
+
47
+ console.log(kleur.gray("[zipping tmp dir]..."))
48
+ const output = fs.createWriteStream(params.outputfile)
49
+ const archive = archiver("zip", {
50
+ zlib: { level: 9 },
51
+ })
52
+
53
+ archive.pipe(output)
54
+ archive.directory(tempDir, false)
55
+
56
+ await new Promise((resolve, reject) => {
57
+ output.on("close", resolve)
58
+ output.on("error", reject)
59
+ })
60
+ }
@@ -36,3 +36,4 @@ export { devServerUpload } from "./dev-server-upload"
36
36
  export { configClear } from "./config-clear"
37
37
  export { openCmd as open } from "./open"
38
38
  export { versionCmd as version } from "./version"
39
+ export { exportGerbersCmd as exportGerbers } from "./export-gerbers"
@@ -251,6 +251,21 @@ export const getProgram = (ctx: AppContext) => {
251
251
  .description("Clear your local authentication")
252
252
  .action((args) => CMDFN.authLogout(ctx, args))
253
253
 
254
+ const exportCmd = cmd
255
+ .command("export")
256
+ .description("Export Gerbers, Drill Files, Netlists and more")
257
+
258
+ exportCmd
259
+ .command("gerbers")
260
+ .description("Export Gerber files from an example file")
261
+ .requiredOption("--file <file>", "Input example files")
262
+ .option(
263
+ "--export <export_name>",
264
+ "Name of export to soupify, if not specified, soupify the default/only export"
265
+ )
266
+ .option("--outputfile <outputfile>", "Output file name", "gerbers.zip")
267
+ .action((args) => CMDFN.exportGerbers(ctx, args))
268
+
254
269
  cmd
255
270
  .command("soupify")
256
271
  .description("Convert an example file to tscircuit soup")
package/lib/soupify.ts CHANGED
@@ -5,6 +5,7 @@ import * as Path from "path"
5
5
  import { unlink } from "node:fs/promises"
6
6
  import kleur from "kleur"
7
7
  import { writeFileSync } from "fs"
8
+ import { readFile } from "fs/promises"
8
9
 
9
10
  export const soupify = async (
10
11
  {
@@ -16,6 +17,27 @@ export const soupify = async (
16
17
  },
17
18
  ctx: { runtime: "node" | "bun" }
18
19
  ) => {
20
+ const targetFileContent = await readFile(filePath, "utf-8")
21
+
22
+ if (!exportName) {
23
+ if (targetFileContent.includes("export default")) {
24
+ exportName = "default"
25
+ } else {
26
+ // Look for "export const <name>" or "export function <name>"
27
+ const exportRegex = /export\s+(?:const|function)\s+(\w+)/g
28
+ const match = exportRegex.exec(targetFileContent)
29
+ if (match) {
30
+ exportName = match[1]
31
+ }
32
+ }
33
+ }
34
+
35
+ if (!exportName) {
36
+ throw new Error(
37
+ `Couldn't derive an export name and didn't find default export in "${filePath}"`
38
+ )
39
+ }
40
+
19
41
  const tmpFilePath = Path.join(
20
42
  Path.dirname(filePath),
21
43
  Path.basename(filePath).replace(/\.[^\.]+$/, "") + ".__tmp_entrypoint.tsx"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.0.57",
3
+ "version": "0.0.58",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Command line tool for developing, publishing and installing tscircuit circuits",
@@ -35,8 +35,9 @@
35
35
  "dependencies": {
36
36
  "@edge-runtime/primitives": "^4.1.0",
37
37
  "@hono/node-server": "^1.8.2",
38
- "@tscircuit/builder": "latest",
38
+ "@tscircuit/builder": "1.5.53",
39
39
  "@tscircuit/react-fiber": "latest",
40
+ "archiver": "^7.0.1",
40
41
  "axios": "^1.6.7",
41
42
  "better-sqlite3": "^9.4.3",
42
43
  "chokidar": "^3.6.0",
@@ -61,9 +62,11 @@
61
62
  "prompts": "^2.4.2",
62
63
  "react": "^18.2.0",
63
64
  "semver": "^7.6.0",
65
+ "zip-a-folder": "^3.1.6",
64
66
  "zod": "latest"
65
67
  },
66
68
  "devDependencies": {
69
+ "@types/archiver": "^6.0.2",
67
70
  "@types/bun": "^1.0.8",
68
71
  "@types/chokidar": "^2.1.3",
69
72
  "@types/configstore": "^6.0.2",