/
eapostnova
/
2026-1--study--simulation-modeling
Обзор
Документация
Войти
/
eapostnova
/
2026-1--study--simulation-modeling
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
3
CI/CD
Аналитика
Безопасность
develop
node_modules/get-pkg-repo/src/cli.js
77 строк
2 KB
Елизавета Постнова
chore(site): add changelog
06 мар 2026, 00:34
Верифицирован
06 мар 2026, 00:34
8cca814
Код
Авторство
О чём код?
#!/usr/bin/env node 'use strict'; const fs = require(`fs`); const getPkgRepo = require(`../`); const through = require(`through2`); const util = require(`util`); const yargs = require('yargs/yargs')(process.argv.slice(2)) .usage( '\nPractice writing repository URL or validate the repository in a package.json file. If used without specifying a package.json file path, you will enter an interactive shell. Otherwise, the repository info in package.json is printed.' ) .scriptName('get-pkg-repo') .command('$0') .command('<path> [<path> ...]') .example('get-pkg-repo') .example('get-pkg-repo package.json') .example('cat package.json | get-pkg-repo') .help().argv; const input = yargs._; if (process.stdin.isTTY) { if (input.length > 0) { input.forEach(path => { let repo; fs.readFile(path, 'utf8', (err, data) => { if (err) { console.error(err); return; } try { repo = getPkgRepo(JSON.parse(data)); console.log(repo); } catch (e) { console.error(`${path}: ${e.toString()}`); } }); }); } else { process.stdin .pipe( through.obj((chunk, enc, cb) => { let repo; const pkgData = { repository: chunk.toString(), }; try { repo = getPkgRepo(pkgData); cb(null, util.format(repo) + '\n'); } catch (e) { console.error(e.toString()); cb(); } }) ) .pipe(process.stdout); } } else { process.stdin .pipe( through.obj((chunk, enc, cb) => { let repo; try { repo = getPkgRepo(JSON.parse(chunk.toString())); } catch (e) { console.error(e.toString()); process.exit(1); } cb(null, util.format(repo) + '\n'); }) ) .pipe(process.stdout); }