-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/template-path-resolution
- Loading branch information
Showing
7 changed files
with
64 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"@t1mmen/srtd": patch | ||
--- | ||
|
||
Attempt to identify "root of project", so srtd can be run from subdirectories as well. |
This file contains 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 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 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 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 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,28 @@ | ||
import path from 'node:path'; | ||
import { fileExists } from './fileExists.js'; | ||
|
||
async function isProjectDir(dir: string): Promise<boolean> { | ||
// Check for srtd config files | ||
if (await fileExists(path.join(dir, 'srtd.config.json'))) return true; | ||
|
||
// Check for package.json | ||
if (await fileExists(path.join(dir, 'package.json'))) return true; | ||
|
||
// Check for supabase directory | ||
if (await fileExists(path.join(dir, 'supabase'))) return true; | ||
|
||
return false; | ||
} | ||
|
||
export async function findProjectRoot(startDir?: string): Promise<string> { | ||
let currentDir = startDir || process.cwd(); | ||
|
||
while (currentDir !== path.parse(currentDir).root) { | ||
if (await isProjectDir(currentDir)) { | ||
return currentDir; | ||
} | ||
currentDir = path.dirname(currentDir); | ||
} | ||
|
||
throw new Error('Could not find project root. Are you in a Supabase project directory?'); | ||
} |
This file contains 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