xcraft-core-utils 4.18.0 → 4.18.2
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/lib/file-crypto.js +3 -3
- package/lib/json.js +3 -4
- package/lib/rest.js +6 -2
- package/lib/yaml.js +3 -3
- package/package.json +2 -2
package/lib/file-crypto.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const watt = require('gigawatts');
|
|
4
4
|
const crypto = require('crypto');
|
|
5
|
-
const
|
|
5
|
+
const fse = require('fs-extra');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Compute the checksum of the file given as parameter using a specified algorithm.
|
|
@@ -23,7 +23,7 @@ exports.fileChecksum = watt(function* (filePath, options, next) {
|
|
|
23
23
|
options.encoding = 'hex';
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const stat = yield
|
|
26
|
+
const stat = yield fse.stat(filePath);
|
|
27
27
|
if (!stat.isFile()) {
|
|
28
28
|
throw new Error(`${filePath} is not a file`);
|
|
29
29
|
}
|
|
@@ -31,7 +31,7 @@ exports.fileChecksum = watt(function* (filePath, options, next) {
|
|
|
31
31
|
const hash = crypto.createHash(options.algorithm);
|
|
32
32
|
hash.setEncoding(options.encoding);
|
|
33
33
|
|
|
34
|
-
const fileStream =
|
|
34
|
+
const fileStream = fse.createReadStream(filePath);
|
|
35
35
|
fileStream.pipe(hash, {end: false});
|
|
36
36
|
yield fileStream.once('end', next);
|
|
37
37
|
|
package/lib/json.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const fse = require('fs-extra');
|
|
4
4
|
const traverse = require('xcraft-traverse');
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -9,8 +9,7 @@ const traverse = require('xcraft-traverse');
|
|
|
9
9
|
* @returns {object}
|
|
10
10
|
*/
|
|
11
11
|
exports.fromFile = function (jsonFile) {
|
|
12
|
-
|
|
13
|
-
return JSON.parse(data);
|
|
12
|
+
return fse.readJSONSync(jsonFile);
|
|
14
13
|
};
|
|
15
14
|
|
|
16
15
|
/**
|
|
@@ -19,7 +18,7 @@ exports.fromFile = function (jsonFile) {
|
|
|
19
18
|
* @param {*} destFile
|
|
20
19
|
*/
|
|
21
20
|
exports.toFile = function (json, destFile) {
|
|
22
|
-
|
|
21
|
+
fse.writeJSONSync(destFile, json);
|
|
23
22
|
};
|
|
24
23
|
|
|
25
24
|
/**
|
package/lib/rest.js
CHANGED
|
@@ -136,11 +136,15 @@ class RestAPI {
|
|
|
136
136
|
/**
|
|
137
137
|
* @param {string} query
|
|
138
138
|
* @param {object} payload
|
|
139
|
+
* @param {object} [options]
|
|
139
140
|
* @returns {object}
|
|
140
141
|
*/
|
|
141
|
-
async _post(query, payload) {
|
|
142
|
+
async _post(query, payload, options = {}) {
|
|
142
143
|
const {got} = await import('got');
|
|
143
|
-
const result = await got.post(
|
|
144
|
+
const result = await got.post(
|
|
145
|
+
query,
|
|
146
|
+
this.#buildOptions({json: payload, ...options})
|
|
147
|
+
);
|
|
144
148
|
return result.body;
|
|
145
149
|
}
|
|
146
150
|
|
package/lib/yaml.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const fse = require('fs-extra');
|
|
4
4
|
|
|
5
5
|
exports.fromFile = function (yamlFile) {
|
|
6
|
-
|
|
6
|
+
const yaml = require('js-yaml');
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const data = fse.readFileSync(yamlFile, 'utf8');
|
|
9
9
|
return yaml.safeLoad(data);
|
|
10
10
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xcraft-core-utils",
|
|
3
|
-
"version": "4.18.
|
|
3
|
+
"version": "4.18.2",
|
|
4
4
|
"description": "Xcraft utils",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"engines": {
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"escape-regexp": "0.0.1",
|
|
26
26
|
"escape-string-regexp": "^1.0.5",
|
|
27
27
|
"figlet": "^1.2.1",
|
|
28
|
-
"fs-extra": "^
|
|
28
|
+
"fs-extra": "^11.3.0",
|
|
29
29
|
"got": "^13.0.0",
|
|
30
30
|
"gigawatts": "^4.0.1",
|
|
31
31
|
"js-yaml": "^3.9.0",
|