You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by za...@apache.org on 2014/12/15 14:32:55 UTC

[06/37] cordova-ubuntu git commit: add bin/update

add bin/update


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

Branch: refs/heads/master
Commit: 0aa3d662bceb768983f13ddacababdb686e8a034
Parents: 7307032
Author: Maxim Ermilov <ma...@canonical.com>
Authored: Tue Sep 9 13:57:45 2014 +0400
Committer: Maxim Ermilov <ma...@canonical.com>
Committed: Tue Sep 9 13:57:45 2014 +0400

----------------------------------------------------------------------
 bin/build/lib/ubuntu.js | 57 +++++++++++++++++++++++++++++++++++++++++
 bin/create              | 25 +++---------------
 bin/update              | 61 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 121 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/0aa3d662/bin/build/lib/ubuntu.js
----------------------------------------------------------------------
diff --git a/bin/build/lib/ubuntu.js b/bin/build/lib/ubuntu.js
index 1f56ce3..5351964 100644
--- a/bin/build/lib/ubuntu.js
+++ b/bin/build/lib/ubuntu.js
@@ -133,6 +133,63 @@ function checkEnv(ubuntuDir) {
     }
 }
 
+module.exports.createProject = function(projectPath, ROOT) {
+    if (fs.existsSync(projectPath)) {
+        console.error('Project already exists! Delete and recreate');
+        process.exit(2);
+    }
+
+    shell.mkdir(projectPath);
+    shell.cp('-r', path.join(ROOT, '*'), path.join(projectPath, 'build'));
+    shell.mkdir(path.join(projectPath, 'native'));
+    shell.cp('-r', path.join(ROOT, 'bin/build/*'), path.join(projectPath, 'cordova'));
+    shell.cp('-r', path.join(ROOT, 'bin/check_reqs'), path.join(projectPath, 'cordova'));
+
+    shell.cp('-r', path.join(ROOT, 'bin/node_modules'), path.join(projectPath, 'cordova'));
+
+    shell.cp('-r', path.join(ROOT, 'xml/config.xml'), projectPath);
+
+    shell.mkdir(path.join(projectPath, 'www'));
+    shell.cp(path.join(ROOT, 'www/cordova.js'), path.join(projectPath, 'www'));
+
+    shell.cd(projectPath);
+}
+
+module.exports.updateProject = function(projectPath, ROOT) {
+    if (!fs.existsSync(projectPath)) {
+        console.error('Project does not exist!');
+        process.exit(2);
+    }
+
+    shell.rm('-r', path.join(projectPath, 'www'));
+    shell.mkdir(path.join(projectPath, 'www'));
+    shell.cp(path.join(ROOT, 'www/cordova.js'), path.join(projectPath, 'www'));
+
+    shell.rm('-r', path.join(projectPath, 'cordova'));
+    shell.cp('-r', path.join(ROOT, 'bin/build/*'), path.join(projectPath, 'cordova'));
+    shell.cp('-r', path.join(ROOT, 'bin/check_reqs'), path.join(projectPath, 'cordova'));
+    shell.cp('-r', path.join(ROOT, 'bin/node_modules'), path.join(projectPath, 'cordova'));
+
+    var tmp = path.join(projectPath, 'tmp');
+    shell.mkdir(tmp);
+
+    var pluginsDir = path.join(projectPath, 'build', 'src', 'plugins');
+    var coreplugins = path.join(projectPath, 'build', 'src', 'coreplugins.cpp');
+    shell.mv(coreplugins, tmp);
+    shell.mv(pluginsDir, tmp);
+    shell.rm('-r', path.join(projectPath, 'build'));
+
+    shell.cp('-r', path.join(ROOT, '*'), path.join(projectPath, 'build'));
+
+    shell.rm('-r', coreplugins);
+    shell.rm('-r', pluginsDir);
+    shell.mv(path.join(tmp, 'plugins'), path.join(projectPath, 'build', 'src'));
+    shell.mv(path.join(tmp, 'coreplugins.cpp'), path.join(projectPath, 'build', 'src'));
+
+    shell.rm('-r', tmp);
+    console.log('project updated'.green);
+}
+
 function checkClickPackage(prefixDir) {
     pushd(prefixDir);
 

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/0aa3d662/bin/create
----------------------------------------------------------------------
diff --git a/bin/create b/bin/create
index 92a9d61..cb75109 100755
--- a/bin/create
+++ b/bin/create
@@ -31,28 +31,9 @@ function help() {
     process.exit(0);
 }
 
-function create(project_path, package_name, project_name, project_template_dir) {
+function create(projectPath) {
     function create_project() {
-        var shell = require("shelljs");
-        // Check if project already exists
-        if(fs.existsSync(project_path)) {
-            console.error('Project already exists! Delete and recreate');
-            process.exit(2);
-        }
-        shell.mkdir(project_path);
-        shell.cp('-r', path.join(ROOT, '*'), path.join(project_path, 'build'));
-        shell.mkdir(path.join(project_path, 'native'));
-        shell.cp('-r', path.join(ROOT, 'bin/build/*'), path.join(project_path, 'cordova'));
-        shell.cp('-r', path.join(ROOT, 'bin/check_reqs'), path.join(project_path, 'cordova'));
-
-        shell.cp('-r', path.join(ROOT, 'bin/node_modules'), path.join(project_path, 'cordova'));
-
-        shell.cp('-r', path.join(ROOT, 'xml/config.xml'), project_path);
-
-        shell.mkdir(path.join(project_path, 'www'));
-        shell.cp(path.join(ROOT, 'www/cordova.js'), path.join(project_path, 'www'));
-
-        shell.cd(project_path);
+        require('./build/lib/ubuntu').createProject(projectPath, ROOT);
     }
 
     try {
@@ -90,5 +71,5 @@ if(args.length < 3 || (args[2] == '--help' || args[2] == '/?' || args[2] == '-h'
                        args[2] == 'help' || args[2] == '-help' || args[2] == '/help')) {
     help();
 } else {
-    create(args[2], args[3], args[4], args[5]);
+    create(args[2]);
 }

http://git-wip-us.apache.org/repos/asf/cordova-ubuntu/blob/0aa3d662/bin/update
----------------------------------------------------------------------
diff --git a/bin/update b/bin/update
new file mode 100755
index 0000000..636396c
--- /dev/null
+++ b/bin/update
@@ -0,0 +1,61 @@
+#!/usr/bin/env node
+
+/*
+ *
+ * Copyright 2014 Canonical Ltd.
+ *
+ * Licensed 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.
+ *
+*/
+var path = require('path');
+var args = process.argv;
+var ROOT = path.join(__dirname, '..');
+var fs    = require('fs');
+
+function installDependecies(cb) {
+    console.log('running \'npm install\'.....');
+    var exec = require('child_process').exec;
+    var cwd = process.cwd();
+
+    var block = true;
+    exec('npm install', {cwd: __dirname}, function (error, stdout, stderr) {
+        block = false;
+        if (error !== null) {
+            console.error('ERROR : running \'npm install\' is npm installed? ' + error);
+            console.error(stderr);
+            process.exit(error.code);
+        }
+    });
+    function wait() {
+        if (block)
+            setTimeout(wait, 1500);
+        else
+            cb();
+    };
+    setTimeout(wait, 1500);
+}
+
+
+function updateProject(projectPath, ROOT) {
+    installDependecies(function () {
+        var currentVersion = fs.readFileSync(path.join(projectPath, 'build', 'VERSION'), {encoding: "utf8"});
+        var version = fs.readFileSync(path.join(ROOT, 'VERSION'), {encoding: "utf8"});
+        if (version == currentVersion)
+            return;
+
+        require('./build/lib/ubuntu').updateProject(projectPath, ROOT);
+    });
+}
+
+updateProject(args[2], ROOT);


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