-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#187 Moved os platform selection to a reusable function
- Loading branch information
Showing
2 changed files
with
44 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import os from "os"; | ||
|
||
export default new class { | ||
/** | ||
* Get the platform specific command | ||
* @param {Platforms} platforms | ||
* @returns {string} | ||
*/ | ||
get(platforms) { | ||
switch (os.platform()) { | ||
case 'win32': | ||
return platforms.windows; | ||
case 'darwin': | ||
return platforms.darwin; | ||
case 'linux': | ||
return platforms.linux; | ||
default: | ||
throw new Error(`Unsupported platform: ${os.platform()}`); | ||
} | ||
} | ||
} | ||
|
||
export class Platforms { | ||
/** | ||
* @type {string} windows | ||
*/ | ||
windows; | ||
|
||
/** | ||
* @type {string} darwin | ||
*/ | ||
darwin; | ||
|
||
/** | ||
* @type {string} linux | ||
*/ | ||
linux; | ||
} |