Created
April 2, 2015 09:11
-
-
Save JamieMason/b41d6b22124f4c008e61 to your computer and use it in GitHub Desktop.
Shrinkpack locations.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
module.exports = { | |
create: create | |
}; | |
var path = require('path'); | |
var terminal = require('terminal'); | |
function create(options) { | |
options = options || {}; | |
options.projectRoot = options.projectRoot || process.env.PWD; | |
options.registryRoot = options.registryRoot || 'https://registry.npmjs.org'; | |
options.projectCacheName = options.projectCacheName || 'node_shrinkwrap'; | |
options.systemCacheRoot = ''; | |
terminal.exec('npm config get cache') | |
.then(provideApi); | |
function provideApi(systemCacheRoot) { | |
options.systemCacheRoot = systemCacheRoot; | |
return { | |
projectCache: { | |
root: projectCacheRoot, | |
pkg: projectCachePackage | |
}, | |
systemCache: { | |
root: systemCacheRoot, | |
pkg: systemCachePackage | |
}, | |
publicRegistry: { | |
root: registryRoot, | |
pkg: registryPackage | |
} | |
}; | |
} | |
function projectCacheRoot() { | |
return path.resolve(path.join(options.projectRoot, options.projectCacheName)); | |
} | |
function systemCacheRoot() { | |
return options.systemCacheRoot; | |
} | |
function registryRoot() { | |
return options.registryRoot; | |
} | |
function projectCachePackage(name, version) { | |
return path.join(projectCacheRoot(), name + '-' + version + '.tgz'); | |
} | |
function systemCachePackage(name, version) { | |
return path.join(systemCacheRoot(), name, version, '/package.tgz'); | |
} | |
function registryPackage(name, version) { | |
return registryRoot() + '/' + name + '/-/' + name + '-' + version + '.tgz'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment