vitepress-jsdoc
Version:
A bridge between Vitepress and JSDoc-style commented codebases for hassle-free documentation.
69 lines • 2.25 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.computePaths = exports.getFileFolder = exports.getFileName = void 0;
const node_path_1 = require("node:path");
/**
* @file This module provides utility functions for handling file paths.
*/
/**
* Retrieves the file name. If the file name is '\_\_index\_\_', it returns 'index'.
*
* @function
*
* @param {DirectoryFile} file - The file object to retrieve the name from.
*
* @returns {string} The name of the file.
*
* @example
*
* const file = {name: '__index__'};
* const name = getFileName(file); // 'index'
*/
const getFileName = (file) => {
return file.name === '__index__' ? 'index' : file.name;
};
exports.getFileName = getFileName;
/**
* Retrieves the folder of the file.
*
* @function
*
* @param {DirectoryFile} file - The file object to retrieve the folder from.
*
* @returns {string} The folder of the file.
*
* @example
*
* const file = {folder: '/src/components'};
* const folder = getFileFolder(file); // '/src/components'
*/
const getFileFolder = (file) => {
return file.folder ?? '';
};
exports.getFileFolder = getFileFolder;
/**
* Computes the relative destination path and the absolute folder path in the destination directory.
*
* @function
*
* @param {DirectoryFile} file - The file object to compute paths for.
* @param {ParserConfig} config - The configuration object containing source and documentation folders.
*
* @returns {object} An object containing:
* - relativePathDest: The relative path in the destination directory.
* - folderInDest: The absolute path of the folder in the destination directory.
*
* @example
*
* const file = {folder: '/src/components'};
* const config = {srcFolder: '/src', docsFolder: '/docs'};
* const paths = computePaths(file, config);
*/
const computePaths = (file, config) => {
const { srcFolder, docsFolder } = config;
const relativePathDest = (0, node_path_1.join)(docsFolder, (0, exports.getFileFolder)(file).replace(srcFolder, ''));
const folderInDest = (0, node_path_1.join)(process.cwd(), relativePathDest);
return { relativePathDest, folderInDest };
};
exports.computePaths = computePaths;
//# sourceMappingURL=file-path.js.map