Skip to content
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

Fix: Add fallback for multiple frameworks #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
18 changes: 17 additions & 1 deletion commands/secret.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function action(options) {
introCopy:
"Secret generated. Copy it to your .env/.env.local file (depending on your framework):",
value: `\n${line}`,
multipleFrameworks: `Secret generated. Copy it to your .env/.env.local file (depending on your framework):${value}`,
}

if (options.copy) {
Expand All @@ -47,7 +48,22 @@ export async function action(options) {
}

try {
await requireFramework(options.path)
const framework = await requireFramework(options.path)
if (framework === "multiple-frameworks-detected") {
try {
clipboard.writeSync(line)
console.log(message.introClipboard)
} catch (error) {
console.log(
"An error occurred while copying the secret to your clipboard."
)
console.log(message.multipleFrameworks)
console.log(message.value)
} finally {
process.exit(0)
}
}

await updateEnvFile({ [key]: value }, options.path)
} catch (error) {
console.error(y.red(error))
Expand Down
11 changes: 5 additions & 6 deletions lib/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as y from "yoctocolors"
* When this function runs in a framework directory we support,
* it will return the framework's name
* @param {string} path
* @returns {Promise<import("./meta").SupportedFramework | "unknown">}
* @returns {Promise<import("./meta").SupportedFramework | "unknown" | "multiple-frameworks-detected">}
*/
export async function detectFramework(path = "") {
const dir = process.cwd()
Expand All @@ -27,15 +27,14 @@ export async function detectFramework(path = "") {
if (foundFrameworks.length === 1) return foundFrameworks[0]

if (foundFrameworks.length > 1) {
console.error(
`Multiple supported frameworks detected: ${foundFrameworks.join(", ")}`
)
return "unknown"
console.log("Multiple supported frameworks detected.")
return "multiple-frameworks-detected"
}
return "unknown"
} catch (error) {
console.error("An error occurred while detecting the framework.")
console.error(error)
return "unknown"
process.exit(0)
}
}

Expand Down