Skip to content

Instantly share code, notes, and snippets.

@JamieMason
Created April 2, 2015 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamieMason/b41d6b22124f4c008e61 to your computer and use it in GitHub Desktop.
Save JamieMason/b41d6b22124f4c008e61 to your computer and use it in GitHub Desktop.
Shrinkpack locations.js
'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