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
Generates a relative path from the root of your project.
Parameters:
..._path: The segments of the path to join.
Example:
constrelativePath=rootPath("src","index.ts") // Relative path from project root
fullPath
Generates an absolute path starting from the current working directory of your project.
Parameters:
..._path: The segments of the path to join.
Example:
packageJSON
Loads 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:
getDatabaseDriverName
Determines the database driver in use by inspecting the dependencies in package.json. It supports PostgreSQL (pg), MySQL (mysql2), and SQLite (sqlite3).
Example:
Throws:
If no supported database driver is found in the dependencies.
convertDistPathToSrc
Converts 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:
getFileGitURL
Generates 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:
Returns:
A URL string pointing to the file in the repository, or undefined if it cannot generate the URL.