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 2014/08/20 20:11:57 UTC
[05/11] CB-7341 Port tooling/platform scripts from WSH to NodeJS
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/CordovaDeploy/CordovaDeploy/Program.cs
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/CordovaDeploy/CordovaDeploy/Program.cs b/wp8/template/cordova/lib/CordovaDeploy/CordovaDeploy/Program.cs
deleted file mode 100644
index 6f1cab0..0000000
--- a/wp8/template/cordova/lib/CordovaDeploy/CordovaDeploy/Program.cs
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
- 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.
-*/
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Collections.ObjectModel;
-using System.Diagnostics;
-using System.IO;
-using System.Xml.XPath;
-using System.Xml;
-using System.Xml.Linq;
-using System.Globalization;
-// Windows Phone Emulator Libraries
-using Microsoft.SmartDevice.Connectivity;
-using Microsoft.SmartDevice.Connectivity.Interface;
-using Microsoft.SmartDevice.MultiTargeting.Connectivity;
-using System.Threading;
-
-
-namespace CordovaDeploy
-{
-
- class DeployTool
- {
-
- static void Usage()
- {
- Log("Usage: CordovaDeploy [ -devices BuildOutputPath -d:DeviceIndex -uninstall ]");
- Log(" -devices : lists the devices and exits");
- Log(" BuildOutputPath : path to the built application, typically Bin/Debug/ or Bin/Release/");
- Log(" -d : index of the device to deploy, default is 0 ");
- Log(" -uninstall : will uninstall the application before re-installing it, removing all app documents and temp files");
- Log("examples:");
- Log(" CordovaDeploy -devices");
- Log(" CordovaDeploy Bin/Debug");
- Log(" CordovaDeploy Bin/Release -d:1");
- }
-
- static void ReadWait()
- {
- // This is used when running in Visual Studio, the Command Window is created at launch, and disappears at the
- // end of the program run, this let's us see the output before the window is closed.
- //if (Debugger.IsAttached)
- //{
- // Console.WriteLine("\nPress ENTER to continue...");
- // Console.Read();
- //}
- }
-
- static void Log(string msg, bool error = false)
- {
- Debug.WriteLine(msg);
- if (error)
- {
- Console.Error.WriteLine(msg);
- }
- else
- {
- Console.Out.WriteLine(msg);
- }
- }
-
- static Guid ReadAppId(string root)
- {
- Guid appID = Guid.Empty;
- string manifestFilePath = root + @"\Properties\WMAppManifest.xml";
-
- if (File.Exists(manifestFilePath))
- {
- XDocument xdoc = XDocument.Load(manifestFilePath);
- var appNode = xdoc.Root.Descendants("App").FirstOrDefault();
- if (appNode != null)
- {
- string guidStr = appNode.Attribute("ProductID").Value;
- appID = new Guid(guidStr);
- }
- else
- {
- Log(string.Format("Unable to find appID, expected to find an App.ProductID property defined in the file {0}", manifestFilePath), true);
- }
- }
- else
- {
- Log(string.Format("Error: the file {0} does not exist", manifestFilePath), true);
- }
- return appID;
- }
-
- static void ListDevices()
- {
- MultiTargetingConnectivity mtConn = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);
- Collection<ConnectableDevice> deviceList = mtConn.GetConnectableDevices();
-
- for (int index = 0; index < deviceList.Count; index++)
- {
- ConnectableDevice d = deviceList[index];
- string info = string.Format("{0} : {1} : {2}", index.ToString(), d.Id, d.Name);
- Log(info);
- }
- }
-
- static ConnectableDevice GetDeviceAtIndex(int index)
- {
- MultiTargetingConnectivity mtConn = new MultiTargetingConnectivity(CultureInfo.CurrentUICulture.LCID);
- Collection<ConnectableDevice> deviceList = mtConn.GetConnectableDevices();
- return deviceList[index];
- }
-
- static void Main(string[] args)
- {
- int deviceIndex = 0;
-
- string iconFilePath = "";
- string xapFilePath = "";
- Guid appID = Guid.Empty;
- bool uninstallFirst = args.Contains("-uninstall");
- bool awaitAppClose = args.Contains("-wait");
-
- string root = Directory.GetCurrentDirectory();
-
- if (args.Length < 1)
- {
- Usage();
- ReadWait();
- return;
- }
- else if (args.Contains("-devices"))
- {
- ListDevices();
- ReadWait();
- return;
- }
- else if (args.Length > 1 && args[1].StartsWith("-d:"))
- {
- deviceIndex = int.Parse(args[1].Substring(3));
- }
-
- if (Directory.Exists(args[0]))
- {
- var info = new DirectoryInfo(args[0]);
- root = info.FullName;
-
- try
- {
- xapFilePath = Directory.GetFiles(root + @"\Bin\Debug", "*.xap").FirstOrDefault();
- }
- catch (DirectoryNotFoundException)
- {
- try
- {
- xapFilePath = Directory.GetFiles(root + @"\Bin\Release", "*.xap").FirstOrDefault();
- }
- catch (DirectoryNotFoundException)
- {
- Log(string.Format("Error: could not find project build directoy in {0}", root), true);
- Log("make sure your app has been successfully built before deploying.", true);
- }
- }
- }
-
- if (File.Exists(args[0]))
- {
- var info = new FileInfo(args[0]);
- if (info.Extension == ".xap")
- {
- root = info.DirectoryName;
- xapFilePath = info.FullName;
- }
- }
-
- appID = ReadAppId(root);
- if (appID == Guid.Empty)
- {
- return; // Logging of errors is done in ReadAppId
- }
-
- if (File.Exists(root + @"\ApplicationIcon.png"))
- {
- iconFilePath = root + @"\ApplicationIcon.png";
- }
- else
- {
- Log(string.Format("Error: could not find application icon at {0}", root + @"\ApplicationIcon.png"), true);
- ReadWait();
- return;
- }
-
- if (string.IsNullOrEmpty(xapFilePath))
- {
- Log(string.Format("Error: could not find application .xap in folder {0}", root), true);
- ReadWait();
- return;
- }
-
- ConnectableDevice deviceConn = GetDeviceAtIndex(deviceIndex);
- Log("Connecting to device :: " + deviceConn.Id + " : " + deviceConn.Name);
- try
- {
- IDevice device = deviceConn.Connect();
- IRemoteApplication app = null;
- if (device.IsApplicationInstalled(appID))
- {
- app = device.GetApplication(appID);
- if (uninstallFirst)
- {
- Log("Uninstalling app on " + deviceConn.Name);
- app.Uninstall();
- Log("Installing app on " + deviceConn.Name);
- app = device.InstallApplication(appID, appID, "NormalApp", iconFilePath, xapFilePath);
- }
- else
- {
- Log("Updating app on " + deviceConn.Name);
- app.UpdateApplication("NormalApp", iconFilePath, xapFilePath);
- }
-
- }
- else
- {
- Log("Installing app on " + deviceConn.Name);
- app = device.InstallApplication(appID, appID, "NormalApp", iconFilePath, xapFilePath);
- }
-
- Log("Launching app on " + deviceConn.Name);
- app.Launch();
-
- if (awaitAppClose)
- {
- // wait for the app to launch
- Thread.Sleep(4000);
-
- bool isExiting = false;
-
- string tempFileName = Path.GetTempFileName();
-
- try
- {
- IRemoteIsolatedStorageFile isoFile = app.GetIsolatedStore();
- int index = 0;
- while (!isExiting) //app.IsRunning()) // not implemented ... wtf?
- {
-
- char[] buffer = new char[1000];
-
- isoFile.ReceiveFile((object)Path.DirectorySeparatorChar + "debugOutput.txt", tempFileName, true);
- using (StreamReader reader = System.IO.File.OpenText(tempFileName))
- {
- try
- {
- int newLinesRead = 0;
- for (int lineNum = 0; ; lineNum++)
- {
- if (reader.Peek() > -1)
- {
- string str = reader.ReadLine();
- if (lineNum >= index)
- {
- newLinesRead++;
- if (str == "EXIT")
- {
- isExiting = true;
- }
- Log(str);
- }
- }
- else
- {
- break;
- }
- }
- index += newLinesRead;
- }
- catch (Exception)
- {
- // at end of stream most likely, no worries, ... move along.
- }
- }
-
- Thread.Sleep(1000);
- }
-
- System.IO.File.Delete(tempFileName);
- }
- catch (Exception ex)
- {
- Log(ex.Message);
- }
- }
-
- // To Stop :
- //app.TerminateRunningInstances();
-
- device.Disconnect();
-
- ReadWait();
-
- }
- catch (Exception ex)
- {
- Log("Error :: " + ex.Message, true);
- }
- }
-
- // To read and write ISO storage files!! :
- /*
- try
- {
- IRemoteIsolatedStorageFile isoStore = app.GetIsolatedStore();
- remoteIsolatedStorageFile.ReceiveFile("sourcePath", "destPath", true);
- }
- catch (Exception ex) { }
- */
-
- }
-}
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/CordovaDeploy/CordovaDeploy/Properties/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/CordovaDeploy/CordovaDeploy/Properties/AssemblyInfo.cs b/wp8/template/cordova/lib/CordovaDeploy/CordovaDeploy/Properties/AssemblyInfo.cs
deleted file mode 100644
index 2b6c01b..0000000
--- a/wp8/template/cordova/lib/CordovaDeploy/CordovaDeploy/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- 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.
-*/
-
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("CordovaDeploy")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("CordovaDeploy")]
-[assembly: AssemblyCopyright("Copyright © 2012")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("256b11aa-d4bb-48cf-8024-7c040421fa8d")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/CordovaDeploy/CordovaDeploy/app.config
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/CordovaDeploy/CordovaDeploy/app.config b/wp8/template/cordova/lib/CordovaDeploy/CordovaDeploy/app.config
deleted file mode 100644
index 306e79e..0000000
--- a/wp8/template/cordova/lib/CordovaDeploy/CordovaDeploy/app.config
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0"?>
-<!--
- 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.
--->
-<configuration>
-<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/MSBuildTools.js
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/MSBuildTools.js b/wp8/template/cordova/lib/MSBuildTools.js
new file mode 100644
index 0000000..ba1ee79
--- /dev/null
+++ b/wp8/template/cordova/lib/MSBuildTools.js
@@ -0,0 +1,73 @@
+/*
+ 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.
+*/
+
+var Q = require('Q'),
+ path = require('path'),
+ utils = require('./utils');
+
+function MSBuildTools (version, path) {
+ this.version = version;
+ this.path = path;
+}
+
+MSBuildTools.prototype.buildProject = function(projFile, buildType, buildarch) {
+ console.log("\nBuilding project: " + projFile);
+ console.log("\tConfiguration : " + buildType);
+ console.log("\tPlatform : " + buildarch);
+
+ var args = ['/clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal', '/nologo',
+ '/p:Configuration=' + buildType,
+ '/p:Platform=' + buildarch];
+
+ return utils.spawn(path.join(this.path, 'msbuild'), [projFile].concat(args));
+};
+
+// returns full path to msbuild tools required to build the project and tools version
+module.exports.findAvailableVersion = function (searchFor32Bit) {
+ var versions = ['12.0', '4.0'];
+
+ return Q.all(versions.map(function (version) {
+ return checkMSBuildVersion(version, searchFor32Bit);
+ }))
+ .then(function (versions) {
+ // select first msbuild version available, and resolve promise with it
+ var msbuildTools = versions[0] || versions[1];
+ return msbuildTools ? Q.resolve(msbuildTools) : Q.reject('MSBuild tools not found');
+ });
+};
+
+function checkMSBuildVersion(version, searchFor32Bit) {
+ var deferred = Q.defer();
+
+ var regRoot = searchFor32Bit ? 'HKLM\\SOFTWARE\\Wow6432Node' : 'HKLM\\SOFTWARE';
+
+ utils.exec('reg query ' + regRoot + '\\Microsoft\\MSBuild\\ToolsVersions\\' + version + ' /v MSBuildToolsPath')
+ .then(function(output) {
+ // fetch msbuild path from 'reg' output
+ var path = /MSBuildToolsPath\s+REG_SZ\s+(.*)/i.exec(output);
+ if (path) {
+ deferred.resolve(new MSBuildTools(version, path[1]));
+ return;
+ }
+ deferred.resolve(null); // not found
+ }, function () {
+ deferred.resolve(null);
+ });
+ return deferred.promise;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/build.js
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/build.js b/wp8/template/cordova/lib/build.js
index 9644988..90e07c0 100644
--- a/wp8/template/cordova/lib/build.js
+++ b/wp8/template/cordova/lib/build.js
@@ -17,267 +17,76 @@
under the License.
*/
-
-var fso = WScript.CreateObject('Scripting.FileSystemObject');
-var wscript_shell = WScript.CreateObject("WScript.Shell");
-var procEnv = wscript_shell.Environment("Process");
-// possible values and additional details: http://msdn.microsoft.com/en-us/library/aa384274.aspx
-var procArchitecture = procEnv("PROCESSOR_ARCHITECTURE").toLowerCase();
-var is64Mode = procArchitecture && procArchitecture != 'x86';
-
-// build type. Possible values: "debug", "release"
-var buildType = null,
-// list of build architectures. list of strings
-buildArchs = null;
-
-var args = WScript.Arguments;
-
-// working dir
-var ROOT = WScript.ScriptFullName.split('\\cordova\\lib\\build.js').join('');
-
-// help/usage function
-function Usage() {
- Log("");
- Log("Usage: build [ --debug | --release ] [--archs=\"<list of architectures...>\"]");
- Log(" --help : Displays this dialog.");
- Log(" --debug : Cleans and builds project in debug mode.");
- Log(" --release : Cleans and builds project in release mode.");
- Log(" --release : Cleans and builds project in release mode.");
- Log(" --archs : Builds project binaries for specific chip architectures. `arm` and `x86` are supported for wp8");
- Log("examples:");
- Log(" build ");
- Log(" build --debug");
- Log(" build --release");
- Log(" build --release --archs=\"arm x86\"");
- Log("");
-}
-
-// logs messaged to stdout and stderr
-function Log(msg, error) {
- if (error) {
- WScript.StdErr.WriteLine(msg);
- }
- else {
- WScript.StdOut.WriteLine(msg);
- }
-}
-
-// executes a commmand in the shell
-function exec_verbose(command) {
- //Log("Command: " + command);
- var oShell=wscript_shell.Exec(command);
- while (oShell.Status == 0) {
- //Wait a little bit so we're not super looping
- WScript.sleep(100);
- //Print any stdout output from the script
- while (!oShell.StdOut.AtEndOfStream) {
- var line = oShell.StdOut.ReadLine();
- Log(line);
- }
- }
- //Check to make sure our scripts did not encounter an error
- if (!oShell.StdErr.AtEndOfStream) {
- var line = oShell.StdErr.ReadAll();
- Log("ERROR: command failed in build.js : " + command);
- Log(line, true);
- WScript.Quit(2);
- }
- return oShell.ExitCode;
-}
-
-// escapes a path so that it can be passed to shell command.
-function escapePath(path) {
- return '"' + path + '"';
+var Q = require('Q'),
+ path = require('path'),
+ nopt = require('nopt'),
+ utils = require('./utils'),
+ shell = require('shelljs'),
+ MSBuildTools = require('./MSBuildTools');
+
+// Platform project root folder
+var ROOT = path.join(__dirname, '..', '..');
+
+function parseAndValidateArgs(argv) {
+ // parse and validate args
+ args = nopt({'debug': Boolean, 'release': Boolean, 'archs': [String]}, {'-r': '--release'}, argv);
+ // Validate args
+ if (args.debug && args.release) {
+ return Q.reject('Only one of "debug"/"release" options should be specified');
+ }
+ // get build options/defaults and resolvew with buildopts object
+ return Q.resolve({
+ buildType: args.release ? 'release' : 'debug',
+ buildArchs: args.archs ? args.archs.split(' ') : ['anycpu'],
+ });
}
-// checks to see if a .csproj file exists in the project root
-function is_cordova_project(path) {
- if (fso.FolderExists(path)) {
- var proj_folder = fso.GetFolder(path);
- var proj_files = new Enumerator(proj_folder.Files);
- for (;!proj_files.atEnd(); proj_files.moveNext()) {
- if (fso.GetExtensionName(proj_files.item()) == 'csproj') {
- return true;
- }
- }
- }
- return false;
-}
-
-function get_solution_name(path) {
- if (fso.FolderExists(path)) {
- var proj_folder = fso.GetFolder(path);
- var proj_files = new Enumerator(proj_folder.Files);
- for (;!proj_files.atEnd(); proj_files.moveNext()) {
- if (fso.GetExtensionName(proj_files.item()) == 'sln') {
- return proj_files.item();
- }
- }
- }
- return null;
-}
-
-// returns full path to msbuild tools required to build the project
-function getMSBuildToolsPath() {
- // WP8 requires x86 version of MSBuild, CB-6732
- var regRoot = is64Mode ? 'HKLM\\SOFTWARE\\Wow6432Node' : 'HKLM\\SOFTWARE';
-
- // use the latest version of the msbuild tools available on this machine
- var toolsVersions = ['12.0','4.0']; // for WP8 we REQUIRE 4.0 !!!
- for (idx in toolsVersions) {
- try {
- return wscript_shell.RegRead(regRoot + '\\Microsoft\\MSBuild\\ToolsVersions\\' + toolsVersions[idx] + '\\MSBuildToolsPath');
- } catch (err) {
- Log("toolsVersion " + idx + " is not supported");
- }
- }
- Log('MSBuild tools have not been found. Please install Microsoft Visual Studio 2012 or later', true);
- WScript.Quit(2);
-}
-
-// builds the project and .xap with buildtype and architectures specified
-function build_xap(path, buildtype, buildarchs) {
-
- // check if file xap was created for specified buldtype and architecture
- // raises error if xap not found
- function checkForXap (path, mode, arch) {
- var buildFolder = arch.toLowerCase() == 'any cpu' ? path + '\\Bin\\' + mode : path + '\\Bin\\' + arch + '\\' + mode;
- Log('Checking for .xap in: ' + buildFolder);
- if (fso.FolderExists(buildFolder)) {
- var out_folder = fso.GetFolder(buildFolder);
- var out_files = new Enumerator(out_folder.Files);
- for (;!out_files.atEnd(); out_files.moveNext()) {
- if (fso.GetExtensionName(out_files.item()) == 'xap') {
- Log("BUILD SUCCESS.\n");
- return;
- }
- }
- }
- Log('ERROR: MSBuild failed to create .xap when building cordova-wp8 for release.', true);
- WScript.Quit(2);
- }
-
- if (!buildtype) {
- Log("WARNING: [ --debug | --release ] not specified, defaulting to debug...");
- buildtype = "debug";
- }
-
- if (!buildarchs) {
- Log("WARNING: target architecture not specified, defaulting to AnyCPU...");
- buildarchs = ["Any CPU"];
- }
-
- exec_verbose('%comspec% /c "' + path + '\\cordova\\clean"');
-
- var MSBuildToolsPath = getMSBuildToolsPath();
- Log("\tMSBuildToolsPath: " + MSBuildToolsPath);
-
- for (var i = 0; i < buildarchs.length; i++) {
-
- var buildarch = buildarchs[i].toLowerCase();
- // support for "any cpu" specified with or without space
- buildarch = buildarch !== "anycpu" ? buildarch : "any cpu";
-
- Log("Building Cordova-WP8 Project:");
- Log("\tConfiguration : " + buildtype);
- Log("\tPlatform : " + buildarch);
- Log("\tDirectory : " + path);
-
- wscript_shell.CurrentDirectory = path;
-
- var buildCommand = escapePath(MSBuildToolsPath + 'msbuild') +
- ' ' + escapePath(get_solution_name(path)) +
- ' /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal' +
- ' /nologo' +
- ' /p:Configuration=' + buildtype +
- ' /p:Platform="' + buildarch + '"';
-
- // hack to get rid of 'Access is denied.' error when running the shell w/ access to C:\path..
- buildCommand = '%comspec% /c "' + buildCommand + '"';
-
- Log("buildCommand = " + buildCommand);
-
- if (exec_verbose(buildCommand) !== 0) {
- // msbuild failed
- WScript.Quit(2);
- }
-
- checkForXap(path, buildtype, buildarch);
- }
-
- Log("WP8 builds successfully completed.");
-}
-
-// parses script args and set global variables for build
-// throws error if unknown argument specified.
-function parseArgs () {
-
- // return build type, specified by input string, or null, if not build type parameter
- function getBuildType (arg) {
- arg = arg.toLowerCase();
- if (arg == "--debug" || arg == "-d") {
- return "debug";
- }
- else if (arg == "--release" || arg == "-r") {
- return "release";
- }
- return null;
- }
-
- // returns build architectures list, specified by input string
- // or null if nothing specified, or not --archs parameter
- function getBuildArchs (arg) {
- arg = arg.toLowerCase();
- var archs = /--archs=(.+)/.exec(arg);
- if (archs) {
- // if architectures list contains commas, suppose that is comma delimited
- if (archs[1].indexOf(',') != -1){
- return archs[1].split(',');
- }
- // else space delimited
- return archs[1].split(/\s/);
- }
- return null;
- }
-
- for (var i = 0; i < args.Length; i++) {
- if (getBuildType(args(i))) {
- buildType = getBuildType(args(i));
- } else if (getBuildArchs(args(i))) {
- buildArchs = getBuildArchs(args(i));
- } else {
- Log("Error: \"" + args(i) + "\" is not recognized as a build option", true);
- Usage();
- WScript.Quit(2);
- }
- }
-}
-
-
-Log("");
-
-if (args.Count() > 0) {
- // support help flags
- if (args(0) == "--help" || args(0) == "/?" ||
- args(0) == "help" || args(0) == "-help" || args(0) == "/help") {
- Usage();
- WScript.Quit(2);
- }
- // Handle project errors
- else if (!fso.FolderExists(ROOT)) {
- Log("Error: Project directory not found,", true);
- Usage();
- WScript.Quit(2);
- }
- else if (!is_cordova_project(ROOT)) {
- Log('Error: .csproj file not found in ' + ROOT, true);
- Log('could not build project.', true);
- WScript.Quit(2);
- }
- // Parse arguments
- else {
- parseArgs();
- }
-}
-
-build_xap(ROOT, buildType, buildArchs);
\ No newline at end of file
+// help/usage function
+module.exports.help = function () {
+ console.log("");
+ console.log("Usage: build [ --debug | --release ] [--archs=\"<list of architectures...>\"]");
+ console.log(" --help : Displays this dialog.");
+ console.log(" --debug : Cleans and builds project in debug mode.");
+ console.log(" --release : Cleans and builds project in release mode.");
+ console.log(" --release : Cleans and builds project in release mode.");
+ console.log(" --archs : Builds project binaries for specific chip architectures. `arm` and `x86` are supported for wp8");
+ console.log("examples:");
+ console.log(" build ");
+ console.log(" build --debug");
+ console.log(" build --release");
+ console.log(" build --release --archs=\"arm x86\"");
+ console.log("");
+};
+
+// builds cordova-windows application with parameters provided.
+// See 'help' function for args list
+module.exports.run = function (argv) {
+ if (!utils.isCordovaProject(ROOT)){
+ return Q.reject('Could not find project at ' + ROOT);
+ }
+
+ return parseAndValidateArgs(argv)
+ .then(function (buildopts) {
+ // WP8 requires x86 version of MSBuild, CB-6732
+ var is64bitSystem = process.env["PROCESSOR_ARCHITECTURE"] != 'x86';
+
+ // Get available msbuild tools
+ return MSBuildTools.findAvailableVersion(is64bitSystem)
+ .then(function (msbuildTools) {
+ // then build all architectures specified
+ // chain promises each after previous with reduce function
+ return buildopts.buildArchs.reduce(function (promise, buildarch) {
+ return promise.then(function () {
+ buildarch = buildarch == "anycpu" ? "any cpu" : buildarch;
+ // serach for first solution file found
+ // this is performed due to solution file can be renamed in create
+ var solutionFiles = shell.ls(path.join(ROOT, '*.sln'));
+ if (solutionFiles && solutionFiles[0]) {
+ return msbuildTools.buildProject(solutionFiles[0], buildopts.buildType, buildarch);
+ }
+ return Q.reject('No solution files found in project directory');
+ });
+ }, Q());
+ });
+ });
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/clean.js
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/clean.js b/wp8/template/cordova/lib/clean.js
index f5bdbfc..6d1248c 100644
--- a/wp8/template/cordova/lib/clean.js
+++ b/wp8/template/cordova/lib/clean.js
@@ -17,72 +17,16 @@
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\\clean.js').join('');
-
-
-// help function
-function Usage() {
- Log("");
- Log("Usage: clean");
- Log("examples:");
- Log(" clean");
- Log(" - deletes all generated files in project");
- Log("");
-}
-
-// logs to stdout or stderr
-function Log(msg, error) {
- if (error) {
- WScript.StdErr.WriteLine(msg);
- }
- else {
- WScript.StdOut.WriteLine(msg);
- }
-}
-
-// cleans any generated files in the cordova project
-function clean_project(path) {
- delete_if_exists(path + "\\obj");
- delete_if_exists(path + "\\Bin");
-}
-
-// deletes the path element if it exists
-function delete_if_exists(path) {
- if (fso.FolderExists(path)) {
- fso.DeleteFolder(path);
- }
- else if (fso.FileExists(path)) {
- fso.DeleteFile(path);
- }
-}
-
-
-if (args.Count() > 0) {
- // support help flags
- if (args(0) == "--help" || args(0) == "/?" ||
- args(0) == "help" || args(0) == "-help" || args(0) == "/help") {
- Usage();
- WScript.Quit(2);
- }
- else {
- Log("Error: \"" + args(0) + "\" is not recognized as a valid option", true);
- Usage();
- WScript.Quit(2);
- }
-}
-else {
- if (fso.FolderExists(ROOT)) {
- Log("Cleaning cordova project...");
- clean_project(ROOT);
- }
- else {
- Log("Error: Project directory not found,", true);
- Usage();
- WScript.Quit(2);
- }
-}
\ No newline at end of file
+var Q = require('q'),
+ path = require('path'),
+ shell = require('shelljs');
+
+var ROOT = path.join(__dirname, '..', '..');
+
+module.exports.run = function (argv) {
+ var projectPath = ROOT;
+ ['obj', 'Bin'].forEach(function(dir) {
+ shell.rm('-rf', path.join(projectPath, dir));
+ });
+ return Q.resolve();
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/deploy.js
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/deploy.js b/wp8/template/cordova/lib/deploy.js
deleted file mode 100644
index 3b601ce..0000000
--- a/wp8/template/cordova/lib/deploy.js
+++ /dev/null
@@ -1,422 +0,0 @@
-/*
- 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.
-*/
-
-
-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';
-//device_id for targeting specific device
-var device_id;
-
-// build type. Possible values: "debug", "release"
-// required to determine which package should be deployed
-var buildType = null,
- // nobuild flag
- noBuild = false,
- // list of build architectures. list of strings
- // required to determine which package should be deployed
- buildArchs = null,
- // build target. Possible values: "device", "emulator", "<target_name>"
- buildTarget = null;
-
-// help function
-function Usage() {
- Log("");
- Log("Usage:");
- Log(" run [ --device || --emulator || --target=<id> ] ");
- Log(" [ --debug || --release || --nobuild ]");
- Log(" [--archs=\"<list of architectures...>\"]");
- Log(" --device : Deploys and runs the project on the connected device.");
- Log(" --emulator : [DEFAULT] Deploys and runs the project on an emulator.");
- Log(" --target=<id> : Deploys and runs the project on the specified target.");
- Log(" --debug : [DEFAULT] Builds project in debug mode.");
- Log(" --release : Builds project in release mode.");
- Log(" --nobuild : Ueses pre-built xap, or errors if project is not built.");
- Log(" --archs : Builds project binaries for specific chip architectures.");
- Log(" Deploys and runs package with first architecture specified.");
- Log(" arm` and `x86` are supported for wp8");
- Log("Examples:");
- Log(" run");
- Log(" run --emulator");
- Log(" run --device");
- Log(" run --target=7988B8C3-3ADE-488d-BA3E-D052AC9DC710");
- Log(" run --device --release");
- Log(" run --emulator --debug");
- Log("");
-}
-
-// log to stdout or stderr
-function Log(msg, error) {
- if (error) {
- WScript.StdErr.WriteLine(msg);
- }
- else {
- WScript.StdOut.WriteLine(msg);
- }
-}
-
-var ForReading = 1, ForWriting = 2, ForAppending = 8;
-var TristateUseDefault = 2, TristateTrue = 1, TristateFalse = 0;
-
-
-// executes a commmand in the shell
-function exec(command) {
- var oShell=wscript_shell.Exec(command);
- while (oShell.Status == 0) {
- WScript.sleep(100);
- }
-}
-
-// executes a commmand in the shell
-function exec_verbose(command) {
- //Log("Command: " + command);
- var oShell=wscript_shell.Exec(command);
- while (oShell.Status == 0) {
- //Wait a little bit so we're not super looping
- WScript.sleep(100);
- //Print any stdout output from the script
- while (!oShell.StdOut.AtEndOfStream) {
- var line = oShell.StdOut.ReadLine();
- Log(line);
- }
- }
- //Check to make sure our scripts did not encounter an error
- if (!oShell.StdErr.AtEndOfStream) {
- var line = oShell.StdErr.ReadAll();
- Log("ERROR: command failed in deploy.js : " + command);
- Log(line, true);
- WScript.Quit(2);
- }
-
- return oShell.ExitCode;
-}
-
-// returns the contents of a file
-function read(filename) {
- if (fso.FileExists(filename)) {
- var f=fso.OpenTextFile(filename, 1,2);
- var s=f.ReadAll();
- f.Close();
- return s;
- }
- else {
- Log('Cannot read non-existant file : ' + filename, true);
- WScript.Quit(2);
- }
- return null;
-}
-
-// escapes a path so that it can be passed to shell command.
-function escapePath(path) {
- return '"' + path + '"';
-}
-
-// returns full path to msbuild tools required to build the project
-function getMSBuildToolsPath() {
- // use the latest version of the msbuild tools available on this machine
- var toolsVersions = ['12.0','4.0']; // for WP8 we REQUIRE 4.0 !!!
- for (idx in toolsVersions) {
- try {
- return wscript_shell.RegRead('HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\' + toolsVersions[idx] + '\\MSBuildToolsPath');
- } catch (err) {
- Log("toolsVersion " + idx + " is not supported");
- }
- }
- Log('MSBuild tools have not been found. Please install Microsoft Visual Studio 2012 or later', true);
- WScript.Quit(2);
-}
-
-// 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...');
-
- // 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');
- }
-
- var MSBuildToolsPath = getMSBuildToolsPath();
- Log("\tMSBuildToolsPath: " + MSBuildToolsPath);
-
- var buildCommand = escapePath(MSBuildToolsPath + 'msbuild') +
- ' ' + escapePath(path + CORDOVA_DEPLOY + '\\CordovaDeploy.sln') +
- ' /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo';
-
- // hack to get rid of 'Access is denied.' error when running the shell w/ access to C:\path..
- buildCommand = '%comspec% /c "' + buildCommand + '"';
- Log("buildCommand = " + buildCommand);
-
- if (exec_verbose(buildCommand) != 0 || !fso.FileExists(path + CORDOVA_DEPLOY_EXE)) {
- Log('ERROR: MSBUILD FAILED TO COMPILE CordovaDeploy.exe', true);
- WScript.Quit(2);
- }
- Log('CordovaDeploy.exe compiled, SUCCESS.');
- }
- else {
- Log('ERROR: CordovaDeploy.sln not found, unable to compile CordovaDeploy tool.', true);
- WScript.Quit(2);
- }
-}
-
-// check if file xap was created for specified buldtype and architecture
-// raises error if xap not found
-function getXap (path, buildtype, buildarch) {
- var buildFolder = buildarch.toLowerCase() == 'any cpu' ?
- path + '\\Bin\\' + buildtype :
- path + '\\Bin\\' + buildarch + '\\' + buildtype;
-
- if (fso.FolderExists(buildFolder)) {
- var out_folder = fso.GetFolder(buildFolder);
- var out_files = new Enumerator(out_folder.Files);
- for (;!out_files.atEnd(); out_files.moveNext()) {
- // search for first .xap file in folder
- if (fso.GetExtensionName(out_files.item()) == 'xap') {
- Log('Found .xap: ' + out_files.item().Path);
- return out_files.item().Path;
- }
- }
- }
- Log('No .xap found for ' + buildtype + ' build type and ' + buildarch + ' architecture', true);
- WScript.Quit(2);
-}
-
-// launches project on device
-function device(path, buildtype, buildarchs)
-{
- // set default values
- var build = buildtype ? buildtype : "debug";
- var arch = buildarchs ? buildarchs[0] : "any cpu";
-
- 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('"' + path + CORDOVA_DEPLOY_EXE + '" "' + getXap(path, build, arch) + '" -d:0');
- }
- else
- {
- Log('Error: Failed to find CordovaDeploy.exe in ' + path, true);
- Log('DEPLOY FAILED.', true);
- WScript.Quit(2);
- }
-}
-
-// launches project on emulator
-function emulator(path, buildtype, buildarchs)
-{
- var build = buildtype ? buildtype : "debug";
- var arch = buildarchs ? buildarchs[0] : "any cpu";
-
- 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('"' + path + CORDOVA_DEPLOY_EXE + '" "' + getXap(path, build, arch) + '" -d:1');
- }
- else
- {
- Log('Error: Failed to find CordovaDeploy.exe in ' + path, true);
- Log('DEPLOY FAILED.', true);
- WScript.Quit(2);
- }
-}
-
-// builds and launches the project on the specified target
-function target(path, buildtarget, buildtype, buildarchs) {
- if (!fso.FileExists(path + CORDOVA_DEPLOY_EXE)) {
- cordovaDeploy(path);
- }
- var cmd = '"' + path + CORDOVA_DEPLOY_EXE + '" -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);
- }
- 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);
- var build = buildtype ? buildtype : "debug";
- var arch = buildarchs ? buildarch[0] : "any cpu";
- exec_verbose('"' + path + CORDOVA_DEPLOY_EXE + '" "' + getXap(path, build, arch) + '" -d:' + index);
- 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);
- }
- }
-}
-
-function build(path, buildtype, buildarchs) {
- // if --nobuild flag is specified, no action required here
- if (noBuild) return;
-
- var cmd = '%comspec% /c ""' + path + '\\cordova\\build"';
- if (buildtype){
- cmd += " --" + buildtype;
- }
- if (buildarchs){
- cmd += ' --archs="' + buildarchs.join(",") + '"';
- }
- cmd += '"';
-
- exec_verbose(cmd);
-}
-
-function run(path, buildtarget, buildtype, buildarchs) {
- switch(buildtarget) {
- case "emulator" :
- emulator(path, buildtype, buildarchs);
- break;
- case "device" :
- device(path, buildtype, buildarchs);
- break;
- case null :
- Log("WARNING: [ --target=<ID> | --emulator | --device ] not specified, defaulting to --emulator");
- emulator(path, buildtype, buildarchs);
- break;
- default :
- // if buildTarget is neither "device", "emulator" or null
- // then it is a name of target
- target(path, buildtarget, buildtype, buildarchs);
- break;
- }
-}
-
-// parses script args and set global variables for build/deploy
-// throws error if unknown argument specified.
-function parseArgs () {
-
- // return build type, specified by input string, or null, if not build type parameter
- function getBuildType (arg) {
- arg = arg.toLowerCase();
- if (arg == "--debug" || arg == "-d") {
- return "debug";
- }
- else if (arg == "--release" || arg == "-r") {
- return "release";
- }
- else if (arg == "--nobuild") {
- noBuild = true;
- return true;
- }
- return null;
- }
-
- // returns build architectures list, specified by input string
- // or null if nothing specified, or not --archs parameter
- function getBuildArchs (arg) {
- arg = arg.toLowerCase();
- var archs = /--archs=(.+)/.exec(arg);
- if (archs) {
- // if architectures list contains commas, suppose that is comma delimited
- if (archs[1].indexOf(',') != -1){
- return archs[1].split(',');
- }
- // else space delimited
- return archs[1].split(/\s/);
- }
- return null;
- }
-
- // returns deploy target, specified by input string or null, if not deploy target parameter
- function getBuildTarget (arg) {
- arg = arg.toLowerCase();
- if (arg == "--device"){
- return "device";
- }
- else if (arg == "--emulator"){
- return "emulator";
- }
- else {
- var target = /--target=(.*)/.exec(arg);
- if (target){
- return target[1];
- }
- }
- return null;
- }
-
- for (var i = 0; i < args.Length; i++) {
- if (getBuildType(args(i))) {
- buildType = getBuildType(args(i));
- } else if (getBuildArchs(args(i))) {
- buildArchs = getBuildArchs(args(i));
- } else if (getBuildTarget(args(i))){
- buildTarget = getBuildTarget(args(i));
- } else {
- Log("Error: \"" + args(i) + "\" is not recognized as a build/deploy option", true);
- Usage();
- WScript.Quit(2);
- }
- }
-}
-
-if (args.Count() > 0) {
- // support help flags
- if (args(0) == "--help" || args(0) == "/?" ||
- args(0) == "help" || args(0) == "-help" || args(0) == "/help") {
- Usage();
- WScript.Quit(2);
- }
- else if (!fso.FolderExists(ROOT)) {
- Log('Error: Project directory not found,', true);
- Usage();
- WScript.Quit(2);
- }
- parseArgs();
-}
-
-// build and run the project!
-build(ROOT, buildType, buildArchs);
-run(ROOT, buildTarget, buildType, buildArchs);
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/device.js
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/device.js b/wp8/template/cordova/lib/device.js
new file mode 100644
index 0000000..f79a4fe
--- /dev/null
+++ b/wp8/template/cordova/lib/device.js
@@ -0,0 +1,54 @@
+/*
+ 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.
+*/
+
+var Q = require('q'),
+ fs = require('fs'),
+ path = require('path'),
+ shell = require('shelljs'),
+ utils = require('./utils');
+
+// returns one of available devices which name match with parovided string
+// return rejected promise if device with name specified not found
+module.exports.findDevice = function (target) {
+ return module.exports.listDevices()
+ .then(function(deviceList) {
+ for (var idx in deviceList){
+ if (deviceList[idx].indexOf(target) > -1) {
+ return Q.resolve(idx);
+ }
+ }
+ return Q.reject('Specified device not found');
+ });
+};
+
+// returns array of available devices names
+module.exports.listDevices = function () {
+ return utils.getXapDeploy()
+ .then(function(xapDeploy) {
+ return utils.exec('"' + xapDeploy + '" /enumeratedevices')
+ .then(function(output) {
+ return Q.resolve(output.split('\n').map(function(line) {
+ var match = /\s*(\d)+\s+(.*)/.exec(line);
+ return match && match[2];
+ }).filter(function (line) {
+ return line;
+ }));
+ });
+ });
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/install-device.bat
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/install-device.bat b/wp8/template/cordova/lib/install-device.bat
index c656e54..01dd232 100644
--- a/wp8/template/cordova/lib/install-device.bat
+++ b/wp8/template/cordova/lib/install-device.bat
@@ -20,12 +20,11 @@ goto endheader
#
:endheader
-@ECHO OFF
-SET script_path="%~dp0deploy.js"
+SET script_path="%~dp0\..\run"
IF EXIST %script_path% (
- cscript %script_path% %* --device --nobuild //nologo
+ node %script_path% %* --device --nobuild
) ELSE (
ECHO.
- ECHO ERROR: Could not find 'deploy.js' in cordova/lib, aborting...>&2
+ ECHO ERROR: Could not find 'deploy' in cordova, aborting...>&2
EXIT /B 1
)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/install-emulator.bat
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/install-emulator.bat b/wp8/template/cordova/lib/install-emulator.bat
index a6c42c9..c3a2b73 100644
--- a/wp8/template/cordova/lib/install-emulator.bat
+++ b/wp8/template/cordova/lib/install-emulator.bat
@@ -20,12 +20,11 @@ goto endheader
#
:endheader
-@ECHO OFF
-SET script_path="%~dp0deploy.js"
+SET script_path="%~dp0\..\run"
IF EXIST %script_path% (
- cscript %script_path% %* --emulator --nobuild //nologo
+ node %script_path% %* --emulator --nobuild
) ELSE (
ECHO.
- ECHO ERROR: Could not find 'deploy.js' in cordova/lib, aborting...>&2
+ ECHO ERROR: Could not find 'run' in cordova, aborting...>&2
EXIT /B 1
)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/list-devices.bat
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/list-devices.bat b/wp8/template/cordova/lib/list-devices.bat
index 53be19a..47e911d 100644
--- a/wp8/template/cordova/lib/list-devices.bat
+++ b/wp8/template/cordova/lib/list-devices.bat
@@ -20,10 +20,9 @@ goto endheader
#
:endheader
-@ECHO OFF
SET script_path="%~dp0target-list.js"
IF EXIST %script_path% (
- cscript %script_path% %* --devices //nologo
+ node %script_path% %* --devices
) ELSE (
ECHO.
ECHO ERROR: Could not find 'target-list.js' in cordova/lib, aborting...>&2
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/list-emulator-images.bat
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/list-emulator-images.bat b/wp8/template/cordova/lib/list-emulator-images.bat
index bdfb164..0232002 100644
--- a/wp8/template/cordova/lib/list-emulator-images.bat
+++ b/wp8/template/cordova/lib/list-emulator-images.bat
@@ -20,10 +20,9 @@ goto endheader
#
:endheader
-@ECHO OFF
SET script_path="%~dp0target-list.js"
IF EXIST %script_path% (
- cscript %script_path% %* --emulators //nologo
+ node %script_path% %* --emulators
) ELSE (
ECHO.
ECHO ERROR: Could not find 'target-list.js' in cordova/lib, aborting...>&2
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/list-started-emulators.bat
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/list-started-emulators.bat b/wp8/template/cordova/lib/list-started-emulators.bat
index 04b365b..7c5c7f9 100644
--- a/wp8/template/cordova/lib/list-started-emulators.bat
+++ b/wp8/template/cordova/lib/list-started-emulators.bat
@@ -20,6 +20,5 @@ goto endheader
#
:endheader
-@ECHO OFF
ECHO Sorry, list-started-emulators is not availible yet for Windows Phone. 1>&2
EXIT /B 1
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/log.js
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/log.js b/wp8/template/cordova/lib/log.js
deleted file mode 100644
index 0b4ea7d..0000000
--- a/wp8/template/cordova/lib/log.js
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- 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.
-*/
-
-
-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\\log.js').join('');
-
-
-// help function
-function Usage() {
- Log("");
- Log("Usage: log");
- Log("examples:");
- Log(" log");
- Log(" - logs output from running application *NOT IMPLIMENTED*");
- Log("");
-}
-
-// logs to stdout or stderr
-function Log(msg, error) {
- if (error) {
- WScript.StdErr.WriteLine(msg);
- }
- else {
- WScript.StdOut.WriteLine(msg);
- }
-}
-
-// log output from running projects *NOT IMPLEMENTED*
-function log_output(path) {
- Log("ERROR: Logging is not supported on Windows Phone", true);
- WScript.Quit(1);
-}
-
-
-if (args.Count() > 0) {
- // support help flags
- if (args(0) == "--help" || args(0) == "/?" ||
- args(0) == "help" || args(0) == "-help" || args(0) == "/help") {
- Usage();
- WScript.Quit(2);
- }
- else {
- Log("Error: \"" + args(0) + "\" is not recognized as a log option.", true);
- Usage();
- WScript.Quit(2);
- }
-}
-else {
- if (fso.FolderExists(ROOT)) {
- log_output(ROOT);
- }
- else {
- Log("Error: Project directory not found,", true);
- Usage();
- WScript.Quit(2);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/package.js
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/package.js b/wp8/template/cordova/lib/package.js
new file mode 100644
index 0000000..e7eeb89
--- /dev/null
+++ b/wp8/template/cordova/lib/package.js
@@ -0,0 +1,63 @@
+/*
+ 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.
+*/
+
+var Q = require('q'),
+ fs = require('fs'),
+ path = require('path'),
+ shell = require('shelljs'),
+ utils = require('./utils');
+
+function Package (packagepath) {
+ this.packagePath = packagepath;
+}
+
+Package.prototype.deployTo = function (deployTarget) {
+ var pkg = this;
+ return utils.getXapDeploy()
+ .then(function (xapDeploy) {
+ var getTarget = deployTarget == "device" ? Q("de") :
+ deployTarget == "emulator" ? Q("xd") : module.exports.findDevice(deployTarget);
+
+ return getTarget.then(function (target) {
+ return utils.spawn(xapDeploy, ['/installlaunch', pkg.packagePath, '/targetdevice:' + target]);
+ });
+ });
+};
+
+// returns full path to package with chip architecture, build and project types specified
+module.exports.getPackage = function (buildtype, buildarch) {
+ var projectPath = path.resolve(path.join(__dirname, '..', '..'));
+ var buildFolder = buildarch.toLowerCase() == 'anycpu' ?
+ path.join(projectPath, 'Bin', buildtype) :
+ path.join(projectPath, 'Bin', buildarch, buildtype);
+
+ // reject promise if buildFolder folder doesn't exists
+ if (!fs.existsSync(buildFolder)) {
+ return Q.reject('Directory with build artefacts doesn\'t exists');
+ }
+
+ // search for first .appx file in specified folder
+ var appxFiles = shell.ls(path.join(buildFolder, '*.xap'));
+ if (appxFiles && appxFiles[0]) {
+ // resolve with full path to file if found
+ return Q.resolve(new Package(appxFiles[0]));
+ }
+ // else reject with error
+ return Q.reject('Can\'t find package with ' + buildtype + ' build type and ' + buildarch + ' chip architecture');
+};
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/run.js
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/run.js b/wp8/template/cordova/lib/run.js
new file mode 100644
index 0000000..c179ced
--- /dev/null
+++ b/wp8/template/cordova/lib/run.js
@@ -0,0 +1,88 @@
+/*
+ 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.
+*/
+
+var Q = require('q'),
+ nopt = require('nopt'),
+ path = require('path'),
+ build = require('./build'),
+ utils = require('./utils'),
+ packages = require('./package');
+
+var ROOT = path.join(__dirname, '..', '..');
+
+module.exports.run = function (argv) {
+ if (!utils.isCordovaProject(ROOT)){
+ return Q.reject("Could not find project at " + ROOT);
+ }
+
+ // parse args
+ var args = nopt({"debug": Boolean, "release": Boolean, "nobuild": Boolean,
+ "device": Boolean, "emulator": Boolean, "target": String, "archs": String},
+ {"r" : "--release"}, argv);
+
+ // Validate args
+ if (args.debug && args.release) {
+ return Q.reject('Only one of "debug"/"release" options should be specified');
+ }
+ if ((args.device && args.emulator) || ((args.device || args.emulator) && args.target)) {
+ return Q.reject('Only one of "device"/"emulator"/"target" options should be specified');
+ }
+
+ // Get build/deploy options
+ var buildType = args.release ? "release" : "debug",
+ buildArchs = args.archs ? args.archs.split(' ') : ["anycpu"],
+ deployTarget = args.target ? args.target : args.device ? "device" : "emulator";
+
+ // if --nobuild isn't specified then build app first
+ var buildPackages = args.nobuild ? Q() : build.run(argv);
+
+ return buildPackages
+ .then(function () {
+ return packages.getPackage(buildType, buildArchs[0]);
+ })
+ .then(function(builtPackage) {
+ console.log('\nDeploying package to ' + deployTarget);
+ return builtPackage.deployTo(deployTarget);
+ });
+};
+
+module.exports.help = function () {
+ console.log("");
+ console.log("Usage:");
+ console.log(" run [ --device || --emulator || --target=<id> ] ");
+ console.log(" [ --debug || --release || --nobuild ]");
+ console.log(" [--archs=\"<list of architectures...>\"]");
+ console.log(" --device : Deploys and runs the project on the connected device.");
+ console.log(" --emulator : [DEFAULT] Deploys and runs the project on an emulator.");
+ console.log(" --target=<id> : Deploys and runs the project on the specified target.");
+ console.log(" --debug : [DEFAULT] Builds project in debug mode.");
+ console.log(" --release : Builds project in release mode.");
+ console.log(" --nobuild : Ueses pre-built xap, or errors if project is not built.");
+ console.log(" --archs : Builds project binaries for specific chip architectures.");
+ console.log(" Deploys and runs package with first architecture specified.");
+ console.log(" arm` and `x86` are supported for wp8");
+ console.log("Examples:");
+ console.log(" run");
+ console.log(" run --emulator");
+ console.log(" run --device");
+ console.log(" run --target=7988B8C3-3ADE-488d-BA3E-D052AC9DC710");
+ console.log(" run --device --release");
+ console.log(" run --emulator --debug");
+ console.log("");
+};
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/start-emulator.bat
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/start-emulator.bat b/wp8/template/cordova/lib/start-emulator.bat
index db7b055..ca7c18e 100644
--- a/wp8/template/cordova/lib/start-emulator.bat
+++ b/wp8/template/cordova/lib/start-emulator.bat
@@ -20,6 +20,5 @@ goto endheader
#
:endheader
-@ECHO OFF
ECHO Sorry, start-emulator is not availible yet for Windows Phone. 1>&2
EXIT /B 1
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/target-list.js
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/target-list.js b/wp8/template/cordova/lib/target-list.js
index c899a27..9d85510 100644
--- a/wp8/template/cordova/lib/target-list.js
+++ b/wp8/template/cordova/lib/target-list.js
@@ -17,218 +17,33 @@
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\\target-list.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';
+var devices = require('./device'),
+ args = process.argv.slice(2);
// help/usage function
-function Usage() {
- Log("");
- Log("Usage: cscript target-list.js [ --emulators | --devices | --started_emulators | --all ]");
- Log(" --emulators : List the possible target emulators availible.");
- Log(" --devices : List the possible target devices availible. *NOT IMPLEMENTED YET*");
- Log(" --started_emulators : List any started emulators availible. *NOT IMPLEMENTED YET*");
- Log(" --all : List all devices returned by CordovaDeploy.exe -devices ");
- Log("examples:");
- Log(" cscript target-list.js --emulators");
- Log(" cscript target-list.js --devices");
- Log(" cscript target-list.js --started_emulators");
- Log(" cscript target-list.js --all");
- Log("");
-}
-
-// logs messaged to stdout and stderr
-function Log(msg, error) {
- if (error) {
- WScript.StdErr.WriteLine(msg);
- }
- else {
- WScript.StdOut.WriteLine(msg);
- }
-}
-
-// executes a commmand in the shell
-function exec(command) {
- var oShell=wscript_shell.Exec(command);
- while (oShell.Status == 0) {
- //Wait a little bit so we're not super looping
- WScript.sleep(100);
- //Print output? Naa.....
- if (!oShell.StdOut.AtEndOfStream) {
- var line = oShell.StdOut.ReadAll();
- //Log(line);
- }
- }
- //Check to make sure our scripts did not encounter an error
- if (!oShell.StdErr.AtEndOfStream) {
- var line = oShell.StdErr.ReadAll();
- Log("ERROR: command failed in target-list.js : " + command);
- Log(line, true);
- WScript.Quit(2);
- }
-}
-
-// returns all possible targets generated by the CordovaDeploy tool
-function get_targets(path) {
- 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);
- }
- //Check to make sure our script did not encounter an error
- if (!out.StdErr.AtEndOfStream) {
- var line = out.StdErr.ReadAll();
- Log("Error calling CordovaDeploy : ", true);
- Log(line, true);
- WScript.Quit(2);
- }
- else {
- if (!out.StdOut.AtEndOfStream) {
- var line = out.StdOut.ReadAll();
- var targets = line.split('\r\n');
- //format (ID DESCRIPTION)
- for (i in targets) {
- // remove device index and separator colen
- targets[i] = targets[i].replace(/\d*\s\:\s/, '').replace(/\:\s/, '');
- }
- return targets;
- }
- else {
- Log('Error : CordovaDeploy Failed to find any devices', true);
- WScript.Quit(2);
- }
- }
-}
-
-function list_targets(path) {
- var targets = get_targets(path);
- for (i in targets) {
- Log(targets[i]);
- }
-}
-
-// lists the Device returned by CordovaDeploy (NOTE: this does not indicate that a device is connected)
-function list_devices(path) {
- var targets = get_targets(path);
- var device_found = false;
- for (i in targets) {
- if (targets[i].match(/Device/)) {
- Log(targets[i]);
- device_found = true;
- }
- }
- if (device_found) {
- Log('');
- Log('WARNING : This does not mean that a device is connected, make');
- Log(' sure your device is connected before deploying to it.');
- }
-}
-
-// lists the emulators availible to CordovaDeploy
-function list_emulator_images(path) {
- var targets = get_targets(path);
- for (i in targets) {
- if (targets[i].match(/Emulator/)) {
- Log(targets[i]);
- }
- }
-}
-
-// lists any started emulators *NOT IMPLEMENTED*
-function list_started_emulators(path) {
- Log('ERROR : list-started-emulators is not supported on Windows Phone.', true);
- WScript.Quit(1);
-}
-
-// builds the CordovaDeploy.exe if it does not already exist
-function cordovaDeploy(path) {
- if (fso.FileExists(path + CORDOVA_DEPLOY_EXE)) {
- return;
- }
-
- // 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('msbuild "' + path + CORDOVA_DEPLOY + '\\CordovaDeploy.sln"');
-
- if (fso.FileExists(path + CORDOVA_DEPLOY_EXE)) {
- return;
- }
- 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);
- }
-}
-
-
-if (args.Count() > 0) {
- // support help flags
- if (args(0) == "--help" || args(0) == "/?" ||
- args(0) == "help" || args(0) == "-help" || args(0) == "/help") {
- Usage();
- WScript.Quit(2);
- }
- else if (args.Count() > 1) {
- Log("Error: Too many arguments.", true);
- Usage();
- WScript.Quit(2);
- }
- else if (fso.FolderExists(ROOT)) {
- if (!fso.FolderExists(ROOT + '\\cordova')) {
- Log("Error: cordova tooling folder not found in project directory,", true);
- Log("could not lsit targets.", true);
- WScript.Quit(2);
- }
-
- if (args(0) == "--emulators" || args(0) == "-e") {
- list_emulator_images(ROOT);
- }
- else if (args(0) == "--devices" || args(0) == "-d") {
- list_devices(ROOT);
- }
- else if (args(0) == "--started_emulators" || args(0) == "-s") {
- list_started_emulators(ROOT);
- }
- else if (args(0) == "--all" || args(0) == "-a") {
- list_targets(ROOT);
- }
- else {
- Log("Error: \"" + args(0) + "\" is not recognized as a target-list option", true);
- Usage();
- WScript.Quit(2);
- }
- }
- else {
- Log("Error: Project directory not found,", true);
- Usage();
- WScript.Quit(2);
- }
-}
-else {
- Log("WARNING: target list not specified, showing all targets...");
- list_targets(ROOT);
-}
+function help() {
+ console.log("");
+ console.log("Usage: node target-list.js [ --emulators | --devices | --started_emulators | --all ]");
+ console.log(" --emulators : List the possible target emulators availible.");
+ console.log(" --devices : List the possible target devices availible. *NOT IMPLEMENTED YET*");
+ console.log(" --started_emulators : List any started emulators availible. *NOT IMPLEMENTED YET*");
+ console.log(" --all : List all devices returned by CordovaDeploy.exe -devices ");
+ console.log("examples:");
+ console.log(" node target-list.js --emulators");
+ console.log(" node target-list.js --devices");
+ console.log(" node target-list.js --started_emulators");
+ console.log(" node target-list.js --all");
+ console.log("");
+}
+
+// Handle help flag
+if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(args[0]) > -1) {
+ help();
+} else {
+ devices.listDevices()
+ .then(function (deviceList) {
+ deviceList.forEach(function (device) {
+ console.log(device);
+ });
+ });
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/utils.js
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/utils.js b/wp8/template/cordova/lib/utils.js
new file mode 100644
index 0000000..28fb018
--- /dev/null
+++ b/wp8/template/cordova/lib/utils.js
@@ -0,0 +1,120 @@
+/*
+ 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.
+*/
+
+var Q = require('Q'),
+ fs = require('fs'),
+ path = require('path'),
+ proc = require('child_process'),
+ msbuildTools = require('./MSBuildTools');
+
+// returns path to XapDeploy util from Windows Phone 8.1 SDK
+module.exports.getXapDeploy = function () {
+ var xapDeployUtils = path.join((process.env["ProgramFiles(x86)"] || process.env["ProgramFiles"]),
+ 'Microsoft SDKs', 'Windows Phone', 'v8.0', 'Tools', 'Xap Deployment', 'XapDeployCmd.exe');
+ // Check if XapDeployCmd is exists
+ if (!fs.existsSync(xapDeployUtils)) {
+ console.warn("WARNING: XapDeploy tool (XapDeployCmd.exe) didn't found. Assume that it's in %PATH%");
+ return Q.resolve("XapDeployCmd");
+ }
+ return Q.resolve(xapDeployUtils);
+};
+
+module.exports.getOSVersion = function () {
+ return module.exports.exec('reg query "HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion" /v CurrentVersion')
+ .then(function(output) {
+ // fetch msbuild path from 'reg' output
+ var version = /CurrentVersion\s+REG_SZ\s+(.*)/i.exec(output);
+ if (version) {
+ return Q.resolve(version[1]);
+ }
+ return Q.reject('Can\'t fetch version number from reg output');
+ }, function (err) {
+ return Q.reject('Failed to query OS version ' + err);
+ });
+};
+
+module.exports.getSDKVersion = function () {
+ var is64bitSystem = process.env["PROCESSOR_ARCHITECTURE"] != 'x86';
+ return msbuildTools.findAvailableVersion(is64bitSystem)
+ .then(function (msbuild) {
+ return module.exports.exec(module.exports.quote(path.join(msbuild.path, 'msbuild')) + ' -version')
+ .then(function (output) {
+ var version = /\.NET\sFramework\,\s[a-z]+\s(\d+\.\d+\.\d+)/gi.exec(output);
+ if (version) {
+ return Q.resolve(version[1]);
+ }
+ return Q.reject('Unable to get the .NET Framework version');
+ }, function (err) {
+ return Q.reject('Unable to get the .NET Framework version: ' + err);
+ });
+ });
+};
+
+// checks to see if a .jsproj file exists in the project root
+module.exports.isCordovaProject = function (platformpath) {
+ if (fs.existsSync(platformpath)) {
+ var files = fs.readdirSync(platformpath);
+ for (var i in files){
+ if (path.extname(files[i]) == '.csproj'){
+ return true;
+ }
+ }
+ }
+ return false;
+};
+
+// Takes a command and optional current working directory.
+// Returns a promise that either resolves with the stdout, or
+// rejects with an error message and the stderr.
+module.exports.exec = function(cmd, opt_cwd) {
+ var d = Q.defer();
+ try {
+ proc.exec(cmd, {cwd: opt_cwd, maxBuffer: 1024000}, function(err, stdout, stderr) {
+ if (err) d.reject('Error executing "' + cmd + '": ' + stderr);
+ else d.resolve(stdout);
+ });
+ } catch(e) {
+ console.error('error caught: ' + e);
+ d.reject(e);
+ }
+ return d.promise;
+};
+
+// Takes a command and optional current working directory.
+module.exports.spawn = function(cmd, args, opt_cwd) {
+ var d = Q.defer();
+ try {
+ var child = proc.spawn(cmd, args, {cwd: opt_cwd, stdio: 'inherit'});
+ child.on('exit', function(code) {
+ if (code) {
+ d.reject('Error code ' + code + ' for command: ' + cmd + ' with args: ' + args);
+ } else {
+ d.resolve();
+ }
+ });
+ } catch(e) {
+ console.error('error caught: ' + e);
+ d.reject(e);
+ }
+ return d.promise;
+};
+
+module.exports.quote = function(str) {
+ return '"' + str + '"';
+};
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/win_os_version.js
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/win_os_version.js b/wp8/template/cordova/lib/win_os_version.js
index 4137dae..c6d940f 100644
--- a/wp8/template/cordova/lib/win_os_version.js
+++ b/wp8/template/cordova/lib/win_os_version.js
@@ -17,20 +17,11 @@
under the License.
*/
-var wscript_shell = WScript.CreateObject("WScript.Shell");
+var utils = require('./utils');
-// log to stdout or stderr
-function Log(msg, error) {
- if (error) {
- WScript.StdErr.WriteLine(msg);
- }
- else {
- WScript.StdOut.WriteLine(msg);
- }
-}
-
-function getWindowsVersion() {
- var version = wscript_shell.RegRead("HKLM\\Software\\Microsoft\\Windows NT\\CurrentVersion\\CurrentVersion");
- Log(version);
-}
-getWindowsVersion();
+utils.getOSVersion().then(function (version) {
+ console.log(version);
+}, function (err) {
+ console.error(err);
+ process.exit(2);
+});
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/lib/win_sdk_version.js
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/lib/win_sdk_version.js b/wp8/template/cordova/lib/win_sdk_version.js
index 773e140..e624ac8 100644
--- a/wp8/template/cordova/lib/win_sdk_version.js
+++ b/wp8/template/cordova/lib/win_sdk_version.js
@@ -17,63 +17,11 @@
under the License.
*/
-var wscript_shell = WScript.CreateObject("WScript.Shell");
-
-// log to stdout or stderr
-function Log(msg, error) {
- if (error) {
- WScript.StdErr.WriteLine(msg);
- }
- else {
- WScript.StdOut.WriteLine(msg);
- }
-}
-
-// gets the output from a command, failing with the given error message
-function check_command(cmd, fail_msg) {
- try {
- var out = wscript_shell.Exec(cmd);
- } catch(exception) {
- Log(fail_msg, true);
- WScript.Quit(1);
- }
- while (out.Status == 0) {
- WScript.Sleep(100);
- }
-
- //Check that command executed
- if (!out.StdErr.AtEndOfStream) {
- var line = out.StdErr.ReadLine();
- Log(fail_msg, true);
- Log('Output : ' + line, true);
- WScript.Quit(1);
- }
-
- if (!out.StdOut.AtEndOfStream) {
- var line = out.StdOut.ReadAll();
- return line;
- }
- else {
- Log('Unable to get output from command "' + cmd + '"', true);
- WScript.Quit(1);
- }
-}
-
-// Returns the sdk version of the .Net Framework
-function getSdkVersion() {
- var cmd = 'msbuild -version'
- var fail_msg = 'The command `msbuild` failed. Make sure you have the latest Windows Phone SDKs installed, AND have the latest .NET framework added to your path (i.e C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319).'
- var output = check_command(cmd, fail_msg);
- var msversion = '';
- var msversion_reg = /\.NET\sFramework\,\s[a-z]+\s\d+\.\d+\.\d+/gi;
- if(msversion_reg.test(output)){
- msversion = output.match(msversion_reg)[0].match(/\d+\.\d+\.\d+/g);
- Log(msversion);
- }else {
- Log('Unable to get the .NET Framework version.',true);
- Log('Make sure the "msbuild" command is in your path', true);
- WScript.Quit(1);
- }
-}
-
-getSdkVersion();
\ No newline at end of file
+var utils = require('./utils');
+
+utils.getSDKVersion().then(function (version) {
+ console.log(version);
+}, function (err) {
+ console.error(err);
+ process.exit(2);
+});
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/node_modules/.bin/nopt
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/node_modules/.bin/nopt b/wp8/template/cordova/node_modules/.bin/nopt
new file mode 100644
index 0000000..25995f3
--- /dev/null
+++ b/wp8/template/cordova/node_modules/.bin/nopt
@@ -0,0 +1,15 @@
+#!/bin/sh
+basedir=`dirname "$0"`
+
+case `uname` in
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
+esac
+
+if [ -x "$basedir/node" ]; then
+ "$basedir/node" "$basedir/../nopt/bin/nopt.js" "$@"
+ ret=$?
+else
+ node "$basedir/../nopt/bin/nopt.js" "$@"
+ ret=$?
+fi
+exit $ret
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/node_modules/.bin/nopt.cmd
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/node_modules/.bin/nopt.cmd b/wp8/template/cordova/node_modules/.bin/nopt.cmd
new file mode 100644
index 0000000..c8e8216
--- /dev/null
+++ b/wp8/template/cordova/node_modules/.bin/nopt.cmd
@@ -0,0 +1,5 @@
+@IF EXIST "%~dp0\node.exe" (
+ "%~dp0\node.exe" "%~dp0\..\nopt\bin\nopt.js" %*
+) ELSE (
+ node "%~dp0\..\nopt\bin\nopt.js" %*
+)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/node_modules/.bin/shjs
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/node_modules/.bin/shjs b/wp8/template/cordova/node_modules/.bin/shjs
new file mode 100644
index 0000000..9908675
--- /dev/null
+++ b/wp8/template/cordova/node_modules/.bin/shjs
@@ -0,0 +1,15 @@
+#!/bin/sh
+basedir=`dirname "$0"`
+
+case `uname` in
+ *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
+esac
+
+if [ -x "$basedir/node" ]; then
+ "$basedir/node" "$basedir/../shelljs/bin/shjs" "$@"
+ ret=$?
+else
+ node "$basedir/../shelljs/bin/shjs" "$@"
+ ret=$?
+fi
+exit $ret
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/node_modules/.bin/shjs.cmd
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/node_modules/.bin/shjs.cmd b/wp8/template/cordova/node_modules/.bin/shjs.cmd
new file mode 100644
index 0000000..9ce460a
--- /dev/null
+++ b/wp8/template/cordova/node_modules/.bin/shjs.cmd
@@ -0,0 +1,5 @@
+@IF EXIST "%~dp0\node.exe" (
+ "%~dp0\node.exe" "%~dp0\..\shelljs\bin\shjs" %*
+) ELSE (
+ node "%~dp0\..\shelljs\bin\shjs" %*
+)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cordova-wp8/blob/c2c2e564/wp8/template/cordova/node_modules/nopt/.npmignore
----------------------------------------------------------------------
diff --git a/wp8/template/cordova/node_modules/nopt/.npmignore b/wp8/template/cordova/node_modules/nopt/.npmignore
new file mode 100644
index 0000000..3c3629e
--- /dev/null
+++ b/wp8/template/cordova/node_modules/nopt/.npmignore
@@ -0,0 +1 @@
+node_modules