all files / htmlcs/lib/ fs-util.js

100% Statements 12/12
100% Branches 2/2
100% Functions 1/1
100% Lines 12/12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47                                                                     
/**
 * @file fs-relative util methods
 * @author nighca<nighca@live.cn>
 */
 
var fs = require('fs');
var path = require('path');
 
/**
 * Application (htmlcs) info.
 *
 * @type {Object}
 * @property {string} root - root path of application (htmlcs) code
 */
var app = {
    root: path.resolve(__dirname, '../')
};
 
 
/**
 * Get path of home(~).
 *
 * @return {string} path of home
 */
var getHomePath = function () {
    var homePath = '';
    var environment = process.env;
    var paths = [
        environment.USERPROFILE,
        environment.HOME,
        environment.HOMEPATH,
        environment.HOMEDRIVE + environment.HOMEPATH
    ];
 
    while (paths.length) {
        homePath = paths.shift();
        if (fs.existsSync(homePath)) {
            return homePath;
        }
    }
};
 
module.exports = {
    app: app,
    getHomePath: getHomePath
};