Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Add flag #93

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions lib/cmd-fns/dev-server-fulfill-export-requests.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { AppContext } from "../util/app-context"
import { z } from "zod"
import { getDevServerAxios } from "./dev/get-dev-server-axios"
import kleur from "kleur"
import { AppContext } from "../util/app-context"
import { fulfillExportRequests } from "./dev/fulfill-export-requests"
import { getDevServerAxios } from "./dev/get-dev-server-axios"

export const devServerFulfillExportRequests = async (
ctx: AppContext,
args: any
) => {
const params = z.object({}).parse(args)

let server_url = `http://localhost:3020`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should revert, no reason to change this file afaik

let dev_server_axios = getDevServerAxios({ serverUrl: server_url })

Expand Down
10 changes: 6 additions & 4 deletions lib/cmd-fns/dev-server-upload.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { AppContext } from "../util/app-context"
import kleur from "kleur"
import { z } from "zod"
import { AppContext } from "../util/app-context"
import { getDevServerAxios } from "./dev/get-dev-server-axios"
import { uploadExamplesFromDirectory } from "./dev/upload-examples-from-directory"
import { startFsWatcher } from "./dev/start-fs-watcher"
import kleur from "kleur"
import { AxiosInstance } from "axios"
import { uploadExamplesFromDirectory } from "./dev/upload-examples-from-directory"

export const devServerUpload = async (ctx: AppContext, args: any) => {
const params = z
.object({
dir: z.string().optional().default(ctx.cwd),
port: z.coerce.number().optional().nullable().default(null),
watch: z.boolean().optional().default(false),
no_cleanup: z.boolean().optional().default(true),
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not default to true

.parse(args)

ctx.args.no_cleanup = params.no_cleanup

let serverUrl = `http://localhost:${params.port ?? 3020}`
let devServerAxios = getDevServerAxios({ serverUrl })

Expand Down
21 changes: 12 additions & 9 deletions lib/cmd-fns/dev/fulfill-export-requests.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AppContext } from "../../util/app-context"
import { ExportRequest } from "@server/lib/zod/export_request"
import { AxiosInstance } from "axios"
import kleur from "kleur"
import { exportBomCsvToBuffer } from "lib/export-fns/export-bom-csv"
import { exportGerbersToZipBuffer } from "lib/export-fns/export-gerbers"
import { AxiosInstance } from "axios"
import { ExportRequest } from "@server/lib/zod/export_request"
import { exportPnpCsvToBuffer } from "lib/export-fns/export-pnp-csv"
import { exportBomCsvToBuffer } from "lib/export-fns/export-bom-csv"
import { soupify } from "lib/soupify"
import { AppContext } from "../../util/app-context"

export const uploadBufferToExportFile = async ({
dev_server_axios,
Expand Down Expand Up @@ -48,6 +48,8 @@ export const fulfillExportRequests = async (
})
.then((r) => r.data.export_requests)

const no_cleanup = ctx.args.no_cleanup

for (const export_request of export_requests) {
console.log(
kleur.gray(
Expand Down Expand Up @@ -99,12 +101,13 @@ export const fulfillExportRequests = async (
{
example_file_path: export_request.example_file_path,
export_name: export_request.export_name,
no_cleanup,
},
ctx
)

const pnpFileName = `${export_request.export_name}-${export_request.export_parameters.pnp_csv_file_name!}`

await uploadBufferToExportFile({
dev_server_axios,
file_buffer: csv_buffer,
Expand All @@ -122,9 +125,9 @@ export const fulfillExportRequests = async (
},
ctx
)

const bomFileName = `${export_request.export_name}-${export_request.export_parameters.bom_csv_file_name!}`

await uploadBufferToExportFile({
dev_server_axios,
file_buffer: csv_buffer,
Expand All @@ -151,4 +154,4 @@ export const fulfillExportRequests = async (
})
}
}
}
}
11 changes: 7 additions & 4 deletions lib/cmd-fns/dev/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ export const devCmd = async (ctx: AppContext, args: any) => {
const params = z
.object({
port: z.coerce.number().optional().default(3020),
no_cleanup: z.boolean().optional().default(true),
})
.parse(args)

let { port } = params
let { port, no_cleanup } = params
const { cwd } = ctx

ctx.args.no_cleanup = no_cleanup

// Find an available port
port = await findAvailablePort(port)

Expand Down Expand Up @@ -152,16 +155,16 @@ export const devCmd = async (ctx: AppContext, args: any) => {
fs_watcher.stop()
er_watcher.stop()
ee_watcher.stop()

posthog.capture({
distinctId: projectHash,
event: 'tsci_dev_stopped'
})

if (posthog.shutdown) {
await posthog.shutdown()
}

break
}
}
Expand Down
5 changes: 4 additions & 1 deletion lib/cmd-fns/dev/soupify-and-upload-example-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export const soupifyAndUploadExampleFile = async (
exampleFileName: string
devServerAxios: AxiosInstance
},
ctx: { runtime: "node" | "bun" }
ctx: {
runtime: "node" | "bun",
args: { no_cleanup: boolean }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args is too generic. Rename to cliArgs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also use camelCase since thats the convention from other
parts of the code (it seems)

}
) => {
try {
const startTime = Date.now()
Expand Down
8 changes: 6 additions & 2 deletions lib/cmd-fns/dev/start-fs-watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ export const startFsWatcher = async (
devServerAxios,
}: {
cwd: string
devServerAxios: AxiosInstance
devServerAxios: AxiosInstance,
},
ctx: { runtime: "node" | "bun" }
ctx: {
runtime: "node" | "bun",
args: { no_cleanup: boolean }
}
) => {
const watcher = chokidar.watch([`${cwd}/**/*.tsx`, `${cwd}/**/*.ts`], {
ignored: /node_modules/,
Expand All @@ -22,6 +25,7 @@ export const startFsWatcher = async (
dirty: false,
should_run: true,
}

watcher.on("change", async (path) => {
console.log(path)
if (path.endsWith(".__tmp_entrypoint.tsx")) return
Expand Down
11 changes: 8 additions & 3 deletions lib/cmd-fns/dev/upload-examples-from-directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,26 @@ export const uploadExamplesFromDirectory = async (
devServerAxios,
}: {
cwd: string
devServerAxios: AxiosInstance
devServerAxios: AxiosInstance,
},
ctx: { runtime: "node" | "bun" }
ctx: {
runtime: "node" | "bun",
args: { no_cleanup: boolean }
}
) => {
const examplesDir = joinPath(cwd, "examples")
const exampleFileNames = await readdir(examplesDir).catch((e) => {
console.log(kleur.red(`Error reading examples directory: "${examplesDir}"`))
throw e
})

const no_cleanup = ctx.args.no_cleanup

// Mark all examples as being "reloaded" in the database
await markAllExamplesLoading({ devServerAxios })

for (const exampleFileName of exampleFileNames) {
if (exampleFileName.endsWith(".__tmp_entrypoint.tsx")) continue
if (exampleFileName.endsWith(".__tmp_entrypoint.tsx") && !no_cleanup) continue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should revert, doesnt make sense, the idea with this loop is to ignore entrypoint files, doesnt make sense to have the cleanup flag change that behavior

if (!exampleFileName.endsWith(".tsx")) continue
await soupifyAndUploadExampleFile(
{
Expand Down
2 changes: 2 additions & 0 deletions lib/cmd-fns/package-examples-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ export const packageExamplesCreate = async (ctx: AppContext, args: any) => {
packageNameWithVersion: z.string(),
file: z.string(),
export: z.string().optional().default("default"),
no_cleanup: z.boolean().optional().default(true),
})
.parse(args)

const tscircuit_soup = await soupify(
{
filePath: params.file,
exportName: params.export,
no_cleanup: params.no_cleanup,
},
ctx
)
Expand Down
34 changes: 18 additions & 16 deletions lib/cmd-fns/publish/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import kleur from "kleur"
import { z } from "zod"
import { AppContext } from "../../util/app-context"
import * as Path from "path"
import * as fs from "fs/promises"
import $ from "dax-sh"
import { existsSync, readFileSync } from "fs"
import * as fs from "fs/promises"
import { unlink } from "fs/promises"
import kleur from "kleur"
import { getAllPackageFiles } from "lib/util/get-all-package-files"
import * as Path from "path"
import prompts from "prompts"
import { getGeneratedReadme } from "../init/get-generated-readme"
import semver from "semver"
import { z } from "zod"
import { soupify } from "../../soupify"
import { AppContext } from "../../util/app-context"
import { inferExportNameFromSource } from "../dev/infer-export-name-from-source"
import $ from "dax-sh"
import semver from "semver"
import { unlink } from "fs/promises"
import esbuild from "esbuild"
import { getGeneratedReadme } from "../init/get-generated-readme"

export const publish = async (ctx: AppContext, args: any) => {
const params = z
.object({
increment: z.boolean().optional(),
patch: z.boolean().optional(),
lock: z.boolean().optional(),
no_cleanup: z.boolean().optional().default(true),
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not be on this command. Only put on "tsci dev" command

.parse(args)

Expand Down Expand Up @@ -269,6 +269,7 @@ export const publish = async (ctx: AppContext, args: any) => {
{
filePath,
exportName,
no_cleanup: params.no_cleanup,
},
ctx
).catch((e) => e)
Expand Down Expand Up @@ -298,11 +299,10 @@ export const publish = async (ctx: AppContext, args: any) => {
`${name.replace(/\//g, "-")}-${version}.tgz`
)
await fs.mkdir(Path.dirname(tmpTarballPath), { recursive: true })
const npm_pack_outputs = await $`cd ${
ctx.cwd
} && npm pack --json --pack-destination ${Path.dirname(
tmpTarballPath
)}`.json()
const npm_pack_outputs = await $`cd ${ctx.cwd
} && npm pack --json --pack-destination ${Path.dirname(
tmpTarballPath
)}`.json()

if (!existsSync(tmpTarballPath)) {
console.log(kleur.red(`Couldn't find tarball at ${tmpTarballPath}`))
Expand All @@ -319,7 +319,9 @@ export const publish = async (ctx: AppContext, args: any) => {
})

// Clean up .tscircuit/tmp
await unlink(tmpTarballPath)
if (!params.no_cleanup) {
await unlink(tmpTarballPath)
}

// 8. Lock/set release to latest version
await ctx.axios.post("/package_releases/update", {
Expand Down
2 changes: 2 additions & 0 deletions lib/cmd-fns/soupify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export const soupifyCmd = async (ctx: AppContext, args: any) => {
file: z.string(),
export: z.string().optional(),
output: z.string().optional(),
no_cleanup: z.boolean().optional().default(true),
})
.parse(args)

const soup = await soupify(
{
filePath: params.file,
exportName: params.export,
no_cleanup: params.no_cleanup,
},
ctx
)
Expand Down
1 change: 1 addition & 0 deletions lib/export-fns/export-bom-csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const exportBomCsvToBuffer = async (
ctx: AppContext
) => {
console.log(kleur.gray("[soupifying]..."))

const soup = await soupify(
{
filePath: params.example_file_path,
Expand Down
15 changes: 5 additions & 10 deletions lib/export-fns/export-pnp-csv.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
import { AppContext } from "../util/app-context"
import { z } from "zod"
import * as Path from "path"
import { unlink } from "node:fs/promises"
import { soupify } from "lib/soupify"
import * as fs from "fs"
import {
stringifyGerberCommandLayers,
convertSoupToGerberCommands,
convertSoupToPickAndPlaceCsv,
convertSoupToPickAndPlaceCsv
} from "@tscircuit/builder"
import kleur from "kleur"
import archiver from "archiver"
import { soupify } from "lib/soupify"
import { AppContext } from "../util/app-context"

export const exportPnpCsvToBuffer = async (
params: {
example_file_path: string
export_name?: string
no_cleanup: boolean
},
ctx: AppContext
) => {
Expand All @@ -24,6 +18,7 @@ export const exportPnpCsvToBuffer = async (
{
filePath: params.example_file_path,
exportName: params.export_name,
no_cleanup: params.no_cleanup,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesnt match naming convention

ctx
)
Expand Down
8 changes: 5 additions & 3 deletions lib/get-program.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Command } from "commander"
import packageJson from "../package.json"
import { AppContext } from "./util/app-context"
import * as CMDFN from "lib/cmd-fns"
import { AppContext } from "./util/app-context"

export const getProgram = (ctx: AppContext) => {
const cmd = new Command("tsci").description(
Expand All @@ -13,6 +12,7 @@ export const getProgram = (ctx: AppContext) => {
.description("Run development server in current directory")
.option("--cwd <cwd>", "Current working directory")
.option("--port <port>", "Port to run dev server on")
.option("--no-cleanup", "Don't delete the temporary directory", true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not default to true

.action((args) => CMDFN.dev(ctx, args))

cmd
Expand Down Expand Up @@ -313,11 +313,13 @@ export const getProgram = (ctx: AppContext) => {
)
.option("-w, --watch", "Watch for changes")
.option("-p, --port", "Port dev server is running on (default: 3020)")
.option("--no-cleanup", "Don't delete the temporary directory", true)
.action((args) => CMDFN.devServerUpload(ctx, args))

devServerCmd
.command("fulfill-export-requests")
.action((args) => CMDFN.devServerFulfillExportRequests(ctx, args))
.option("--no-cleanup", "Don't delete the temporary directory", true)
.action(() => CMDFN.devServerFulfillExportRequests(ctx))

cmd
.command("open")
Expand Down
Loading
Loading