cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From na...@apache.org
Subject [02/32] git commit: CB-5232 Change create script to use Cordova as a library.
Date Mon, 03 Feb 2014 20:26:03 GMT
CB-5232 Change create script to use Cordova as a library.


Project: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/commit/2a5d8815
Tree: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/tree/2a5d8815
Diff: http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/diff/2a5d8815

Branch: refs/heads/3.4.x
Commit: 2a5d8815af4742168f95e252cbe0b0ac9aba001b
Parents: 445bd55
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Wed Oct 30 12:18:20 2013 -0400
Committer: Archana Naik <naika@lab126.com>
Committed: Mon Feb 3 11:09:46 2014 -0800

----------------------------------------------------------------------
 bin/create            | 17 +++------
 bin/lib/create.js     | 95 +++++++++++++++++++++-------------------------
 bin/lib/simpleargs.js | 32 ++++++++++++++++
 bin/update            | 15 +++-----
 4 files changed, 87 insertions(+), 72 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/2a5d8815/bin/create
----------------------------------------------------------------------
diff --git a/bin/create b/bin/create
index 455ba30..7b64d5f 100755
--- a/bin/create
+++ b/bin/create
@@ -20,21 +20,16 @@
 */
 var path = require('path');
 var create = require('./lib/create');
-var args = process.argv;
+var args  = require('./lib/simpleargs').getArgs(process.argv);
 
-// Support basic help commands
-if(args.length < 3 || (args[2] == '--help' || args[2] == '/?' || args[2] == '-h' ||
-                    args[2] == 'help' || args[2] == '-help' || args[2] == '/help')) {
-    console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'create'))
+ ' <path_to_new_project> <package_name> <project_name>');
+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('    <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.');
     process.exit(1);
-} else {
-    create.createProject(args[2], args[3], args[4], args[5]).done(null, function(err) {
-        console.error(err);
-        process.exit(2);
-    });
 }
 
-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['--shared']).done();
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/2a5d8815/bin/lib/create.js
----------------------------------------------------------------------
diff --git a/bin/lib/create.js b/bin/lib/create.js
index 2314c6e..23449bd 100755
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -29,14 +29,13 @@ var shell = require('shelljs'),
 // Returns a promise.
 function exec(command, opt_cwd) {
     var d = Q.defer();
-    try {
-        child_process.exec(command, { cwd: opt_cwd }, function(err, stdout, stderr) {
-            if (err) d.reject(err);
-            else d.resolve(stdout);
-        });
-    } catch(e) {
-        return Q.reject('Command error on execution: ' + command + '\n' + e);
-    }
+    console.log('Running: ' + command);
+    child_process.exec(command, { cwd: opt_cwd }, function(err, stdout, stderr) {
+        stdout && console.log(stdout);
+        stderr && console.error(stderr);
+        if (err) d.reject(err);
+        else d.resolve(stdout);
+    });
     return d.promise;
 }
 
@@ -47,38 +46,48 @@ function setShellFatal(value, func) {
     shell.config.fatal = oldVal;
 }
 
