Repository: cordova-windows
Updated Branches:
  refs/heads/master e0f3560ba -> 58047a3da


http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/58047a3d/template/cordova/lib/run.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/run.js b/template/cordova/lib/run.js
index 80ebf1e..0a770d9 100644
--- a/template/cordova/lib/run.js
+++ b/template/cordova/lib/run.js
@@ -17,74 +17,74 @@
        under the License.
 */
 
-var Q = require('q'),
-    nopt  = require('nopt'),
-    path  = require('path'),
-    build = require('./build'),
-    utils = require('./utils'),
-    packages = require('./package'),
-    execSync = require('child_process').execSync;
-
-var ROOT = path.join(__dirname, '..', '..');
-
-module.exports.run = function (argv) {
-    if (!utils.isCordovaProject(ROOT)){
-        return Q.reject('Could not find project at ' + ROOT);
+var Q = require('q');
+var nopt  = require('nopt');
+var build = require('./build');
+var utils = require('./utils');
+var packages = require('./package');
+var execSync = require('child_process').execSync;
+var CordovaError = require('cordova-common').CordovaError;
+var events = require('cordova-common').events;
+
+module.exports.run = function (options) {
+    if (!utils.isCordovaProject(this.root)){
+        return Q.reject(new CordovaError('Could not find project at ' + 
this.root));
     }
 
     // Check if ran from admin prompt and fail quickly if CLI has 
administrative permissions
     // http://stackoverflow.com/a/11995662/64949
     if (ranWithElevatedPermissions())
-        return Q.reject('Can not run this platform with administrative 
permissions. Please run from a non-admin prompt.');
+        return Q.reject(new CordovaError('Can not run this platform with 
administrative ' +
+            'permissions. Please run from a non-admin prompt.'));
 
     // parse arg
-    var args  = nopt({'debug': Boolean, 'release': Boolean, 'nobuild': Boolean,
-        'device': Boolean, 'emulator': Boolean, 'target': String, 'archs': 
String,
-        'phone': Boolean, 'win': Boolean, 'appx': String, 'win10tools': 
Boolean }, {'r' : '--release'}, argv);
+    var args  = nopt({
+        'archs': String,
+        'phone': Boolean,
+        'win': Boolean,
+        'appx': String,
+        'win10tools': Boolean
+    }, {'r' : '--release'}, options.argv, 0);
 
     // Validate args
-    if (args.debug && args.release) {
-        return Q.reject('Only one of "debug"/"release" options should be 
specified');
+    if (options.debug && options.release) {
+        return Q.reject(new CordovaError('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');
+    if ((options.device && options.emulator) || ((options.device || 
options.emulator) && options.target)) {
+        return Q.reject(new CordovaError('Only one of 
"device"/"emulator"/"target" options should be specified'));
     }
     if (args.phone && args.win) {
-        return Q.reject('Only one of "phone"/"win" options should be 
specified');
+        return Q.reject(new CordovaError('Only one of "phone"/"win" options 
should be specified'));
     }
 
     // Get build/deploy options
-    var buildType    = args.release ? 'release' : 'debug',
+    var buildType    = options.release ? 'release' : 'debug',
         buildArchs   = args.archs ? args.archs.split(' ') : ['anycpu'],
-        deployTarget = args.target ? args.target : (args.emulator ? 'emulator' 
: 'device');
+        deployTarget = options.target ? options.target : (options.emulator ? 
'emulator' : 'device');
 
      var buildTargets = build.getBuildTargets(args.win, args.phone, args.appx);
 
-     if (!buildTargets || buildTargets.lenght <= 0) {
-         return Q.reject('Unable to determine deploy target.');
+     if (!buildTargets || buildTargets.length <= 0) {
+         return Q.reject(new CordovaError('Unable to determine deploy 
target.'));
      }
 
      // we deploy the first build target so we use buildTargets[0] to determine
      // what project type we should deploy
      var projectType = projFileToType(buildTargets[0]);
 
-    if (projectType === 'windows80' && argv.indexOf('--bundle') > -1) {
-        // Don't enable bundling for Windows 8.
-        // Assumes the commander only enters the --bundle param once
-        argv.splice(argv.indexOf('--bundle'), 1);
-    }
-
     // if --nobuild isn't specified then build app first
-    var buildPackages = args.nobuild ? packages.getPackage(projectType, 
buildType, buildArchs) : build.run(argv);
+    var buildPackages = options.nobuild ? packages.getPackage(projectType, 
buildType, buildArchs) : build.run.call(this, options);
 
     // buildPackages also deploys bundles
-    return buildPackages.then(function(pkg) {
-        console.log('\nDeploying ' + pkg.type + ' package to ' + deployTarget 
+ ':\n' + pkg.appx);
+    return buildPackages
+    .then(function(pkg) {
+        events.emit('log', 'Deploying ' + pkg.type + ' package to ' + 
deployTarget + ':\n' + pkg.appx);
         switch (pkg.type) {
             case 'phone':
-                return packages.deployToPhone(pkg, deployTarget, 
args.win10tools).catch(function(e) {
-                    if (args.target || args.emulator || args.device) {
-                        throw e; // Explicit target, carry on
+                return packages.deployToPhone(pkg, deployTarget, 
args.win10tools)
+                .catch(function(e) {
+                    if (options.target || options.emulator || options.device) {
+                        return Q.reject(e); // Explicit target, carry on
                     }
                     // 'device' was inferred initially, because no target was 
specified
                     return packages.deployToPhone(pkg, 'emulator', 
args.win10tools);
@@ -92,14 +92,13 @@ module.exports.run = function (argv) {
             case 'windows10':
                 if (args.phone) {
                     // Win10 emulator launch is not currently supported, 
always force device
-                    if (args.emulator || args.target === 'emulator') {
-                        console.warn('Windows 10 Phone emulator is currently 
not supported.');
-                        console.warn('If you want to deploy to emulator, 
please use Visual Studio instead.');
-                        console.warn('Attempting to deploy to device...');
+                    if (options.emulator || options.target === 'emulator') {
+                        events.emit('warn', 'Windows 10 Phone emulator is 
currently not supported. ' +
+                            'If you want to deploy to emulator, please use 
Visual Studio instead. ' +
+                            'Attempting to deploy to device...');
                     }
                     return packages.deployToPhone(pkg, deployTarget, true);
-                }
-                else {
+                } else {
                     return packages.deployToDesktop(pkg, deployTarget, 
projectType);
                 }
                 break;
@@ -109,46 +108,10 @@ module.exports.run = function (argv) {
     });
 };
 
-module.exports.help = function () {
-    console.log('\nUsage: run [ --device | --emulator | --target=<id> ] [ 
--debug | --release | --nobuild ]');
-    console.log('           [ --x86 | --x64 | --arm | --archs="list" ] 
[--bundle] [--phone | --win]');
-    console.log('    --device      : Deploys and runs the project on the 
connected device.');
-    console.log('    --emulator    : Deploys and runs the project on an 
emulator.');
-    console.log('    --target=<id> : Deploys and runs the project on the 
specified target.');
-    console.log('    --debug       : Builds project in debug mode.');
-    console.log('    --release     : Builds project in release mode.');
-    console.log('    --nobuild     : Uses pre-built package, or errors if 
project is not built.');
-    console.log('    --archs       : Specific chip architectures (`anycpu`, 
`arm`, `x86`, `x64`).');
-    console.log('                        Separate multiple choices with a 
space and, if choosing');
-    console.log('                        multiple choices, enclose in quotes 
(").');
-    console.log('    --bundle      : Generates an .appxbundle. Not valid if 
anycpu AND chip-specific');
-    console.log('                    architectures are used.');
-    console.log('    --phone, --win');
-    console.log('                  : Specifies project type to deploy');
-    console.log('    --appx=<8.1-win|8.1-phone|uap>');
-    console.log('                  : Overrides windows-target-version to build 
Windows 8.1, ');
-    console.log('                              Windows Phone 8.1, or Windows 
10.');
-    console.log('    --win10tools  : Uses Windows 10 deployment tools (used 
for a Windows 8.1 app when');
-    console.log('                         being deployed to a Windows 10 
device)');
-    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('    run --archs="x64 x86 arm" --no-bundle');
-    console.log('    run --device --appx=phone-8.1');
-    console.log('    run --device --archs="x64 x86 arm"');
-    console.log('');
-
-    process.exit(0);
-};
-
 // Retrieves project type for the project file specified.
 // @param   {String}  projFile Project file, for example 
'CordovaApp.Windows10.jsproj'
 // @returns {String}  Proejct type, for example 'windows10'
-function projFileToType(projFile) 
+function projFileToType(projFile)
 {
     return projFile.replace(/CordovaApp|jsproj|\./gi, '').toLowerCase();
 }

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/58047a3d/template/cordova/lib/spawn.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/spawn.js b/template/cordova/lib/spawn.js
deleted file mode 100644
index 0ccb0f5..0000000
--- a/template/cordova/lib/spawn.js
+++ /dev/null
@@ -1,40 +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 Q    = require('q'),
-    proc = require('child_process');
-
-// Takes a command and optional current working directory.
-module.exports = 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;
-};

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/58047a3d/template/cordova/lib/target-list.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/target-list.js 
b/template/cordova/lib/target-list.js
index 79ca647..44880b1 100644
--- a/template/cordova/lib/target-list.js
+++ b/template/cordova/lib/target-list.js
@@ -58,7 +58,7 @@ if (['--help', '/?', '-h', 'help', '-help', 
'/help'].indexOf(args[0]) > -1) {
     }
 
     if (onlyDevices && onlyEmulators) {
-        console.warn('Error: Cannot specify both --emulators and --devices');
+        console.error('Cannot specify both --emulators and --devices');
         help();
         return;
     }
@@ -76,7 +76,7 @@ if (['--help', '/?', '-h', 'help', '-help', 
'/help'].indexOf(args[0]) > -1) {
         });
 
         if (deviceList.length === 0) {
-            console.log('No devices found matching the specified criteria.');
+            console.error('No devices found matching the specified criteria.');
         }
     });
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/58047a3d/template/cordova/lib/utils.js
----------------------------------------------------------------------
diff --git a/template/cordova/lib/utils.js b/template/cordova/lib/utils.js
index 3918dff..c0786a5 100644
--- a/template/cordova/lib/utils.js
+++ b/template/cordova/lib/utils.js
@@ -19,37 +19,11 @@
 
 /* jshint sub:true */
 
-var Q     = require('q'),
-    fs    = require('fs'),
-    path  = require('path'),
-    exec  = require('./exec'),
-    spawn = require('./spawn'),
-    deploy = require('./deployment');
-
-// returns full path to msbuild tools required to build the project and tools 
version
-module.exports.getMSBuildTools = function () {
-    var versions = ['12.0', '4.0'];
-    // create chain of promises, which returns specific msbuild version object
-    // or null, if specific msbuild path not found in registry
-    return Q.all(versions.map(function (version) {
-        return exec(
-            'reg query HKLM\\SOFTWARE\\Microsoft\\MSBuild\\ToolsVersions\\' + 
version + ' /v MSBuildToolsPath'
-        ).then(function(output) {
-            // fetch msbuild path from 'reg' output
-            var msbPath = /MSBuildToolsPath\s+REG_SZ\s+(.*)/i.exec(output);
-            if (msbPath) {
-                return {version: version, path: msbPath[1]};
-            }
-            return null;
-        });
-    })).then(function (versions) {
-        // select first msbuild version available, and resolve promise with it
-        return versions[0] || versions[1] ?
-            Q.resolve(versions[0] || versions[1]) :
-            // Reject promise if no msbuild versions found
-            Q.reject('MSBuild tools not found');
-    });
-};
+var Q     = require('q');
+var fs    = require('fs');
+var path  = require('path');
+var spawn = require('cordova-common').superspawn.spawn;
+var DeploymentTool = require('./deployment');
 
 // unblocks and returns path to WindowsStoreAppUtils.ps1
 // which provides helper functions to install/unistall/start Windows Store app
@@ -58,17 +32,14 @@ module.exports.getAppStoreUtils = function () {
     if (!fs.existsSync (appStoreUtils)) {
         return Q.reject('Can\'t unblock AppStoreUtils script');
     }
-    return spawn('powershell', ['Unblock-File', 
module.exports.quote(appStoreUtils)]).then(function () {
-        return Q.resolve(appStoreUtils);
-    }).fail(function (err) {
-        return Q.reject(err);
-    });
+    return spawn('powershell', ['Unblock-File', 
module.exports.quote(appStoreUtils)], {stdio: 'ignore'})
+    .thenResolve(appStoreUtils);
 };
 
 // returns path to AppDeploy util from Windows Phone 8.1 SDK
 module.exports.getAppDeployUtils = function (targetWin10) {
     var version = targetWin10 ? '10.0' : '8.1';
-    var tool = deploy.getDeploymentTool(version);
+    var tool = DeploymentTool.getDeploymentTool(version);
 
     if (!tool.isAvailable()) {
         return Q.reject('App deployment utilities: "' + tool.path + '", not 
found.  Ensure the Windows SDK is installed.');

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/58047a3d/template/cordova/log
----------------------------------------------------------------------
diff --git a/template/cordova/log b/template/cordova/log
index 63876a4..8ccfd5b 100644
--- a/template/cordova/log
+++ b/template/cordova/log
@@ -31,7 +31,7 @@ Q().then(function() {
     }
     log.run(argsToPass);
 }, function(err) {
-    console.error('ERROR: ' + err);
+    console.error(err);
     process.exit(2);
 });
 

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/58047a3d/template/cordova/run
----------------------------------------------------------------------
diff --git a/template/cordova/run b/template/cordova/run
index 48c77d5..27f7805 100644
--- a/template/cordova/run
+++ b/template/cordova/run
@@ -19,16 +19,62 @@
        under the License.
 */
 
-var args = process.argv,
-    run   = require('./lib/run');
+var args = process.argv;
+var Api = require('./Api');
+var nopt = require('nopt');
+var path = require('path');
 
 // Handle help flag
 if (['--help', '/?', '-h', 'help', '-help', '/help'].indexOf(args[2]) > -1) {
-    run.help();
-} else {
-    run.run(args).done(null, function (err) {
-        var errorMessage = (err && err.stack) ? err.stack : err;
-        console.error('ERROR: ' + errorMessage);
-        process.exit(2);
-    });
-}
\ No newline at end of file
+    console.log('\nUsage: run [ --device | --emulator | --target=<id> ] [ 
--debug | --release | --nobuild ]');
+    console.log('           [ --x86 | --x64 | --arm | --archs="list" ] 
[--bundle] [--phone | --win]');
+    console.log('    --device      : Deploys and runs the project on the 
connected device.');
+    console.log('    --emulator    : Deploys and runs the project on an 
emulator.');
+    console.log('    --target=<id> : Deploys and runs the project on the 
specified target.');
+    console.log('    --debug       : Builds project in debug mode.');
+    console.log('    --release     : Builds project in release mode.');
+    console.log('    --nobuild     : Uses pre-built package, or errors if 
project is not built.');
+    console.log('    --archs       : Specific chip architectures (`anycpu`, 
`arm`, `x86`, `x64`).');
+    console.log('                        Separate multiple choices with a 
space and, if choosing');
+    console.log('                        multiple choices, enclose in quotes 
(").');
+    console.log('    --bundle      : Generates an .appxbundle. Not valid if 
anycpu AND chip-specific');
+    console.log('                    architectures are used.');
+    console.log('    --phone, --win');
+    console.log('                  : Specifies project type to deploy');
+    console.log('    --appx=<8.1-win|8.1-phone|uap>');
+    console.log('                  : Overrides windows-target-version to build 
Windows 8.1, ');
+    console.log('                              Windows Phone 8.1, or Windows 
10.');
+    console.log('    --win10tools  : Uses Windows 10 deployment tools (used 
for a Windows 8.1 app when');
+    console.log('                         being deployed to a Windows 10 
device)');
+    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('    run --archs="x64 x86 arm" --no-bundle');
+    console.log('    run --device --appx=phone-8.1');
+    console.log('    run --device --archs="x64 x86 arm"');
+    console.log('');
+
+    process.exit(0);
+}
+
+// Do some basic argument parsing
+var runOpts = nopt({
+    'silent' : Boolean,
+    'verbose' : Boolean,
+    'debug' : Boolean,
+    'release' : Boolean,
+    'nobuild': Boolean,
+    'device': Boolean,
+    'emulator': Boolean,
+    'target': String,
+    'buildConfig' : path
+}, { d : '--verbose', r: '--release' });
+
+// Make buildOptions compatible with PlatformApi build method spec
+runOpts.argv = runOpts.argv.original;
+
+new Api().run(runOpts).done();

http://git-wip-us.apache.org/repos/asf/cordova-windows/blob/58047a3d/template/cordova/version
----------------------------------------------------------------------
diff --git a/template/cordova/version b/template/cordova/version
index fd228ac..83b0253 100644
--- a/template/cordova/version
+++ b/template/cordova/version
@@ -22,4 +22,8 @@
 // Coho updates this line:
 var VERSION = "4.3.0-dev";
 
-console.log(VERSION);
+module.exports.version = VERSION;
+
+if (!module.parent) {
+    console.log(VERSION);
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to