cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marc...@apache.org
Subject [1/2] spec commit: CB-6437 [Improvements & support for more platforms]
Date Mon, 28 Apr 2014 19:11:17 GMT
Repository: cordova-mobile-spec
Updated Branches:
  refs/heads/master 5d930ca8e -> ff3a26a77


CB-6437 [Improvements & support for more platforms]

-Added full compatibility cross platform
-Working with absolute paths
-Added support for Blackberry10, Windows 8 and Windows Phone 8
-Added functionality to add platforms according to the development
environment
-- Android, Blackberry, iOS ---> Mac.
-- Android, Blackberry, Windows 8, Windows Phone 8 ---> Windows 8.
-- Android, Blackberry ---> Linux or any other Windows OS.
- Added more requirements checks
- Added functionality to delete project folder if exists (recursive
function)
- Added functionality to locate libraries
- Added function to copy with exclusion list
- Added createmobilespec.bat & createmobilespec.sh
- Added symlink for windows & Linux based OS.

Changed tabs for spaces
My mistake, it's done.

Added logic to kill ADB.exe, apache header
Apache header added to createmobilespec.cmd & createmobilespec.sh
- Added logic to kill ADB.exe process under windows, when locks project
folder.

createmobilespec cmd & sh

Changed comments to # in sh file
Indent to 4 in Apache license header

Added args logic & other changes

Added:
-Logic to deal with arguments, to accept platforms.
-Logic when no arguments are present, to fail and throw error.
-Support for help argument, to show usage.

Supported platforms (args): --android, --ios, --blackberry10, --wp8,
--windows8.
Removed: top level function for custom copy
Changed:
-Path directory for mobilespec, current location at
cordova-coho/mobilespec.
-link-to instead of copy for mobilespec project.

Changes createmobilespec

-Deleted top level functions.
-Used optimist methods to print help.
-Changes on paths.
-Other minor changes.

Removed, unnecessary outputs

shows help when error, mobilespec peer of coho

-Changed mobilespec project as cordova-coho peer.
-Added usage description, to set more usage information.
-Changed error outputs with help output and notice messages.


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

Branch: refs/heads/master
Commit: e7f314d919eb25669acb17f9aecefe3129575d94
Parents: 5d930ca
Author: Martin Gonzalez <martin.c.glez.glez@gmail.com>
Authored: Mon Apr 14 14:46:17 2014 -0500
Committer: Marcel Kinard <cmarcelk@gmail.com>
Committed: Mon Apr 28 15:10:55 2014 -0400

----------------------------------------------------------------------
 createmobilespec/createmobilespec.cmd |  19 +++
 createmobilespec/createmobilespec.js  | 215 +++++++++++++++++++----------
 createmobilespec/createmobilespec.sh  |  22 +++
 createmobilespec/package.json         |  12 +-
 4 files changed, 189 insertions(+), 79 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/e7f314d9/createmobilespec/createmobilespec.cmd
----------------------------------------------------------------------
diff --git a/createmobilespec/createmobilespec.cmd b/createmobilespec/createmobilespec.cmd
new file mode 100644
index 0000000..63f5117
--- /dev/null
+++ b/createmobilespec/createmobilespec.cmd
@@ -0,0 +1,19 @@
+
+    ::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.
+
+@node "%~dpn0" %*

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/e7f314d9/createmobilespec/createmobilespec.js
----------------------------------------------------------------------
diff --git a/createmobilespec/createmobilespec.js b/createmobilespec/createmobilespec.js
index 8802e6c..e098556 100755
--- a/createmobilespec/createmobilespec.js
+++ b/createmobilespec/createmobilespec.js
@@ -1,6 +1,5 @@
 #!/usr/bin/env node
-
-/**
+    /**
     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
@@ -17,102 +16,170 @@
     KIND, either express or implied.  See the License for the
     specific language governing permissions and limitations
     under the License.
-*/
-
-var fs = require('fs'),
-    path = require('path'),
+     */
+     
+var fs            = require("fs"),
+    path          = require("path"),
+    child_process = require("child_process"),
     shelljs,
     optimist;
