Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (51 loc) · 1.53 KB
/
Copy pathindex.js
File metadata and controls
58 lines (51 loc) · 1.53 KB
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
53
54
55
56
57
58
#!/usr/bin/env node
/**
* @copyright 2022 John Wiley & Sons, Inc.
* @license MIT
*/
import EleventyFetch from '@11ty/eleventy-fetch';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import { readdir } from 'fs/promises';
const { argv } = yargs(hideBin(process.argv))
.scriptName('gh-org-repos')
.usage(
'$0 [path] [org]',
'Match local folder to GitHub repo list.',
(y) => {
y.positional('path', {
describe: 'Path to a directory to compare to GitHub',
type: 'string',
default: '.'
});
y.positional('org', {
describe: 'GitHub orginization or username for repo list.',
type: 'string'
});
}
)
.help()
.version();
(async () => {
// get the list of folder names
const directories = await (async () => {
const dirs = await readdir(argv.path, { withFileTypes: true });
return dirs.filter((d) => d.isDirectory()).map((d) => d.name).sort();
})();
// get the list of repo names
const repos = await EleventyFetch(
`https://api.github.com/orgs/${argv.org}/repos?per_page=1000`,
{ directory: '.cache', duration: '1d', type: 'json' }
).then((rv) => rv.map((repo) => repo.name).sort());
// combine the list
const everything = repos.concat(directories);
// are in the current directory (assuming no renames...)
console.log(' L', ' R');
(new Set(everything.sort())).forEach((name) => {
console.log(
(directories.includes(name) ? '✅' : '❌'),
(repos.includes(name) ? '✅' : '❌'),
name
);
});
})();