-// Returns a promise.
-function ensureJarIsBuilt(version, target_api) {
-    var isDevVersion = /-dev$/.test(version);
-    if (isDevVersion || !fs.existsSync(path.join(ROOT, 'framework', 'cordova-' + version
+ '.jar')) && fs.existsSync(path.join(ROOT, 'framework'))) {
-        var valid_target = check_reqs.get_target();
-        console.log('Building cordova-' + version + '.jar');
-        // update the cordova-android framework for the desired target
-        return exec('android --silent update lib-project --target "' + target_api + '" --path
"' + path.join(ROOT, 'framework') + '"')
-        .then(function() {
-            // compile cordova.js and cordova.jar
-            return exec('ant jar', path.join(ROOT, 'framework'));
-        });
-    }
-    return Q();
+function getFrameworkDir(projectPath, shared) {
+    return shared ? path.join(ROOT, 'framework') : path.join(projectPath, 'CordovaLib');
 }
 
-function copyJsAndJar(projectPath, version) {
+function copyJsAndLibrary(projectPath, shared, projectName) {
+    var nestedCordovaLibPath = getFrameworkDir(projectPath, false);
     shell.cp('-f', path.join(ROOT, 'framework', 'assets', 'www', 'cordova.js'), path.join(projectPath,
'assets', 'www', 'cordova.js'));
     // Don't fail if there are no old jars.
     setShellFatal(false, function() {
         shell.ls(path.join(projectPath, 'libs', 'cordova-*.jar')).forEach(function(oldJar)
{
             console.log("Deleting " + oldJar);
-            shell.rm('-f', path.join(oldJar));
+            shell.rm('-f', oldJar);
         });
+        // Delete old library project if it existed.
+        if (shared) {
+            shell.rm('-rf', nestedCordovaLibPath);
+        } else {
+            // Delete only the src, since eclipse can't handle its .project file being deleted.
+            shell.rm('-rf', path.join(nestedCordovaLibPath, 'src'));
+        }
     });
-    shell.cp('-f', path.join(ROOT, 'framework', 'cordova-' + version + '.jar'), path.join(projectPath,
'libs', 'cordova-' + version + '.jar'));
-    shell.cp('-f', path.join(ROOT, 'framework', 'libs','awv_interface.jar'), path.join(projectPath,
'libs', 'awv_interface.jar'));
+    
+    if (!shared) {
+        shell.mkdir('-p', nestedCordovaLibPath);
+        shell.cp('-f', path.join(ROOT, 'framework', 'AndroidManifest.xml'), nestedCordovaLibPath);
+        shell.cp('-f', path.join(ROOT, 'framework', 'project.properties'), nestedCordovaLibPath);
+        shell.cp('-r', path.join(ROOT, 'framework', 'src'), nestedCordovaLibPath);
+        shell.cp('-r', path.join(ROOT, 'framework', 'libs'), nestedCordovaLibPath);
+        // Create an eclipse project file and set the name of it to something unique.
+        // Without this, you can't import multiple CordovaLib projects into the same workspace.
+        var eclipseProjectFilePath = path.join(nestedCordovaLibPath, '.project');
+        if (!fs.existsSync(eclipseProjectFilePath)) {
+            var data = '<?xml version="1.0" encoding="UTF-8"?><projectDescription><name>'
+ projectName + '-' + 'CordovaLib</name></projectDescription>';
+            fs.writeFileSync(eclipseProjectFilePath, data, 'utf8');
+        }
+    }
 }
 
-function copyAntRules(projectPath) {
-    var srcDir = path.join(ROOT, 'bin', 'templates', 'project');
-    shell.cp('-f', path.join(srcDir, 'custom_rules.xml'), projectPath);
+function runAndroidUpdate(projectPath, target_api, shared) {
+    var targetFrameworkDir = getFrameworkDir(projectPath, shared);
+    return exec('android update project --subprojects --path "' + projectPath + '" --target
' + target_api + ' --library "' + path.relative(projectPath, targetFrameworkDir) + '"');
+
 }
 
 function copyScripts(projectPath) {
@@ -110,7 +119,7 @@ function copyScripts(projectPath) {
  * Returns a promise.
  */
 
-exports.createProject = function(project_path, package_name, project_name, project_template_dir,
use_shared_project, use_cli_template) {
+exports.createProject = function(project_path, package_name, project_name, project_template_dir,
use_shared_project) {
     var VERSION = fs.readFileSync(path.join(ROOT, 'VERSION'), 'utf-8').trim();
 
     // Set default values for path, package and name
@@ -152,9 +161,6 @@ exports.createProject = function(project_path, package_name, project_name,
proje
         console.log('\tName: ' + project_name);
         console.log('\tAndroid target: ' + target_api);
 
-        // build from source. distro should have these files
-        return ensureJarIsBuilt(VERSION, target_api);
-    }).then(function() {
         console.log('Copying template files...');
 
         setShellFatal(true, function() {
@@ -166,18 +172,9 @@ exports.createProject = function(project_path, package_name, project_name,
proje
             // Manually create directories that would be empty within the template (since
git doesn't track directories).
             shell.mkdir(path.join(project_path, 'libs'));
 
-            // Add in the proper eclipse project file.
-            if (use_cli_template) {
-                var note = 'To show `assets/www` or `res/xml/config.xml`, go to:\n' +
-                           '    Project -> Properties -> Resource -> Resource Filters\n'
+
-                           'And delete the exclusion filter.\n';
-                shell.cp(path.join(project_template_dir, 'eclipse-project-CLI'), path.join(project_path,
'.project'));
-                fs.writeFileSync(path.join(project_path, 'assets', '_where-is-www.txt'),
note);
-            } else {
-                shell.cp(path.join(project_template_dir, 'eclipse-project'), path.join(project_path,
'.project'));
-            }
-
-            // copy cordova.js, cordova.jar
+            // copy cordova.js, cordova.jar and res/xml
+            shell.cp('-r', path.join(ROOT, 'framework', 'res', 'xml'), path.join(project_path,
'res'));
+
             copyJsAndLibrary(project_path, use_shared_project, safe_activity_name);
 
             // interpolate the activity name and package
@@ -196,8 +193,7 @@ exports.createProject = function(project_path, package_name, project_name,
proje
             copyAntRules(project_path);
         });
         // Link it to local android install.
-        console.log('Running "android update project"');
-        return exec('android --silent update project --target "'+target_api+'" --path "'+
project_path+'"');
+        return runAndroidUpdate(project_path, target_api, use_shared_project);
     }).then(function() {
         console.log('Project successfully created.');
     });
@@ -227,14 +223,11 @@ exports.updateProject = function(projectPath) {
     .then(function() {
         var projectName = extractProjectNameFromManifest(projectPath);
         var target_api = check_reqs.get_target();
-        copyJsAndLibrary(projectPath, false, projectName);
+        copyJsAndLibrary(projectPath, false, null);
         copyScripts(projectPath);
-        copyAntRules(projectPath);
-        removeDebuggableFromManifest(projectPath);
         return runAndroidUpdate(projectPath, target_api, false)
         .then(function() {
             console.log('Android project is now at version ' + version);
-            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.');
         });
     });
 };

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/2a5d8815/bin/lib/simpleargs.js
----------------------------------------------------------------------
diff --git a/bin/lib/simpleargs.js b/bin/lib/simpleargs.js
new file mode 100644
index 0000000..d286f06
--- /dev/null
+++ b/bin/lib/simpleargs.js
@@ -0,0 +1,32 @@
+/*
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+*/
+
+exports.getArgs = function(argv) {
+    var ret = {};
+    var posArgs = [];
+    for (var i = 2, arg; arg = argv[i] || i < argv.length; ++i) {
+        if (/^--/.exec(arg)) {
+            ret[arg] = true;
+        } else {
+            posArgs.push(arg);
+        }
+    }
+    ret._ = posArgs;
+    return ret;
+};

http://git-wip-us.apache.org/repos/asf/cordova-amazon-fireos/blob/2a5d8815/bin/update
----------------------------------------------------------------------
diff --git a/bin/update b/bin/update
index 59f2bb6..40c1474 100755
--- a/bin/update
+++ b/bin/update
@@ -19,18 +19,13 @@
        under the License.
 */
 var path   = require('path');
-var args  = process.argv;
 var create = require('./lib/create');
+var args  = require('./lib/simpleargs').getArgs(process.argv);
 
-// Support basic help commands
-if(args.length < 3 || (args[2] == '--help' || args[2] == '/?' || args[2] == '-h' ||
-                    args[2] == 'help' || args[2] == '-help' || args[2] == '/help')) {
-    console.log('Usage: ' + path.relative(process.cwd(), path.join(__dirname, 'update'))
+ ' <path_to_project>');
+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.');
     process.exit(1);
-} else {
-    create.updateProject(args[2]).done(null, function(err) {
-        console.error(err);
-        process.exit(2);
-    });
 }
+create.updateProject(args._[0], args['--shared']).done();
 


Mime
View raw message