Repository navigation
Refactor stack builder and CLI command boundaries #869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
97e85eb
refactor stack builder and cli command boundaries
AmanVarshney01 fb9a6f3
fix(web): restore prebuild for workspace package deps
AmanVarshney01 54e9318
chore(turbo): refine outputs and non-cacheable tasks
AmanVarshney01 48a97b6
update deps
AmanVarshney01 d4fe1c9
fix: address CodeRabbit feedback on cli and stack builder
AmanVarshney01 db63195
refactor(cli): use Result flow for external URL command
AmanVarshney01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,90 @@ | ||
| import { intro, log } from "@clack/prompts"; | ||
| import pc from "picocolors"; | ||
|
|
||
| import { clearHistory, getHistory, type ProjectHistoryEntry } from "../utils/project-history"; | ||
| import { renderTitle } from "../utils/render-title"; | ||
|
|
||
| export type HistoryCommandInput = { | ||
| limit: number; | ||
| clear: boolean; | ||
| json: boolean; | ||
| }; | ||
|
|
||
| function formatStackSummary(entry: ProjectHistoryEntry): string { | ||
| const parts: string[] = []; | ||
|
|
||
| if (entry.stack.frontend.length > 0 && !entry.stack.frontend.includes("none")) { | ||
| parts.push(entry.stack.frontend.join(", ")); | ||
| } | ||
|
|
||
| if (entry.stack.backend && entry.stack.backend !== "none") { | ||
| parts.push(entry.stack.backend); | ||
| } | ||
|
|
||
| if (entry.stack.database && entry.stack.database !== "none") { | ||
| parts.push(entry.stack.database); | ||
| } | ||
|
|
||
| if (entry.stack.orm && entry.stack.orm !== "none") { | ||
| parts.push(entry.stack.orm); | ||
| } | ||
|
|
||
| return parts.length > 0 ? parts.join(" + ") : "minimal"; | ||
| } | ||
|
|
||
| function formatDate(isoString: string): string { | ||
| const date = new Date(isoString); | ||
| return date.toLocaleDateString("en-US", { | ||
| year: "numeric", | ||
| month: "short", | ||
| day: "numeric", | ||
| hour: "2-digit", | ||
| minute: "2-digit", | ||
| }); | ||
| } | ||
|
|
||
| export async function historyHandler(input: HistoryCommandInput): Promise<void> { | ||
| if (input.clear) { | ||
| const clearResult = await clearHistory(); | ||
| if (clearResult.isErr()) { | ||
| log.warn(pc.yellow(clearResult.error.message)); | ||
| return; | ||
| } | ||
| log.success(pc.green("Project history cleared.")); | ||
| return; | ||
| } | ||
|
|
||
| const historyResult = await getHistory(input.limit); | ||
| if (historyResult.isErr()) { | ||
| log.warn(pc.yellow(historyResult.error.message)); | ||
| return; | ||
| } | ||
| const entries = historyResult.value; | ||
|
|
||
| if (entries.length === 0) { | ||
| log.info(pc.dim("No projects in history yet.")); | ||
| log.info(pc.dim("Create a project with: create-better-t-stack my-app")); | ||
| return; | ||
| } | ||
|
|
||
| if (input.json) { | ||
| console.log(JSON.stringify(entries, null, 2)); | ||
| return; | ||
| } | ||
|
|
||
| renderTitle(); | ||
| intro(pc.magenta(`Project History (${entries.length} entries)`)); | ||
|
|
||
| for (const [index, entry] of entries.entries()) { | ||
| const num = pc.dim(`${index + 1}.`); | ||
| const name = pc.cyan(pc.bold(entry.projectName)); | ||
| const stack = pc.dim(formatStackSummary(entry)); | ||
|
|
||
| log.message(`${num} ${name}`); | ||
| log.message(` ${pc.dim("Created:")} ${formatDate(entry.createdAt)}`); | ||
| log.message(` ${pc.dim("Path:")} ${entry.projectDir}`); | ||
| log.message(` ${pc.dim("Stack:")} ${stack}`); | ||
| log.message(` ${pc.dim("Command:")} ${pc.dim(entry.reproducibleCommand)}`); | ||
| log.message(""); | ||
| } | ||
| } |
This file contains hidden or 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,53 @@ | ||
| import { intro, log } from "@clack/prompts"; | ||
| import { Result } from "better-result"; | ||
| import pc from "picocolors"; | ||
|
|
||
| import { CLIError, displayError } from "../utils/errors"; | ||
| import { openUrl } from "../utils/open-url"; | ||
| import { renderTitle } from "../utils/render-title"; | ||
| import { displaySponsors, fetchSponsors } from "../utils/sponsors"; | ||
|
|
||
| const DOCS_URL = "https://better-t-stack.dev/docs"; | ||
| const BUILDER_URL = "https://better-t-stack.dev/new"; | ||
|
|
||
| async function openExternalUrl(url: string, successMessage: string) { | ||
| const result = await Result.tryPromise({ | ||
| try: () => openUrl(url), | ||
| catch: () => null, | ||
| }); | ||
|
|
||
| if (result.isOk()) { | ||
| log.success(pc.blue(successMessage)); | ||
| } else { | ||
| log.message(`Please visit ${url}`); | ||
| } | ||
| } | ||
|
|
||
| export async function showSponsorsCommand() { | ||
| const result = await Result.tryPromise({ | ||
| try: async () => { | ||
| renderTitle(); | ||
| intro(pc.magenta("Better-T-Stack Sponsors")); | ||
| const sponsors = await fetchSponsors(); | ||
| displaySponsors(sponsors); | ||
| }, | ||
| catch: (error: unknown) => | ||
| new CLIError({ | ||
| message: error instanceof Error ? error.message : "Failed to display sponsors", | ||
| cause: error, | ||
| }), | ||
| }); | ||
|
|
||
| if (result.isErr()) { | ||
| displayError(result.error); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| export async function openDocsCommand() { | ||
| await openExternalUrl(DOCS_URL, "Opened docs in your default browser."); | ||
| } | ||
|
|
||
| export async function openBuilderCommand() { | ||
| await openExternalUrl(BUILDER_URL, "Opened builder in your default browser."); | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,26 +1,19 @@ | ||
| import { log } from "@clack/prompts"; | ||
| import { Result } from "better-result"; | ||
| import { $ } from "execa"; | ||
|
AmanVarshney01 marked this conversation as resolved.
Resolved
|
||
|
|
||
| export async function openUrl(url: string): Promise<void> { | ||
| const platform = process.platform; | ||
|
|
||
| const result = await Result.tryPromise({ | ||
| try: async () => { | ||
| if (platform === "darwin") { | ||
| await $({ stdio: "ignore" })`open ${url}`; | ||
| } else if (platform === "win32") { | ||
| // Windows needs special handling for ampersands | ||
| const escapedUrl = url.replace(/&/g, "^&"); | ||
| await $({ stdio: "ignore" })`cmd /c start "" ${escapedUrl}`; | ||
| } else { | ||
| await $({ stdio: "ignore" })`xdg-open ${url}`; | ||
| } | ||
| }, | ||
| catch: () => undefined, | ||
| }); | ||
| if (platform === "darwin") { | ||
| await $({ stdio: "ignore" })`open ${url}`; | ||
| return; | ||
| } | ||
|
|
||
| if (result.isErr()) { | ||
| log.message(`Please open ${url} in your browser.`); | ||
| if (platform === "win32") { | ||
| // Windows needs special handling for ampersands | ||
| const escapedUrl = url.replace(/&/g, "^&"); | ||
| await $({ stdio: "ignore" })`cmd /c start "" ${escapedUrl}`; | ||
| return; | ||
|
AmanVarshney01 marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| await $({ stdio: "ignore" })`xdg-open ${url}`; | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.