UNPKG

fs-match

Version:

A NodeJS package for finding folders, files & apps by Regular expression based on Asynchronous iteration of ES 9 & TypeScript

58 lines (57 loc) 2.23 kB
#! /usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const jsx_runtime_1 = require("commander-jsx/jsx-runtime"); const commander_jsx_1 = require("commander-jsx"); const promises_1 = require("fs/promises"); const path_1 = require("path"); const core_1 = require("./core"); async function match({ 'max-count': maxCount, 'ini-file': iniFile, 'NPM-config': NPMConfig }, ...list) { var _a, e_1, _b, _c; const show_log = iniFile || NPMConfig; let count = 0; if (show_log) console.time('Search'); try { for (var _d = true, _e = tslib_1.__asyncValues((0, core_1.which)(...list)), _f; _f = await _e.next(), _a = _f.done, !_a; _d = true) { _c = _f.value; _d = false; const path = _c; const name = list.find(name => (0, path_1.parse)(path).base.startsWith(name)) || ''; console.info((show_log || list[1] ? `${name}=` : '') + path); if (iniFile || NPMConfig) await (0, promises_1.appendFile)(iniFile || '.env', `${name}=${path}\n`); if (++count >= +maxCount) break; } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (!_d && !_a && (_b = _e.return)) await _b.call(_e); } finally { if (e_1) throw e_1.error; } } if (!show_log) return; console.info('--------------------'); console.timeEnd('Search'); process.exit(); } commander_jsx_1.Command.execute((0, jsx_runtime_1.jsx)(commander_jsx_1.Command, { parameters: "[name ...]", description: "Search App paths with App Name", options: { 'max-count': { shortcut: 'm', parameters: '<number>', description: 'Limit the number of results' }, 'ini-file': { shortcut: 'f', parameters: '<path>', description: 'Append result to an ini-like file' }, 'NPM-config': { shortcut: 'c', description: 'Append result to ".env" file in working directory (since npm@9 & fs-match@1.7)' } }, executor: match }), process.argv.slice(2));