luca 1.0.0 → 1.0.1
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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Luca · [](https://github.com/iZemil/luca/blob/main/LICENSE) 
|
|
2
2
|
|
|
3
|
-
Tiny [
|
|
3
|
+
Tiny [NPM package](https://www.npmjs.com/package/luca) to check urls by name list and getting statuses.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
package/dist/config/runConfig.js
CHANGED
|
@@ -35,7 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.runConfig = void 0;
|
|
38
|
+
exports.runConfig = exports.isAxiosError = void 0;
|
|
39
39
|
const axios_1 = __importDefault(require("axios"));
|
|
40
40
|
const chalk_1 = __importDefault(require("chalk"));
|
|
41
41
|
const fs = __importStar(require("fs/promises"));
|
|
@@ -48,40 +48,47 @@ function isAxiosError(error) {
|
|
|
48
48
|
}
|
|
49
49
|
return false;
|
|
50
50
|
}
|
|
51
|
+
exports.isAxiosError = isAxiosError;
|
|
51
52
|
const log = console.log;
|
|
53
|
+
// TODO: error retry
|
|
54
|
+
// TODO: run from last element
|
|
55
|
+
// TODO: clear result
|
|
56
|
+
// TODO: validat config - no config
|
|
52
57
|
const runConfig = (options = require((0, consts_1.getConfigPath)())) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
58
|
const resultPath = (0, consts_1.getResultPath)();
|
|
54
59
|
try {
|
|
55
|
-
(0, validateConfig_1.validateConfig)(options);
|
|
56
60
|
log(chalk_1.default.blue('Luca is running...'));
|
|
57
|
-
const
|
|
61
|
+
const config = (0, validateConfig_1.validateConfig)(options);
|
|
62
|
+
const { baseUrl, items, query, handler } = config;
|
|
58
63
|
const total = items.length;
|
|
59
64
|
let index = 0;
|
|
60
65
|
for (const item of items) {
|
|
66
|
+
const num = (index += 1);
|
|
67
|
+
const isFirst = num === 1;
|
|
68
|
+
const isLast = num === total;
|
|
61
69
|
const url = query(baseUrl, item);
|
|
62
|
-
let status = undefined;
|
|
63
70
|
let response = null;
|
|
71
|
+
let isErroredRequest = false;
|
|
64
72
|
try {
|
|
65
|
-
response =
|
|
66
|
-
status = response.status;
|
|
73
|
+
response = yield axios_1.default.get(url);
|
|
67
74
|
}
|
|
68
75
|
catch (e) {
|
|
76
|
+
isErroredRequest = true;
|
|
69
77
|
if (isAxiosError(e) && e.response) {
|
|
70
|
-
|
|
78
|
+
response = e.response;
|
|
71
79
|
}
|
|
72
80
|
}
|
|
73
|
-
|
|
81
|
+
finally {
|
|
82
|
+
log(chalk_1.default.blue(`${num}/${total}`), `GET ${chalk_1.default[isErroredRequest ? 'red' : 'green'](`(${response === null || response === void 0 ? void 0 : response.status})`)}:`, url);
|
|
83
|
+
}
|
|
74
84
|
try {
|
|
75
85
|
const data = handler(response, item);
|
|
76
|
-
const isFirst = index === 0;
|
|
77
|
-
const isLast = index + 1 === total;
|
|
78
86
|
yield fs.appendFile(resultPath, `${isFirst ? '[' : ''}${JSON.stringify(data)}${isLast ? ']' : ','}`);
|
|
79
87
|
}
|
|
80
88
|
catch (error) {
|
|
81
89
|
console.error('handler error', error);
|
|
82
90
|
}
|
|
83
91
|
finally {
|
|
84
|
-
index += 1;
|
|
85
92
|
yield (0, utils_1.delay)(options.delay);
|
|
86
93
|
}
|
|
87
94
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { TConfig } from './types';
|
|
2
|
-
export declare const validateConfig: (config: TConfig) =>
|
|
2
|
+
export declare const validateConfig: (config: TConfig) => TConfig;
|