forked from frangoteam/FUXA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaths.js
44 lines (39 loc) · 1.12 KB
/
paths.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//@ts-check
'use strict';
// @ts-ignore
const pkg = require('./package.json');
const path = require('path');
const os = require('os');
var fs = require('fs-extra');
/**
* @param {string} platform
* @returns {string}
*/
function getAppDataPath(platform) {
switch (platform) {
case 'win32': return process.env['FUXA_APPDATA'] || process.env['APPDATA'] || path.join(process.env['USERPROFILE'], 'AppData', 'Roaming');
case 'darwin': return process.env['FUXA_APPDATA'] || path.join(os.homedir(), 'Library', 'Application Support');
case 'linux': return process.env['FUXA_APPDATA'] || process.env['XDG_CONFIG_HOME'] || path.join(os.homedir(), '.config');
default: throw new Error('Platform not supported');
}
}
/**
* @param {string} platform
* @returns {string}
*/
function getDefaultUserDataPath(platform) {
return path.join(getAppDataPath(platform), pkg.name);
}
/**
*
* @param {*} dirPath
*/
function ensureDirs(dirPath) {
if (fs.existsSync(dirPath)) {
return;
}
fs.mkdirSync(dirPath);
}
exports.getAppDataPath = getAppDataPath;
exports.getDefaultUserDataPath = getDefaultUserDataPath;
exports.ensureDirs = ensureDirs;