lib/ttb-cache.js
function cacheModule(config) {
    config = utilities.parseConfig(config);
    var moduleCache = utilities.getCachePath();
    console.log('Module cache at ' + moduleCache);

    var version = getModuleVersionFromConfig(config);

    var pkgStr = config.nodePackageName + (version ? '@' + version : '');
    return utilities.getVersionForNpmPackage(pkgStr).then(function (versionString) {
        // Install correct cordova version if not available
        var packagePath = path.join(moduleCache, config.nodePackageName || CORDOVA);
        var versionPath = path.join(packagePath, version ? version : versionString);
        var targetModulePath = path.join(versionPath, 'node_modules', config.nodePackageName)
        if (!utilities.fileExistsSync(targetModulePath)) {  // Fix: Check module is there not just root path
            if (!utilities.fileExistsSync(packagePath)) {
                fs.mkdirSync(packagePath);
            }
            
            if (!utilities.fileExistsSync(versionPath)) {
                fs.mkdirSync(versionPath);
                fs.mkdirSync(path.join(versionPath, 'node_modules')); // node_modules being present ensures correct install loc
            }

            console.log('Installing ' + pkgStr + ' to ' + versionPath + '. (This may take a few minutes.)');
            var cmd = 'npm install --force ' + pkgStr + ' 2>&1';
            return exec(cmd, { cwd: versionPath })
                .then(utilities.handleExecReturn)
                .then(function () {
                return {
                    version: version,
                    path: targetModulePath
                };
            });
        } else {
            console.log(pkgStr + ' already installed.');
            return Q({
                version: version,
                path: targetModulePath
            });
        }
    });
}
function cacheModule(config) {
    config = utilities.parseConfig(config);
    var moduleCache = utilities.getCachePath();
    console.log('Module cache at ' + moduleCache);

    var version = getModuleVersionFromConfig(config);

    var pkgStr = config.nodePackageName + (version ? '@' + version : '');
    return utilities.getVersionForNpmPackage(pkgStr).then(function (versionString) {
        // Install correct cordova version if not available
        var packagePath = path.join(moduleCache, config.nodePackageName || CORDOVA);
        var versionPath = path.join(packagePath, version ? version : versionString);
        var targetModulePath = path.join(versionPath, 'node_modules', config.nodePackageName)
        if (!utilities.fileExistsSync(targetModulePath)) {  // Fix: Check module is there not just root path
            if (!utilities.fileExistsSync(packagePath)) {
                fs.mkdirSync(packagePath);
            }
            
            if (!utilities.fileExistsSync(versionPath)) {
                fs.mkdirSync(versionPath);
                fs.mkdirSync(path.join(versionPath, 'node_modules')); // node_modules being present ensures correct install loc
            }

            console.log('Installing ' + pkgStr + ' to ' + versionPath + '. (This may take a few minutes.)');
            var cmd = 'npm install --force ' + pkgStr + ' 2>&1';
            return exec(cmd, { cwd: versionPath })
                .then(utilities.handleExecReturn)
                .then(function () {
                return {
                    version: version,
                    path: targetModulePath
                };
            });
        } else {
            console.log(pkgStr + ' already installed.');
            return Q({
                version: version,
                path: targetModulePath
            });
        }
    });
}
function cacheModule ( config ) { config = utilities . parseConfig ( config ) ; var moduleCache = utilities . getCachePath ( ) ; console . log ( 'Module cache at ' + moduleCache ) ; var version = getModuleVersionFromConfig ( config ) ; var pkgStr = config . nodePackageName + ( version ? '@' + version : '' ) ; return utilities . getVersionForNpmPackage ( pkgStr ) . then ( function ( versionString ) { // Install correct cordova version if not available var packagePath = path . join ( moduleCache , config . nodePackageName || CORDOVA ) ; var versionPath = path . join ( packagePath , version ? version : versionString ) ; var targetModulePath = path . join ( versionPath , 'node_modules' , config . nodePackageName ) if ( ! utilities . fileExistsSync ( targetModulePath ) ) { // Fix: Check module is there not just root path if ( ! utilities . fileExistsSync ( packagePath ) ) { fs . mkdirSync ( packagePath ) ; } if ( ! utilities . fileExistsSync ( versionPath ) ) { fs . mkdirSync ( versionPath ) ; fs . mkdirSync ( path . join ( versionPath , 'node_modules' ) ) ; // node_modules being present ensures correct install loc } console . log ( 'Installing ' + pkgStr + ' to ' + versionPath + '. (This may take a few minutes.)' ) ; var cmd = 'npm install --force ' + pkgStr + ' 2>&1' ; return exec ( cmd , { cwd : versionPath } ) . then ( utilities . handleExecReturn ) . then ( function ( ) { return { version : version , path : targetModulePath } ; } ) ; } else { console . log ( pkgStr + ' already installed.' ) ; return Q ( { version : version , path : targetModulePath } ) ; } } ) ; }
Install module method
Install module method