all files / tool/ path.js

100% Statements 10/10
100% Branches 0/0
100% Functions 4/4
100% Lines 10/10
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65                                                                                                             
/**
 * @file
 * @desc path handers
 * @author liuyuanyangscript@gmail.com
 * @date  2017/08/11
 */
 
const path = require('path');
const md5 = require('md5');
 
module.exports = {
 
    // config file of current project
    configName: '.biorc',
 
    // cache path for storing modules like cmd/scaffold
    cacheFolder: path.join(process.env.HOME, '.bio'),
 
    /**
     * @func
     * @desc get dir path of scaffold wrapper
     * @param {String} scaffoldName
     * @return {String} scaffold wrapper path
     */
    getScaffoldWrapper() {
        return path.join(this.cacheFolder, 'scaffold');
    },
 
    /**
     * @func
     * @desc get dir path for execing installing scaffold
     * @param {String} scaffoldName
     * @return {String} dir path for execing installing scaffold
     */
    getScaffoldExecInstallFolder(scaffoldName) {
        return path.join(this.getScaffoldWrapper(scaffoldName), 'tmp-install-cache', `${md5(scaffoldName)}`);
    },
 
    /**
     * @func
     * @desc get scaffold dir path
     * @param {String} scaffoldName
     * @return {String} scaffold dir path
     */
    getScaffoldFolder(scaffoldName) {
        return path.join(this.getScaffoldWrapper(scaffoldName), scaffoldName);
    },
 
    /**
     * @func
     * @desc get workspace dir path
     * @param {Object}
     * @param {String} object.cwd: current project path
     * @param {String} object.scaffoldName
     * @return {String} workspace dir path
     */
    getWorkspaceFolder({ cwd, scaffoldName }) {
        const currentDirname = cwd.replace(path.dirname(cwd), '').replace(/^\//, '').replace(/\/$/, '');
        const scaffoldFolder = this.getScaffoldFolder(scaffoldName);
        const workspaceFolder = path.join(scaffoldFolder, 'workspace', md5(cwd), currentDirname);
        return workspaceFolder;
    },
 
};