luca 1.1.2 → 2.0.0
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 +2 -1
- package/dist/cli/cli.d.ts +12 -0
- package/dist/cli/cli.js +48 -0
- package/dist/cli/common.d.ts +2 -0
- package/dist/cli/common.js +6 -0
- package/dist/cli/index.js +2 -2
- package/dist/cli/run.d.ts +1 -12
- package/dist/cli/run.js +31 -35
- package/dist/core/index.d.ts +4 -0
- package/dist/core/index.js +32 -0
- package/dist/core/read.d.ts +2 -0
- package/dist/core/read.js +29 -0
- package/dist/core/request.d.ts +1 -0
- package/dist/core/write.d.ts +2 -0
- package/dist/core/write.js +21 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/utils/common.d.ts +7 -0
- package/dist/utils/common.js +31 -26
- package/dist/utils/consts.d.ts +3 -0
- package/dist/utils/consts.js +11 -0
- package/dist/utils/dict.d.ts +1 -0
- package/dist/utils/dict.js +7 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/log.d.ts +1 -0
- package/dist/utils/log.js +5 -0
- package/dist/utils/types.d.ts +1 -0
- package/dist/utils/types.js +2 -0
- package/dist/utils/utils.test.d.ts +1 -0
- package/dist/utils/utils.test.js +7 -0
- package/package.json +13 -21
- package/dist/config/consts.d.ts +0 -2
- package/dist/config/consts.js +0 -29
- package/dist/config/default.d.ts +0 -8
- package/dist/config/default.js +0 -15
- package/dist/config/initConfig.d.ts +0 -1
- package/dist/config/initConfig.js +0 -52
- package/dist/config/openConfig.d.ts +0 -2
- package/dist/config/openConfig.js +0 -24
- package/dist/config/runConfig.d.ts +0 -3
- package/dist/config/runConfig.js +0 -117
- package/dist/config/types.d.ts +0 -13
- /package/dist/{config/types.js → core/request.js} +0 -0
package/README.md
CHANGED
|
@@ -14,5 +14,6 @@ Tiny [NPM package](https://www.npmjs.com/package/luca) to check urls by name lis
|
|
|
14
14
|
|
|
15
15
|
## Development
|
|
16
16
|
|
|
17
|
+
- install ts-node globally `npm i ts-node -g`
|
|
17
18
|
- main lib dev `yarn dev` and work with dev.ts file
|
|
18
|
-
- cli dev `
|
|
19
|
+
- cli dev `ts-node ./src/cli --help`
|
package/dist/cli/cli.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.start = void 0;
|
|
16
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
17
|
+
const helpers_1 = require("yargs/helpers");
|
|
18
|
+
const utils_1 = require("../utils");
|
|
19
|
+
const common_1 = require("./common");
|
|
20
|
+
const run_1 = require("./run");
|
|
21
|
+
/**
|
|
22
|
+
* @docs https://yargs.js.org/docs
|
|
23
|
+
*/
|
|
24
|
+
const start = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
return (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
|
|
26
|
+
.usage("Luca's manual")
|
|
27
|
+
// run command
|
|
28
|
+
.command({
|
|
29
|
+
command: 'run',
|
|
30
|
+
describe: 'Run mass requests (see examples)',
|
|
31
|
+
handler: (args) => {
|
|
32
|
+
const { dict, url } = args;
|
|
33
|
+
(0, utils_1.showErrorIf)(!(0, utils_1.isString)(dict), '--dict is required', 'example: --dict=1_char');
|
|
34
|
+
(0, utils_1.showErrorIf)(!(0, utils_1.isString)(url), `--url is required', 'example: ${(0, common_1.getUrlMaskExample)()}`);
|
|
35
|
+
(0, run_1.run)(dict, url);
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
.example(`luca run ${(0, common_1.getUrlMaskExample)()} --dict=1_char`, `for built-in dictionaries (${utils_1.DICT_NAMES.join('|')})`)
|
|
39
|
+
.example(`luca run ${(0, common_1.getUrlMaskExample)()} --dict=./my-dict.txt`, 'for your txt dict path')
|
|
40
|
+
.command({
|
|
41
|
+
command: '*',
|
|
42
|
+
handler: () => void yargs_1.default.showHelp(),
|
|
43
|
+
})
|
|
44
|
+
.demandCommand()
|
|
45
|
+
.alias('h', 'help')
|
|
46
|
+
.alias('v', 'version').argv;
|
|
47
|
+
});
|
|
48
|
+
exports.start = start;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getUrlMaskExample = exports.WORD_PATTERN = void 0;
|
|
4
|
+
exports.WORD_PATTERN = '{0}';
|
|
5
|
+
const getUrlMaskExample = (baseUrl = 'https://github.com') => `--url='${baseUrl}/${exports.WORD_PATTERN}'`;
|
|
6
|
+
exports.getUrlMaskExample = getUrlMaskExample;
|
package/dist/cli/index.js
CHANGED
package/dist/cli/run.d.ts
CHANGED
|
@@ -1,12 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* @docs https://yargs.js.org/docs
|
|
3
|
-
*/
|
|
4
|
-
export declare const run: () => Promise<{
|
|
5
|
-
[x: string]: unknown;
|
|
6
|
-
_: (string | number)[];
|
|
7
|
-
$0: string;
|
|
8
|
-
} | {
|
|
9
|
-
[x: string]: unknown;
|
|
10
|
-
_: (string | number)[];
|
|
11
|
-
$0: string;
|
|
12
|
-
}>;
|
|
1
|
+
export declare const run: (dict: string, urlMask: string) => void;
|
package/dist/cli/run.js
CHANGED
|
@@ -1,42 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
exports.run = void 0;
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
const core_1 = require("../core");
|
|
10
|
+
const write_1 = require("../core/write");
|
|
11
|
+
const utils_1 = require("../utils");
|
|
12
|
+
const common_1 = require("./common");
|
|
13
|
+
// [x] Github username
|
|
14
|
+
// [x] Npm package
|
|
15
|
+
// [ ] Telegram username/botname
|
|
16
|
+
// [ ] Whois small size domains
|
|
17
|
+
const formatUrl = (urlMask) => {
|
|
18
|
+
if (!['http', 'https'].includes(urlMask)) {
|
|
19
|
+
return `https://${urlMask}`;
|
|
20
|
+
}
|
|
21
|
+
return urlMask;
|
|
22
|
+
};
|
|
23
|
+
const getUrlByMask = (urlMask) => (word) => {
|
|
24
|
+
const formatted = formatUrl(urlMask);
|
|
25
|
+
if (formatted.includes(common_1.WORD_PATTERN)) {
|
|
26
|
+
return formatted.replace(common_1.WORD_PATTERN, word);
|
|
27
|
+
}
|
|
28
|
+
return `${formatted}/${word}`;
|
|
29
|
+
};
|
|
30
|
+
const run = (dict, urlMask) => {
|
|
31
|
+
const isBuiltInDict = utils_1.DICT_NAMES.includes(dict);
|
|
32
|
+
const dictPath = isBuiltInDict ? (0, utils_1.getDict)(dict) : (0, path_1.resolve)(dict);
|
|
33
|
+
(0, core_1.luca)(dictPath, getUrlByMask(urlMask)).subscribe({
|
|
34
|
+
next: ({ res }) => (0, utils_1.log)(`${(0, utils_1.ifSuccessResponse)(res.status, chalk_1.default.green, chalk_1.default.red)} ${res.config.url}`)(),
|
|
35
|
+
complete: (0, utils_1.log)(`\n${chalk_1.default.green('Luca finished')} ${(0, path_1.resolve)(write_1.LUCA_LOG_PATH)}`),
|
|
36
|
+
});
|
|
37
|
+
};
|
|
42
38
|
exports.run = run;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.luca = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const rxjs_1 = require("rxjs");
|
|
18
|
+
const read_1 = require("./read");
|
|
19
|
+
const write_1 = require("./write");
|
|
20
|
+
const luca = (dict, getUrl) => (0, read_1.parse)(dict).pipe((0, rxjs_1.concatMap)((arr) => arr.map((item) => (0, rxjs_1.of)(getUrl(item)).pipe((0, rxjs_1.delay)(500), (0, rxjs_1.map)((url) => axios_1.default.get(url)), (0, rxjs_1.mergeMap)((res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
try {
|
|
22
|
+
return yield res;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
return error.response;
|
|
26
|
+
}
|
|
27
|
+
})), (0, rxjs_1.map)((res) => {
|
|
28
|
+
return {
|
|
29
|
+
res: res,
|
|
30
|
+
};
|
|
31
|
+
}), (0, rxjs_1.tap)(({ res }) => (0, write_1.writeLog)(res.config.url, res.status))))), (0, rxjs_1.concatAll)());
|
|
32
|
+
exports.luca = luca;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.parse = exports.read = void 0;
|
|
13
|
+
const function_1 = require("fp-ts/lib/function");
|
|
14
|
+
const promises_1 = require("fs/promises");
|
|
15
|
+
const path_1 = require("path");
|
|
16
|
+
const rxjs_1 = require("rxjs");
|
|
17
|
+
const utils_1 = require("../utils");
|
|
18
|
+
const log_1 = require("../utils/log");
|
|
19
|
+
const getFileContent = (path) => (0, promises_1.readFile)(path, { encoding: 'utf8' })
|
|
20
|
+
.catch((0, log_1.log)('read error'))
|
|
21
|
+
.then((data) => data !== null && data !== void 0 ? data : null);
|
|
22
|
+
const parseLines = (fileContent) => { var _a; return (_a = fileContent === null || fileContent === void 0 ? void 0 : fileContent.split('\n')) !== null && _a !== void 0 ? _a : []; };
|
|
23
|
+
const rmInvalids = (0, utils_1.filter)((val) => val.trim() !== '');
|
|
24
|
+
const findUniqs = (list) => Array.from(new Set(list));
|
|
25
|
+
const parseTxt = (content) => (0, function_1.pipe)(content, parseLines, findUniqs, rmInvalids);
|
|
26
|
+
const read = (filepath) => (0, rxjs_1.of)((0, path_1.resolve)(filepath)).pipe((0, rxjs_1.map)(getFileContent));
|
|
27
|
+
exports.read = read;
|
|
28
|
+
const parse = (filepath) => (0, exports.read)(filepath).pipe((0, rxjs_1.mergeMap)((file) => __awaiter(void 0, void 0, void 0, function* () { return file; })), (0, rxjs_1.map)(parseTxt));
|
|
29
|
+
exports.parse = parse;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.writeLog = exports.LUCA_LOG_PATH = void 0;
|
|
13
|
+
const promises_1 = require("fs/promises");
|
|
14
|
+
const log_1 = require("../utils/log");
|
|
15
|
+
exports.LUCA_LOG_PATH = 'luca.log';
|
|
16
|
+
const writeLog = (url, status) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
return (0, promises_1.appendFile)(exports.LUCA_LOG_PATH, `\n${JSON.stringify({ url, status })}`)
|
|
18
|
+
.then(() => void 1)
|
|
19
|
+
.catch((0, log_1.log)('writeLog error'));
|
|
20
|
+
});
|
|
21
|
+
exports.writeLog = writeLog;
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { luca } from './core';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.luca = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "luca", { enumerable: true, get: function () { return
|
|
4
|
+
var core_1 = require("./core");
|
|
5
|
+
Object.defineProperty(exports, "luca", { enumerable: true, get: function () { return core_1.luca; } });
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
export declare function checkPath(path: string, isDir?: boolean): boolean;
|
|
2
2
|
export declare const wait: (ms: number) => Promise<unknown>;
|
|
3
|
+
export declare function curry(fn: any): (...args: any[]) => any;
|
|
4
|
+
export declare const filter: <T>(predicate: (value: T) => boolean) => (list: T[]) => T[];
|
|
5
|
+
declare type TNumStr = string | number;
|
|
6
|
+
export declare const ifSuccessResponse: (status: TNumStr, yes: (status: TNumStr) => string, no: (status: TNumStr) => string) => string;
|
|
7
|
+
export declare const isString: <T>(str: T) => boolean;
|
|
8
|
+
export declare const showErrorIf: (condition: boolean, msg: string, submsg?: string) => void;
|
|
9
|
+
export {};
|
package/dist/utils/common.js
CHANGED
|
@@ -1,27 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -31,12 +8,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
31
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
9
|
});
|
|
33
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
34
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.wait = exports.checkPath = void 0;
|
|
36
|
-
const
|
|
15
|
+
exports.showErrorIf = exports.isString = exports.ifSuccessResponse = exports.filter = exports.curry = exports.wait = exports.checkPath = void 0;
|
|
16
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
17
|
+
const fs_1 = require("fs");
|
|
18
|
+
const log_1 = require("./log");
|
|
37
19
|
function checkPath(path, isDir = false) {
|
|
38
20
|
try {
|
|
39
|
-
const stat =
|
|
21
|
+
const stat = (0, fs_1.lstatSync)(path);
|
|
40
22
|
if (isDir) {
|
|
41
23
|
return stat.isDirectory();
|
|
42
24
|
}
|
|
@@ -50,3 +32,26 @@ function checkPath(path, isDir = false) {
|
|
|
50
32
|
exports.checkPath = checkPath;
|
|
51
33
|
const wait = (ms) => __awaiter(void 0, void 0, void 0, function* () { return new Promise((res) => setTimeout(res, ms)); });
|
|
52
34
|
exports.wait = wait;
|
|
35
|
+
function curry(fn) {
|
|
36
|
+
const arity = fn.length;
|
|
37
|
+
return function $curry(...args) {
|
|
38
|
+
if (args.length < arity) {
|
|
39
|
+
return $curry.bind(null, ...args);
|
|
40
|
+
}
|
|
41
|
+
return fn.call(null, ...args);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
exports.curry = curry;
|
|
45
|
+
const filter = (predicate) => (list) => list.filter(predicate);
|
|
46
|
+
exports.filter = filter;
|
|
47
|
+
const ifSuccessResponse = (status, yes, no) => String(status).startsWith('2') ? yes(status) : no(status);
|
|
48
|
+
exports.ifSuccessResponse = ifSuccessResponse;
|
|
49
|
+
const isString = (str) => typeof str === 'string';
|
|
50
|
+
exports.isString = isString;
|
|
51
|
+
const showErrorIf = (condition, msg, submsg = '') => {
|
|
52
|
+
if (condition) {
|
|
53
|
+
(0, log_1.log)(chalk_1.default.red(msg))(submsg);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
exports.showErrorIf = showErrorIf;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DICT_NAMES = exports.DICTS = exports.DICTS_DIR = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
exports.DICTS_DIR = (0, path_1.resolve)('dicts');
|
|
7
|
+
exports.DICTS = (() => {
|
|
8
|
+
const files = (0, fs_1.readdirSync)(exports.DICTS_DIR);
|
|
9
|
+
return files;
|
|
10
|
+
})();
|
|
11
|
+
exports.DICT_NAMES = exports.DICTS.map((d) => d.split('.')[0]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getDict: (name: string) => string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDict = void 0;
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const consts_1 = require("./consts");
|
|
6
|
+
const getDict = (name) => (0, path_1.resolve)(consts_1.DICTS_DIR, `${name}.txt`);
|
|
7
|
+
exports.getDict = getDict;
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -15,3 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./consts"), exports);
|
|
19
|
+
__exportStar(require("./dict"), exports);
|
|
20
|
+
__exportStar(require("./log"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const log: (title?: string) => (data?: unknown) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare type Empty<T> = T | null | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const function_1 = require("fp-ts/lib/function");
|
|
4
|
+
const log_1 = require("./log");
|
|
5
|
+
const add = (x) => (y) => x + y;
|
|
6
|
+
const multiply = (x) => (y) => x * y;
|
|
7
|
+
(0, log_1.log)('check pipe fn')((0, function_1.pipe)(100, add(5), multiply(2)) === 210);
|
package/package.json
CHANGED
|
@@ -1,41 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "luca",
|
|
3
|
-
"description": "",
|
|
3
|
+
"description": "mass checker for http-requests",
|
|
4
4
|
"keywords": [],
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"version": "2.0.0",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
8
|
"bin": "dist/cli/index.js",
|
|
9
9
|
"private": false,
|
|
10
|
-
"
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
11
13
|
"repository": {
|
|
12
14
|
"type": "git",
|
|
13
15
|
"url": "https://github.com/iZemil/luca.git"
|
|
14
16
|
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
"license": "MIT",
|
|
19
|
-
"version": "1.1.2",
|
|
17
|
+
"author": {
|
|
18
|
+
"name": "zemil"
|
|
19
|
+
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "tsc",
|
|
22
|
-
"dev": "tsc-watch ./src/dev.ts --outDir ./dist/ --onSuccess \"node ./dist/dev.js\" --esModuleInterop"
|
|
23
|
-
"dev:cli": "tsc && node dist/cli/index.js",
|
|
24
|
-
"test": "jest"
|
|
22
|
+
"dev": "tsc-watch ./src/dev.ts --outDir ./dist/ --onSuccess \"node ./dist/dev.js\" --esModuleInterop"
|
|
25
23
|
},
|
|
26
24
|
"dependencies": {
|
|
27
25
|
"axios": "0.27.2",
|
|
28
26
|
"chalk": "4.1.2",
|
|
27
|
+
"fp-ts": "^2.16.1",
|
|
28
|
+
"rxjs": "^7.8.1",
|
|
29
29
|
"yargs": "17.6.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@trivago/prettier-plugin-sort-imports": "3.3.0",
|
|
33
|
-
"@types/glob": "8.0.0",
|
|
34
|
-
"@types/jest": "27.5.2",
|
|
35
|
-
"@types/lodash.camelcase": "4.3.7",
|
|
36
|
-
"@types/lodash.kebabcase": "4.1.7",
|
|
37
|
-
"@types/lodash.snakecase": "4.1.7",
|
|
38
|
-
"@types/lodash.startcase": "4.4.7",
|
|
39
33
|
"@types/node": "16.11.47",
|
|
40
34
|
"@types/yargs": "17.0.13",
|
|
41
35
|
"@typescript-eslint/eslint-plugin": "5.33.1",
|
|
@@ -45,10 +39,8 @@
|
|
|
45
39
|
"eslint-plugin-import": "2.26.0",
|
|
46
40
|
"eslint-plugin-simple-import-sort": "7.0.0",
|
|
47
41
|
"eslint-plugin-unused-imports": "2.0.0",
|
|
48
|
-
"jest": "^29.1.2",
|
|
49
42
|
"prettier": "^2.5.1",
|
|
50
43
|
"semantic-release": "19.0.3",
|
|
51
|
-
"ts-jest": "^29.0.3",
|
|
52
44
|
"ts-node": "^10.9.1",
|
|
53
45
|
"tsc-watch": "^5.0.3",
|
|
54
46
|
"typescript": "~4.6.2"
|
package/dist/config/consts.d.ts
DELETED
package/dist/config/consts.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.LOG_PATH = exports.CONFIG_PATH = void 0;
|
|
27
|
-
const path = __importStar(require("path"));
|
|
28
|
-
exports.CONFIG_PATH = path.resolve('luca.config.js');
|
|
29
|
-
exports.LOG_PATH = path.resolve('luca.log');
|
package/dist/config/default.d.ts
DELETED
package/dist/config/default.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = {
|
|
3
|
-
delay: 500,
|
|
4
|
-
baseUrl: 'https://www.npmjs.com/package',
|
|
5
|
-
query: (baseUrl, item) => {
|
|
6
|
-
return `${baseUrl}/${item}`;
|
|
7
|
-
},
|
|
8
|
-
handler: (response, item) => {
|
|
9
|
-
return {
|
|
10
|
-
item,
|
|
11
|
-
data: response.data,
|
|
12
|
-
};
|
|
13
|
-
},
|
|
14
|
-
items: ['foo', 'bar'],
|
|
15
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const initConfig: () => Promise<void>;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.initConfig = void 0;
|
|
39
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
40
|
-
const fs = __importStar(require("fs/promises"));
|
|
41
|
-
const path = __importStar(require("path"));
|
|
42
|
-
const consts_1 = require("./consts");
|
|
43
|
-
const initConfig = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
44
|
-
try {
|
|
45
|
-
yield fs.copyFile(path.resolve(__dirname, `default.js`), consts_1.CONFIG_PATH);
|
|
46
|
-
console.log(chalk_1.default.green(`Configuration file was created:\n> ${consts_1.CONFIG_PATH}`));
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
console.error(e);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
exports.initConfig = initConfig;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.openConfig = void 0;
|
|
4
|
-
const utils_1 = require("../utils");
|
|
5
|
-
const consts_1 = require("./consts");
|
|
6
|
-
const openConfig = () => {
|
|
7
|
-
if (!(0, utils_1.checkPath)(consts_1.CONFIG_PATH)) {
|
|
8
|
-
throw new Error(`Config not found`);
|
|
9
|
-
}
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
11
|
-
const config = require(consts_1.CONFIG_PATH);
|
|
12
|
-
const { baseUrl, items, query, handler } = config;
|
|
13
|
-
if (items.length === 0) {
|
|
14
|
-
throw new Error(`Specify config items, eg: items: ["foo", "bar"]`);
|
|
15
|
-
}
|
|
16
|
-
if (!baseUrl) {
|
|
17
|
-
throw new Error(`Specify config baseUrl`);
|
|
18
|
-
}
|
|
19
|
-
if (!handler) {
|
|
20
|
-
throw new Error(`Specify config handler`);
|
|
21
|
-
}
|
|
22
|
-
return config;
|
|
23
|
-
};
|
|
24
|
-
exports.openConfig = openConfig;
|
package/dist/config/runConfig.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.runConfig = exports.isAxiosError = void 0;
|
|
39
|
-
const axios_1 = __importDefault(require("axios"));
|
|
40
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
41
|
-
const fs = __importStar(require("fs/promises"));
|
|
42
|
-
const utils_1 = require("../utils");
|
|
43
|
-
const consts_1 = require("./consts");
|
|
44
|
-
const openConfig_1 = require("./openConfig");
|
|
45
|
-
function isAxiosError(error) {
|
|
46
|
-
if ('response' in error) {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
exports.isAxiosError = isAxiosError;
|
|
52
|
-
const log = console.log;
|
|
53
|
-
const ONE_MINUTE = 60 * 1000;
|
|
54
|
-
const handleRequest = (options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
const { url, num, total, sleepDelay = ONE_MINUTE, sleepCount = 0 } = options;
|
|
56
|
-
let response = null;
|
|
57
|
-
let isErroredRequest = false;
|
|
58
|
-
try {
|
|
59
|
-
response = yield axios_1.default.get(url);
|
|
60
|
-
}
|
|
61
|
-
catch (e) {
|
|
62
|
-
isErroredRequest = true;
|
|
63
|
-
if (isAxiosError(e) && e.response) {
|
|
64
|
-
response = e.response;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
finally {
|
|
68
|
-
log(chalk_1.default.blue(`${num}/${total}`), `GET ${chalk_1.default[isErroredRequest ? 'red' : 'green'](`(${response === null || response === void 0 ? void 0 : response.status})`)}:`, url);
|
|
69
|
-
}
|
|
70
|
-
// Handle: Too Many Requests
|
|
71
|
-
if (sleepCount > 3) {
|
|
72
|
-
throw new Error(`Exceeded ${sleepCount} requests`);
|
|
73
|
-
}
|
|
74
|
-
if (response && response.status === 429) {
|
|
75
|
-
log(chalk_1.default.grey(`sleep...`));
|
|
76
|
-
yield (0, utils_1.wait)(sleepDelay);
|
|
77
|
-
return handleRequest(Object.assign(Object.assign({}, options), { sleepDelay: sleepDelay + ONE_MINUTE, sleepCount: sleepCount + 1 }));
|
|
78
|
-
}
|
|
79
|
-
return response;
|
|
80
|
-
});
|
|
81
|
-
const writeToLog = (...strs) => __awaiter(void 0, void 0, void 0, function* () {
|
|
82
|
-
yield fs.appendFile(consts_1.LOG_PATH, '\n' + strs.join('\n'));
|
|
83
|
-
});
|
|
84
|
-
// TODO: run from last log element
|
|
85
|
-
// TODO: add log name --name
|
|
86
|
-
const runConfig = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
87
|
-
try {
|
|
88
|
-
const config = (0, openConfig_1.openConfig)();
|
|
89
|
-
const { baseUrl, items, query } = config;
|
|
90
|
-
const total = items.length;
|
|
91
|
-
const axmTime = total * (config.delay + 300);
|
|
92
|
-
const axmMin = Math.floor(axmTime / 60000);
|
|
93
|
-
log(chalk_1.default.blue('Luca starts a session'), `approximate end in ${axmMin} minutes`);
|
|
94
|
-
yield writeToLog('Start session', `time: ${new Date()}`);
|
|
95
|
-
let index = 0;
|
|
96
|
-
for (const item of items) {
|
|
97
|
-
const num = (index += 1);
|
|
98
|
-
const url = query(baseUrl, item);
|
|
99
|
-
try {
|
|
100
|
-
const response = yield handleRequest({ url, num, total });
|
|
101
|
-
yield writeToLog(`\nurl: ${url}`, `status: ${response === null || response === void 0 ? void 0 : response.status}`, `data: ${response ? JSON.stringify(config.handler(response, item)) : null}`);
|
|
102
|
-
}
|
|
103
|
-
catch (error) {
|
|
104
|
-
console.error('handler error', error);
|
|
105
|
-
}
|
|
106
|
-
finally {
|
|
107
|
-
yield (0, utils_1.wait)(config.delay);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
log(chalk_1.default.green(`Luca finished:\n> ${consts_1.LOG_PATH}`));
|
|
111
|
-
writeToLog(`\nEnd session`, `time: ${new Date()}`, '');
|
|
112
|
-
}
|
|
113
|
-
catch (e) {
|
|
114
|
-
log(chalk_1.default.red(e));
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
exports.runConfig = runConfig;
|
package/dist/config/types.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { AxiosResponse } from 'axios';
|
|
2
|
-
export interface TConfig<T = unknown> {
|
|
3
|
-
baseUrl: string;
|
|
4
|
-
query: (baseUrl: string, item: T) => string;
|
|
5
|
-
/** ms delay after request */
|
|
6
|
-
delay: number;
|
|
7
|
-
handler: (response: AxiosResponse | null, item: T) => any;
|
|
8
|
-
items: T[];
|
|
9
|
-
}
|
|
10
|
-
export interface THandledData<T = unknown> {
|
|
11
|
-
status: number | null;
|
|
12
|
-
data: T | null;
|
|
13
|
-
}
|
|
File without changes
|