1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const
|
15 | appc = require('node-appc'),
|
16 | async = require('async'),
|
17 | fs = require('fs'),
|
18 | magik = require('./utilities').magik,
|
19 | os = require('os'),
|
20 | path = require('path'),
|
21 | __ = appc.i18n(__dirname).__;
|
22 |
|
23 | var cache;
|
24 |
|
25 | exports.detect = detect;
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | function detect(options, callback) {
|
41 | return magik(options, callback, function (emitter, options, callback) {
|
42 | if (cache && !options.bypassCache) {
|
43 | emitter.emit('detected', cache);
|
44 | return callback(null, cache);
|
45 | }
|
46 |
|
47 | var results = cache = {
|
48 | os: {
|
49 | name: 'Windows',
|
50 | version: os.release()
|
51 | },
|
52 | powershell: {
|
53 | enabled: null
|
54 | },
|
55 | issues: []
|
56 | };
|
57 |
|
58 | if (appc.version.lt(os.release(), '6.2.0')) {
|
59 | results.issues.push({
|
60 | id: 'WINDOWS_STORE_APPS_NOT_SUPPORTED',
|
61 | type: 'warning',
|
62 | message: __('Windows Store apps are not supported on this version of Windows.') + '\n' +
|
63 | __('You must use Windows 8 or newer to create Windows Store apps.')
|
64 | });
|
65 | emitter.emit('detected', results);
|
66 | return callback(null, results);
|
67 | }
|
68 |
|
69 | async.series([
|
70 | function osInfo(next) {
|
71 | appc.subprocess.run('wmic', ['os', 'get', 'Caption,Version'], function (code, out, err) {
|
72 | if (code) return next(code);
|
73 |
|
74 | var s = out.split('\n')[1].split(/ {2,}/);
|
75 | s.length > 0 && (results.os.name = s[0].trim());
|
76 | s.length > 1 && (results.os.version = s[1].trim());
|
77 |
|
78 | next();
|
79 | });
|
80 | },
|
81 |
|
82 | function powershell(next) {
|
83 | if (!results.os.version) return next();
|
84 |
|
85 | appc.subprocess.getRealName(path.resolve(__dirname, '..', 'bin', 'test_permissions.ps1'), function (err, psScript) {
|
86 | if (err) {
|
87 | return next(err);
|
88 | }
|
89 |
|
90 | appc.subprocess.run(options.powershell || 'powershell', [
|
91 | '-ExecutionPolicy', 'Bypass', '-NoLogo', '-NonInteractive', '-NoProfile', '-File', psScript
|
92 | ], function (code, out, err) {
|
93 | if (!code && /success/i.test(out.trim().split('\n').shift())) {
|
94 | results.powershell.enabled = true;
|
95 | } else {
|
96 | results.powershell.enabled = false;
|
97 | results.issues.push({
|
98 | id: 'WINDOWS_POWERSHELL_SCRIPTS_DISABLED',
|
99 | type: 'error',
|
100 | message: __('Executing PowerShell scripts is disabled.') + '\n' +
|
101 | __('In order to build Windows Hybrid apps for the Windows Store (winstore), you must change the execution policy to allow PowerShell scripts.') + '\n' +
|
102 | __('To enable PowerShell scripts, search __PowerShell__ in the __Start__ menu, right click the icon, select __Run as administrator__, then run:') + '\n' +
|
103 | ' __Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser__'
|
104 | });
|
105 | }
|
106 | next();
|
107 | });
|
108 | });
|
109 | }
|
110 | ], function (err) {
|
111 | if (err) {
|
112 | emitter.emit('error', err);
|
113 | callback(err);
|
114 | } else {
|
115 | emitter.emit('detected', results);
|
116 | callback(null, results);
|
117 | }
|
118 | });
|
119 | });
|
120 | };
|