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 2016/06/01 23:36:01 UTC

cordova-lib git commit: CB-11349 added --fetch and cordova fetch to create --template

Repository: cordova-lib
Updated Branches:
  refs/heads/master 61f584de5 -> cc0e0e9ac


CB-11349 added --fetch and cordova fetch to create --template


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

Branch: refs/heads/master
Commit: cc0e0e9ac2f1a589bb6a13be4a1d4299fe1bdba1
Parents: 61f584d
Author: carynbear <ca...@berkeley.edu>
Authored: Tue May 31 15:30:37 2016 -0700
Committer: carynbear <ca...@berkeley.edu>
Committed: Wed Jun 1 15:55:46 2016 -0700

----------------------------------------------------------------------
 cordova-lib/spec-cordova/create.spec.js | 33 ++++++++++++++++++++++++++--
 cordova-lib/src/cordova/create.js       | 32 +++++++++++++++++----------
 2 files changed, 51 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/cc0e0e9a/cordova-lib/spec-cordova/create.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/create.spec.js b/cordova-lib/spec-cordova/create.spec.js
index 99579a2..b7dae0c 100644
--- a/cordova-lib/spec-cordova/create.spec.js
+++ b/cordova-lib/spec-cordova/create.spec.js
@@ -69,7 +69,6 @@ var configNPM = {
 };
 
 describe('cordova create checks for valid-identifier', function(done) {
-
     it('should reject reserved words from start of id', function(done) {
         cordova.raw.create('projectPath', 'int.bob', 'appName')
         .fail(function(err) {
@@ -77,7 +76,7 @@ describe('cordova create checks for valid-identifier', function(done) {
         })
         .fin(done);
     });
-
+    
     it('should reject reserved words from end of id', function(done) {
         cordova.raw.create('projectPath', 'bob.class', 'appName')
         .fail(function(err) {
@@ -191,6 +190,36 @@ describe('create end-to-end', function() {
             })
             .fin(done);
     });
+
+    it('should successfully run with Git URL --fetch', function(done) {
+        // Call cordova create with no args, should return help.
+        Q()
+            .then(function() {
+                // Create a real project
+                return cordova.raw.create(project, appId, appName, configGit, true);
+            })
+            .then(checkProject)
+            .fail(function(err) {
+                console.log(err && err.stack);
+                expect(err).toBeUndefined();
+            })
+            .fin(done);
+    }, 60000);
+
+    it('should successfully run with NPM package --fetch', function(done) {
+        // Call cordova create with no args, should return help.
+        Q()
+            .then(function() {
+                // Create a real project
+                return cordova.raw.create(project, appId, appName, configNPM, true);
+            })
+            .then(checkProject)
+            .fail(function(err) {
+                console.log(err && err.stack);
+                expect(err).toBeUndefined();
+            })
+            .fin(done);
+    });
     
     it('should successfully run with template not having a package.json at toplevel', function(done) {
         // Call cordova create with no args, should return help.

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/cc0e0e9a/cordova-lib/src/cordova/create.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/create.js b/cordova-lib/src/cordova/create.js
index 7f5c2d3..c98ab90 100644
--- a/cordova-lib/src/cordova/create.js
+++ b/cordova-lib/src/cordova/create.js
@@ -27,6 +27,7 @@ var path          = require('path'),
     CordovaError  = require('cordova-common').CordovaError,
     ConfigParser  = require('cordova-common').ConfigParser,
     cordova_util  = require('./util'),
+    fetch         = require('cordova-fetch'),
     validateIdentifier = require('valid-identifier');
 
 /**
@@ -35,15 +36,15 @@ var path          = require('path'),
  * @optionalId - app id. Optional.
  * @optionalName - app name. Optional.
  * @cfg - extra config to be saved in .cordova/config.json
+ * @fetchOpt- boolean for --fetch. Optional(?)
  **/
 // Returns a promise.
 module.exports = create;
-function create(dir, optionalId, optionalName, cfg) {
+function create(dir, optionalId, optionalName, cfg, fetchOpt) {
     var argumentCount = arguments.length;
-
+    fetchOpt = fetchOpt || false;
     return Q.fcall(function() {
-        // Lets check prerequisites first
-
+        // Lets check prerequisites first; NOTE: argCount is always 5 when run with cli
         if (argumentCount == 3) {
           cfg = optionalName;
           optionalName = undefined;
@@ -178,11 +179,18 @@ function create(dir, optionalId, optionalName, cfg) {
             return cfg.lib.www.url;
         } else {
             events.emit('verbose', 'Copying assets."');
-
             isGit = cfg.lib.www.template && cordova_util.isUrl(cfg.lib.www.url);
             isNPM = cfg.lib.www.template && (cfg.lib.www.url.indexOf('@') > -1 || !fs.existsSync(path.resolve(cfg.lib.www.url)));
 
-            if (isGit) {
+            //If --fetch flag is passed, use cordova fetch to obtain the npm or git template
+            if((isGit || isNPM) && fetchOpt) {
+                //Saved to .Cordova folder (ToDo: Delete installed template after using)
+                var tempDest = cordova_util.globalConfig;
+                events.emit('log', 'Using cordova-fetch for '+ cfg.lib.www.url);
+                return fetch(cfg.lib.www.url, tempDest, {});
+            //Otherwise use remote-load to get git template
+            } else if (isGit) {
+
                 parseArr = cfg.lib.www.url.split('#');
                 gitURL = parseArr[0];
                 branch = parseArr[1];
@@ -194,6 +202,7 @@ function create(dir, optionalId, optionalName, cfg) {
                         return Q.reject(new CordovaError('Failed to retrieve '+ cfg.lib.www.url + ' using git: ' + err.message));
                     }
                 );
+            //Otherwise use remote-load to get npm template
             } else if (isNPM) {
                 events.emit('log', 'Retrieving ' + cfg.lib.www.url + ' using npm...');
 
@@ -213,24 +222,24 @@ function create(dir, optionalId, optionalName, cfg) {
                         return Q.reject(new CordovaError('Failed to retrieve '+ cfg.lib.www.url + ' using npm: ' + err.message));
                     }
                 );
+            //If assets are not online, resolve as a relative path on local computer
             } else {
                 cfg.lib.www.url = path.resolve(cfg.lib.www.url);
 
                 return Q(cfg.lib.www.url);
             }
         }
-    })
-    .then(function(input_directory) {
+    }).then(function(input_directory) {
         var import_from_path = input_directory;
-
-        //handle when input wants to specify sub-directory
+        //handle when input wants to specify sub-directory (specified in index.js); 
+        //
         try {
             var templatePkg = require(input_directory);
             if (templatePkg && templatePkg.dirname){
                 import_from_path = templatePkg.dirname;
             }
         } catch (e) {
-            events.emit('verbose', 'Can not load template package.json using directory ' + input_directory);
+            events.emit('verbose', 'index.js does not specific valid sub-directory: ' + input_directory);
         }
 
         if (!fs.existsSync(import_from_path)) {
@@ -244,7 +253,6 @@ function create(dir, optionalId, optionalName, cfg) {
         };
 
         // Keep going into child "www" folder if exists in stock app package.
-        // why?
         while (fs.existsSync(path.join(paths.www, 'www'))) {
             paths.root = paths.www;
             paths.www = path.join(paths.root, 'www');


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