You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2013/12/01 08:40:50 UTC

git commit: CB-5040 cordova run windows8 has no effect

Updated Branches:
  refs/heads/master d4deba4a8 -> d32a3cf03


CB-5040 cordova run windows8 has no effect


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

Branch: refs/heads/master
Commit: d32a3cf03110890d44736aa19f569dcb1e493c50
Parents: d4deba4
Author: sgrebnov <se...@gmail.com>
Authored: Mon Nov 25 20:41:24 2013 +0400
Committer: sgrebnov <se...@gmail.com>
Committed: Mon Nov 25 20:41:24 2013 +0400

----------------------------------------------------------------------
 windows8/bin/create.js                          |   1 +
 .../template/cordova/lib/WindowsStoreAppUtils   |  92 ++++++++++
 windows8/template/cordova/lib/build.js          |   7 +-
 windows8/template/cordova/lib/deploy.js         | 180 ++++++++-----------
 4 files changed, 172 insertions(+), 108 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/d32a3cf0/windows8/bin/create.js
----------------------------------------------------------------------
diff --git a/windows8/bin/create.js b/windows8/bin/create.js
index 2428cb4..6a4128a 100644
--- a/windows8/bin/create.js
+++ b/windows8/bin/create.js
@@ -149,6 +149,7 @@ function create(destPath, namespace, name, guid) {
     // replace the guid in the AppManifest and deploy script
     replaceInFile(destPath + "\\package.appxmanifest","$guid1$",newProjGuid);
     replaceInFile(destPath + "\\cordova\\lib\\deploy.js","$guid1$",newProjGuid);
+    replaceInFile(destPath + "\\cordova\\lib\\deploy.js","$namespace$",namespace);
 
     // replace $safeprojectname$ and $projectname$ in AppManifest
     replaceInFile(destPath + "\\package.appxmanifest",/\$safeprojectname\$/g,safeProjectName);

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/d32a3cf0/windows8/template/cordova/lib/WindowsStoreAppUtils
----------------------------------------------------------------------
diff --git a/windows8/template/cordova/lib/WindowsStoreAppUtils b/windows8/template/cordova/lib/WindowsStoreAppUtils
new file mode 100644
index 0000000..ded93cf
--- /dev/null
+++ b/windows8/template/cordova/lib/WindowsStoreAppUtils
@@ -0,0 +1,92 @@
+<#
+       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.
+#>
+$code = @"
+using System;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+namespace StoreAppRunner 
+{
+    public enum ActivateOptions
+    {
+        None = 0,
+        DesignMode = 0x1,
+        NoErrorUI = 0x2,
+        NoSplashScreen = 0x4
+    }
+
+    [ComImport]
+    [Guid("2e941141-7f97-4756-ba1d-9decde894a3d")]
+    [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
+    public interface IApplicationActivationManager
+    {
+        IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId);
+        IntPtr ActivateForFile([In] String appUserModelId, [In] IntPtr itemArray, [In] String verb, [Out] out UInt32 processId);
+        IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr itemArray, [Out] out UInt32 processId);
+    }
+    [ComImport]
+    [Guid("45BA127D-10A8-46EA-8AB7-56EA9078943C")]
+    public class ApplicationActivationManager : IApplicationActivationManager
+    {
+        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
+        public extern IntPtr ActivateApplication([In] String appUserModelId, [In] String arguments, [In] ActivateOptions options, [Out] out UInt32 processId);
+        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
+        public extern IntPtr ActivateForFile([In] String appUserModelId, [In] IntPtr itemArray, [In] String verb, [Out] out UInt32 processId);
+        [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
+        public extern IntPtr ActivateForProtocol([In] String appUserModelId, [In] IntPtr itemArray, [Out] out UInt32 processId);
+    }
+}
+"@
+
+function Uninstall-App {
+    param(
+        [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
+        [string] $ID <# package.appxmanifest//Identity@name #>
+    )
+
+    $package = Get-AppxPackage $ID
+
+    if($package) {
+        Remove-AppxPackage $package.PackageFullName
+    }
+}
+
+function Install-App {
+    param(
+        [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
+        [string] $Path <# Full path to Add-AppDevPackage.ps1 #>
+    )
+    Invoke-Expression ($Path + " -force")
+}
+
+function Start-Locally {
+    param(
+        [Parameter(Mandatory=$true, Position=0, ValueFromPipelineByPropertyName=$true)]
+        [string] $ID <# package.appxmanifest//Identity@name #>
+    )
+
+    $package = Get-AppxPackage $ID
+    $manifest = Get-appxpackagemanifest $package
+    $applicationUserModelId = $package.PackageFamilyName + "!" + $manifest.package.applications.application.id
+
+    Write-Host "ActivateApplication: " $applicationUserModelId
+
+    add-type -TypeDefinition $code
+    $appActivator = new-object StoreAppRunner.ApplicationActivationManager
+    $appActivator.ActivateApplication($applicationUserModelId,$null,[StoreAppRunner.ActivateOptions]::None,[ref]0)
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/d32a3cf0/windows8/template/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/windows8/template/cordova/lib/build.js b/windows8/template/cordova/lib/build.js
index 9499eb6..87fd42c 100644
--- a/windows8/template/cordova/lib/build.js
+++ b/windows8/template/cordova/lib/build.js
@@ -110,11 +110,8 @@ function build_appx(path,isRelease) {
             {
                 if(fso.GetExtensionName(files.item()) == "ps1")
                 {
-                    var command = "PowerShell " + files.item();
-                    Log("\nRunning Command :: " + command);
-                    // run it and wait for the result
-                    var retCode = wscript_shell.Run(command, 1, true);
-                    return retCode == 0 ? "Success" : "Error running PowerShell script : " + retCode;
+                    // app was built, installation script exists
+                    return "Success";
                 }
 
             }

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/d32a3cf0/windows8/template/cordova/lib/deploy.js
----------------------------------------------------------------------
diff --git a/windows8/template/cordova/lib/deploy.js b/windows8/template/cordova/lib/deploy.js
index d079253..c771f12 100644
--- a/windows8/template/cordova/lib/deploy.js
+++ b/windows8/template/cordova/lib/deploy.js
@@ -17,17 +17,15 @@
        under the License.
 */
 
-
 var fso = WScript.CreateObject('Scripting.FileSystemObject');
 var wscript_shell = WScript.CreateObject("WScript.Shell");
 
 var args = WScript.Arguments;
 // working dir
 var ROOT = WScript.ScriptFullName.split('\\cordova\\lib\\deploy.js').join('');
-    // path to CordovaDeploy.exe
-var CORDOVA_DEPLOY_EXE = '\\cordova\\lib\\CordovaDeploy\\CordovaDeploy\\bin\\Debug\\CordovaDeploy.exe';
-    // path to CordovaDeploy
-var CORDOVA_DEPLOY = '\\cordova\\lib\\CordovaDeploy';
+// path to WindowsStoreAppUtils.ps1; provides helper functions to install/unistall/start Windows Store app
+var WINDOWS_STORE_UTILS = '\\cordova\\lib\\WindowsStoreAppUtils.ps1';
+var WINDOWS_STORE_UTILS_SRC = '\\cordova\\lib\\WindowsStoreAppUtils';
 
 //build types
 var NONE = 0,
@@ -36,6 +34,7 @@ var NONE = 0,
     NO_BUILD = 3;
 var build_type = NONE;
 
+var PACKAGE_NAME = '$namespace$';
 
 // help function
 function Usage() {
@@ -115,114 +114,101 @@ function read(filename) {
     return null;
 }
 
-// builds the CordovaDeploy.exe if it does not already exist 
-function cordovaDeploy(path) {
-    if (fso.FileExists(path + CORDOVA_DEPLOY_EXE)) {
-        return;
-    }
-
-    Log('CordovaDeploy.exe not found, attempting to build CordovaDeploy.exe...');
+// writes content to a file
+function write(filename, content) {
+    var f=fso.OpenTextFile(filename, 2,2);
+    f.Write(content);
+    f.Close();
+}
 
-    // build CordovaDeploy.exe
-    if (fso.FolderExists(path + '\\cordova') && fso.FolderExists(path + CORDOVA_DEPLOY) && 
-        fso.FileExists(path + CORDOVA_DEPLOY + '\\CordovaDeploy.sln')) {
-        // delete any previously generated files
-        if (fso.FolderExists(path + CORDOVA_DEPLOY + '\\CordovaDeploy\\obj')) {
-            fso.DeleteFolder(path + CORDOVA_DEPLOY + '\\CordovaDeploy\\obj');
-        }
-        if (fso.FolderExists(path + CORDOVA_DEPLOY + '\\CordovaDeploy\\Bin')) {
-            fso.DeleteFolder(path + CORDOVA_DEPLOY + '\\CordovaDeploy\\Bin');
-        }
-        exec_verbose('msbuild ' + path + CORDOVA_DEPLOY + '\\CordovaDeploy.sln');
+function localMachine(path) {
+    Log('Deploying to local machine ...');
+    makeAppStoreUtils(path);
+    uninstallApp(path);
+    installApp(path);
 
-        if (fso.FileExists(path + CORDOVA_DEPLOY_EXE)) {
-            Log('CordovaDeploy.exe compiled, SUCCESS.');
-        }
-        else {
-            Log('ERROR: MSBUILD FAILED TO COMPILE CordovaDeploy.exe', true);
-            WScript.Quit(2);
-        }
-    }
-    else {
-        Log('ERROR: CordovaDeploy.sln not found, unable to compile CordovaDeploy tool.', true);
-        WScript.Quit(2);
-    }
+    var command = "powershell \". .\\" + WINDOWS_STORE_UTILS + "; Start-Locally " + PACKAGE_NAME;
+    Log(command);
+    exec_verbose(command);
 }
 
 // launches project on device
 function device(path)
 {
-    cordovaDeploy(path);
-    if (fso.FileExists(path + CORDOVA_DEPLOY_EXE)) {
-        Log('Deploying to device ...');
-        //TODO: get device ID from list-devices and deploy to first one
-        exec_verbose('%comspec% /c ' + path + CORDOVA_DEPLOY_EXE + ' ' + path + ' -d:0');
-    }
-    else
-    {
-        Log('Error: Failed to find CordovaDeploy.exe in ' + path, true);
-        Log('DEPLOY FAILED.', true);
-        WScript.Quit(2);
-    }
+    // on windows8 platform we treat this command as running application on local machine
+    localMachine(path);
 }
 
 // launches project on emulator
 function emulator(path)
 {
-    cordovaDeploy(path);
-    if (fso.FileExists(path + CORDOVA_DEPLOY_EXE)) {
-        Log('Deploying to emulator ...');
-        //TODO: get emulator ID from list-emulators and deploy to first one
-        exec_verbose('%comspec% /c ' + path + CORDOVA_DEPLOY_EXE + ' ' + path + ' -d:1');
-    }
-    else
-    {
-        Log('Error: Failed to find CordovaDeploy.exe in ' + path, true);
-        Log('DEPLOY FAILED.', true);
-        WScript.Quit(2);
-    }
+    // TODO: currently we can run application on local machine only
+    localMachine(path);
 }
 
 // builds and launches the project on the specified target
 function target(path, device_id) {
-    if (!fso.FileExists(path + CORDOVA_DEPLOY_EXE)) {
-        cordovaDeploy(path);
-    }
-    wscript_shell.CurrentDirectory = path + CORDOVA_DEPLOY + '\\CordovaDeploy\\bin\\Debug';
-    var cmd = 'CordovaDeploy -devices';
-    var out = wscript_shell.Exec(cmd);
-    while(out.Status == 0) {
-        WScript.Sleep(100);
-    }
-    if (!out.StdErr.AtEndOfStream) {
-        var line = out.StdErr.ReadAll();
-        Log("Error calling CordovaDeploy : ", true);
-        Log(line, true);
-        WScript.Quit(2);
+    Log('ERROR: not supported yet', true);
+    Log('DEPLOY FAILED.', true);
+    WScript.Quit(2);
+    
+}
+
+function makeAppStoreUtils(path) {
+
+    if (fso.FileExists(path + WINDOWS_STORE_UTILS)) {
+        return;
     }
-    else {
-        if (!out.StdOut.AtEndOfStream) {
-            var line = out.StdOut.ReadAll();
-            var targets = line.split('\r\n');
-            var check_id = new RegExp(device_id);
-            for (target in targets) {
-                if (targets[target].match(check_id)) {
-                    //TODO: this only gets single digit index, account for device index of 10+?
-                    var index = targets[target].substr(0,1);
-                    exec_verbose(path + CORDOVA_DEPLOY_EXE + ' ' + path + ' -d:' + index);
+
+    Log("Making PowerShell script for Windows Store Apps..");
+
+    write(path + WINDOWS_STORE_UTILS, read(path + WINDOWS_STORE_UTILS_SRC));
+}
+
+// uninstalls previous application instance (if exists)
+function uninstallApp(path) {
+    Log("Attempt to uninstall previous application version...");
+    Log("\tDirectory : " + path);
+
+    wscript_shell.CurrentDirectory = path;
+    var command = "powershell \". .\\" + WINDOWS_STORE_UTILS + "; Uninstall-App " + PACKAGE_NAME;
+    Log(command);
+    exec_verbose(command);
+}
+
+// executes store application installation script (Add-AppDevPackage.ps1)
+function installApp(path) {
+
+    Log("Attempt to install application...");
+    Log("\tDirectory : " + path);
+    
+    wscript_shell.CurrentDirectory = path;
+
+    // TODO: there could be multiple AppPackages
+    // check if AppPackages created
+    if (fso.FolderExists(path + '\\AppPackages')) {
+        var out_folder = fso.GetFolder(path + '\\AppPackages');
+        var subFolders = new Enumerator(out_folder.SubFolders);
+        for(;!subFolders.atEnd();subFolders.moveNext())
+        {
+            var subFolder = subFolders.item();
+            var files = new Enumerator(subFolder.Files);
+            for(;!files.atEnd();files.moveNext())
+            {
+                if(fso.GetExtensionName(files.item()) == "ps1")
+                {
+                    var command = "powershell \". .\\" + WINDOWS_STORE_UTILS + "; Install-App " + files.item();
+                    Log(command);
+                    exec_verbose(command);
                     return;
                 }
+
             }
-            Log('Error : target ' + device_id + ' was not found.', true);
-            Log('DEPLOY FAILED.', true);
-            WScript.Quit(2);
-        }
-        else {
-            Log('Error : CordovaDeploy Failed to find any devices', true);
-            Log('DEPLOY FAILED.', true);
-            WScript.Quit(2);
         }
+
     }
+    Log('Error : AppPackages were not built or Add-AppDevPackage.ps1 was not found', true);
+    WScript.Quit(2);
 }
 
 function build(path) {
@@ -246,18 +232,6 @@ function build(path) {
     }
 }
 
-function getPackageFamilyName(srcId) {
-    var outShell = wscript_shell.Exec('powershell -executionpolicy bypass -Command write-output((Get-AppxPackage ' + srcId + ').PackageFamilyName)');
-    var result = outShell.StdOut.ReadAll();
-    return result;
-}
-
-
-var res = getPackageFamilyName('$guid1$');
-Log("Res = " + res);
-WScript.Quit(0);
-
-
 if (args.Count() > 0) {
     // support help flags
     if (args(0) == "--help" || args(0) == "/?" ||