cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [1/3] cordova-lib git commit: CB-8286 Never persist value of create --link-to within .cordova/config.json
Date Fri, 09 Jan 2015 20:54:03 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master a78aea189 -> 18c9a5209


CB-8286 Never persist value of create --link-to within .cordova/config.json


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

Branch: refs/heads/master
Commit: 18c9a52091937346b96b573fec474850097a7158
Parents: e14fd53
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Fri Jan 9 15:06:55 2015 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Fri Jan 9 15:47:43 2015 -0500

----------------------------------------------------------------------
 cordova-lib/src/cordova/create.js | 50 ++++++++++++++++++----------------
 cordova-lib/src/cordova/plugin.js |  2 +-
 2 files changed, 28 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/18c9a520/cordova-lib/src/cordova/create.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/create.js b/cordova-lib/src/cordova/create.js
index 3964d26..c8a051a 100644
--- a/cordova-lib/src/cordova/create.js
+++ b/cordova-lib/src/cordova/create.js
@@ -92,34 +92,43 @@ function create(dir, id, name, cfg) {
         return Q.reject(new CordovaError('Path already exists and is not empty: ' + dir));
     }
 
-    // Read / Write .cordova/config.json file if necessary.
+    var symlink = false; // Whether to symlink the www dir instead of copying.
+    var diskConfig = config.read(dir);
+    var wwwLib = cfg.lib && cfg.lib.www || diskConfig.lib && diskConfig.lib.www;
+    if (wwwLib) {
+        // This was changed from "uri" to "url", but checking uri for backwards compatibility.
+        wwwLib.url = wwwLib.url || wwwLib.uri;
+        // TODO (kamrik): extend lazy_load for retrieval without caching to allow net urls
for --src.
+        wwwLib.version = wwwLib.version || 'not_versioned';
+        wwwLib.id = wwwLib.id || 'dummy_id';
+        symlink  = !!wwwLib.link;
+        // Strip link and url from cfg to avoid them being persisted to disk via .cordova/config.json.
+        cfg = JSON.parse(JSON.stringify(cfg));
+        cfg.lib.www = 0;
+        cfg = JSON.parse(JSON.stringify(cfg).replace(',"www":0', '').replace(/"www":0,?/,
'').replace(',"lib":{}', '').replace(/"lib":{},?/, ''));
+    }
+
+    // Update cached version of config.json
     var origAutoPersist = config.getAutoPersist();
     config.setAutoPersist(false);
-    var config_json = config(dir, cfg);
+    config(dir, cfg);
     config.setAutoPersist(origAutoPersist);
 
     var p;
-    var symlink = false; // Whether to symlink the www dir instead of copying.
     var www_parent_dir;
     var custom_config_xml;
     var custom_merges;
     var custom_hooks;
 
-    if (config_json.lib && config_json.lib.www) {
-        // This was changed from "uri" to "url", but checking uri for backwards compatibility.
-        config_json.lib.www.url = config_json.lib.www.url || config_json.lib.www.uri;
-        events.emit('log', 'Using custom www assets from '+config_json.lib.www.url);
-        // TODO (kamrik): extend lazy_load for retrieval without caching to allow net urls
for --src.
-        config_json.lib.www.version = config_json.lib.www.version || 'not_versioned';
-        config_json.lib.www.id = config_json.lib.www.id || 'dummy_id';
-        symlink  = !!config_json.lib.www.link;
+    if (wwwLib && wwwLib.url) {
+        events.emit('log', 'Using custom www assets from ' + wwwLib.url);
 
         // Make sure that the source www/ is not a direct ancestor of the
         // target www/, or else we will recursively copy forever. To do this,
         // we make sure that the shortest relative path from source-to-target
         // must start by going up at least one directory or with a drive
         // letter for Windows.
-        var rel_path = path.relative(config_json.lib.www.url, www_dir);
+        var rel_path = path.relative(wwwLib.url, www_dir);
         var goes_up = rel_path.split(path.sep)[0] == '..';
 
         if (!(goes_up || rel_path[1] == ':')) {
@@ -127,14 +136,14 @@ function create(dir, id, name, cfg) {
                 'Project dir "' +
                 dir +
                 '" must not be created at/inside the template used to create the project
"' +
-                config_json.lib.www.url + '".'
+                wwwLib.url + '".'
             );
         }
-        if(symlink) {
-            p = Q(config_json.lib.www.url);
+        if (symlink) {
+            p = Q(wwwLib.url);
             events.emit('verbose', 'Symlinking custom www assets into "' + www_dir + '"');
         } else {
-            p = lazy_load.custom(config_json.lib, 'www')
+            p = lazy_load.custom({'www': wwwLib}, 'www')
             .then(function(d) {
                 events.emit('verbose', 'Copying custom www assets into "' + www_dir + '"');
                 return d;
@@ -151,7 +160,6 @@ function create(dir, id, name, cfg) {
     }
 
     return p.then(function(www_lib) {
-        var cfg, config_json;
         if (!fs.existsSync(www_lib)) {
             throw new CordovaError('Could not find directory: '+www_lib);
         }
@@ -161,12 +169,8 @@ function create(dir, id, name, cfg) {
             www_lib = path.join(www_lib, 'www');
         }
 
-        cfg = config.read(dir);
-        config.setAutoPersist(true);
-        config_json = config(dir, cfg);
-
         // Find if we also have custom merges and config.xml as siblings of custom www.
-        if (www_parent_dir && config_json.lib && config_json.lib.www) {
+        if (www_parent_dir && wwwLib) {
             custom_config_xml = path.join(www_parent_dir, 'config.xml');
             if ( !fs.existsSync(custom_config_xml) ) {
                 custom_config_xml = null;
@@ -183,7 +187,7 @@ function create(dir, id, name, cfg) {
 
         var dirAlreadyExisted = fs.existsSync(dir);
         if (!dirAlreadyExisted) {
-            shell.mkdir(dir);
+            fs.mkdirSync(dir);
         }
         if (symlink) {
             try {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/18c9a520/cordova-lib/src/cordova/plugin.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/plugin.js b/cordova-lib/src/cordova/plugin.js
index f954a14..2485daf 100644
--- a/cordova-lib/src/cordova/plugin.js
+++ b/cordova-lib/src/cordova/plugin.js
@@ -95,7 +95,7 @@ module.exports = function plugin(command, targets, opts) {
                 return Q.reject(new CordovaError('No plugin specified. Please specify a plugin
to add. See `'+cordova_util.binname+' plugin search`.'));
             }
 
-            var config_json = config(projectRoot, {});
+            var config_json = config.read(projectRoot);
             var searchPath = config_json.plugin_search_path || [];
             if (typeof opts.searchpath == 'string') {
                 searchPath = opts.searchpath.split(path.delimiter).concat(searchPath);


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


Mime
View raw message