All files / src/config paths.js

69.56% Statements 16/23
100% Branches 1/1
0% Functions 0/2
69.56% Lines 16/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24193x 193x 193x 193x 193x 193x 193x 193x 193x 193x     193x 193x 193x 193x 193x 193x            
import path from 'node:path';
// @ts-ignore - no types available for this module
import xdg from 'xdg';
 
/**
 * Resolves the full path for a configuration file.
 * @param {string} configFile - The name of the configuration file
 * @returns {string} The absolute path to the configuration file
 */
export function getConfigPath(configFile) {
  return path.resolve(getConfigDir(), configFile);
}
 
/**
 * Gets the configuration directory path based on the operating system.
 * On Windows, uses APPDATA/clever-cloud, on other platforms uses XDG config path.
 * @returns {string} The absolute path to the configuration directory
 */
function getConfigDir() {
  return process.platform === 'win32' && process.env.APPDATA != null
    ? path.resolve(process.env.APPDATA, 'clever-cloud')
    : xdg.basedir.configPath('clever-cloud');
}