You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2015/03/06 01:26:41 UTC

[05/27] cordova-lib git commit: plugins are fetched from npm before cordova registry

plugins are fetched from npm before cordova registry


Project: http://git-wip-us.apache.org/repos/asf/cordova-lib/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-lib/commit/7db3df13
Tree: http://git-wip-us.apache.org/repos/asf/cordova-lib/tree/7db3df13
Diff: http://git-wip-us.apache.org/repos/asf/cordova-lib/diff/7db3df13

Branch: refs/heads/master
Commit: 7db3df134aba1bb5b5c1ea547ff919d621c30575
Parents: 8fe6b47
Author: Steve Gill <st...@gmail.com>
Authored: Fri Jan 23 15:25:33 2015 -0800
Committer: Steve Gill <st...@gmail.com>
Committed: Mon Jan 26 16:59:29 2015 -0800

----------------------------------------------------------------------
 cordova-lib/src/plugman/fetch.js             |   1 -
 cordova-lib/src/plugman/registry/registry.js | 121 ++++++++++++++++++----
 2 files changed, 99 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/7db3df13/cordova-lib/src/plugman/fetch.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/fetch.js b/cordova-lib/src/plugman/fetch.js
index e0f1cf4..dd78c84 100644
--- a/cordova-lib/src/plugman/fetch.js
+++ b/cordova-lib/src/plugman/fetch.js
@@ -124,7 +124,6 @@ function fetchPlugin(plugin_src, plugins_dir, options) {
                 ));
             }
             // If not found in local search path, fetch from the registry.
-            events.emit('log', 'Fetching plugin "' + plugin_src + '" via plugin registry');
             return registry.fetch([plugin_src], options.client)
             .then(function(dir) {
                 return {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/7db3df13/cordova-lib/src/plugman/registry/registry.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/plugman/registry/registry.js b/cordova-lib/src/plugman/registry/registry.js
index 7c33b27..d6e86d0 100644
--- a/cordova-lib/src/plugman/registry/registry.js
+++ b/cordova-lib/src/plugman/registry/registry.js
@@ -149,29 +149,15 @@ module.exports = {
      */
     fetch: function(plugin, client) {
         plugin = plugin.shift();
-        return initSettings()
-        .then(function (settings) {
-            return Q.nfcall(npm.load)
-            // configure npm here instead of passing parameters to npm.load due to CB-7670
-            .then(function () {
-                for (var prop in settings){
-                    npm.config.set(prop, settings[prop]);
-                }
-            });
-        })
-        .then(function() {
-            return Q.ninvoke(npm.commands, 'cache', ['add', plugin]);
-        })
-        .then(function(info) {
-            var cl = (client === 'plugman' ? 'plugman' : 'cordova-cli');
-            bumpCounter(info, cl);
-            var pluginDir = path.resolve(npm.cache, info.name, info.version, 'package');
-            // Unpack the plugin that was added to the cache (CB-8154)
-            var package_tgz = path.resolve(npm.cache, info.name, info.version, 'package.tgz');
-            return unpack.unpackTgz(package_tgz, pluginDir);
+        return fetchNPM(plugin, client)
+        .fail(function() {
+            events.emit('log', 'Fetching from npm failed');
+            //reset settings to fetch from cordova registry
+            module.exports.settings = null;
+            return fetchPlugReg(plugin,client);
         });
     },
-
+ 
     /**
      * @method info
      * @param {String} name Plugin name
@@ -192,7 +178,6 @@ module.exports = {
             // Plugin info should be accessed as info[version]. If a version
             // specifier like >=x.y.z was used when calling npm view, info
             // can contain several versions, but we take the first one here.
-            console.log(info);
             var version = Object.keys(info)[0];
             return info[version];
         });
@@ -227,6 +212,33 @@ function initSettings() {
     return Q(settings);
 }
 
+/**
+ * @method initSettingsNPM
+ * @return {Promise.<Object>} Promised settings.
+ */
+function initSettingsNPM() {
+    var settings = module.exports.settings;
+    // check if settings already set
+    if(settings !== null) return Q(settings);
+
+    // setting up settings
+    // obviously if settings dir does not exist settings is going to be empty
+    if(!fs.existsSync(plugmanConfigDir)) {
+        fs.mkdirSync(plugmanConfigDir);
+        fs.mkdirSync(plugmanCacheDir);
+    }
+
+    settings =
+    module.exports.settings =
+    rc('plugman', {
+        cache: plugmanCacheDir,
+        registry: 'http://registry.npmjs.org',
+        logstream: fs.createWriteStream(path.resolve(plugmanConfigDir, 'plugman.log')),
+        'cache-min': oneDay
+    });
+    return Q(settings);
+}
+
 
 // Send a message to the registry to update download counts.
 function bumpCounter(info, client) {
@@ -305,3 +317,68 @@ function makeRequest (method, where, what, cb_) {
 
     return req;
 }
+
+/**
+     * @method fetchNPM
+     * @param {Array} with one element - the plugin id or "id@version"
+     * @return {Promise.<string>} Promised path to fetched package.
+     */
+function fetchNPM(plugin, client) {
+    events.emit('log', 'Fetching plugin "' + plugin + '" via npm');
+    return initSettingsNPM()
+    .then(function (settings) {
+        return Q.nfcall(npm.load)
+        // configure npm here instead of passing parameters to npm.load due to CB-7670
+        .then(function () {
+            for (var prop in settings){
+                npm.config.set(prop, settings[prop]);
+            }
+        });
+    })
+    .then(function() {
+        return Q.ninvoke(npm.commands, 'cache', ['add', plugin]);
+    })
+    .then(function(info) {
+        var cl = (client === 'plugman' ? 'plugman' : 'cordova-cli');
+        bumpCounter(info, cl);
+        var pluginDir = path.resolve(npm.cache, info.name, info.version, 'package');
+        // Unpack the plugin that was added to the cache (CB-8154)
+        var package_tgz = path.resolve(npm.cache, info.name, info.version, 'package.tgz');
+        return unpack.unpackTgz(package_tgz, pluginDir);
+    });
+}
+
+
+/**
+ * @method fetchPlugReg
+ * @param {Array} with one element - the plugin id or "id@version"
+ * @return {Promise.<string>} Promised path to fetched package.
+ */
+function fetchPlugReg(plugin, client) {
+    events.emit('log', 'Fetching plugin "' + plugin + '" via plugin registry');
+        return initSettings()
+        .then(function (settings) {
+            return Q.nfcall(npm.load)
+            // configure npm here instead of passing parameters to npm.load due to CB-7670
+            .then(function () {
+                for (var prop in settings){
+                    npm.config.set(prop, settings[prop]);
+                }
+            });
+        })
+        .then(function() {
+            return Q.ninvoke(npm.commands, 'cache', ['add', plugin]);
+        })
+        .then(function(info) {
+            var cl = (client === 'plugman' ? 'plugman' : 'cordova-cli');
+            bumpCounter(info, cl);
+            var pluginDir = path.resolve(npm.cache, info.name, info.version, 'package');
+            // Unpack the plugin that was added to the cache (CB-8154)
+            var package_tgz = path.resolve(npm.cache, info.name, info.version, 'package.tgz');
+            return unpack.unpackTgz(package_tgz, pluginDir);
+        })
+        .fail(function() {
+            events.emit('log', 'Fetching from plugin registry failed');
+        });
+}
+


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org