Skip to content

Commit

Permalink
Use the new bower-config module.
Browse files Browse the repository at this point in the history
  • Loading branch information
satazor committed Jul 6, 2013
1 parent 746c050 commit 4d8dbef
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 74 deletions.
69 changes: 2 additions & 67 deletions lib/config.js
@@ -1,72 +1,7 @@
var path = require('path');
var os = require('os');
var mout = require('mout');
var rc = require('rc');
var config = require('bower-config').read();
var cli = require('./util/cli');

// Guess some needed properties based on the user OS
var temp = os.tmpdir ? os.tmpdir() : os.tmpDir();

var home = (process.platform === 'win32'
? process.env.USERPROFILE
: process.env.HOME) || temp;

var roaming = process.platform === 'win32'
? path.join(path.resolve(process.env.APPDATA || home || temp), 'bower_new') // TODO: change this to bower before release
: path.join(path.resolve(home || temp), '.bower_new'); // TODO: change this to bower before release

// Guess proxy defined in the env
var proxy = process.env.HTTP_PROXY
|| process.env.http_proxy || null;

var httpsProxy = process.env.HTTPS_PROXY
|| process.env.https_proxy
|| process.env.HTTP_PROXY
|| process.env.http_proxy
|| null;

var rc;
var config = {};

// -----------

// TODO: Move this whole module to a separate repository in bower/config
// TODO: There are some options that are not yet being applied in the codebase

// Read rc
try {
rc = rc('bower', {
'cwd': process.cwd(),
'directory': 'bower_components',
'registry': 'https://bower.herokuapp.com',
'shorthand-resolver': 'git://github.com/{{owner}}/{{package}}.git',
'tmp': temp,
'proxy': proxy,
'https-proxy': httpsProxy,
'ca': null,
'strict-ssl': true,
'user-agent': 'node/' + process.version + ' ' + process.platform + ' ' + process.arch,
'git': 'git',
'color': true,
'interactive': false,
'storage': {
cache: path.join(roaming, 'cache'),
links: path.join(roaming, 'links'),
completion: path.join(roaming, 'completion'),
registry: path.join(roaming, 'registry'),
git: path.join(roaming, 'git')
}
});
} catch (e) {
throw new Error('Unable to parse runtime configuration: ' + e.message);
}

// Generate config based on the rc, making every key camelCase
mout.object.forOwn(rc, function (value, key) {
key = key.replace(/_/g, '-'); // For backwards compatibility
config[mout.string.camelCase(key)] = value;
});

// Merge common CLI options into the config
mout.object.mixIn(config, cli.readOptions({
force: { type: Boolean, shorthand: 'f' },
Expand All @@ -78,6 +13,6 @@ mout.object.mixIn(config, cli.readOptions({
silent: { type: Boolean, shorthand: 's' }
}));

// TODO: check if config.cwd is a valid directory
// TODO: some config's are not being used thorough the architecture components

module.exports = config;
6 changes: 5 additions & 1 deletion lib/core/ResolveCache.js
Expand Up @@ -16,7 +16,7 @@ function ResolveCache(config) {
// - Max MB per source
// - etc..
this._config = config;
this._dir = this._config.storage.cache;
this._dir = this._config.storage.packages;

// Cache is stored/retrieved statically to ensure singularity
// among instances
Expand Down Expand Up @@ -190,6 +190,10 @@ ResolveCache.prototype.clear = function () {
}.bind(this));
};

ResolveCache.prototype.reset = function () {
this._cache.reset();
};

ResolveCache.prototype.list = function () {
var promises;
var dirs = [];
Expand Down
6 changes: 3 additions & 3 deletions lib/index.js
Expand Up @@ -3,11 +3,11 @@ var mout = require('mout');
var commands = require('./commands');
var PackageRepository = require('./core/PackageRepository');

var abbreviations = abbrev(names(commands));
var abbreviations = abbrev(expandNames(commands));
abbreviations.i = 'install';
abbreviations.rm = 'uninstall';

function names(obj, prefix, stack) {
function expandNames(obj, prefix, stack) {
prefix = prefix || '';
stack = stack || [];

Expand All @@ -17,7 +17,7 @@ function names(obj, prefix, stack) {
stack.push(name);

if (typeof value === 'object' && !value.line) {
names(value, name + ' ', stack);
expandNames(value, name + ' ', stack);
}
});

Expand Down
6 changes: 3 additions & 3 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "bower_new",
"version": "0.0.0",
"version": "1.0.0-rc.1",
"description": "The browser package manager.",
"author": "Twitter",
"licenses": [
Expand All @@ -21,6 +21,7 @@
"dependencies": {
"archy": "0.0.2",
"abbrev": "~1.0.4",
"bower-config": "~0.0.0",
"bower-json": "~0.0.0",
"bower-registry-client": "~0.0.0",
"chmodr": "~0.1.0",
Expand All @@ -37,7 +38,6 @@
"lru-cache": "~2.3.0",
"promptly": "~0.2.0",
"q": "~0.9.2",
"rc": "~0.3.0",
"request": "~2.21.0",
"rimraf": "~2.1.4",
"semver": "~2.0.8",
Expand All @@ -49,7 +49,7 @@
"which": "~1.0.5"
},
"devDependencies": {
"mocha": "~1.8.2",
"mocha": "~1.12.0",
"expect.js": "~0.2.0",
"nock": "~0.17.5",
"grunt-simple-mocha": "~0.4.0",
Expand Down

0 comments on commit 4d8dbef

Please sign in to comment.