cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [2/4] android commit: CB-8358 Make --link an alias for --shared for create/update. Make it work with gradle
Date Mon, 26 Jan 2015 21:28:49 GMT
CB-8358 Make --link an alias for --shared for create/update. Make it work with gradle


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

Branch: refs/heads/4.0.x
Commit: a4c9bf7d30433c50a4412f3871f202997c76ed14
Parents: f459eaa
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Fri Jan 23 14:38:05 2015 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Mon Jan 26 10:07:14 2015 -0500

----------------------------------------------------------------------
 bin/create        |  6 +++---
 bin/lib/create.js | 38 +++++++++++++++++++++++++++-----------
 bin/update        |  6 +++---
 3 files changed, 33 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/a4c9bf7d/bin/create
----------------------------------------------------------------------
diff --git a/bin/create b/bin/create
index 9a4fc90..7063033 100755
--- a/bin/create
+++ b/bin/create
@@ -23,14 +23,14 @@ var create = require('./lib/create');
 var args  = require('./lib/simpleargs').getArgs(process.argv);
 
 if (args['--help'] || args._.length === 0) {
-    console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'create'))
+ ' <path_to_new_project> <package_name> <project_name> [<template_path>]
[--shared]');
+    console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'create'))
+ ' <path_to_new_project> <package_name> <project_name> [<template_path>]
[--link]');
     console.log('    <path_to_new_project>: Path to your new Cordova Android project');
     console.log('    <package_name>: Package name, following reverse-domain style convention');
     console.log('    <project_name>: Project name');
     console.log('    <template_path>: Path to a custom application template to use');
-    console.log('    --shared will use the CordovaLib project directly instead of making
a copy.');
+    console.log('    --link will use the CordovaLib project directly instead of making a
copy.');
     process.exit(1);
 }
 
-create.createProject(args._[0], args._[1], args._[2], args._[3], args['--shared'], args['--cli']).done();
+create.createProject(args._[0], args._[1], args._[2], args._[3], args['--link'] || args['--shared'],
args['--cli']).done();
 

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/a4c9bf7d/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index 5471bb4..5c2fc1c 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -59,15 +59,25 @@ function copyJsAndLibrary(projectPath, shared, projectName) {
             console.log("Deleting " + oldJar);
             shell.rm('-f', oldJar);
         });
+        var wasSymlink = true;
+        try {
+            // Delete the symlink if it was one.
+            fs.unlinkSync(nestedCordovaLibPath)
+        } catch (e) {
+            wasSymlink = false;
+        }
         // Delete old library project if it existed.
         if (shared) {
             shell.rm('-rf', nestedCordovaLibPath);
-        } else {
+        } else if (!wasSymlink) {
             // Delete only the src, since eclipse can't handle its .project file being deleted.
             shell.rm('-rf', path.join(nestedCordovaLibPath, 'src'));
         }
     });
-    if (!shared) {
+    if (shared) {
+        var relativeFrameworkPath = path.relative(projectPath, getFrameworkDir(projectPath,
true));
+        fs.symlinkSync(relativeFrameworkPath, nestedCordovaLibPath, 'dir');
+    } else {
         shell.mkdir('-p', nestedCordovaLibPath);
         shell.cp('-f', path.join(ROOT, 'framework', 'AndroidManifest.xml'), nestedCordovaLibPath);
         shell.cp('-f', path.join(ROOT, 'framework', 'project.properties'), nestedCordovaLibPath);
@@ -94,7 +104,7 @@ function extractSubProjectPaths(data) {
     return Object.keys(ret);
 }
 
-function writeProjectProperties(projectPath, target_api, shared) {
+function writeProjectProperties(projectPath, target_api) {
     var dstPath = path.join(projectPath, 'project.properties');
     var templatePath = path.join(ROOT, 'bin', 'templates', 'project', 'project.properties');
     var srcPath = fs.existsSync(dstPath) ? dstPath : templatePath;
@@ -107,7 +117,7 @@ function writeProjectProperties(projectPath, target_api, shared) {
                  /^(\.\.[\\\/])+framework$/m.exec(p)
                  );
     });
-    subProjects.unshift(shared ? path.relative(projectPath, path.join(ROOT, 'framework'))
: 'CordovaLib');
+    subProjects.unshift('CordovaLib');
     data = data.replace(/^\s*android\.library\.reference\.\d+=.*\n/mg, '');
     if (!/\n$/.exec(data)) {
         data += '\n';
@@ -278,12 +288,20 @@ exports.createProject = function(project_path, package_name, project_name,
proje
             copyBuildRules(project_path);
         });
         // Link it to local android install.
-        writeProjectProperties(project_path, target_api, use_shared_project);
-    }).then(function() {
-        console.log('Project successfully created.');
+        writeProjectProperties(project_path, target_api);
+        console.log(generateDoneMessage('create', use_shared_project));
     });
 }
 
+function generateDoneMessage(type, link) {
+    var pkg = require('../../package');
+    var msg = 'Android project ' + (type == 'update' ? 'updated ' : 'created ') + 'with '
+ pkg.name + '@' + pkg.version;
+    if (link) {
+        msg += ' and has a linked CordovaLib';
+    }
+    return msg;
+}
+
 // Attribute removed in Cordova 4.4 (CB-5447).
 function removeDebuggableFromManifest(projectPath) {
     var manifestPath = path.join(projectPath, 'AndroidManifest.xml');
@@ -302,7 +320,6 @@ function extractProjectNameFromManifest(projectPath) {
 
 // Returns a promise.
 exports.updateProject = function(projectPath, shared) {
-    var newVersion = fs.readFileSync(path.join(ROOT, 'VERSION'), 'utf-8').trim();
     return Q()
     .then(function() {
         var projectName = extractProjectNameFromManifest(projectPath);
@@ -311,9 +328,8 @@ exports.updateProject = function(projectPath, shared) {
         copyScripts(projectPath);
         copyBuildRules(projectPath);
         removeDebuggableFromManifest(projectPath);
-        writeProjectProperties(projectPath, target_api, shared);
-        console.log('Android project is now at version ' + newVersion);
-        console.log('If you updated from a pre-3.2.0 version and use an IDE, we now require
that you import the "CordovaLib" library project.');
+        writeProjectProperties(projectPath, target_api);
+        console.log(generateDoneMessage('update', shared));
     });
 };
 

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/a4c9bf7d/bin/update
----------------------------------------------------------------------
diff --git a/bin/update b/bin/update
index 40c1474..a93f369 100755
--- a/bin/update
+++ b/bin/update
@@ -23,9 +23,9 @@ var create = require('./lib/create');
 var args  = require('./lib/simpleargs').getArgs(process.argv);
 
 if (args['--help'] || args._.length === 0) {
-    console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'update'))
+ ' <path_to_project> [--shared]');
-    console.log('    --shared will use the CordovaLib project directly instead of making
a copy.');
+    console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'update'))
+ ' <path_to_project> [--link]');
+    console.log('    --link will use the CordovaLib project directly instead of making a
copy.');
     process.exit(1);
 }
-create.updateProject(args._[0], args['--shared']).done();
+create.updateProject(args._[0], args['--link'] || args['--shared']).done();
 


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


Mime
View raw message