1 | 'use strict';
|
2 |
|
3 | const os = require('os');
|
4 | const config = require('./config');
|
5 |
|
6 | const folders = {
|
7 | 'osx': 'osx',
|
8 | 'darwin': 'osx',
|
9 | 'linux': 'linux',
|
10 | 'sunos': 'sunos',
|
11 | 'win32': 'win32'
|
12 | };
|
13 |
|
14 |
|
15 | function isSupported(platform) {
|
16 | return folders.hasOwnProperty(platform);
|
17 | }
|
18 |
|
19 |
|
20 |
|
21 | function getPreferredPlatform() {
|
22 | let platform = config.get().platform;
|
23 | if (isSupported(platform)) {
|
24 | return platform;
|
25 | }
|
26 | return os.platform();
|
27 | }
|
28 |
|
29 | function specific(command, platform) {
|
30 | return platform + '/' + command + '.md';
|
31 | }
|
32 |
|
33 | function resolve(command) {
|
34 | return [
|
35 | specific(command, getPreferredPlatformFolder()),
|
36 | specific(command, 'common')
|
37 | ];
|
38 | }
|
39 |
|
40 |
|
41 | function getPreferredPlatformFolder() {
|
42 | let platform = getPreferredPlatform();
|
43 | return folders[platform];
|
44 | }
|
45 |
|
46 | module.exports = {
|
47 | isSupported,
|
48 | getPreferredPlatform,
|
49 | getPreferredPlatformFolder,
|
50 | resolve
|
51 | };
|