cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject cordova-lib git commit: CB-12425 & CB-12517 :12425: autocreate a package.json if it doesn't exist during restore & 12517: pkgJson name is config id and pkgJson displayname is config's name CB-12517 : pkgJson's name is config.xml's id and pkgjson's displa
Date Wed, 05 Apr 2017 21:20:43 GMT
Repository: cordova-lib
Updated Branches:
  refs/heads/master a20d770ab -> 08d47d86e


CB-12425 & CB-12517 :12425: autocreate a package.json if it doesn't exist during restore
& 12517: pkgJson name is config id and pkgJson displayname is config's name
CB-12517 : pkgJson's name is config.xml's id and pkgjson's displayName is config.xml's name

 This closes #521


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

Branch: refs/heads/master
Commit: 08d47d86e55b5e471d1a8eac709d2191eecb09cb
Parents: a20d770
Author: Audrey So <audreyso@apache.org>
Authored: Wed Feb 22 16:24:48 2017 -0800
Committer: Steve Gill <stevengill97@gmail.com>
Committed: Wed Apr 5 16:18:57 2017 -0500

----------------------------------------------------------------------
 .../spec-cordova/pkgJson-restore.spec.js        | 15 ++++++++--
 cordova-lib/spec-cordova/save.spec.js           | 28 +++++++++---------
 cordova-lib/src/cordova/platform.js             |  5 ++--
 cordova-lib/src/cordova/plugin.js               |  3 +-
 cordova-lib/src/cordova/restore-util.js         | 31 ++++++++++++++++----
 5 files changed, 54 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/08d47d86/cordova-lib/spec-cordova/pkgJson-restore.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/pkgJson-restore.spec.js b/cordova-lib/spec-cordova/pkgJson-restore.spec.js
index 43880eb..fa52ea2 100644
--- a/cordova-lib/spec-cordova/pkgJson-restore.spec.js
+++ b/cordova-lib/spec-cordova/pkgJson-restore.spec.js
@@ -128,7 +128,7 @@ describe('tests platform/spec restore with --save', function () {
             expect(err).toBeUndefined();
         }).fin(done);
     // Cordova prepare needs extra wait time to complete.
-},300000);
+    },300000);
 
     /** Test#017
     *   When platform is added with url and fetch and restored with fetch, 
@@ -1289,7 +1289,7 @@ describe('platforms and plugins should be restored with config.xml even
without
         expect(Object.keys(configPlugins).length === 1);
 
         emptyPlatformList().then(function() {
-            // Run cordova prepare.
+            // Run platform add.
             return cordova.raw.platform('add', browserPlatform, {'save':true});
         }).then(function () {
             // Android and browser are in config.xml.
@@ -1306,6 +1306,16 @@ describe('platforms and plugins should be restored with config.xml
even without
             expect(platformsJson).toBeDefined();
             expect(platformsJson[androidPlatform]).not.toBeDefined();
             expect(platformsJson[browserPlatform]).toBeDefined();
+            // Package.json should be auto-created.
+            expect(path.join(cwd,'package.json')).toExist();
+            var pkgJsonPath = path.join(cwd,'package.json');
+            delete require.cache[require.resolve(pkgJsonPath)];
+            var pkgJson = require(pkgJsonPath);
+            // Expect that pkgJson name, version, and displayName should use
+            // config.xml's id, version, and name.
+            expect(pkgJson.name).toEqual(cfg3.packageName().toLowerCase());
+            expect(pkgJson.version).toEqual(cfg3.version());
+            expect(pkgJson.displayName).toEqual(cfg3.name());
             // Remove android without --save.
             return cordova.raw.platform('rm', [browserPlatform]);
         }).then(function () {
@@ -1373,7 +1383,6 @@ describe('platforms and plugins should be restored with config.xml even
without
     },TIMEOUT);
 });
 
-
 // Use basePkgJson
 describe('tests platform/spec restore with --save', function () {
     var tmpDir = helpers.tmpDir('platform_test_pkgjson2');

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/08d47d86/cordova-lib/spec-cordova/save.spec.js
----------------------------------------------------------------------
diff --git a/cordova-lib/spec-cordova/save.spec.js b/cordova-lib/spec-cordova/save.spec.js
index 8c0aa86..7117789 100644
--- a/cordova-lib/spec-cordova/save.spec.js
+++ b/cordova-lib/spec-cordova/save.spec.js
@@ -626,36 +626,36 @@ describe('(save flag)', function () {
             });
         }, TIMEOUT);
 
-        it('Test 030 : spec.23.1 should restore scoped plugins', function (done) {
-            redirectRegistryCalls(pluginName2 + '@~' + pluginVersion2);
-            var scopedPackage = '@test-scope/' + pluginName2;
+        it('Test 030 : spec.23.2 should restore plugins without spec attribute', function
(done) {
+            redirectRegistryCalls(pluginName2);
             helpers.setEngineSpec(appPath, platformName, platformLocalPathNewer);
-            helpers.setPluginSpec(appPath, pluginName2, scopedPackage + '@~' + pluginVersion2);
+            helpers.setPluginSpec(appPath, pluginName2/**, do not specify spec here */);
             prepare()
             .then(function () {
-                expect(registry.fetch).toHaveBeenCalledWith([scopedPackage + '@~' + pluginVersion2]);
+                expect(registry.fetch).toHaveBeenCalledWith([pluginName2]);
                 expect(path.join(appPath, 'plugins', pluginName2)).toExist();
-                done();
             }).catch(function (err) {
                 expect(true).toBe(false);
                 console.log(err.message);
-                done();
-            });
+            })
+            .fin(done);
         }, TIMEOUT);
 