+
+// Dependencies requirements check
 try {
-    shelljs = require('shelljs');
-    optimist = require('optimist');
+    shelljs = require("shelljs");
+    optimist = require("optimist");
 } catch (e) {
-    console.error('Missing module. Please run "npm install" from this directory:\n\t' +
+    console.error('Missing module. Please run \"npm install\" from this directory:\n\t' +
                    path.dirname(__dirname));
     process.exit(2);
 }
-
-var tokens = process.argv.slice(2);
-var argv = optimist(tokens)
-           .default('android', false)
-           .default('ios', false)
-           .usage('Usage: $0 [--android] [--ios]\nDefault is to use Android and iOS.')
-           .argv;
-// preserve the original behavior when there are no args
-if (tokens.length === 0) {
-    argv.android = true;
-    argv.ios = true;
+// Print relevant information
+console.log("Creating \"mobilespec\" project. If you have any errors, it may be from missing
repositories.");
+console.log("To clone needed repositories:");
+console.log("  ./cordova-coho/coho repo-clone -r plugins -r mobile-spec -r android -r ios
-r cli");
+console.log("To update all repositories:");
+console.log("  ./cordova-coho/coho repo-update");
+
+// Setting up vars, folders and libraries, to ensure full compatibility cross platform, absolute
paths are used instead of relative paths
+// Cordova Coho dir, it should contain all libraries and required repositories
+// [cordova-cli, cordova-android, cordova-blackberry, cordova-ios, cordova-windows, cordova-windows8,
all plugins libraries, cordova-mobile-spec, cordova-js]
+// searchDir function it was added, to look for cordova-coho folder backwards, for cases
like absolute/path/cordova-coho/cordova-coho/...All libraries
+// This is to make sure that cordova-coho exists and it's the right one.
+shelljs.pushd("../../../cordova-coho");
+var coho_dir       = process.cwd()+path.sep,
+    cordova_cli    = path.join(coho_dir, "cordova-cli", "bin", "cordova"),
+    cordova_ms     = path.join(coho_dir, "cordova-mobile-spec"),
+    cordova_js     = path.join(coho_dir, "cordova-js"),
+    platforms      = [],
+    //Setting up optimist features
+    tokens         = process.argv.slice(2),
+    argv = optimist.usage('\n\nMain usage: \n\n$0 [--android] [--blackberry10] [--ios] [--windows8]
[--wp8]')
+                    .describe('help', 'Shows usage')
+                    .describe('platformId', 'Add supported platforms to mobilespec project
(Android, Blackberry10, iOS, Windows 8, Windows Phone 8)')
+                    .alias('h', 'help')
+                    .argv;
+shelljs.pushd("../");
+var ms_project_dir = path.join(process.cwd(),"mobilespec");
+
+// Main libraries and path"s requirements check
+if (!fs.existsSync(coho_dir)) {
+    console.log("Please run this script from the directory that contains cordova-coho");
+    shelljs.exit(1);
 }
-var platforms = [];
-if (argv.android) { platforms.push('android'); }
-if (argv.ios) { platforms.push('ios'); }
 
-if (!fs.existsSync('cordova-mobile-spec')) {
-    console.log('Please run this script from the directory that contains cordova-mobile-spec');
+if (!fs.existsSync(cordova_ms)) {
+    console.log("Please run this script from the directory that contains cordova-mobile-spec");
     shelljs.exit(1);
 }
 
-if (fs.existsSync('mobilespec')) {
-    console.log('Directory "mobilespec" already exists. Delete it first then re-run.');
+if (!fs.existsSync(cordova_js)) {
+    console.log("Please run this script from the directory that contains cordova-js");
     shelljs.exit(1);
 }
 
-console.log('Creating mobilespec project. If you have any errors, it may be from missing
repositories.');
-console.log('To clone needed repositories:');
-console.log("  ./cordova-coho/coho repo-clone -r plugins -r mobile-spec -r cli -r " + platforms.join('
-r '));
-console.log('To update all repositories:');
-console.log('  ./cordova-coho/coho repo-update');
+// No arguments show help
+if (tokens.length === 0) {
+    console.log("\n\nNo Arguments were found");
+    optimist.showHelp();
+    process.exit(2);
+}
+
+if (argv.help) {optimist.showHelp(); return;}
+if (argv.android) { platforms.push("android");}
+if (argv.ios) { platforms.push("ios");}
+if (argv.blackberry10) { platforms.push("blackberry10");}
+if (argv.wp8) { platforms.push("wp8");}
+if (argv.windows8) { platforms.push("windows8");}
+
+// No platforms show help
+if (platforms.length === 0){
+    console.log("\n\nNo platforms were selected. Please choose at least one of the supported
platforms.");
+    optimist.showHelp();
+    process.exit(2);
+}
 
-var repoParent = process.cwd();
+// Custom function to delete project folder, using recursive actions
+try {
+    shelljs.rm('-rf', ms_project_dir);
+} catch (e) {
+    //The project directory after an android build and emulation is locked by ADB.exe (Android
Debug Bridge).
+    //Kill the process & restart folder deletion
+    console.log("Not all files were deleted, killing Adb.exe process to unlock project folder
...");
+    if (/^win/.test(process.platform)) {
+        shelljs.exec("TASKKILL /F /IM ADB.exe /T");
+        shelljs.rm('-r', ms_project_dir);
+        }else
+            throw new Error("Error during folder deletion, try to remove mobilespec project
folder manually");
+    }
+
+// Setting up config.fatal as true, if something goes wrong the program it will terminate
 shelljs.config.fatal = true;
+// Creating the project, linked to cordova-mobile-spec library
+shelljs.exec(cordova_cli + " create mobilespec org.apache.cordova.mobilespec MobileSpec_Tests
--link-to cordova-coho/cordova-mobile-spec");
 
-shelljs.exec('./cordova-cli/bin/cordova create mobilespec --link-to cordova-mobile-spec');
+// Executing grunt task, to generate updated js files for each platform
+shelljs.pushd(cordova_js);
+shelljs.exec("grunt");
 
-shelljs.pushd('cordova-js');
-var code = shelljs.exec('grunt').code;
-if (code) {
-    process.exit(1);
-}
-shelljs.popd();
+// Config.json file ---> linked to local libraries
+shelljs.pushd(ms_project_dir);
 
-shelljs.pushd('mobilespec');
 var localPlatforms = {
-    "id": "org.apache.mobilespec",
-    "name": "mobilespec",
-    "lib": {
-        "android": {
-            "uri": repoParent + "/cordova-android"
+    "id" : "org.apache.cordova",
+    "name" : "mobilespec",
+    "lib" : {
+        "android" : {
+            "uri" : coho_dir + "cordova-android"
+        },
+        "ios" : {
+            "uri" : coho_dir + "cordova-ios"
         },
-        "ios": {
-            "uri": repoParent + "/cordova-ios"
+        "blackberry10" : {
+            "uri" : coho_dir + "cordova-blackberry"
+        },
+        "wp8" : {
+            "uri" : coho_dir + "cordova-wp8"
+        },
+        "windows8" : {
+            "uri" : coho_dir + "cordova-windows"
         }
     }
 };
-JSON.stringify(localPlatforms).to('.cordova/config.json');
-
-console.log('Adding platforms...');
-shelljs.exec('../cordova-cli/bin/cordova platform add ' + platforms.join(' '));
-
-console.log('Adding plugins...');
-shelljs.exec('../cordova-cli/bin/cordova plugin add ../cordova-mobile-spec/dependencies-plugin
--searchpath ' + repoParent);
-
-if (argv.ios) {
-    console.log('Updating iOS subproject...');
-    shelljs.rm('-rf', 'platforms/ios/CordovaLib');
-    shelljs.exec('../cordova-ios/bin/update_cordova_subproject platforms/ios/mobilespec.xcodeproj');
+JSON.stringify(localPlatforms).to(".cordova/config.json");
+
+//Executing platform Add
+console.log("Adding platforms...");
+platforms.forEach(function (platform) {
+    console.log("Adding Platform: " + platform);
+    shelljs.exec(cordova_cli + " platform add " + platform + " --verbose");
+});
+
+// Installing plugins, using local library and dependencies file.
+console.log("Adding plugins...");
+shelljs.exec(cordova_cli +" plugin add " + path.join(cordova_ms, "dependencies-plugin") +
" --searchpath " + coho_dir);
+
+// Updating Js files for each added platform
+console.log("Updating js for platforms...");
+platforms.forEach(function (platform) {
+    shelljs.cp("-f", path.join(cordova_js, "pkg", "cordova." + (function () {
+                return platform === "wp8" ? "windowsphone" : platform;
+            }
+                ()) + ".js"), path.join(ms_project_dir, "platforms", platform, "platform_www",
"cordova.js"));
+    console.log("Javascript file updated for " + platform);
+});
+
+// Executing cordova prepare
+console.log("Preparing project...");
+shelljs.exec(cordova_cli + " prepare");
+console.log("Linking CLI...");
+
+// Writing link files to use Local CLI
+if (/^win/.test(process.platform)) {
+    var winBatchFile = "node  " + cordova_cli + " %*";
+    fs.writeFileSync(path.join(ms_project_dir, "cordova.bat"), winBatchFile);
+} else {
+    fs.symlinkSync(cordova_cli, "cordova");
 }
 
-console.log('Updating js...');
-if (argv.android) { shelljs.cp('-f', '../cordova-js/pkg/cordova.android.js', 'platforms/android/platform_www/cordova.js');
}
-if (argv.ios) { shelljs.cp('-f', '../cordova-js/pkg/cordova.ios.js', 'platforms/ios/platform_www/cordova.js');
}
-
-console.log('Preparing...');
-shelljs.exec('../cordova-cli/bin/cordova prepare');
-
-console.log('Linking CLI...');
-fs.symlinkSync('../cordova-cli/bin/cordova', 'cordova');
-shelljs.popd();
-
-console.log('App created in the mobilespec/ directory.');
-console.log('Symlink to CLI created as mobilespec/cordova');
-
+console.log("\"mobilespec\" project created at:\n" + ms_project_dir);
+console.log("Symlink to CLI created as mobilespec/cordova");

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/e7f314d9/createmobilespec/createmobilespec.sh
----------------------------------------------------------------------
diff --git a/createmobilespec/createmobilespec.sh b/createmobilespec/createmobilespec.sh
new file mode 100644
index 0000000..e26b708
--- /dev/null
+++ b/createmobilespec/createmobilespec.sh
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+    #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.*/
+
+set -x
+node ~+/createmobilespec.js
+

http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/e7f314d9/createmobilespec/package.json
----------------------------------------------------------------------
diff --git a/createmobilespec/package.json b/createmobilespec/package.json
index e53e817..29e04b4 100644
--- a/createmobilespec/package.json
+++ b/createmobilespec/package.json
@@ -1,14 +1,16 @@
 { "name": "createmobilespec",
+  "version": "1.2.0",
   "description": "Create the mobilespec project and populate it.",
   "homepage": "http://cordova.apache.org",
   "bugs": { "url": "https://issues.apache.org/jira/browse/CB" },
   "license": "Apache-2.0",
-  "bin": {"createmobilespec": "./createmobilespec.js" },
+  "main": "./createmobilespec",
+  "bin": {"createmobilespec": "./createmobilespec" },
   "repository": {
-     "type": "git",
+     "type": "git", 
      "url": "https://git-wip-us.apache.org/repos/asf/cordova-mobile-spec.git"},
-  "dependencies": {
-     "shelljs": "0.2.6",
-     "optimist": "0.6.1" },
+  "dependencies": { 
+    "shelljs": "0.2.6",
+    "optimist": "0.6.1" },
   "private": true
 }


Mime
View raw message