@bemoje/fs 0.2.9 → 0.2.10
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.
- package/package.json +2 -2
- package/src/index.d.ts +3 -6
- package/src/index.js +3 -6
- package/src/index.js.map +1 -1
- package/src/lib/getDiskDrivesWindows.js +2 -2
- package/src/lib/getDiskDrivesWindows.js.map +1 -1
- package/src/lib/getJsonIndentation.d.ts +6 -0
- package/src/lib/getJsonIndentation.js +17 -0
- package/src/lib/getJsonIndentation.js.map +1 -0
- package/src/lib/updateJsonFile.d.ts +18 -0
- package/src/lib/updateJsonFile.js +44 -0
- package/src/lib/updateJsonFile.js.map +1 -0
- package/src/lib/updateJsonFileSync.d.ts +18 -0
- package/src/lib/updateJsonFileSync.js +42 -0
- package/src/lib/updateJsonFileSync.js.map +1 -0
- package/src/lib/writeJsonFile.d.ts +1 -1
- package/src/lib/writeJsonFile.js +2 -2
- package/src/lib/writeJsonFile.js.map +1 -1
- package/src/lib/writeJsonFileSync.d.ts +1 -1
- package/src/lib/writeJsonFileSync.js +2 -2
- package/src/lib/writeJsonFileSync.js.map +1 -1
- package/src/lib/getOS.d.ts +0 -6
- package/src/lib/getOS.js +0 -22
- package/src/lib/getOS.js.map +0 -1
- package/src/lib/isLinux.d.ts +0 -6
- package/src/lib/isLinux.js +0 -13
- package/src/lib/isLinux.js.map +0 -1
- package/src/lib/isOSX.d.ts +0 -6
- package/src/lib/isOSX.js +0 -13
- package/src/lib/isOSX.js.map +0 -1
- package/src/lib/isWindows.d.ts +0 -8
- package/src/lib/isWindows.js +0 -15
- package/src/lib/isWindows.js.map +0 -1
- package/src/lib/unzipFile.d.ts +0 -1
- package/src/lib/unzipFile.js +0 -12
- package/src/lib/unzipFile.js.map +0 -1
- package/src/lib/unzipMergeFiles.d.ts +0 -4
- package/src/lib/unzipMergeFiles.js +0 -29
- package/src/lib/unzipMergeFiles.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bemoje/fs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Tools for working with the local filesystem in nodejs.",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"scripts": {},
|
|
@@ -12,9 +12,9 @@
|
|
|
12
12
|
"license": "MIT",
|
|
13
13
|
"keywords": [],
|
|
14
14
|
"dependencies": {
|
|
15
|
+
"@bemoje/os": "latest",
|
|
15
16
|
"@bemoje/string": "latest",
|
|
16
17
|
"appdata-path": "^1.0.0",
|
|
17
|
-
"extract-zip": "^2.0.1",
|
|
18
18
|
"read-last-lines": "^1.8.0",
|
|
19
19
|
"tslib": "^2.3.0"
|
|
20
20
|
},
|
package/src/index.d.ts
CHANGED
|
@@ -14,12 +14,9 @@ export * from './lib/ensureValidWindowsPath';
|
|
|
14
14
|
export * from './lib/getDiskDrivesWindows';
|
|
15
15
|
export * from './lib/getDownloadsDirectory';
|
|
16
16
|
export * from './lib/getHomeDirectory';
|
|
17
|
+
export * from './lib/getJsonIndentation';
|
|
17
18
|
export * from './lib/getLastMofifiedFileIn';
|
|
18
|
-
export * from './lib/getOS';
|
|
19
19
|
export * from './lib/getRootDir';
|
|
20
|
-
export * from './lib/isLinux';
|
|
21
|
-
export * from './lib/isOSX';
|
|
22
|
-
export * from './lib/isWindows';
|
|
23
20
|
export * from './lib/JsonFile';
|
|
24
21
|
export * from './lib/LogFile';
|
|
25
22
|
export * from './lib/normalizeFileExtension';
|
|
@@ -31,8 +28,8 @@ export * from './lib/removeIllegalFilenameCharacters';
|
|
|
31
28
|
export * from './lib/tempFile';
|
|
32
29
|
export * from './lib/types/IEnsureValidWindowsPathOptions';
|
|
33
30
|
export * from './lib/types/ILogFileData';
|
|
34
|
-
export * from './lib/
|
|
35
|
-
export * from './lib/
|
|
31
|
+
export * from './lib/updateJsonFile';
|
|
32
|
+
export * from './lib/updateJsonFileSync';
|
|
36
33
|
export * from './lib/wipeDirectorySafe';
|
|
37
34
|
export * from './lib/writeJsonFile';
|
|
38
35
|
export * from './lib/writeJsonFileSync';
|
package/src/index.js
CHANGED
|
@@ -17,12 +17,9 @@ tslib_1.__exportStar(require("./lib/ensureValidWindowsPath"), exports);
|
|
|
17
17
|
tslib_1.__exportStar(require("./lib/getDiskDrivesWindows"), exports);
|
|
18
18
|
tslib_1.__exportStar(require("./lib/getDownloadsDirectory"), exports);
|
|
19
19
|
tslib_1.__exportStar(require("./lib/getHomeDirectory"), exports);
|
|
20
|
+
tslib_1.__exportStar(require("./lib/getJsonIndentation"), exports);
|
|
20
21
|
tslib_1.__exportStar(require("./lib/getLastMofifiedFileIn"), exports);
|
|
21
|
-
tslib_1.__exportStar(require("./lib/getOS"), exports);
|
|
22
22
|
tslib_1.__exportStar(require("./lib/getRootDir"), exports);
|
|
23
|
-
tslib_1.__exportStar(require("./lib/isLinux"), exports);
|
|
24
|
-
tslib_1.__exportStar(require("./lib/isOSX"), exports);
|
|
25
|
-
tslib_1.__exportStar(require("./lib/isWindows"), exports);
|
|
26
23
|
tslib_1.__exportStar(require("./lib/JsonFile"), exports);
|
|
27
24
|
tslib_1.__exportStar(require("./lib/LogFile"), exports);
|
|
28
25
|
tslib_1.__exportStar(require("./lib/normalizeFileExtension"), exports);
|
|
@@ -34,8 +31,8 @@ tslib_1.__exportStar(require("./lib/removeIllegalFilenameCharacters"), exports);
|
|
|
34
31
|
tslib_1.__exportStar(require("./lib/tempFile"), exports);
|
|
35
32
|
tslib_1.__exportStar(require("./lib/types/IEnsureValidWindowsPathOptions"), exports);
|
|
36
33
|
tslib_1.__exportStar(require("./lib/types/ILogFileData"), exports);
|
|
37
|
-
tslib_1.__exportStar(require("./lib/
|
|
38
|
-
tslib_1.__exportStar(require("./lib/
|
|
34
|
+
tslib_1.__exportStar(require("./lib/updateJsonFile"), exports);
|
|
35
|
+
tslib_1.__exportStar(require("./lib/updateJsonFileSync"), exports);
|
|
39
36
|
tslib_1.__exportStar(require("./lib/wipeDirectorySafe"), exports);
|
|
40
37
|
tslib_1.__exportStar(require("./lib/writeJsonFile"), exports);
|
|
41
38
|
tslib_1.__exportStar(require("./lib/writeJsonFileSync"), exports);
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/fs/src/index.ts"],"names":[],"mappings":";;;AAAA,uEAA4C;AAC5C,wDAA6B;AAC7B,iEAAsC;AACtC,mEAAwC;AACxC,gEAAqC;AACrC,oEAAyC;AACzC,0EAA+C;AAC/C,wDAA6B;AAC7B,gEAAqC;AACrC,oEAAyC;AACzC,wEAA6C;AAC7C,oEAAyC;AACzC,uEAA4C;AAC5C,qEAA0C;AAC1C,sEAA2C;AAC3C,iEAAsC;AACtC,sEAA2C;AAC3C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/fs/src/index.ts"],"names":[],"mappings":";;;AAAA,uEAA4C;AAC5C,wDAA6B;AAC7B,iEAAsC;AACtC,mEAAwC;AACxC,gEAAqC;AACrC,oEAAyC;AACzC,0EAA+C;AAC/C,wDAA6B;AAC7B,gEAAqC;AACrC,oEAAyC;AACzC,wEAA6C;AAC7C,oEAAyC;AACzC,uEAA4C;AAC5C,qEAA0C;AAC1C,sEAA2C;AAC3C,iEAAsC;AACtC,mEAAwC;AACxC,sEAA2C;AAC3C,2DAAgC;AAChC,yDAA8B;AAC9B,wDAA6B;AAC7B,uEAA4C;AAC5C,kEAAuC;AACvC,6DAAkC;AAClC,iEAAsC;AACtC,gEAAqC;AACrC,gFAAqD;AACrD,yDAA8B;AAC9B,qFAA0D;AAC1D,mEAAwC;AACxC,+DAAoC;AACpC,mEAAwC;AACxC,kEAAuC;AACvC,8DAAmC;AACnC,kEAAuC"}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDiskDrivesWindows = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const os_1 = require("@bemoje/os");
|
|
5
6
|
const child_process_1 = require("child_process");
|
|
6
7
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
-
const isWindows_1 = require("./isWindows");
|
|
8
8
|
function getDiskDrivesWindows() {
|
|
9
|
-
if (!(0,
|
|
9
|
+
if (!(0, os_1.isWindows)())
|
|
10
10
|
throw new Error('This function is only available on Windows.');
|
|
11
11
|
return (0, child_process_1.execSync)('wmic logicaldisk get name')
|
|
12
12
|
.toString()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDiskDrivesWindows.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/getDiskDrivesWindows.ts"],"names":[],"mappings":";;;;AAAA,iDAAwC;AACxC,wDAAuB;
|
|
1
|
+
{"version":3,"file":"getDiskDrivesWindows.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/getDiskDrivesWindows.ts"],"names":[],"mappings":";;;;AAAA,mCAAsC;AACtC,iDAAwC;AACxC,wDAAuB;AAEvB,SAAgB,oBAAoB;IAClC,IAAI,CAAC,IAAA,cAAS,GAAE;QAAE,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAA;IAChF,OAAO,IAAA,wBAAQ,EAAC,2BAA2B,CAAC;SACzC,QAAQ,EAAE;SACV,KAAK,CAAC,IAAI,CAAC;SACX,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SACjC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,cAAI,CAAC,GAAG,CAAC,CAAA;AAC7C,CAAC;AARD,oDAQC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function calculates the indentation level of a JSON string.
|
|
3
|
+
* @param json - The JSON string whose indentation level is to be calculated.
|
|
4
|
+
* @returns The number of leading spaces on the second line of the JSON string, or 0 if the JSON string has less than two lines or if the second line does not start with any spaces.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getJsonIndentation(json: string): number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This function calculates the indentation level of a JSON string.
|
|
4
|
+
* @param json - The JSON string whose indentation level is to be calculated.
|
|
5
|
+
* @returns The number of leading spaces on the second line of the JSON string, or 0 if the JSON string has less than two lines or if the second line does not start with any spaces.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.getJsonIndentation = void 0;
|
|
9
|
+
function getJsonIndentation(json) {
|
|
10
|
+
const lines = json.split('\n');
|
|
11
|
+
if (lines.length < 2)
|
|
12
|
+
return 0;
|
|
13
|
+
const leadingSpaces = lines[1].match(/^(\s+)/);
|
|
14
|
+
return leadingSpaces ? leadingSpaces[0].length : 0;
|
|
15
|
+
}
|
|
16
|
+
exports.getJsonIndentation = getJsonIndentation;
|
|
17
|
+
//# sourceMappingURL=getJsonIndentation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getJsonIndentation.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/getJsonIndentation.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAC9B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,CAAC,CAAA;IAC9B,MAAM,aAAa,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAA;IAC9C,OAAO,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AACpD,CAAC;AALD,gDAKC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Updates a JSON file asynchronously based on a provided update function.
|
|
3
|
+
* The update function takes the current JSON object as a parameter and should return the updated JSON object.
|
|
4
|
+
* If the update function returns a falsy value, the JSON file will not be written to.
|
|
5
|
+
* The indentation of the original JSON file is preserved.
|
|
6
|
+
*
|
|
7
|
+
* @param filepath - The path to the JSON file to update.
|
|
8
|
+
* @param update - The function to update the JSON object. Takes the current JSON object as a parameter and should return the updated JSON object.
|
|
9
|
+
* @throws If the file cannot be read or written to.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* await updateJsonFileSync('./package.json', (json) => {
|
|
13
|
+
* json.version = '1.0.1';
|
|
14
|
+
* return json;
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function updateJsonFile(filepath: string, update: (o: Record<string, unknown>) => Record<string, unknown> | Promise<Record<string, unknown>>, defaultJson?: string): Promise<void>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateJsonFile = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
+
const getJsonIndentation_1 = require("./getJsonIndentation");
|
|
7
|
+
const writeJsonFile_1 = require("./writeJsonFile");
|
|
8
|
+
/**
|
|
9
|
+
* Updates a JSON file asynchronously based on a provided update function.
|
|
10
|
+
* The update function takes the current JSON object as a parameter and should return the updated JSON object.
|
|
11
|
+
* If the update function returns a falsy value, the JSON file will not be written to.
|
|
12
|
+
* The indentation of the original JSON file is preserved.
|
|
13
|
+
*
|
|
14
|
+
* @param filepath - The path to the JSON file to update.
|
|
15
|
+
* @param update - The function to update the JSON object. Takes the current JSON object as a parameter and should return the updated JSON object.
|
|
16
|
+
* @throws If the file cannot be read or written to.
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* await updateJsonFileSync('./package.json', (json) => {
|
|
20
|
+
* json.version = '1.0.1';
|
|
21
|
+
* return json;
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function updateJsonFile(filepath, update, defaultJson) {
|
|
26
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
let json;
|
|
28
|
+
try {
|
|
29
|
+
json = yield fs_1.default.promises.readFile(filepath, 'utf8');
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (!defaultJson)
|
|
33
|
+
throw error;
|
|
34
|
+
json = defaultJson;
|
|
35
|
+
}
|
|
36
|
+
const result = yield update(JSON.parse(json));
|
|
37
|
+
if (!result)
|
|
38
|
+
return;
|
|
39
|
+
const indents = (0, getJsonIndentation_1.getJsonIndentation)(json);
|
|
40
|
+
yield (0, writeJsonFile_1.writeJsonFile)(filepath, result, !!indents, indents);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
exports.updateJsonFile = updateJsonFile;
|
|
44
|
+
//# sourceMappingURL=updateJsonFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateJsonFile.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/updateJsonFile.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AACnB,6DAAyD;AACzD,mDAA+C;AAE/C;;;;;;;;;;;;;;;;GAgBG;AACH,SAAsB,cAAc,CAClC,QAAgB,EAChB,MAAkG,EAClG,WAAoB;;QAEpB,IAAI,IAAY,CAAA;QAChB,IAAI;YACF,IAAI,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;SACpD;QAAC,OAAO,KAAK,EAAE;YACd,IAAI,CAAC,WAAW;gBAAE,MAAM,KAAK,CAAA;YAC7B,IAAI,GAAG,WAAW,CAAA;SACnB;QACD,MAAM,MAAM,GAA4B,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;QACtE,IAAI,CAAC,MAAM;YAAE,OAAM;QACnB,MAAM,OAAO,GAAG,IAAA,uCAAkB,EAAC,IAAI,CAAC,CAAA;QACxC,MAAM,IAAA,6BAAa,EAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;IAC3D,CAAC;CAAA;AAhBD,wCAgBC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Updates a JSON file synchronously based on a provided update function.
|
|
3
|
+
* The update function takes the current JSON object as a parameter and should return the updated JSON object.
|
|
4
|
+
* If the update function returns a falsy value, the JSON file will not be written to.
|
|
5
|
+
* The indentation of the original JSON file is preserved.
|
|
6
|
+
*
|
|
7
|
+
* @param filepath - The path to the JSON file to update.
|
|
8
|
+
* @param update - The function to update the JSON object. Takes the current JSON object as a parameter and should return the updated JSON object.
|
|
9
|
+
* @throws If the file cannot be read or written to.
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* updateJsonFileSync('./package.json', (json) => {
|
|
13
|
+
* json.version = '1.0.1';
|
|
14
|
+
* return json;
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function updateJsonFileSync(filepath: string, update: (o: Record<string, unknown>) => Record<string, unknown>, defaultJson?: string): void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateJsonFileSync = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
6
|
+
const getJsonIndentation_1 = require("./getJsonIndentation");
|
|
7
|
+
const writeJsonFileSync_1 = require("./writeJsonFileSync");
|
|
8
|
+
/**
|
|
9
|
+
* Updates a JSON file synchronously based on a provided update function.
|
|
10
|
+
* The update function takes the current JSON object as a parameter and should return the updated JSON object.
|
|
11
|
+
* If the update function returns a falsy value, the JSON file will not be written to.
|
|
12
|
+
* The indentation of the original JSON file is preserved.
|
|
13
|
+
*
|
|
14
|
+
* @param filepath - The path to the JSON file to update.
|
|
15
|
+
* @param update - The function to update the JSON object. Takes the current JSON object as a parameter and should return the updated JSON object.
|
|
16
|
+
* @throws If the file cannot be read or written to.
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* updateJsonFileSync('./package.json', (json) => {
|
|
20
|
+
* json.version = '1.0.1';
|
|
21
|
+
* return json;
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
function updateJsonFileSync(filepath, update, defaultJson) {
|
|
26
|
+
let json;
|
|
27
|
+
try {
|
|
28
|
+
json = fs_1.default.readFileSync(filepath, 'utf8');
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
if (!defaultJson)
|
|
32
|
+
throw error;
|
|
33
|
+
json = defaultJson;
|
|
34
|
+
}
|
|
35
|
+
const result = update(JSON.parse(json));
|
|
36
|
+
if (!result)
|
|
37
|
+
return;
|
|
38
|
+
const indents = (0, getJsonIndentation_1.getJsonIndentation)(json);
|
|
39
|
+
(0, writeJsonFileSync_1.writeJsonFileSync)(filepath, result, !!indents, indents);
|
|
40
|
+
}
|
|
41
|
+
exports.updateJsonFileSync = updateJsonFileSync;
|
|
42
|
+
//# sourceMappingURL=updateJsonFileSync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateJsonFileSync.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/updateJsonFileSync.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AACnB,6DAAyD;AACzD,2DAAuD;AAEvD;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,kBAAkB,CAChC,QAAgB,EAChB,MAA+D,EAC/D,WAAoB;IAEpB,IAAI,IAAY,CAAA;IAChB,IAAI;QACF,IAAI,GAAG,YAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;KACzC;IAAC,OAAO,KAAK,EAAE;QACd,IAAI,CAAC,WAAW;YAAE,MAAM,KAAK,CAAA;QAC7B,IAAI,GAAG,WAAW,CAAA;KACnB;IACD,MAAM,MAAM,GAA4B,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAA;IAChE,IAAI,CAAC,MAAM;QAAE,OAAM;IACnB,MAAM,OAAO,GAAG,IAAA,uCAAkB,EAAC,IAAI,CAAC,CAAA;IACxC,IAAA,qCAAiB,EAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AACzD,CAAC;AAhBD,gDAgBC"}
|
|
@@ -11,4 +11,4 @@
|
|
|
11
11
|
* await writeJsonFile('./data.json', data, true);
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
|
-
export declare function writeJsonFile<T>(filepath: string, data: T, pretty?: boolean): Promise<void>;
|
|
14
|
+
export declare function writeJsonFile<T>(filepath: string, data: T, pretty?: boolean, indents?: number): Promise<void>;
|
package/src/lib/writeJsonFile.js
CHANGED
|
@@ -16,9 +16,9 @@ const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
|
16
16
|
* await writeJsonFile('./data.json', data, true);
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
|
-
function writeJsonFile(filepath, data, pretty = false) {
|
|
19
|
+
function writeJsonFile(filepath, data, pretty = false, indents = 2) {
|
|
20
20
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
yield fs_1.default.promises.writeFile(filepath, JSON.stringify(data, null, pretty ?
|
|
21
|
+
yield fs_1.default.promises.writeFile(filepath, JSON.stringify(data, null, pretty ? indents : undefined));
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
exports.writeJsonFile = writeJsonFile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeJsonFile.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/writeJsonFile.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AAEnB;;;;;;;;;;;;GAYG;AACH,SAAsB,aAAa,CAAI,QAAgB,EAAE,IAAO,EAAE,MAAM,GAAG,KAAK;;
|
|
1
|
+
{"version":3,"file":"writeJsonFile.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/writeJsonFile.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AAEnB;;;;;;;;;;;;GAYG;AACH,SAAsB,aAAa,CAAI,QAAgB,EAAE,IAAO,EAAE,MAAM,GAAG,KAAK,EAAE,OAAO,GAAG,CAAC;;QAC3F,MAAM,YAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;IACjG,CAAC;CAAA;AAFD,sCAEC"}
|
|
@@ -10,4 +10,4 @@
|
|
|
10
10
|
* writeJsonFileSync('./data.json', data, true);
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
|
-
export declare function writeJsonFileSync<T>(filepath: string, data: T, pretty?: boolean): void;
|
|
13
|
+
export declare function writeJsonFileSync<T>(filepath: string, data: T, pretty?: boolean, indents?: number): void;
|
|
@@ -15,8 +15,8 @@ const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
|
15
15
|
* writeJsonFileSync('./data.json', data, true);
|
|
16
16
|
* ```
|
|
17
17
|
*/
|
|
18
|
-
function writeJsonFileSync(filepath, data, pretty = false) {
|
|
19
|
-
fs_1.default.writeFileSync(filepath, JSON.stringify(data, null, pretty ?
|
|
18
|
+
function writeJsonFileSync(filepath, data, pretty = false, indents = 2) {
|
|
19
|
+
fs_1.default.writeFileSync(filepath, JSON.stringify(data, null, pretty ? indents : undefined));
|
|
20
20
|
}
|
|
21
21
|
exports.writeJsonFileSync = writeJsonFileSync;
|
|
22
22
|
//# sourceMappingURL=writeJsonFileSync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeJsonFileSync.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/writeJsonFileSync.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AAEnB;;;;;;;;;;;GAWG;AACH,SAAgB,iBAAiB,CAAI,QAAgB,EAAE,IAAO,EAAE,MAAM,GAAG,KAAK;
|
|
1
|
+
{"version":3,"file":"writeJsonFileSync.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/writeJsonFileSync.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AAEnB;;;;;;;;;;;GAWG;AACH,SAAgB,iBAAiB,CAAI,QAAgB,EAAE,IAAO,EAAE,MAAM,GAAG,KAAK,EAAE,OAAO,GAAG,CAAC;IACzF,YAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;AACtF,CAAC;AAFD,8CAEC"}
|
package/src/lib/getOS.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Determines the current operating system.
|
|
3
|
-
* It uses the isWindows, isOSX, and isLinux functions to determine the current operating system.
|
|
4
|
-
* @returns A string indicating the current operating system. It can be 'windows', 'osx', 'linux', or 'unknown'.
|
|
5
|
-
*/
|
|
6
|
-
export declare function getOS(): 'windows' | 'osx' | 'linux' | 'unknown';
|
package/src/lib/getOS.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getOS = void 0;
|
|
4
|
-
const isLinux_1 = require("./isLinux");
|
|
5
|
-
const isOSX_1 = require("./isOSX");
|
|
6
|
-
const isWindows_1 = require("./isWindows");
|
|
7
|
-
/**
|
|
8
|
-
* Determines the current operating system.
|
|
9
|
-
* It uses the isWindows, isOSX, and isLinux functions to determine the current operating system.
|
|
10
|
-
* @returns A string indicating the current operating system. It can be 'windows', 'osx', 'linux', or 'unknown'.
|
|
11
|
-
*/
|
|
12
|
-
function getOS() {
|
|
13
|
-
if ((0, isLinux_1.isLinux)())
|
|
14
|
-
return 'linux';
|
|
15
|
-
if ((0, isOSX_1.isOSX)())
|
|
16
|
-
return 'osx';
|
|
17
|
-
if ((0, isWindows_1.isWindows)())
|
|
18
|
-
return 'windows';
|
|
19
|
-
return 'unknown';
|
|
20
|
-
}
|
|
21
|
-
exports.getOS = getOS;
|
|
22
|
-
//# sourceMappingURL=getOS.js.map
|
package/src/lib/getOS.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getOS.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/getOS.ts"],"names":[],"mappings":";;;AAAA,uCAAmC;AACnC,mCAA+B;AAC/B,2CAAuC;AAEvC;;;;GAIG;AAEH,SAAgB,KAAK;IACnB,IAAI,IAAA,iBAAO,GAAE;QAAE,OAAO,OAAO,CAAA;IAC7B,IAAI,IAAA,aAAK,GAAE;QAAE,OAAO,KAAK,CAAA;IACzB,IAAI,IAAA,qBAAS,GAAE;QAAE,OAAO,SAAS,CAAA;IACjC,OAAO,SAAS,CAAA;AAClB,CAAC;AALD,sBAKC"}
|
package/src/lib/isLinux.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if the current platform is Linux.
|
|
3
|
-
* It checks the 'process' object and the 'platform' property to determine if the platform is 'linux'.
|
|
4
|
-
* @returns A boolean indicating whether the current platform is Linux.
|
|
5
|
-
*/
|
|
6
|
-
export declare function isLinux(): boolean;
|
package/src/lib/isLinux.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Checks if the current platform is Linux.
|
|
4
|
-
* It checks the 'process' object and the 'platform' property to determine if the platform is 'linux'.
|
|
5
|
-
* @returns A boolean indicating whether the current platform is Linux.
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.isLinux = void 0;
|
|
9
|
-
function isLinux() {
|
|
10
|
-
return process.platform === 'linux';
|
|
11
|
-
}
|
|
12
|
-
exports.isLinux = isLinux;
|
|
13
|
-
//# sourceMappingURL=isLinux.js.map
|
package/src/lib/isLinux.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isLinux.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/isLinux.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,SAAgB,OAAO;IACrB,OAAO,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAA;AACrC,CAAC;AAFD,0BAEC"}
|
package/src/lib/isOSX.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if the current platform is OSX.
|
|
3
|
-
* It checks the 'process' object and the 'platform' property to determine if the platform is 'darwin'.
|
|
4
|
-
* @returns A boolean indicating whether the current platform is OSX.
|
|
5
|
-
*/
|
|
6
|
-
export declare function isOSX(): boolean;
|
package/src/lib/isOSX.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Checks if the current platform is OSX.
|
|
4
|
-
* It checks the 'process' object and the 'platform' property to determine if the platform is 'darwin'.
|
|
5
|
-
* @returns A boolean indicating whether the current platform is OSX.
|
|
6
|
-
*/
|
|
7
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.isOSX = void 0;
|
|
9
|
-
function isOSX() {
|
|
10
|
-
return process.platform === 'darwin';
|
|
11
|
-
}
|
|
12
|
-
exports.isOSX = isOSX;
|
|
13
|
-
//# sourceMappingURL=isOSX.js.map
|
package/src/lib/isOSX.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isOSX.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/isOSX.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,SAAgB,KAAK;IACnB,OAAO,OAAO,CAAC,QAAQ,KAAK,QAAQ,CAAA;AACtC,CAAC;AAFD,sBAEC"}
|
package/src/lib/isWindows.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if the current platform is Windows.
|
|
3
|
-
* @remarks
|
|
4
|
-
* It checks the 'process' object and the 'platform' property to determine if the platform is 'win32'.
|
|
5
|
-
* It also checks the 'OSTYPE' environment variable to see if it matches 'msys' or 'cygwin'.
|
|
6
|
-
* @returns A boolean indicating whether the current platform is Windows.
|
|
7
|
-
*/
|
|
8
|
-
export declare function isWindows(): boolean;
|
package/src/lib/isWindows.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isWindows = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Checks if the current platform is Windows.
|
|
6
|
-
* @remarks
|
|
7
|
-
* It checks the 'process' object and the 'platform' property to determine if the platform is 'win32'.
|
|
8
|
-
* It also checks the 'OSTYPE' environment variable to see if it matches 'msys' or 'cygwin'.
|
|
9
|
-
* @returns A boolean indicating whether the current platform is Windows.
|
|
10
|
-
*/
|
|
11
|
-
function isWindows() {
|
|
12
|
-
return process && (process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env['OSTYPE'] || ''));
|
|
13
|
-
}
|
|
14
|
-
exports.isWindows = isWindows;
|
|
15
|
-
//# sourceMappingURL=isWindows.js.map
|
package/src/lib/isWindows.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isWindows.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/isWindows.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,SAAgB,SAAS;IACvB,OAAO,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,IAAI,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;AACzG,CAAC;AAFD,8BAEC"}
|
package/src/lib/unzipFile.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function unzipFile(filepath: string, outdir: string): Promise<void>;
|
package/src/lib/unzipFile.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unzipFile = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const extract_zip_1 = tslib_1.__importDefault(require("extract-zip"));
|
|
6
|
-
function unzipFile(filepath, outdir) {
|
|
7
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
8
|
-
yield (0, extract_zip_1.default)(filepath, { dir: outdir });
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
exports.unzipFile = unzipFile;
|
|
12
|
-
//# sourceMappingURL=unzipFile.js.map
|
package/src/lib/unzipFile.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unzipFile.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/unzipFile.ts"],"names":[],"mappings":";;;;AAAA,sEAAiC;AAEjC,SAAsB,SAAS,CAAC,QAAgB,EAAE,MAAc;;QAC9D,MAAM,IAAA,qBAAO,EAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAA;IAC1C,CAAC;CAAA;AAFD,8BAEC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.unzipMergeFiles = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const extract_zip_1 = tslib_1.__importDefault(require("extract-zip"));
|
|
6
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
7
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
|
-
/**
|
|
9
|
-
* @param source Either a directory containing zip files or an array of zip file paths.
|
|
10
|
-
*/
|
|
11
|
-
function unzipMergeFiles(source, target) {
|
|
12
|
-
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
if (typeof source === 'string') {
|
|
14
|
-
source = fs_1.default.readdirSync(source).map((filename) => {
|
|
15
|
-
return path_1.default.join(source, filename);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
for (const filepath of source) {
|
|
19
|
-
const stat = yield fs_1.default.promises.stat(filepath);
|
|
20
|
-
if (stat.isDirectory())
|
|
21
|
-
continue;
|
|
22
|
-
if (!filepath.endsWith('.zip'))
|
|
23
|
-
continue;
|
|
24
|
-
yield (0, extract_zip_1.default)(filepath, { dir: target });
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
exports.unzipMergeFiles = unzipMergeFiles;
|
|
29
|
-
//# sourceMappingURL=unzipMergeFiles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unzipMergeFiles.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/unzipMergeFiles.ts"],"names":[],"mappings":";;;;AAAA,sEAAiC;AACjC,oDAAmB;AACnB,wDAAuB;AAEvB;;GAEG;AACH,SAAsB,eAAe,CAAC,MAAyB,EAAE,MAAc;;QAC7E,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE;YAC9B,MAAM,GAAG,YAAE,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE;gBAC/C,OAAO,cAAI,CAAC,IAAI,CAAC,MAAgB,EAAE,QAAQ,CAAC,CAAA;YAC9C,CAAC,CAAC,CAAA;SACH;QACD,KAAK,MAAM,QAAQ,IAAI,MAAM,EAAE;YAC7B,MAAM,IAAI,GAAG,MAAM,YAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YAC7C,IAAI,IAAI,CAAC,WAAW,EAAE;gBAAE,SAAQ;YAChC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC;gBAAE,SAAQ;YACxC,MAAM,IAAA,qBAAO,EAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAA;SACzC;IACH,CAAC;CAAA;AAZD,0CAYC"}
|