@bemoje/path 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
type GetDownloadsFolder = () => string;
|
|
1
2
|
/**
|
|
2
3
|
* Returns the downloads directory of the current user.
|
|
3
4
|
*/
|
|
4
5
|
export declare function getDownloadsDirectory(): string;
|
|
6
|
+
export declare namespace getDownloadsDirectory {
|
|
7
|
+
var osx: GetDownloadsFolder;
|
|
8
|
+
var linux: GetDownloadsFolder;
|
|
9
|
+
var windows: GetDownloadsFolder;
|
|
10
|
+
}
|
|
11
|
+
export {};
|
|
5
12
|
//# sourceMappingURL=getDownloadsDirectory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDownloadsDirectory.d.ts","sourceRoot":"","sources":["../../../../../packages/path/src/lib/getDownloadsDirectory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDownloadsDirectory.d.ts","sourceRoot":"","sources":["../../../../../packages/path/src/lib/getDownloadsDirectory.ts"],"names":[],"mappings":"AAOA,KAAK,kBAAkB,GAAG,MAAM,MAAM,CAAA;AA6BtC;;GAEG;AACH,wBAAgB,qBAAqB,WAIpC;yBAJe,qBAAqB"}
|
|
@@ -4,15 +4,49 @@ exports.getDownloadsDirectory = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
6
6
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
7
8
|
const getHomeDirectory_1 = require("./getHomeDirectory");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
const os_1 = require("@bemoje/os");
|
|
10
|
+
const fs_1 = require("fs");
|
|
11
|
+
const osx = () => `${process.env.HOME}/Downloads`;
|
|
12
|
+
const linux = () => {
|
|
13
|
+
let dir;
|
|
14
|
+
try {
|
|
15
|
+
dir = (0, child_process_1.execSync)('xdg-user-dir DOWNLOAD', { encoding: 'utf8' }).trim();
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
dir = undefined;
|
|
19
|
+
}
|
|
20
|
+
if (dir && dir !== process.env.HOME)
|
|
21
|
+
return dir;
|
|
22
|
+
const homeDownloads = `${process.env.HOME}/Downloads`;
|
|
23
|
+
try {
|
|
24
|
+
const stat = (0, fs_1.statSync)(homeDownloads);
|
|
25
|
+
if (stat)
|
|
26
|
+
return homeDownloads;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// Ignored
|
|
30
|
+
}
|
|
31
|
+
return '/tmp/';
|
|
32
|
+
};
|
|
33
|
+
const windows = () => {
|
|
12
34
|
const result = path_1.default.join((0, getHomeDirectory_1.getHomeDirectory)(), 'Downloads');
|
|
13
35
|
if (!fs_extra_1.default.existsSync(result))
|
|
14
36
|
throw new Error('Downloads directory does not exist');
|
|
15
37
|
return result;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Returns the downloads directory of the current user.
|
|
41
|
+
*/
|
|
42
|
+
function getDownloadsDirectory() {
|
|
43
|
+
const os = (0, os_1.getOS)();
|
|
44
|
+
if (os === 'unknown')
|
|
45
|
+
throw new Error('Unknown OS');
|
|
46
|
+
return os === 'linux' ? linux() : os === 'windows' ? windows() : osx();
|
|
16
47
|
}
|
|
17
48
|
exports.getDownloadsDirectory = getDownloadsDirectory;
|
|
49
|
+
getDownloadsDirectory.osx = osx;
|
|
50
|
+
getDownloadsDirectory.linux = linux;
|
|
51
|
+
getDownloadsDirectory.windows = windows;
|
|
18
52
|
//# sourceMappingURL=getDownloadsDirectory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDownloadsDirectory.js","sourceRoot":"","sources":["../../../../../packages/path/src/lib/getDownloadsDirectory.ts"],"names":[],"mappings":";;;;AAAA,gEAAyB;AACzB,wDAAuB;AACvB,yDAAqD;
|
|
1
|
+
{"version":3,"file":"getDownloadsDirectory.js","sourceRoot":"","sources":["../../../../../packages/path/src/lib/getDownloadsDirectory.ts"],"names":[],"mappings":";;;;AAAA,gEAAyB;AACzB,wDAAuB;AACvB,iDAAwC;AACxC,yDAAqD;AACrD,mCAAkC;AAClC,2BAA6B;AAI7B,MAAM,GAAG,GAAuB,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,YAAY,CAAA;AAErE,MAAM,KAAK,GAAuB,GAAG,EAAE;IACrC,IAAI,GAAuB,CAAA;IAC3B,IAAI;QACF,GAAG,GAAG,IAAA,wBAAQ,EAAC,uBAAuB,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,IAAI,EAAE,CAAA;KACrE;IAAC,MAAM;QACN,GAAG,GAAG,SAAS,CAAA;KAChB;IACD,IAAI,GAAG,IAAI,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,IAAI;QAAE,OAAO,GAAG,CAAA;IAE/C,MAAM,aAAa,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,YAAY,CAAA;IACrD,IAAI;QACF,MAAM,IAAI,GAAG,IAAA,aAAQ,EAAC,aAAa,CAAC,CAAA;QACpC,IAAI,IAAI;YAAE,OAAO,aAAa,CAAA;KAC/B;IAAC,MAAM;QACN,UAAU;KACX;IACD,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,MAAM,OAAO,GAAuB,GAAG,EAAE;IACvC,MAAM,MAAM,GAAG,cAAI,CAAC,IAAI,CAAC,IAAA,mCAAgB,GAAE,EAAE,WAAW,CAAC,CAAA;IACzD,IAAI,CAAC,kBAAE,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;IACjF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED;;GAEG;AACH,SAAgB,qBAAqB;IACnC,MAAM,E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