-        it('Test 031 : spec.23.2 should restore plugins without spec attribute', function
(done) {
-            redirectRegistryCalls(pluginName2);
+        it('Test 031 : spec.23.1 should restore scoped plugins', function (done) {
+            redirectRegistryCalls(pluginName2 + '@~' + pluginVersion2);
+            var scopedPackage = '@test-scope/' + pluginName2;
             helpers.setEngineSpec(appPath, platformName, platformLocalPathNewer);
-            helpers.setPluginSpec(appPath, pluginName2/**, do not specify spec here */);
+            helpers.setPluginSpec(appPath, pluginName2, scopedPackage + '@~' + pluginVersion2);
             prepare()
             .then(function () {
-                expect(registry.fetch).toHaveBeenCalledWith([pluginName2]);
+                expect(registry.fetch).toHaveBeenCalledWith([scopedPackage + '@~' + pluginVersion2]);
                 expect(path.join(appPath, 'plugins', pluginName2)).toExist();
+                done();
             }).catch(function (err) {
                 expect(true).toBe(false);
                 console.log(err.message);
-            })
-            .fin(done);
+                done();
+            });
         }, TIMEOUT);
 
         it('Test 032 : spec.24 should restore only specified platform', function (done) {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/08d47d86/cordova-lib/src/cordova/platform.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/platform.js b/cordova-lib/src/cordova/platform.js
index aa84948..80a3ebe 100644
--- a/cordova-lib/src/cordova/platform.js
+++ b/cordova-lib/src/cordova/platform.js
@@ -134,7 +134,7 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
                 if( (opts.save || autosave) && !spec && platforms[platform])
{
                     spec = platforms[platform].version;
                 }
-                
+
                 // Handle local paths
                 if (spec) {
                     var maybeDir = cordova_util.fixRelativePath(spec);
@@ -274,10 +274,9 @@ function addHelper(cmd, hooksRunner, projectRoot, targets, opts) {
             var pkgJson;
             var pkgJsonPath = path.join(projectRoot, 'package.json');
             var modifiedPkgJson = false;
+            
             if(fs.existsSync(pkgJsonPath)) {
                 pkgJson = cordova_util.requireNoCache(path.join(pkgJsonPath)); 
-            } else {
-                // TODO: Create package.json in cordova@7
             }
 
             if (pkgJson === undefined) {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/08d47d86/cordova-lib/src/cordova/plugin.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/plugin.js b/cordova-lib/src/cordova/plugin.js
index 377e97b..5580ab5 100644
--- a/cordova-lib/src/cordova/plugin.js
+++ b/cordova-lib/src/cordova/plugin.js
@@ -239,9 +239,8 @@ module.exports = function plugin(command, targets, opts) {
                                 if(fs.existsSync(pkgJsonPath)) {
                                     // Delete any previous caches of require(package.json)
                                     pkgJson = cordova_util.requireNoCache(pkgJsonPath);
-                                } else {
-                                    // Create package.json in cordova@7
                                 }
+
                                 // If package.json exists, the plugin object and plugin name

                                 // will be added to package.json if not already there.
                                 if (!pkgJson) {

http://git-wip-us.apache.org/repos/asf/cordova-lib/blob/08d47d86/cordova-lib/src/cordova/restore-util.js
----------------------------------------------------------------------
diff --git a/cordova-lib/src/cordova/restore-util.js b/cordova-lib/src/cordova/restore-util.js
index 6f4029b..a17e1c1 100644
--- a/cordova-lib/src/cordova/restore-util.js
+++ b/cordova-lib/src/cordova/restore-util.js
@@ -53,6 +53,7 @@ function installPlatformsFromConfigXML(platforms, opts) {
     if(fs.existsSync(pkgJsonPath)) {
         pkgJson = require(pkgJsonPath);
     }
+
     if(pkgJson !== undefined && pkgJson.cordova !== undefined && pkgJson.cordova.platforms
!== undefined) {
         pkgJsonPlatforms = pkgJson.cordova.platforms;
     } 
@@ -63,7 +64,25 @@ function installPlatformsFromConfigXML(platforms, opts) {
             // Combining arrays and checking duplicates.
             comboArray = pkgJsonPlatforms.slice();
         }
+
         engines = cfg.getEngines(projectHome);
+
+        // TODO: CB-12592: Eventually refactor out to pacakge manager module.
+        // If package.json doesn't exist, auto-create one.
+        if (engines.length > 0 && pkgJson === undefined) {
+            pkgJson = {};
+            if(cfg.packageName()){
+                pkgJson.name = cfg.packageName().toLowerCase();
+            }
+            if(cfg.version()) {
+                pkgJson.version = cfg.version();
+            }
+            if(cfg.name()) {
+                pkgJson.displayName = cfg.name();
+            }
+            fs.writeFileSync(pkgJsonPath, JSON.stringify(pkgJson, null, 4), 'utf8');
+        }
+
         configPlatforms = engines.map(function(Engine) {
             var configPlatName = Engine.name;
             // Add specs from config into mergedPlatformSpecs.
@@ -85,14 +104,14 @@ function installPlatformsFromConfigXML(platforms, opts) {
         },[]);
         comboArray = uniq;
         comboArray = comboArray.sort();
-
+ 
         // No platforms to restore from either config.xml or package.json.
         if (comboArray.length <= 0) {
             return Q('No platforms found in config.xml or package.json. Nothing to restore');
         }
 
         // If no package.json, don't continue.
-        if (pkgJson !== undefined) { 
+        if (pkgJson !== undefined) {
             // If config.xml & pkgJson exist and the cordova key is undefined, create
a cordova key.
             if (pkgJson.cordova === undefined) {
                 pkgJson.cordova = {};
@@ -114,10 +133,11 @@ function installPlatformsFromConfigXML(platforms, opts) {
             events.emit('verbose', 'Package.json and config.xml platforms are different.
Updating config.xml with most current list of platforms.');
             comboArray.forEach(function(item) {
                 var prefixItem = ('cordova-'+item);
+
                 // Modify package.json if any of these cases are true:
-                if((pkgJson.dependencies === undefined && Object.keys(mergedPlatformSpecs).length)||
-                    (pkgJson.dependencies[item] === undefined && mergedPlatformSpecs[item])
||
-                    (pkgJson.dependencies[prefixItem] === undefined && mergedPlatformSpecs[prefixItem]))
{
+                if((pkgJson.dependencies === undefined && Object.keys(mergedPlatformSpecs).length)
||
+                (pkgJson.dependencies && mergedPlatformSpecs && pkgJson.dependencies[item]
=== undefined && mergedPlatformSpecs[item]) || 
+                (pkgJson.dependencies && mergedPlatformSpecs && pkgJson.dependencies[prefixItem]
=== undefined && mergedPlatformSpecs[prefixItem])) {
                     modifiedPkgJson = true;
                 }
 
@@ -136,7 +156,6 @@ function installPlatformsFromConfigXML(platforms, opts) {
                     }
                     mergedPlatformSpecs[item] = pkgJson.dependencies[item];
                 }
-
                 // First remove the engine and then add missing engine and elements to config.xml.
                 // Remove to avoid duplicate engines.
                 if(mergedPlatformSpecs[item]) {


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


Mime
View raw message