-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
ember-cli-windows
executable file
·199 lines (168 loc) · 6.56 KB
/
ember-cli-windows
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#! /usr/bin/env node
var program = require('commander'),
spawn = require('child_process').spawn,
path = require('path'),
chalk = require('chalk'),
prompt = require('prompt'),
fs = require('fs'),
version = require('../package.json').version,
_Promise = require('zousan'),
isWin = /^win/.test(process.platform),
args = process.argv,
dir = process.cwd();
program
.version(version)
.option('-D, --defender', 'Configure Windows Defender')
.option('-S, --search', 'Configure Windows Search')
.option('-H, --headless', 'Run without prompting for confirmation')
.parse(process.argv);
// Helper functions
function runPowershell(scriptPath, name) {
return new _Promise(function (resolve) {
var child = spawn('powershell.exe', ['-NoProfile', '-NoLogo', '& {& \'' + scriptPath + '\' -path \'' + dir + '\'}']),
output = [];
child.stdout.on('data', function (data) {
output.push(data.toString());
});
child.stderr.on('data', function (data) {
console.log('Configuration Error: ', data.toString());
output.push(data.toString());
});
child.on('exit', function () {
resolve(output);
});
child.stdin.end();
});
}
function configureSearch() {
var scriptPath = path.resolve(__dirname, '../powershell/setup-search.ps1'),
name = 'Windows Search';
return runPowershell(scriptPath, name).then(function () {
console.log('Finished Search Configuration.');
});
}
function configureDefender() {
var scriptPath = path.resolve(__dirname, '../powershell/setup-defender.ps1'),
name = 'Windows Defender';
return runPowershell(scriptPath, name).then(function (output) {
if (output && output.join().indexOf('fallback required') > -1) {
console.log(chalk.red.bold('Automatic Defender configuration is only available on Windows 8 or newer.'));
console.log(chalk.red.bold('Please follow the following steps for manual configuration:'));
console.log('1) Click "Start", search for "Windows Defender" and open the application.');
console.log('2) Click on "Tools" and then "Options".');
console.log('3) Under "Excluded Files and Folders", add the following directory:');
console.log(chalk.green(dir + '/tmp'));
console.log('All done!');
} else if (output && output.join().indexOf('is it disabled?') > -1) {
console.log(chalk.bold.red('Windows Defender seems to be disabled.'));
console.log('If that is correct, further configuration is not required.');
} else {
console.log('Finished Defender Configuration.');
}
});
}
function checkExecutionPolicy() {
return new _Promise(function (resolve, reject) {
var child = spawn('powershell.exe', ['-NoProfile', '-NoLogo', 'Get-ExecutionPolicy']),
output = [], unrestricted, i;
child.stdout.on('data', function (data) {
output.push(data.toString());
});
child.stderr.on('data', function (data) {
output.push(data.toString());
});
child.on('exit', function () {
unrestricted = false;
for (i = output.length - 1; i >= 0; i = i - 1) {
if (output[i].indexOf('Unrestricted') > -1) {
unrestricted = true;
break;
}
}
if (!unrestricted) {
console.log(chalk.bold.red('Scripts cannot be executed on this system.'));
console.log('To fix, please run the command below using PowerShell as Administrator and try again:');
console.log('Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force');
reject();
} else {
resolve();
}
});
child.stdin.end();
});
}
function executeConfiguration() {
if (program.headless) {
if (program.defender || (!program.defender && !program.search)) {
console.log('Configuring Defender');
configureDefender().then(function () {
console.log('Finished Defender Configuration.');
});
}
if (program.search || (!program.defender && !program.search)) {
console.log('Configuring Search');
configureSearch().then(function () {
console.log('Finished Search Configuration.');
});
}
} else {
prompt.message = 'Confirm';
prompt.start();
console.log(chalk.red.bold('Configure Windows for Ember-Cli Performance'));
console.log('If you continue, this tool will automate the configuration of ' + getTarget());
prompt.get([{
name: 'confirm',
description: 'Do you want to proceed? (Y/N)',
pattern: /[yYnN]/,
type: 'string',
required: true
}], function (err, results) {
var confirm = results.confirm;
if (err) {
return console.error(err);
}
if (confirm === 'n' || confirm === 'N') {
return console.log('Operation aborted');
}
if (program.defender && program.search || (!program.defender && !program.search)) {
return configureSearch().then(configureDefender);
}
if (program.defender) {
console.log('Configuring Defender');
configureDefender();
}
if (program.search) {
console.log('Configuring Search');
configureSearch();
}
});
}
}
function getTarget() {
var target;
if (program.defender && program.search || (!program.defender && !program.search)) {
target = 'Windows Defender and Windows Search';
} else if (program.defender && !program.search) {
target = 'Windows Defender';
} else if (program.search && !program.defender) {
target = 'Windows Search';
}
return target;
}
function ensureTmp() {
return new _Promise(function (resolve) {
if (!fs.existsSync(dir + '/tmp')) {
fs.mkdirSync(dir + '/tmp');
}
resolve();
});
}
console.log('ember-cli-windows v' + version);
// Check OS
if (!isWin) {
return console.log('This script configures Windows, but the OS is not Windows - so we\'re done here.');
}
// Execute
ensureTmp()
.then(checkExecutionPolicy)
.then(executeConfiguration);