Paths and URLs
This section contains utilities to manage file paths and URLs within your project, ensuring consistent path generation from the project root and handling Git URLs for files.
rootPath
rootPathGenerates a relative path from the root of your project.
Parameters:
..._path: The segments of the path to join.
Example:
const relativePath = rootPath("src", "index.ts") // Relative path from project rootfullPath
fullPathGenerates an absolute path starting from the current working directory of your project.
Parameters:
..._path: The segments of the path to join.
Example:
const absolutePath = fullPath("src", "index.ts") // Absolute path from project rootpackageJSON
packageJSONLoads and parses the project's package.json file as an object. This can be used to inspect dependencies and other metadata within your project.
Example:
console.log(packageJSON.version) // Outputs the project version from package.jsongetDatabaseDriverName
getDatabaseDriverNameDetermines the database driver in use by inspecting the dependencies in package.json. It supports PostgreSQL (pg), MySQL (mysql2), and SQLite (sqlite3).
Example:
const driverName = getDatabaseDriverName() // Outputs the name of the database driverThrows:
If no supported database driver is found in the dependencies.
convertDistPathToSrc
convertDistPathToSrcConverts a file path from the dist folder (typically used for compiled JavaScript) to the equivalent src folder (TypeScript source).
Parameters:
path: The file path to convert.
Example:
const sourcePath = convertDistPathToSrc("dist/index.js") // Converts to "src/index.ts"getFileGitURL
getFileGitURLGenerates a GitHub URL for a specific file, using the current branch and remote. This utility is helpful for referencing files in your GitHub repository.
Parameters:
filepath: The path of the file to generate a GitHub URL for.
Example:
const gitURL = await getFileGitURL("src/index.ts")
// Example output: "https://github.com/your-repo/blob/main/src/index.ts"Returns:
A URL string pointing to the file in the repository, or
undefinedif it cannot generate the URL.
Last updated
Was this helpful?