Skip to content

Commit

Permalink
refactor: Remove extra try-catch (#30)
Browse files Browse the repository at this point in the history
* refactor: Remove extra try-catch
* refactor: Rename mdbook to tool
  • Loading branch information
peaceiris authored Jan 3, 2020
1 parent 258d807 commit 17fabeb
Showing 1 changed file with 30 additions and 34 deletions.
64 changes: 30 additions & 34 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,38 @@ if (!tempDir) {
}

export default async function installer(version: string) {
try {
const osName: string = getOS(process.platform);
console.log(`Operating System: ${osName}`);
const osName: string = getOS(process.platform);
console.log(`Operating System: ${osName}`);

const mdbookURL: string = getURL(osName, version);
core.debug(`mdbookURL: ${mdbookURL}`);
const toolURL: string = getURL(osName, version);
core.debug(`toolURL: ${toolURL}`);

let baseLocation: string;
if (process.platform === 'win32') {
baseLocation = process.env['USERPROFILE'] || 'C:\\';
} else {
baseLocation = `${process.env.HOME}`;
}
const mdbookPath: string = path.join(baseLocation, 'mdbookbin');
await io.mkdirP(mdbookPath);
core.addPath(mdbookPath);
let baseLocation: string;
if (process.platform === 'win32') {
baseLocation = process.env['USERPROFILE'] || 'C:\\';
} else {
baseLocation = `${process.env.HOME}`;
}
const toolPath: string = path.join(baseLocation, 'toolbin');
await io.mkdirP(toolPath);
core.addPath(toolPath);

// Download and extract mdbook binary
await io.mkdirP(tempDir);
const mdbookAssets: string = await tc.downloadTool(mdbookURL);
let mdbookBin: string = '';
if (osName === 'pc-windows-msvc') {
const mdbookExtractedFolder: string = await tc.extractZip(
mdbookAssets,
tempDir
);
mdbookBin = `${mdbookExtractedFolder}/mdbook.exe`;
} else {
const mdbookExtractedFolder: string = await tc.extractTar(
mdbookAssets,
tempDir
);
mdbookBin = `${mdbookExtractedFolder}/mdbook`;
}
await io.mv(mdbookBin, mdbookPath);
} catch (error) {
core.setFailed(error.message);
// Download and extract mdbook binary
await io.mkdirP(tempDir);
const toolAssets: string = await tc.downloadTool(toolURL);
let toolBin: string = '';
if (osName === 'pc-windows-msvc') {
const toolExtractedFolder: string = await tc.extractZip(
toolAssets,
tempDir
);
toolBin = `${toolExtractedFolder}/mdbook.exe`;
} else {
const toolExtractedFolder: string = await tc.extractTar(
toolAssets,
tempDir
);
toolBin = `${toolExtractedFolder}/mdbook`;
}
await io.mv(toolBin, toolPath);
}

0 comments on commit 17fabeb

Please sign in to comment.