cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bra...@apache.org
Subject [2/2] git commit: Add .fetch.json metadata file to plugin dirs after fetch
Date Mon, 03 Jun 2013 22:03:34 GMT
Add .fetch.json metadata file to plugin dirs after fetch

This file holds data about where this plugin was fetched from. This
facilitates updating plugins and installing relative dependencies.


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

Branch: refs/heads/master
Commit: f7a7a45e8793b7e2781d3da670a81e29154789da
Parents: fbb7768
Author: Braden Shepherdson <braden.shepherdson@gmail.com>
Authored: Mon Jun 3 15:47:15 2013 -0400
Committer: Braden Shepherdson <braden.shepherdson@gmail.com>
Committed: Mon Jun 3 18:03:21 2013 -0400

----------------------------------------------------------------------
 src/fetch.js         |   24 +++++++++++++++++++++++-
 src/util/metadata.js |   19 +++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f7a7a45e/src/fetch.js
----------------------------------------------------------------------
diff --git a/src/fetch.js b/src/fetch.js
index 201f495..68f5113 100644
--- a/src/fetch.js
+++ b/src/fetch.js
@@ -2,6 +2,7 @@ var shell   = require('shelljs'),
     fs      = require('fs'),
     plugins = require('./util/plugins'),
     xml_helpers = require('./util/xml-helpers'),
+    metadata = require('./util/metadata'),
     path    = require('path');
 
 // possible options: link, subdir, git_ref
@@ -19,7 +20,20 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options,
callback
             if (callback) callback(err);
             else throw err;
         } else {
-            plugins.clonePluginGitRepo(plugin_dir, plugins_dir, options.subdir, options.git_ref,
callback);
+            var data = {
+                source: {
+                    type: 'git',
+                    url:  plugin_dir,
+                    subdir: options.subdir,
+                    ref: options.git_ref
+                }
+            };
+
+            plugins.clonePluginGitRepo(plugin_dir, plugins_dir, options.subdir, options.git_ref,
function(err, dir) {
+                if (!err) {
+                    metadata.save_fetch_metadata(dir, data);
+                }
+            });
         }
     } else {
         if (plugin_dir.lastIndexOf('file://', 0) === 0) {
@@ -42,6 +56,14 @@ module.exports = function fetchPlugin(plugin_dir, plugins_dir, options,
callback
             shell.cp('-R', path.join(plugin_dir, '*') , dest);
         }
 
+        var data = {
+            source: {
+                type: 'local',
+                path: plugin_dir
+            }
+        };
+        metadata.save_fetch_metadata(dest, data);
+
         if (callback) callback(null, dest);
     }
 };

http://git-wip-us.apache.org/repos/asf/cordova-plugman/blob/f7a7a45e/src/util/metadata.js
----------------------------------------------------------------------
diff --git a/src/util/metadata.js b/src/util/metadata.js
new file mode 100644
index 0000000..cfbb643
--- /dev/null
+++ b/src/util/metadata.js
@@ -0,0 +1,19 @@
+var fs = require('fs'),
+    path = require('path');
+
+var filename = '.fetch.json';
+
+exports.get_fetch_metadata = function(plugin_dir) {
+    var filepath = path.join(plugin_dir, filename);
+    if (fs.existsSync(filepath)) {
+        return JSON.parse(fs.readFileSync(filepath, 'utf-8'));
+    } else {
+        return {};
+    }
+};
+
+exports.save_fetch_metadata = function(plugin_dir, data) {
+    var filepath = path.join(plugin_dir, '.fetch.json');
+    fs.writeFileSync(filepath, JSON.stringify(data), 'utf-8');
+};
+


Mime
View raw message