Skip to content

Commit

Permalink
Make assigning of the script path intuitive
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolai Laevskii committed May 30, 2023
1 parent 427804d commit 820f30d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
23 changes: 14 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,14 @@ class DotnetInstallScript {
constructor() {
this.scriptName = utils_1.IS_WINDOWS ? 'install-dotnet.ps1' : 'install-dotnet.sh';
this.scriptArguments = [];
this.scriptPath = '';
this.escapedScript = path_1.default
.join(__dirname, '..', 'externals', this.scriptName)
.replace(/'/g, "''");
this.scriptReady = utils_1.IS_WINDOWS
? this.setupScriptPowershell()
: this.setupScriptBash();
if (utils_1.IS_WINDOWS) {
this.setupScriptPowershell();
return;
}
this.setupScriptBash();
}
setupScriptPowershell() {
return __awaiter(this, void 0, void 0, function* () {
Expand All @@ -368,14 +369,19 @@ class DotnetInstallScript {
if (process.env['no_proxy'] != null) {
this.scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`);
}
this.scriptPath =
(yield io.which('pwsh', false)) || (yield io.which('powershell', true));
});
}
setupScriptBash() {
return __awaiter(this, void 0, void 0, function* () {
(0, fs_1.chmodSync)(this.escapedScript, '777');
this.scriptPath = yield io.which(this.escapedScript, true);
});
}
getScriptPath() {
return __awaiter(this, void 0, void 0, function* () {
if (utils_1.IS_WINDOWS) {
return (yield io.which('pwsh', false)) || io.which('powershell', true);
}
return io.which(this.escapedScript, true);
});
}
useArguments(...args) {
Expand All @@ -401,8 +407,7 @@ class DotnetInstallScript {
ignoreReturnCode: true,
env: process.env
};
yield this.scriptReady;
return exec.getExecOutput(`"${this.scriptPath}"`, this.scriptArguments, getExecOutputOptions);
return exec.getExecOutput(`"${yield this.getScriptPath()}"`, this.scriptArguments, getExecOutputOptions);
});
}
}
Expand Down
27 changes: 15 additions & 12 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,18 @@ export class DotnetInstallScript {
private scriptName = IS_WINDOWS ? 'install-dotnet.ps1' : 'install-dotnet.sh';
private escapedScript: string;
private scriptArguments: string[] = [];
private scriptPath = '';
private scriptReady: Promise<void>;

constructor() {
this.escapedScript = path
.join(__dirname, '..', 'externals', this.scriptName)
.replace(/'/g, "''");

this.scriptReady = IS_WINDOWS
? this.setupScriptPowershell()
: this.setupScriptBash();
if (IS_WINDOWS) {
this.setupScriptPowershell();
return;
}

this.setupScriptBash();
}

private async setupScriptPowershell() {
Expand All @@ -162,14 +163,18 @@ export class DotnetInstallScript {
if (process.env['no_proxy'] != null) {
this.scriptArguments.push(`-ProxyBypassList ${process.env['no_proxy']}`);
}

this.scriptPath =
(await io.which('pwsh', false)) || (await io.which('powershell', true));
}

private async setupScriptBash() {
chmodSync(this.escapedScript, '777');
this.scriptPath = await io.which(this.escapedScript, true);
}

private async getScriptPath() {
if (IS_WINDOWS) {
return (await io.which('pwsh', false)) || io.which('powershell', true);
}

return io.which(this.escapedScript, true);
}

public useArguments(...args: string[]) {
Expand Down Expand Up @@ -202,10 +207,8 @@ export class DotnetInstallScript {
env: process.env as {string: string}
};

await this.scriptReady;

return exec.getExecOutput(
`"${this.scriptPath}"`,
`"${await this.getScriptPath()}"`,
this.scriptArguments,
getExecOutputOptions
);
Expand Down

0 comments on commit 820f30d

Please sign in to comment.