Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.
Merged
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"axios": "^0.24.0",
"chalk": "^4.1.2",
"code-block-writer": "^11.0.0",
"find-up": "^5.0.0",
"glob": "^7.2.0",
"gunzip-maybe": "^1.4.2",
"inquirer": "^8.2.0",
Expand Down
19 changes: 11 additions & 8 deletions src/utils/nodecgInstallation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as findUp from "find-up";
import * as path from "path";
import * as fs from "fs";
import { SemVer } from "semver";
Expand All @@ -7,17 +6,21 @@ import { directoryExists } from "./fs";
/**
* Traverses the filesystem and uses {@link isNodeCGDirectory} to find a local nodecg installation.
*/
export async function findNodeCGDirectory(cwd = process.cwd()): Promise<string> {
const res = await findUp(async (dir) => ((await isNodeCGDirectory(dir)) ? dir : undefined), {
type: "directory",
cwd,
});
if (res === undefined) {
export async function findNodeCGDirectory(dir = process.cwd()): Promise<string> {
if (await isNodeCGDirectory(dir)) {
return dir;
}

const parent = path.dirname(dir);

// We're at the filesystem root because we cannot go one level up more and didn't found a nodecg installation
if (parent === dir) {
throw new Error(
"Couldn't find a nodecg installation. Make sure that you are in the directory of your nodecg installation.",
);
}
return res;

return findNodeCGDirectory(parent);
}

/**
Expand Down