Skip to content

Commit b778705

Browse files
authored
Merge pull request #113 from adaptlearning/issues/#2149
Fix for issue #2149
2 parents e5a0eef + 842bb0d commit b778705

10 files changed

Lines changed: 42 additions & 25 deletions

File tree

lib/Constants.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ module.exports = {
1414
ComponentRepository : process.env.ADAPT_COMPONENT || 'https://github.com/adaptlearning/adapt-component',
1515
ComponentRepositoryName : 'adapt-component',
1616
DefaultBranch : process.env.ADAPT_BRANCH || 'master',
17-
Registry: getRegistry(),
18-
HomeDirectory : searchForHome()
17+
HomeDirectory : searchForHome(),
18+
getRegistry:getRegistry
1919
};
2020

21+
var registry = null;
22+
2123
function searchForHome() {
2224
var locations = [
2325
process.env.HOME,
@@ -31,7 +33,21 @@ function searchForHome() {
3133
}
3234

3335
function getRegistry() {
34-
if (process.env.ADAPT_REGISTRY) return process.env.ADAPT_REGISTRY;
35-
if (fs.existsSync('./.bowerrc')) return bower.config.registry.publish;
36-
return 'http://adapt-bower-repository.herokuapp.com/';
37-
}
36+
if (registry !== null) {
37+
return registry;
38+
}
39+
40+
if (process.env.ADAPT_REGISTRY) {
41+
registry = process.env.ADAPT_REGISTRY;
42+
43+
} else if (fs.existsSync('./.bowerrc')) {
44+
// a manifest exists; let bower determine the registry
45+
registry = undefined;
46+
47+
} else {
48+
// use the default Adapt registry
49+
registry = 'http://adapt-bower-repository.herokuapp.com/';
50+
}
51+
52+
return registry;
53+
}

lib/commands/devinstall.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = function (dependencies) {
3535

3636

3737
function createInstallationTask(plugin, localPath, renderer) {
38-
return PackageMeta.getKeywords(plugin, { registry: Constants.Registry })
38+
return PackageMeta.getKeywords(plugin, { registry: Constants.getRegistry() })
3939
.then(function (keywords) {
4040
var resolver = new PluginTypeResolver(),
4141
pluginType = resolver.resolve(keywords);
@@ -44,7 +44,7 @@ module.exports = function (dependencies) {
4444
return cloneInstall(plugin, {
4545
localPath: localPath,
4646
directory: path.join('src', pluginType.belongsTo),
47-
registry: Constants.Registry
47+
registry: Constants.getRegistry()
4848
});
4949
})
5050
.then(function (installed) {

lib/commands/install.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ module.exports = function (dependencies) {
692692
}
693693

694694
function createInstallationTask(plugin) {
695-
return PackageMeta.getKeywords(plugin, { registry: Constants.Registry }).then(doInstall).then(conclude);
695+
return PackageMeta.getKeywords(plugin, { registry: Constants.getRegistry() }).then(doInstall).then(conclude);
696696

697697
function doInstall(keywords) {
698698
var resolver = new PluginTypeResolver(),
@@ -703,7 +703,7 @@ module.exports = function (dependencies) {
703703

704704
return install(plugin, {
705705
directory: path.join('src', pluginType.belongsTo),
706-
registry: Constants.Registry
706+
registry: Constants.getRegistry()
707707
});
708708
}
709709

lib/commands/install/InstallTarget.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ var bower = require('bower'),
55
endpointParser = require('bower-endpoint-parser'),
66
semver = require('semver'),
77
Plugin = require('../../Plugin'),
8-
InstallLog = require('./InstallLog');
8+
InstallLog = require('./InstallLog'),
9+
Constants = require('../../Constants'),
910
extend = require('./extend');
1011

1112
var any = '*';
@@ -86,7 +87,7 @@ var InstallTarget = extend(Plugin, {
8687
try {
8788
var versionString = this._versions ? '#'+this._versions[this._versionIndex] : '';
8889
this._bowerCmdCount++;
89-
bower.commands.info(this.packageName+versionString).on('end', _.bind(onSuccess, this)).on('error', _.bind(onFail, this));
90+
bower.commands.info(this.packageName+versionString, null, {registry:Constants.getRegistry()}).on('end', _.bind(onSuccess, this)).on('error', _.bind(onFail, this));
9091
} catch(err) {
9192
onFail.call(this, err);
9293
}

lib/commands/register.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ function confirm(properties) {
159159
function register(plugin, repository) {
160160
var deferred = Q.defer();
161161

162-
bower.commands.register(plugin.toString(), repository, { registry: Constants.Registry })
162+
bower.commands.register(plugin.toString(), repository, { registry: Constants.getRegistry() })
163163
.on('end', function(result) {
164164
deferred.resolve({ result: result, plugin: plugin });
165165
})
@@ -172,7 +172,7 @@ function register(plugin, repository) {
172172
function exists(plugin) {
173173
var deferred = Q.defer();
174174

175-
bower.commands.search(plugin.toString(), { registry: Constants.Registry })
175+
bower.commands.search(plugin.toString(), { registry: Constants.getRegistry() })
176176
.on('end', function(result) {
177177
var matches = result.filter(exactMatch(plugin.toString()));
178178
deferred.resolve(!!matches.length);

lib/commands/rename.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424
// use Plugin to standardise name
2525
params.newName = new Plugin(params.newName).packageName;
2626

27-
log(chalk.yellow('Using registry at', Constants.Registry));
27+
log(chalk.yellow('Using registry at', Constants.getRegistry()));
2828
log(chalk.yellow('Plugin will be renamed to', params.newName));
2929

3030
Q(params)
@@ -95,7 +95,7 @@ function rename(params) {
9595
var query = '?access_token='+params.token;
9696

9797
request({
98-
url: Constants.Registry+'/'+path+query,
98+
url: Constants.getRegistry()+'/'+path+query,
9999
method:'GET',
100100
headers: {'User-Agent':'adapt-cli'},
101101
followRedirect:false
@@ -113,7 +113,7 @@ function rename(params) {
113113
function exists(plugin) {
114114
var deferred = Q.defer();
115115

116-
bower.commands.search(plugin.toString(), { registry: Constants.Registry })
116+
bower.commands.search(plugin.toString(), { registry: Constants.getRegistry() })
117117
.on('end', function(result) {
118118
var matches = result.filter(exactMatch(plugin.toString()));
119119
deferred.resolve(!!matches.length);
@@ -135,4 +135,4 @@ function exactMatch(pattern) {
135135
var regexp = new RegExp(pattern, 'i');
136136
return regexp.test(item.name);
137137
};
138-
}
138+
}

lib/commands/search.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111

1212
var plugin = new Plugin(searchTerm);
1313

14-
bower.commands.search(searchTerm, { registry: Constants.Registry })
14+
bower.commands.search(searchTerm, { registry: Constants.getRegistry() })
1515
.on('end', function(results) {
1616
if(!results.length) {
1717
renderer.log(chalk.yellow('no plugins found', plugin.toString()));
@@ -26,4 +26,4 @@ module.exports = {
2626
done(err);
2727
});
2828
}
29-
};
29+
};

lib/commands/uninstall.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = {
2525

2626
var plugin = Plugin.parse(packageName);
2727

28-
PackageMeta.getKeywords(plugin)
28+
PackageMeta.getKeywords(plugin, { registry: Constants.getRegistry() })
2929
.then(function (keywords) {
3030
var resolver = new PluginTypeResolver(),
3131
pluginType = resolver.resolve(keywords);

lib/commands/unregister.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = {
2020
pluginName = arguments[1];
2121
}
2222

23-
log(chalk.yellow('This will unregister the plugin at', Constants.Registry));
23+
log(chalk.yellow('This will unregister the plugin at', Constants.getRegistry()));
2424

2525
getProperties(pluginName)
2626
.then(authenticate)
@@ -92,7 +92,7 @@ function unregister(properties) {
9292
var deferred = Q.defer();
9393

9494
// user (username) with OAuth (token) wants to unregister the registered plugin (name) from registry
95-
bower.commands.unregister(properties.username+'/'+properties.name, {token:properties.token, registry: Constants.Registry})
95+
bower.commands.unregister(properties.username+'/'+properties.name, {token:properties.token, registry: Constants.getRegistry()})
9696
.on('end', function (result) {
9797
//log('end', result);
9898
deferred.resolve();

lib/commands/update.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ module.exports = function() {
334334
//console.log('Querying registry for', plugin.packageName, '(' + plugin.version + ')');
335335
var versionString = plugin._versions ? '#'+plugin._versions[plugin._versionIndex] : '';
336336
plugin._bowerCmdCount++;
337-
bower.commands.info(plugin.packageName+versionString).on('end', onSuccess).on('error', onFail);
337+
bower.commands.info(plugin.packageName+versionString, null, {registry:Constants.getRegistry()}).on('end', onSuccess).on('error', onFail);
338338
} catch(err) {
339339
onFail();
340340
}
@@ -674,7 +674,7 @@ module.exports = function() {
674674
//console.log(JSON.stringify(JsonLoader.readJSONSync('bower.json'), null, 4));
675675
return update(plugin, null, {
676676
directory: path.join('src', plugin._belongsTo),
677-
registry: Constants.Registry,
677+
registry: Constants.getRegistry(),
678678
force:true
679679
})
680680
.then(function (result) {

0 commit comments

Comments
 (0)