Skip to content
This repository was archived by the owner on Apr 13, 2025. It is now read-only.

Commit f2b0595

Browse files
authored
Implement function to find the nodecg installation by ourselfs (#38)
Currently we're using [find-up](https://www.npmjs.com/package/find-up) to traverse the filesystem and find the nodecg installation if the user is an subdirectory like `bundles/`. To reduce our dependencies we can simply implement this ourselfs. I can't remember why I used `find-up` in the first place as using it is almost harder than implementing it directly, lol.
1 parent 6201338 commit f2b0595

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"axios": "^0.24.0",
6464
"chalk": "^4.1.2",
6565
"code-block-writer": "^11.0.0",
66-
"find-up": "^5.0.0",
6766
"glob": "^7.2.0",
6867
"inquirer": "^8.2.0",
6968
"isomorphic-git": "^1.10.1",

src/utils/nodecgInstallation.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as findUp from "find-up";
21
import * as path from "path";
32
import * as fs from "fs";
43
import { SemVer } from "semver";
@@ -7,17 +6,21 @@ import { directoryExists } from "./fs";
76
/**
87
* Traverses the filesystem and uses {@link isNodeCGDirectory} to find a local nodecg installation.
98
*/
10-
export async function findNodeCGDirectory(cwd = process.cwd()): Promise<string> {
11-
const res = await findUp(async (dir) => ((await isNodeCGDirectory(dir)) ? dir : undefined), {
12-
type: "directory",
13-
cwd,
14-
});
15-
if (res === undefined) {
9+
export async function findNodeCGDirectory(dir = process.cwd()): Promise<string> {
10+
if (await isNodeCGDirectory(dir)) {
11+
return dir;
12+
}
13+
14+
const parent = path.dirname(dir);
15+
16+
// We're at the filesystem root because we cannot go one level up more and didn't found a nodecg installation
17+
if (parent === dir) {
1618
throw new Error(
1719
"Couldn't find a nodecg installation. Make sure that you are in the directory of your nodecg installation.",
1820
);
1921
}
20-
return res;
22+
23+
return findNodeCGDirectory(parent);
2124
}
2225

2326
/**

0 commit comments

Comments
 (0)