forked from appcelerator-archive/windowslib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·145 lines (131 loc) · 5.25 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* Main namespace for the windowslib.
*
* @copyright
* Copyright (c) 2014-2016 by Appcelerator, Inc. All Rights Reserved.
*
* @license
* Licensed under the terms of the Apache Public License.
* Please see the LICENSE included with this distribution for details.
*/
const
appc = require('node-appc'),
async = require('async'),
EventEmitter = require('events').EventEmitter,
magik = require('./lib/utilities').magik,
mix = require('./lib/utilities').mix,
__ = appc.i18n(__dirname).__,
packageJson = require('./package.json'),
assemblies = exports.assemblies = require('./lib/assemblies'),
device = exports.device = require('./lib/device'),
emulator = exports.emulator = require('./lib/emulator'),
env = exports.env = require('./lib/env'),
windowsphone = exports.windowsphone = require('./lib/windowsphone'),
wptool = exports.wptool = require('./lib/wptool'),
winstore = exports.winstore = require('./lib/winstore'),
visualstudio = exports.visualstudio = require('./lib/visualstudio');
var cache;
exports.certs = require('./lib/certs');
exports.detect = detect;
exports.install = install;
exports.LogRelay = require('./lib/logrelay');
exports.process = require('./lib/process');
exports.version = packageJson.version;
/**
* Detects the entire Windows phone environment information.
*
* @param {Object} [options] - An object containing various settings.
* @param {Boolean} [options.bypassCache=false] - When true, re-detects the all Windows phone information.
* @param {String} [options.assemblyPath=%WINDIR%\Microsoft.NET\assembly\GAC_MSIL] - Path to .NET global assembly cache.
* @param {String} [options.powershell] - Path to the <code>powershell</code> executable.
* @param {String} [options.preferredWindowsPhoneSDK] - The preferred version of the Windows Phone SDK to use by default. Example "8.0".
* @param {String} [options.preferredVisualStudio] - The preferred version of Visual Studio to use by default. Example: "13".
* @param {Object} [options.requiredAssemblies] - An object containing assemblies to check for in addition to the required windowslib dependencies.
* @param {String} [options.supportedMSBuildVersions] - A string with a version number or range to check if a MSBuild version is supported.
* @param {String} [options.supportedVisualStudioVersions] - A string with a version number or range to check if a Visual Studio install is supported.
* @param {Function} [callback(err, info)] - A function to call when all detection tasks have completed.
*
* @returns {EventEmitter}
*/
function detect(options, callback) {
return magik(options, callback, function (emitter, options, callback) {
if (cache && !options.bypassCache) {
emitter.emit('detected', cache);
return callback(null, cache);
}
var results = {
detectVersion: '3.0',
issues: []
};
async.each([env, visualstudio, windowsphone, assemblies, winstore, wptool], function (lib, next) {
lib.detect(options, function (err, result) {
err || mix(result, results);
next(err);
});
}, function (err) {
if (err) {
emitter.emit('error', err);
callback(err);
} else {
cache = results;
emitter.emit('detected', results);
callback(null, results);
}
});
});
}
/**
* Installs the specified app to an Windows Phone emulator. If the emulator is not running, it will launch it.
*
* @param {String} udid - The UDID of the emulator to install the app to or null if you want windowslib to pick one.
* @param {String} appPath - The path to the Windows Phone app to install.
* @param {Object} [options] - An object containing various settings.
* @param {Boolean} [options.bypassCache=false] - When true, re-detects the environment configuration.
* @param {Number} [options.timeout] - Number of milliseconds to wait before timing out.
* @param {Function} [callback(err)] - A function to call when the simulator has launched.
*
* @emits module:windowslib#error
* @emits module:windowslib#installed
* @emits module:windowslib#launched
*
* @returns {EventEmitter}
*/
function install(udid, appPath, options, callback) {
return magik(options, callback, function (emitter, options, callback) {
detect(options, function (err, results) {
if (err) {
emitter.emit('error', err);
return callback(err);
}
var type;
// determine if this is a device or emulator udid
if (results.devices.some(function (d) { return d.udid === udid; })) {
// it's a device!
type = device;
} else {
Object.keys(results.emulators).some(function (wpsdk) {
return results.emulators[wpsdk].some(function (e) {
if (e.udid === udid) {
type = emulator;
return true;
}
});
});
}
if (!type) {
// oh no
var ex = new Error(__('Invalid device id: %s', udid));
emitter.emit('error', ex);
return callback(ex);
}
var installEmitter = type.install(udid, appPath, options, callback),
originalEmitter = installEmitter.emit;
// make sure we have at least one 'error' handler to keep longjohn from complaining
installEmitter.on('error', function () {});
installEmitter.emit = function () {
originalEmitter.apply(installEmitter, arguments);
emitter.emit.apply(emitter, arguments);
};
});
});
}