Skip to content

Commit f82c03b

Browse files
committed
update routines for package manager installation
1 parent 7aff7fa commit f82c03b

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

bin/installChocolatey.cmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@echo off
22
SET DIR=%~dp0%
33

4-
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "((new-object net.webclient).DownloadFile('https://chocolatey.org/install.ps1','install.ps1'))"
5-
%systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR%install.ps1' %*"
4+
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "((new-object net.webclient).DownloadFile('https://chocolatey.org/install.ps1','install.ps1'))"
5+
powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR%install.ps1' %*"
66
SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

bin/installer.js

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ const require = createRequire(
1818
import.meta.url);
1919
const pack = require('../package.json');
2020

21+
const IS_MACOS = where('osascript');
22+
const CMD = {
23+
win32: join(__dirname, 'sudo.bat'),
24+
darwin: ((IS_MACOS === null) ? 'osascript' : join(IS_MACOS, 'osascript'))
25+
};
26+
const SYSTEM = {
27+
win32: join(__dirname, 'installChocolatey.cmd'),
28+
darwin: join(__dirname, 'xcode-brew-install.scpt')
29+
};
30+
2131
/*
2232
* Arguments.
2333
*/
@@ -61,49 +71,30 @@ if (argv.help || argv.h) {
6171
console.log(help());
6272
} else if (argv.version || argv.v) {
6373
console.log(pack.version);
64-
} else if ((argv.get || argv.g) && process.platform == 'win32' && where('choco') == null) {
65-
console.log('Download and Install Chocolatey');
66-
const ps = new PowerShell("Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))", {
67-
executionpolicy: 'Unrestricted'
68-
});
69-
70-
ps.on('error', (err) => {
71-
return new Error(err);
72-
});
73-
ps.on('output', (data) => console.log(data));
74-
ps.on('error-output', (data) => {
75-
return new Error(data);
76-
});
77-
78-
ps.on('end', () => {
79-
console.log('Chocolatey Installed');
80-
return;
81-
});
82-
} else if ((argv.get || argv.g) && process.platform == 'darwin' && where('brew') == null) {
74+
} else if ((argv.get || argv.g)
75+
&& (
76+
(process.platform == 'darwin' && where('brew') === null)
77+
|| (process.platform == 'win32' && where('choco') === null)
78+
)) {
8379
let installOutput = '';
84-
let args = join(__dirname, 'xcode-brew-install.scpt');
85-
const child = spawn('osascript', [args], {
86-
stdio: 'pipe'
87-
});
88-
89-
child.on('error', (err) => {
90-
console.error(err);
80+
const child = spawn(CMD[process.platform], SYSTEM[process.platform], {
81+
stdio: 'pipe',
9182
});
9283

9384
child.on('close', () => {
94-
console.log(installOutput);
85+
return installOutput;
9586
});
9687

9788
child.on('exit', () => {
98-
console.log(installOutput);
89+
return installOutput;
9990
});
10091

10192
child.stdout.on('data', (data) => {
10293
installOutput += data.toString();
10394
});
10495

10596
child.stderr.on('data', (data) => {
106-
return new Error(data.toString());
97+
throw data.toString();
10798
});
10899
} else if (argv) {
109100
let args = argv._;

0 commit comments

Comments
 (0)