-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bin.mjs
executable file
·52 lines (40 loc) · 1.12 KB
/
bin.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#! /usr/bin/env node
import { readFile } from 'fs/promises';
import path from 'path';
import validateRemote from './validateRemote.mjs';
import getResults from './results.mjs';
import pargs from './pargs.mjs';
async function getHelpText() {
return `${await readFile(path.join(import.meta.dirname, './help.txt'), 'utf-8')}`;
}
const {
values: { help },
positionals,
errors,
} = await pargs(
import.meta.filename,
{
options: {
help: { type: 'boolean' },
},
allowPositionals: 1,
},
);
const remote = validateRemote(positionals[0] ?? 'origin');
if (typeof remote !== 'string') {
errors.push(remote.error);
}
if (help || errors.length > 0) {
const helpText = await getHelpText();
if (errors.length === 0) {
console.log(helpText);
} else {
console.error(`${helpText}${errors.length === 0 ? '' : '\n'}`);
process.exitCode ||= parseInt('1'.repeat(errors.length), 2);
errors.forEach((error) => console.error(error));
}
process.exit();
}
// eslint-disable-next-line no-extra-parens
const results = Array.from(getResults(/** @type {string} */ (remote)), (x) => `Co-authored-by: ${x}`);
console.log(results.join('\n'));