UNPKG

1.06 kBJavaScriptView Raw
1'use strict';
2
3const os = require('os');
4const config = require('./config');
5
6const folders = {
7 'osx': 'osx',
8 'darwin': 'osx',
9 'linux': 'linux',
10 'sunos': 'sunos',
11 'win32': 'win32'
12};
13
14// Check if the platform is there in the list of platforms or not
15function isSupported(platform) {
16 return folders.hasOwnProperty(platform);
17}
18
19// If the platform given in config is present, return that.
20// Else, return the system platform
21function getPreferredPlatform() {
22 let platform = config.get().platform;
23 if (isSupported(platform)) {
24 return platform;
25 }
26 return os.platform();
27}
28
29function specific(command, platform) {
30 return platform + '/' + command + '.md';
31}
32
33function resolve(command) {
34 return [
35 specific(command, getPreferredPlatformFolder()),
36 specific(command, 'common')
37 ];
38}
39
40// Get the folder name for a platform
41function getPreferredPlatformFolder() {
42 let platform = getPreferredPlatform();
43 return folders[platform];
44}
45
46module.exports = {
47 isSupported,
48 getPreferredPlatform,
49 getPreferredPlatformFolder,
50 resolve
51};