repospect 0.0.0-stage → 0.1.1
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/LICENSE +24 -0
- package/README.md +39 -2
- package/bin/repospect.js +59 -0
- package/package.json +32 -4
- package/src/analyze.js +300 -0
- package/src/generate.js +27 -0
- package/src/langs.js +105 -0
- package/src/markdown.js +97 -0
- package/src/open.js +29 -0
- package/src/render.js +254 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
|
+
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
7
|
+
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and successors.
|
|
12
|
+
We intend this dedication to be an overt act of relinquishment in
|
|
13
|
+
perpetuity of all present and future rights to this software under
|
|
14
|
+
copyright law.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
For more information, please refer to <https://unlicense.org>
|
package/README.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# repospect
|
|
2
|
+
|
|
3
|
+
**The grand tour of any codebase.** `repospect` analyzes a repository and writes a
|
|
4
|
+
single self-contained HTML page that gets a newcomer up to speed: overview stats,
|
|
5
|
+
quick-start commands, structure map, language breakdown, the README rendered inline,
|
|
6
|
+
a searchable file list, and git history — all offline, in one file.
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npx repospect # tour the current repo, open the page in your browser
|
|
12
|
+
npx repospect path/to/repo
|
|
13
|
+
repospect --out docs/ # write docs/index.html instead of a temp file
|
|
14
|
+
repospect --no-open # don't open a browser (CI, headless); prints the path
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
No network, no API keys, no dependencies — it reads the files, runs `git log` if
|
|
18
|
+
available, and writes one static page. Safe to run on any repo: by default nothing
|
|
19
|
+
is written into the analyzed repository, the page goes to a temp directory
|
|
20
|
+
(`os.tmpdir()`), which your OS cleans up on its own. Use `--out docs/` if you want
|
|
21
|
+
to keep it (e.g. commit it to a docs site — then add it to git deliberately).
|
|
22
|
+
|
|
23
|
+
## What the page shows
|
|
24
|
+
|
|
25
|
+
- **Overview** — files, lines of code, size, commit count
|
|
26
|
+
- **Quick start** — detected ecosystem (Node / Rust / Go / Python / Docker), install/test commands, scripts, CLI entry points
|
|
27
|
+
- **Structure** — top-level directories by size, "start here" key files, largest files
|
|
28
|
+
- **Languages** — byte-weighted language breakdown
|
|
29
|
+
- **README** — rendered inline (a small, escaped Markdown subset)
|
|
30
|
+
- **Files** — searchable index of every file
|
|
31
|
+
- **History** — branches, commit count, top contributors, recent commits
|
|
32
|
+
|
|
33
|
+
## Develop
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
npm test
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Zero runtime dependencies. Requires Node >= 18.
|
|
2
40
|
|
|
3
|
-
This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
|
package/bin/repospect.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { generate } from '../src/generate.js';
|
|
6
|
+
import { openInBrowser } from '../src/open.js';
|
|
7
|
+
|
|
8
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
9
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
|
10
|
+
|
|
11
|
+
const USAGE = `repospect v${pkg.version}
|
|
12
|
+
|
|
13
|
+
Usage:
|
|
14
|
+
repospect [path] Analyze a repository (default: current directory), write a
|
|
15
|
+
self-contained tour page to a temp file and open it in
|
|
16
|
+
your browser
|
|
17
|
+
repospect --out <dir> Write the page to <dir>/index.html instead of a temp file
|
|
18
|
+
repospect --no-open Don't open a browser (just print the path)
|
|
19
|
+
repospect --version Print version
|
|
20
|
+
repospect --help Show this help
|
|
21
|
+
|
|
22
|
+
The page is fully self-contained: no network, no external assets. Nothing is
|
|
23
|
+
written into the analyzed repository unless you pass --out.`;
|
|
24
|
+
|
|
25
|
+
function main(argv) {
|
|
26
|
+
const args = [...argv];
|
|
27
|
+
let target = '.';
|
|
28
|
+
let outDir = null;
|
|
29
|
+
let open = true;
|
|
30
|
+
|
|
31
|
+
while (args.length) {
|
|
32
|
+
const arg = args.shift();
|
|
33
|
+
if (arg === '--help' || arg === '-h') { console.log(USAGE); return 0; }
|
|
34
|
+
if (arg === '--version' || arg === '-v') { console.log(pkg.version); return 0; }
|
|
35
|
+
if (arg === '--out') {
|
|
36
|
+
outDir = args.shift();
|
|
37
|
+
if (!outDir) { console.error('repospect: --out requires a directory'); return 2; }
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (arg === '--no-open') { open = false; continue; }
|
|
41
|
+
if (arg.startsWith('--out=')) { outDir = arg.slice('--out='.length); continue; }
|
|
42
|
+
if (arg.startsWith('-')) { console.error(`repospect: unknown flag ${arg}\n\n${USAGE}`); return 2; }
|
|
43
|
+
target = arg;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
const { dest, analysis } = generate(target, { outDir });
|
|
48
|
+
console.log(`repospect: ${analysis.name} — ${analysis.totals.files} files, ${analysis.languages.length} languages`);
|
|
49
|
+
console.log(`wrote ${dest}`);
|
|
50
|
+
if (open && openInBrowser(dest)) console.log('opened in your browser');
|
|
51
|
+
else if (open) console.log(`could not open a browser — open the file yourself: ${dest}`);
|
|
52
|
+
return 0;
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.error(`repospect: ${err.message}`);
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
process.exit(main(process.argv.slice(2)));
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "repospect",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Generate a self-contained HTML tour of a repository — run `repospect`, get a page opened in your browser.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"repospect": "bin/repospect.js"
|
|
8
|
+
},
|
|
9
|
+
"exports": {
|
|
10
|
+
"./analyze": "./src/analyze.js",
|
|
11
|
+
"./render": "./src/render.js",
|
|
12
|
+
"./generate": "./src/generate.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin",
|
|
16
|
+
"src"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "node --test test/"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"codebase",
|
|
23
|
+
"onboarding",
|
|
24
|
+
"documentation",
|
|
25
|
+
"explain",
|
|
26
|
+
"repo",
|
|
27
|
+
"tour",
|
|
28
|
+
"cli"
|
|
29
|
+
],
|
|
30
|
+
"license": "Unlicense",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/analyze.js
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { LANGUAGES, FILENAME_LANGUAGES, IGNORED_DIRS, KEY_FILENAMES } from './langs.js';
|
|
5
|
+
|
|
6
|
+
const MAX_FILE_BYTES = 1024 * 1024; // read at most 1 MB of any file
|
|
7
|
+
const MAX_LINE_COUNT_BYTES = 512 * 1024; // only count lines in files below this
|
|
8
|
+
const MAX_README_BYTES = 256 * 1024;
|
|
9
|
+
|
|
10
|
+
function languageFor(rel) {
|
|
11
|
+
const base = path.basename(rel).toLowerCase();
|
|
12
|
+
if (FILENAME_LANGUAGES[base]) return FILENAME_LANGUAGES[base];
|
|
13
|
+
const ext = path.extname(base).toLowerCase();
|
|
14
|
+
return LANGUAGES[ext] || null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function walk(root) {
|
|
18
|
+
const out = [];
|
|
19
|
+
const stack = [''];
|
|
20
|
+
while (stack.length) {
|
|
21
|
+
const rel = stack.pop();
|
|
22
|
+
const abs = path.join(root, rel);
|
|
23
|
+
let entries;
|
|
24
|
+
try {
|
|
25
|
+
entries = fs.readdirSync(abs, { withFileTypes: true });
|
|
26
|
+
} catch {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
for (const entry of entries) {
|
|
30
|
+
if (entry.name.startsWith('.git') && entry.isDirectory()) continue;
|
|
31
|
+
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
32
|
+
if (entry.isDirectory()) {
|
|
33
|
+
if (IGNORED_DIRS.has(entry.name.toLowerCase())) continue;
|
|
34
|
+
stack.push(childRel);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (!entry.isFile()) continue;
|
|
38
|
+
let size = 0;
|
|
39
|
+
try {
|
|
40
|
+
size = fs.statSync(path.join(root, childRel)).size;
|
|
41
|
+
} catch {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
out.push({ path: childRel, size });
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function readSmall(abs, maxBytes) {
|
|
51
|
+
try {
|
|
52
|
+
const fd = fs.openSync(abs, 'r');
|
|
53
|
+
try {
|
|
54
|
+
const buf = Buffer.alloc(Math.min(maxBytes, fs.fstatSync(fd).size));
|
|
55
|
+
const n = fs.readSync(fd, buf, 0, buf.length, 0);
|
|
56
|
+
return buf.subarray(0, n).toString('utf8');
|
|
57
|
+
} finally {
|
|
58
|
+
fs.closeSync(fd);
|
|
59
|
+
}
|
|
60
|
+
} catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function countLines(abs) {
|
|
66
|
+
try {
|
|
67
|
+
const stat = fs.statSync(abs);
|
|
68
|
+
if (stat.size > MAX_LINE_COUNT_BYTES) return null;
|
|
69
|
+
const buf = fs.readFileSync(abs);
|
|
70
|
+
if (buf.includes(0)) return null; // binary
|
|
71
|
+
let n = 0;
|
|
72
|
+
for (let i = 0; i < buf.length; i++) if (buf[i] === 10) n++;
|
|
73
|
+
return buf.length && buf[buf.length - 1] !== 10 ? n + 1 : n;
|
|
74
|
+
} catch {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function gitInfo(root) {
|
|
80
|
+
const run = (args) => {
|
|
81
|
+
try {
|
|
82
|
+
return execFileSync('git', ['-C', root, ...args], {
|
|
83
|
+
encoding: 'utf8',
|
|
84
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
85
|
+
timeout: 5000,
|
|
86
|
+
}).trim();
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
if (!fs.existsSync(path.join(root, '.git'))) return null;
|
|
92
|
+
const branch = run(['rev-parse', '--abbrev-ref', 'HEAD']);
|
|
93
|
+
const countRaw = run(['rev-list', '--count', 'HEAD']);
|
|
94
|
+
const lastDate = run(['log', '-1', '--format=%cs']);
|
|
95
|
+
const firstDate = run(['log', '--reverse', '--format=%cs', '--', '.']) ?.split('\n')[0] ?? null;
|
|
96
|
+
const recent = run(['log', '-8', '--format=%h %cs %s']);
|
|
97
|
+
const authorsRaw = run(['log', '--format=%an']);
|
|
98
|
+
const authors = authorsRaw
|
|
99
|
+
? Object.entries(
|
|
100
|
+
authorsRaw.split('\n').reduce((acc, a) => {
|
|
101
|
+
if (a) acc[a] = (acc[a] || 0) + 1;
|
|
102
|
+
return acc;
|
|
103
|
+
}, {})
|
|
104
|
+
)
|
|
105
|
+
.sort((a, b) => b[1] - a[1])
|
|
106
|
+
.slice(0, 8)
|
|
107
|
+
.map(([name, commits]) => ({ name, commits }))
|
|
108
|
+
: [];
|
|
109
|
+
return {
|
|
110
|
+
branch,
|
|
111
|
+
commitCount: countRaw ? Number(countRaw) : null,
|
|
112
|
+
firstCommit: firstDate || null,
|
|
113
|
+
lastCommit: lastDate,
|
|
114
|
+
recent: recent ? recent.split('\n').filter(Boolean) : [],
|
|
115
|
+
authors,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function parseJson(abs) {
|
|
120
|
+
try {
|
|
121
|
+
return JSON.parse(fs.readFileSync(abs, 'utf8'));
|
|
122
|
+
} catch {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function parseManifests(root) {
|
|
128
|
+
const found = {};
|
|
129
|
+
const read = (rel) => (fs.existsSync(path.join(root, rel)) ? readSmall(path.join(root, rel), MAX_FILE_BYTES) : null);
|
|
130
|
+
|
|
131
|
+
const pkg = read('package.json');
|
|
132
|
+
if (pkg) {
|
|
133
|
+
const json = parseJson(path.join(root, 'package.json'));
|
|
134
|
+
if (json) {
|
|
135
|
+
found.node = {
|
|
136
|
+
ecosystem: 'Node.js',
|
|
137
|
+
name: json.name ?? null,
|
|
138
|
+
version: json.version ?? null,
|
|
139
|
+
description: json.description ?? null,
|
|
140
|
+
license: json.license ?? null,
|
|
141
|
+
type: json.type ?? null,
|
|
142
|
+
bin: json.bin ? (typeof json.bin === 'string' ? { [json.name ?? 'bin']: json.bin } : json.bin) : {},
|
|
143
|
+
main: json.main ?? null,
|
|
144
|
+
scripts: json.scripts ?? {},
|
|
145
|
+
engines: json.engines ?? {},
|
|
146
|
+
dependencies: Object.keys(json.dependencies ?? {}),
|
|
147
|
+
devDependencies: Object.keys(json.devDependencies ?? {}),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const cargo = read('Cargo.toml');
|
|
153
|
+
if (cargo) {
|
|
154
|
+
const get = (key) => (cargo.match(new RegExp(`^${key}\\s*=\\s*"([^"]+)"`, 'm')) || [])[1] ?? null;
|
|
155
|
+
found.rust = { ecosystem: 'Rust', name: get('name'), version: get('version'), edition: get('edition') };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const gomod = read('go.mod');
|
|
159
|
+
if (gomod) {
|
|
160
|
+
const moduleMatch = gomod.match(/^module\s+(\S+)/m);
|
|
161
|
+
const goMatch = gomod.match(/^go\s+(\S+)/m);
|
|
162
|
+
found.go = { ecosystem: 'Go', module: moduleMatch?.[1] ?? null, go: goMatch?.[1] ?? null };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const pyproject = read('pyproject.toml');
|
|
166
|
+
if (pyproject) {
|
|
167
|
+
const get = (key) => (pyproject.match(new RegExp(`^${key}\\s*=\\s*"([^"]+)"`, 'm')) || [])[1] ?? null;
|
|
168
|
+
found.python = { ecosystem: 'Python', name: get('name'), version: get('version'), description: get('description') };
|
|
169
|
+
} else if (fs.existsSync(path.join(root, 'requirements.txt'))) {
|
|
170
|
+
const reqs = read('requirements.txt') ?? '';
|
|
171
|
+
found.python = {
|
|
172
|
+
ecosystem: 'Python',
|
|
173
|
+
requirements: reqs.split('\n').map((l) => l.trim()).filter((l) => l && !l.startsWith('#')).length,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const composer = read('composer.json');
|
|
178
|
+
if (composer) {
|
|
179
|
+
const json = parseJson(path.join(root, 'composer.json'));
|
|
180
|
+
if (json) found.php = { ecosystem: 'PHP', name: json.name ?? null, description: json.description ?? null };
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (fs.existsSync(path.join(root, 'Gemfile'))) found.ruby = { ecosystem: 'Ruby' };
|
|
184
|
+
if (fs.existsSync(path.join(root, 'pom.xml'))) found.java = { ecosystem: 'Java (Maven)' };
|
|
185
|
+
if (fs.existsSync(path.join(root, 'build.gradle')) || fs.existsSync(path.join(root, 'build.gradle.kts')))
|
|
186
|
+
found.gradle = { ecosystem: 'Java/Kotlin (Gradle)' };
|
|
187
|
+
|
|
188
|
+
found.docker = fs.existsSync(path.join(root, 'Dockerfile')) ||
|
|
189
|
+
fs.existsSync(path.join(root, 'docker-compose.yml')) ||
|
|
190
|
+
fs.existsSync(path.join(root, 'docker-compose.yaml')) ||
|
|
191
|
+
fs.existsSync(path.join(root, 'Containerfile'));
|
|
192
|
+
|
|
193
|
+
const workflowsDir = path.join(root, '.github', 'workflows');
|
|
194
|
+
try {
|
|
195
|
+
found.ciWorkflows = fs.readdirSync(workflowsDir).filter((f) => /\.(yml|yaml)$/.test(f));
|
|
196
|
+
} catch {
|
|
197
|
+
found.ciWorkflows = [];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return found;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function findReadme(root) {
|
|
204
|
+
const candidates = ['README.md', 'readme.md', 'Readme.md', 'README.markdown', 'README.rst', 'README.txt', 'README'];
|
|
205
|
+
for (const name of candidates) {
|
|
206
|
+
const abs = path.join(root, name);
|
|
207
|
+
if (fs.existsSync(abs)) {
|
|
208
|
+
return { path: name, content: readSmall(abs, MAX_README_BYTES) ?? '' };
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export function analyze(root) {
|
|
215
|
+
const absRoot = path.resolve(root);
|
|
216
|
+
const files = walk(absRoot);
|
|
217
|
+
|
|
218
|
+
const byLanguage = new Map(); // lang -> { files, bytes }
|
|
219
|
+
const byExt = new Map();
|
|
220
|
+
let totalBytes = 0;
|
|
221
|
+
let lineCount = 0;
|
|
222
|
+
let linesCounted = 0;
|
|
223
|
+
|
|
224
|
+
for (const file of files) {
|
|
225
|
+
totalBytes += file.size;
|
|
226
|
+
const ext = path.extname(file.path).toLowerCase() || '(none)';
|
|
227
|
+
byExt.set(ext, (byExt.get(ext) ?? 0) + 1);
|
|
228
|
+
const lang = languageFor(file.path);
|
|
229
|
+
if (lang) {
|
|
230
|
+
const entry = byLanguage.get(lang[0]) ?? { name: lang[0], color: lang[1], files: 0, bytes: 0 };
|
|
231
|
+
entry.files += 1;
|
|
232
|
+
entry.bytes += file.size;
|
|
233
|
+
byLanguage.set(lang[0], entry);
|
|
234
|
+
}
|
|
235
|
+
const lines = countLines(path.join(absRoot, file.path));
|
|
236
|
+
if (lines !== null) {
|
|
237
|
+
lineCount += lines;
|
|
238
|
+
linesCounted += 1;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const languages = [...byLanguage.values()].sort((a, b) => b.bytes - a.bytes);
|
|
243
|
+
const languageBytes = languages.reduce((sum, l) => sum + l.bytes, 0);
|
|
244
|
+
|
|
245
|
+
// Top-level (and one level of) directory rollup for the map section.
|
|
246
|
+
const dirRollup = new Map();
|
|
247
|
+
for (const file of files) {
|
|
248
|
+
const parts = file.path.split('/');
|
|
249
|
+
const top = parts.length > 1 ? parts[0] + '/' : '(root)';
|
|
250
|
+
const entry = dirRollup.get(top) ?? { name: top, files: 0, bytes: 0 };
|
|
251
|
+
entry.files += 1;
|
|
252
|
+
entry.bytes += file.size;
|
|
253
|
+
dirRollup.set(top, entry);
|
|
254
|
+
}
|
|
255
|
+
const topDirs = [...dirRollup.values()].sort((a, b) => b.bytes - a.bytes);
|
|
256
|
+
|
|
257
|
+
const largest = [...files].sort((a, b) => b.size - a.size).slice(0, 10);
|
|
258
|
+
|
|
259
|
+
const keyFiles = files
|
|
260
|
+
.filter((f) => KEY_FILENAMES.has(path.basename(f.path).toLowerCase()) || /^(license|licence)(\..+)?$/i.test(path.basename(f.path)))
|
|
261
|
+
.map((f) => f.path)
|
|
262
|
+
.sort();
|
|
263
|
+
|
|
264
|
+
const manifests = parseManifests(absRoot);
|
|
265
|
+
const readme = findReadme(absRoot);
|
|
266
|
+
const git = gitInfo(absRoot);
|
|
267
|
+
|
|
268
|
+
let name = path.basename(absRoot);
|
|
269
|
+
let description = null;
|
|
270
|
+
if (manifests.node?.name) name = manifests.node.name;
|
|
271
|
+
description =
|
|
272
|
+
manifests.node?.description ??
|
|
273
|
+
manifests.python?.description ??
|
|
274
|
+
manifests.php?.description ??
|
|
275
|
+
null;
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
root: absRoot,
|
|
279
|
+
name,
|
|
280
|
+
description,
|
|
281
|
+
generatedAt: new Date().toISOString(),
|
|
282
|
+
totals: {
|
|
283
|
+
files: files.length,
|
|
284
|
+
bytes: totalBytes,
|
|
285
|
+
lines: lineCount,
|
|
286
|
+
linesCounted,
|
|
287
|
+
},
|
|
288
|
+
languages: languages.map((l) => ({
|
|
289
|
+
...l,
|
|
290
|
+
percent: languageBytes ? (l.bytes / languageBytes) * 100 : 0,
|
|
291
|
+
})),
|
|
292
|
+
topDirs,
|
|
293
|
+
largest,
|
|
294
|
+
keyFiles,
|
|
295
|
+
manifests,
|
|
296
|
+
readme,
|
|
297
|
+
git,
|
|
298
|
+
files: files.map((f) => ({ path: f.path, size: f.size })).sort((a, b) => a.path.localeCompare(b.path)),
|
|
299
|
+
};
|
|
300
|
+
}
|
package/src/generate.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { analyze } from './analyze.js';
|
|
5
|
+
import { renderHtml } from './render.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Analyze `targetDir` and write a self-contained tour page to `index.html`.
|
|
9
|
+
* Without `outDir`, the page goes into a fresh `mkdtemp` directory under the
|
|
10
|
+
* OS temp dir (nothing is written into the analyzed repo); `outDir` writes
|
|
11
|
+
* there instead. Returns the output path.
|
|
12
|
+
*/
|
|
13
|
+
export function generate(targetDir, { outDir } = {}) {
|
|
14
|
+
const absRoot = path.resolve(targetDir);
|
|
15
|
+
if (!fs.existsSync(absRoot) || !fs.statSync(absRoot).isDirectory()) {
|
|
16
|
+
throw new Error(`Not a directory: ${absRoot}`);
|
|
17
|
+
}
|
|
18
|
+
const analysis = analyze(absRoot);
|
|
19
|
+
const html = renderHtml(analysis);
|
|
20
|
+
const destDir = outDir
|
|
21
|
+
? path.resolve(outDir)
|
|
22
|
+
: fs.mkdtempSync(path.join(os.tmpdir(), 'repospect-'));
|
|
23
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
24
|
+
const dest = path.join(destDir, 'index.html');
|
|
25
|
+
fs.writeFileSync(dest, html, 'utf8');
|
|
26
|
+
return { dest, analysis };
|
|
27
|
+
}
|
package/src/langs.js
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Extension -> language, with a display color. Kept dependency-free on purpose.
|
|
2
|
+
export const LANGUAGES = {
|
|
3
|
+
'.js': ['JavaScript', '#f1e05a'],
|
|
4
|
+
'.mjs': ['JavaScript', '#f1e05a'],
|
|
5
|
+
'.cjs': ['JavaScript', '#f1e05a'],
|
|
6
|
+
'.jsx': ['JavaScript (JSX)', '#f1e05a'],
|
|
7
|
+
'.ts': ['TypeScript', '#3178c6'],
|
|
8
|
+
'.mts': ['TypeScript', '#3178c6'],
|
|
9
|
+
'.cts': ['TypeScript', '#3178c6'],
|
|
10
|
+
'.tsx': ['TypeScript (TSX)', '#3178c6'],
|
|
11
|
+
'.py': ['Python', '#3572A5'],
|
|
12
|
+
'.rs': ['Rust', '#dea584'],
|
|
13
|
+
'.go': ['Go', '#00ADD8'],
|
|
14
|
+
'.java': ['Java', '#b07219'],
|
|
15
|
+
'.kt': ['Kotlin', '#A97BFF'],
|
|
16
|
+
'.kts': ['Kotlin', '#A97BFF'],
|
|
17
|
+
'.rb': ['Ruby', '#701516'],
|
|
18
|
+
'.php': ['PHP', '#4F5D95'],
|
|
19
|
+
'.c': ['C', '#555555'],
|
|
20
|
+
'.h': ['C/C++ header', '#555555'],
|
|
21
|
+
'.cc': ['C++', '#f34b7d'],
|
|
22
|
+
'.cpp': ['C++', '#f34b7d'],
|
|
23
|
+
'.cxx': ['C++', '#f34b7d'],
|
|
24
|
+
'.hpp': ['C++ header', '#f34b7d'],
|
|
25
|
+
'.cs': ['C#', '#178600'],
|
|
26
|
+
'.swift': ['Swift', '#F05138'],
|
|
27
|
+
'.m': ['Objective-C', '#438eff'],
|
|
28
|
+
'.scala': ['Scala', '#c22d40'],
|
|
29
|
+
'.clj': ['Clojure', '#db5855'],
|
|
30
|
+
'.ex': ['Elixir', '#6e4a7e'],
|
|
31
|
+
'.exs': ['Elixir', '#6e4a7e'],
|
|
32
|
+
'.erl': ['Erlang', '#B83998'],
|
|
33
|
+
'.hs': ['Haskell', '#5e5086'],
|
|
34
|
+
'.ml': ['OCaml', '#3be133'],
|
|
35
|
+
'.lua': ['Lua', '#000080'],
|
|
36
|
+
'.r': ['R', '#198CE7'],
|
|
37
|
+
'.jl': ['Julia', '#a270ba'],
|
|
38
|
+
'.dart': ['Dart', '#00B4AB'],
|
|
39
|
+
'.zig': ['Zig', '#ec915c'],
|
|
40
|
+
'.sh': ['Shell', '#89e051'],
|
|
41
|
+
'.bash': ['Shell', '#89e051'],
|
|
42
|
+
'.zsh': ['Shell', '#89e051'],
|
|
43
|
+
'.fish': ['Shell', '#89e051'],
|
|
44
|
+
'.ps1': ['PowerShell', '#012456'],
|
|
45
|
+
'.html': ['HTML', '#e34c26'],
|
|
46
|
+
'.htm': ['HTML', '#e34c26'],
|
|
47
|
+
'.css': ['CSS', '#563d7c'],
|
|
48
|
+
'.scss': ['SCSS', '#c6538c'],
|
|
49
|
+
'.sass': ['Sass', '#a53b70'],
|
|
50
|
+
'.less': ['Less', '#1d365d'],
|
|
51
|
+
'.vue': ['Vue', '#41b883'],
|
|
52
|
+
'.svelte': ['Svelte', '#ff3e00'],
|
|
53
|
+
'.astro': ['Astro', '#ff5a03'],
|
|
54
|
+
'.sql': ['SQL', '#e38c00'],
|
|
55
|
+
'.graphql': ['GraphQL', '#e10098'],
|
|
56
|
+
'.gql': ['GraphQL', '#e10098'],
|
|
57
|
+
'.proto': ['Protocol Buffers', '#62cbfb'],
|
|
58
|
+
'.yaml': ['YAML', '#cb171e'],
|
|
59
|
+
'.yml': ['YAML', '#cb171e'],
|
|
60
|
+
'.toml': ['TOML', '#9c4221'],
|
|
61
|
+
'.ini': ['INI', '#6d6d6d'],
|
|
62
|
+
'.md': ['Markdown', '#083fa1'],
|
|
63
|
+
'.mdx': ['MDX', '#083fa1'],
|
|
64
|
+
'.json': ['JSON', '#292929'],
|
|
65
|
+
'.xml': ['XML', '#0060ac'],
|
|
66
|
+
'.tf': ['Terraform', '#7B42BC'],
|
|
67
|
+
'.dockerfile': ['Dockerfile', '#384d54'],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// Filename-keyed detection for extensionless files.
|
|
71
|
+
export const FILENAME_LANGUAGES = {
|
|
72
|
+
dockerfile: ['Dockerfile', '#384d54'],
|
|
73
|
+
makefile: ['Makefile', '#427819'],
|
|
74
|
+
'cmakelists.txt': ['CMake', '#064F8C'],
|
|
75
|
+
'gemfile': ['Ruby', '#701516'],
|
|
76
|
+
'rakefile': ['Ruby', '#701516'],
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// Directories that never belong in a repo tour.
|
|
80
|
+
export const IGNORED_DIRS = new Set([
|
|
81
|
+
'.git', '.hg', '.svn',
|
|
82
|
+
'node_modules', '.pnpm-store', 'vendor',
|
|
83
|
+
'dist', 'build', 'out', '.next', '.nuxt', '.svelte-kit', '.output',
|
|
84
|
+
'coverage', '.nyc_output', '.turbo', '.cache', '.parcel-cache',
|
|
85
|
+
'__pycache__', '.pytest_cache', '.mypy_cache', '.ruff_cache', '.venv', 'venv', 'env',
|
|
86
|
+
'target', 'bin', 'obj',
|
|
87
|
+
'.gradle', '.idea', '.vscode',
|
|
88
|
+
'.repospect',
|
|
89
|
+
]);
|
|
90
|
+
|
|
91
|
+
// Exact filenames that are interesting enough to list as "key files".
|
|
92
|
+
export const KEY_FILENAMES = new Set([
|
|
93
|
+
'readme.md', 'readme', 'readme.rst', 'readme.txt',
|
|
94
|
+
'package.json', 'package-lock.json', 'pnpm-lock.yaml', 'yarn.lock',
|
|
95
|
+
'cargo.toml', 'cargo.lock', 'go.mod', 'go.sum',
|
|
96
|
+
'pyproject.toml', 'setup.py', 'requirements.txt', 'pipfile',
|
|
97
|
+
'gemfile', 'composer.json', 'pom.xml', 'build.gradle', 'build.gradle.kts',
|
|
98
|
+
'dockerfile', 'docker-compose.yml', 'docker-compose.yaml',
|
|
99
|
+
'makefile', 'justfile', 'taskfile.yml',
|
|
100
|
+
'tsconfig.json', 'jsconfig.json',
|
|
101
|
+
'.gitignore', '.editorconfig', '.nvmrc', '.node-version',
|
|
102
|
+
'license', 'license.md', 'license.txt',
|
|
103
|
+
'contributing.md', 'changelog.md', 'changes.md',
|
|
104
|
+
'security.md', 'code_of_conduct.md',
|
|
105
|
+
]);
|
package/src/markdown.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Minimal, safe Markdown subset renderer for READMEs.
|
|
2
|
+
// Everything is HTML-escaped FIRST, then a small set of block/inline rules run
|
|
3
|
+
// on the escaped text. No raw HTML passes through, so a README cannot inject.
|
|
4
|
+
|
|
5
|
+
export function escapeHtml(s) {
|
|
6
|
+
return String(s)
|
|
7
|
+
.replaceAll('&', '&')
|
|
8
|
+
.replaceAll('<', '<')
|
|
9
|
+
.replaceAll('>', '>')
|
|
10
|
+
.replaceAll('"', '"')
|
|
11
|
+
.replaceAll("'", ''');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function inline(text) {
|
|
15
|
+
let out = text;
|
|
16
|
+
out = out.replace(/`([^`]+)`/g, (_, code) => `<code>${code}</code>`);
|
|
17
|
+
out = out.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
|
|
18
|
+
out = out.replace(/\*([^*]+)\*/g, '<em>$1</em>');
|
|
19
|
+
out = out.replace(/\[([^\]]+)\]\((https?:[^)\s]+)\)/g, '<a href="$2" rel="noopener noreferrer" target="_blank">$1</a>');
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function renderMarkdown(source) {
|
|
24
|
+
const src = escapeHtml(source);
|
|
25
|
+
const lines = src.split(/\r?\n/);
|
|
26
|
+
const html = [];
|
|
27
|
+
let inCode = false;
|
|
28
|
+
let inList = false;
|
|
29
|
+
let inTable = false;
|
|
30
|
+
let para = [];
|
|
31
|
+
|
|
32
|
+
const flushPara = () => {
|
|
33
|
+
if (para.length) {
|
|
34
|
+
html.push(`<p>${inline(para.join(' '))}</p>`);
|
|
35
|
+
para = [];
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const closeList = () => {
|
|
39
|
+
if (inList) {
|
|
40
|
+
html.push('</ul>');
|
|
41
|
+
inList = false;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const closeTable = () => {
|
|
45
|
+
if (inTable) {
|
|
46
|
+
html.push('</table>');
|
|
47
|
+
inTable = false;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
for (const raw of lines) {
|
|
52
|
+
const line = raw;
|
|
53
|
+
|
|
54
|
+
if (/^```/.test(line.trim())) {
|
|
55
|
+
flushPara(); closeList(); closeTable();
|
|
56
|
+
if (inCode) { html.push('</code></pre>'); inCode = false; }
|
|
57
|
+
else { html.push('<pre><code>'); inCode = true; }
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (inCode) { html.push(line); continue; }
|
|
61
|
+
|
|
62
|
+
if (/^\s*$/.test(line)) { flushPara(); closeList(); closeTable(); continue; }
|
|
63
|
+
|
|
64
|
+
const heading = line.match(/^(#{1,6})\s+(.*)$/);
|
|
65
|
+
if (heading) {
|
|
66
|
+
flushPara(); closeList(); closeTable();
|
|
67
|
+
const level = Math.min(heading[1].length + 1, 6); // shift down: README h1 -> page h2
|
|
68
|
+
html.push(`<h${level}>${inline(heading[2].trim())}</h${level}>`);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (/^\s*\|.*\|\s*$/.test(line)) {
|
|
73
|
+
const cells = line.trim().replace(/^\||\|$/g, '').split('|').map((c) => c.trim());
|
|
74
|
+
const isDivider = cells.every((c) => /^:?-{2,}:?$/.test(c));
|
|
75
|
+
flushPara(); closeList();
|
|
76
|
+
if (isDivider) continue; // header separator
|
|
77
|
+
if (!inTable) { html.push('<table>'); inTable = true; }
|
|
78
|
+
html.push(`<tr>${cells.map((c) => `<td>${inline(c)}</td>`).join('')}</tr>`);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const bullet = line.match(/^\s*[-*+]\s+(.*)$/);
|
|
83
|
+
if (bullet) {
|
|
84
|
+
flushPara(); closeTable();
|
|
85
|
+
if (!inList) { html.push('<ul>'); inList = true; }
|
|
86
|
+
html.push(`<li>${inline(bullet[1])}</li>`);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
flushPara(), closeList(), closeTable();
|
|
91
|
+
para.push(line.trim());
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
flushPara(); closeList(); closeTable();
|
|
95
|
+
if (inCode) html.push('</code></pre>');
|
|
96
|
+
return html.join('\n');
|
|
97
|
+
}
|
package/src/open.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Ask the OS to open `target` (a file path) in the default browser.
|
|
6
|
+
* Best-effort: returns false if no opener could be spawned; never throws.
|
|
7
|
+
*/
|
|
8
|
+
export function openInBrowser(target) {
|
|
9
|
+
const url = pathToFileURL(target).href;
|
|
10
|
+
let cmd, args;
|
|
11
|
+
if (process.platform === 'darwin') {
|
|
12
|
+
cmd = 'open';
|
|
13
|
+
args = [url];
|
|
14
|
+
} else if (process.platform === 'win32') {
|
|
15
|
+
cmd = 'cmd.exe';
|
|
16
|
+
args = ['/d', '/s', '/c', 'start', '', url];
|
|
17
|
+
} else {
|
|
18
|
+
cmd = 'xdg-open';
|
|
19
|
+
args = [url];
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const child = spawn(cmd, args, { detached: true, stdio: 'ignore' });
|
|
23
|
+
child.on('error', () => {});
|
|
24
|
+
child.unref();
|
|
25
|
+
return true;
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
package/src/render.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { escapeHtml } from './markdown.js';
|
|
2
|
+
import { renderMarkdown } from './markdown.js';
|
|
3
|
+
|
|
4
|
+
const TOOL_VERSION = '0.1.1';
|
|
5
|
+
const MAX_EMBEDDED_FILES = 5000;
|
|
6
|
+
|
|
7
|
+
function fmtBytes(n) {
|
|
8
|
+
if (n < 1024) return `${n} B`;
|
|
9
|
+
const units = ['KB', 'MB', 'GB'];
|
|
10
|
+
let v = n / 1024, i = 0;
|
|
11
|
+
while (v >= 1024 && i < units.length - 1) { v /= 1024; i++; }
|
|
12
|
+
return `${v.toFixed(v >= 100 ? 0 : 1)} ${units[i]}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function fmtInt(n) {
|
|
16
|
+
return n == null ? '—' : Number(n).toLocaleString('en-US');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function embedJson(value) {
|
|
20
|
+
// Safe to embed in a <script> tag: neutralize any "</script" inside the JSON.
|
|
21
|
+
return JSON.stringify(value).replaceAll('</', '<\\/');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function section(id, title, body) {
|
|
25
|
+
return `<section id="${id}" class="panel"><h2>${escapeHtml(title)}</h2>${body}</section>`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function overviewSection(a) {
|
|
29
|
+
const g = a.git;
|
|
30
|
+
const stats = [
|
|
31
|
+
['Files', fmtInt(a.totals.files)],
|
|
32
|
+
['Lines of code', a.totals.linesCounted ? fmtInt(a.totals.lines) : '—'],
|
|
33
|
+
['Size', fmtBytes(a.totals.bytes)],
|
|
34
|
+
['Languages', fmtInt(a.languages.length)],
|
|
35
|
+
];
|
|
36
|
+
if (g?.commitCount != null) stats.push(['Commits', fmtInt(g.commitCount)]);
|
|
37
|
+
if (g?.branch) stats.push(['Branch', escapeHtml(g.branch)]);
|
|
38
|
+
const cards = stats.map(([k, v]) => `<div class="stat"><div class="stat-value">${v}</div><div class="stat-label">${escapeHtml(k)}</div></div>`).join('');
|
|
39
|
+
const desc = a.description ? `<p class="lede">${escapeHtml(a.description)}</p>` : '<p class="lede dim">No description found in any manifest. Add one to package.json / pyproject.toml to make this page say what the project is for.</p>';
|
|
40
|
+
return section('overview', 'Overview', `${desc}<div class="stats">${cards}</div>`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function quickStartSection(a) {
|
|
44
|
+
const parts = [];
|
|
45
|
+
const n = a.manifests.node;
|
|
46
|
+
if (n) {
|
|
47
|
+
parts.push('<h3>Node.js</h3>');
|
|
48
|
+
parts.push('<pre class="cmd">npm install\nnpm test</pre>');
|
|
49
|
+
if (Object.keys(n.scripts).length) {
|
|
50
|
+
const rows = Object.entries(n.scripts)
|
|
51
|
+
.slice(0, 20)
|
|
52
|
+
.map(([k, v]) => `<tr><td><code>npm run ${escapeHtml(k)}</code></td><td>${escapeHtml(v)}</td></tr>`)
|
|
53
|
+
.join('');
|
|
54
|
+
parts.push(`<table><thead><tr><th>Script</th><th>Runs</th></tr></thead><tbody>${rows}</tbody></table>`);
|
|
55
|
+
}
|
|
56
|
+
const meta = [];
|
|
57
|
+
if (n.version) meta.push(`version ${escapeHtml(n.version)}`);
|
|
58
|
+
if (n.license) meta.push(`license ${escapeHtml(n.license)}`);
|
|
59
|
+
if (n.engines?.node) meta.push(`node ${escapeHtml(n.engines.node)}`);
|
|
60
|
+
if (n.dependencies.length) meta.push(`${n.dependencies.length} deps, ${n.devDependencies.length} dev`);
|
|
61
|
+
if (meta.length) parts.push(`<p class="dim">${meta.join(' · ')}</p>`);
|
|
62
|
+
const bins = Object.entries(n.bin ?? {});
|
|
63
|
+
if (bins.length) {
|
|
64
|
+
parts.push(`<p><strong>CLI entry points:</strong> ${bins.map(([k, v]) => `<code>${escapeHtml(k)}</code> → <code>${escapeHtml(v)}</code>`).join(', ')}</p>`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const rust = a.manifests.rust;
|
|
68
|
+
if (rust) parts.push(`<h3>Rust</h3><pre class="cmd">cargo build\ncargo test</pre><p class="dim">${escapeHtml(rust.name ?? '')} ${escapeHtml(rust.version ?? '')}</p>`);
|
|
69
|
+
const go = a.manifests.go;
|
|
70
|
+
if (go) parts.push(`<h3>Go</h3><pre class="cmd">go build ./...\ngo test ./...</pre><p class="dim">module ${escapeHtml(go.module ?? '')}${go.go ? ` · go ${escapeHtml(go.go)}` : ''}</p>`);
|
|
71
|
+
const py = a.manifests.python;
|
|
72
|
+
if (py) parts.push(`<h3>Python</h3><pre class="cmd">pip install -e .\npytest</pre><p class="dim">${escapeHtml(py.name ?? '')} ${escapeHtml(py.version ?? '')}${py.requirements != null ? `${py.requirements} requirements` : ''}</p>`);
|
|
73
|
+
if (a.manifests.docker) parts.push('<h3>Docker</h3><pre class="cmd">docker build -t app .</pre>');
|
|
74
|
+
if (a.manifests.ciWorkflows?.length) parts.push(`<p class="dim">CI: ${escapeHtml(a.manifests.ciWorkflows.join(', '))}</p>`);
|
|
75
|
+
if (!parts.length) parts.push('<p class="dim">No recognized manifest files. Start from the file tree and README below.</p>');
|
|
76
|
+
return section('quickstart', 'Quick start', parts.join('\n'));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function structureSection(a) {
|
|
80
|
+
const maxBytes = Math.max(1, ...a.topDirs.map((d) => d.bytes));
|
|
81
|
+
const rows = a.topDirs
|
|
82
|
+
.slice(0, 30)
|
|
83
|
+
.map(
|
|
84
|
+
(d) => `<tr><td><code>${escapeHtml(d.name)}</code></td><td>${fmtInt(d.files)}</td><td>${fmtBytes(d.bytes)}</td><td class="barcell"><div class="bar" style="width:${Math.max(2, (d.bytes / maxBytes) * 100).toFixed(1)}%"></div></td></tr>`
|
|
85
|
+
)
|
|
86
|
+
.join('');
|
|
87
|
+
const table = `<table><thead><tr><th>Path</th><th>Files</th><th>Size</th><th></th></tr></thead><tbody>${rows}</tbody></table>`;
|
|
88
|
+
const keys = a.keyFiles.length
|
|
89
|
+
? `<h3>Start here</h3><ul class="keyfiles">${a.keyFiles.map((f) => `<li><code>${escapeHtml(f)}</code></li>`).join('')}</ul>`
|
|
90
|
+
: '';
|
|
91
|
+
const largest = a.largest.length
|
|
92
|
+
? `<h3>Largest files</h3><ul class="keyfiles">${a.largest.slice(0, 8).map((f) => `<li><code>${escapeHtml(f.path)}</code> <span class="dim">${fmtBytes(f.size)}</span></li>`).join('')}</ul>`
|
|
93
|
+
: '';
|
|
94
|
+
return section('structure', 'Structure', `${table}${keys}${largest}`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function languagesSection(a) {
|
|
98
|
+
if (!a.languages.length) return section('languages', 'Languages', '<p class="dim">No source files detected.</p>');
|
|
99
|
+
const rows = a.languages
|
|
100
|
+
.map(
|
|
101
|
+
(l) => `<div class="lang-row"><span class="lang-name"><span class="dot" style="background:${escapeHtml(l.color)}"></span>${escapeHtml(l.name)}</span><div class="lang-track"><div class="lang-fill" style="width:${l.percent.toFixed(2)}%;background:${escapeHtml(l.color)}"></div></div><span class="lang-pct">${l.percent.toFixed(1)}%</span></div>`
|
|
102
|
+
)
|
|
103
|
+
.join('');
|
|
104
|
+
return section('languages', 'Languages', rows);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function readmeSection(a) {
|
|
108
|
+
if (!a.readme) return section('readme', 'README', '<p class="dim">No README found. This repo is missing its front door.</p>');
|
|
109
|
+
return section('readme', `README <span class="dim">${escapeHtml(a.readme.path)}</span>`, `<article class="readme">${renderMarkdown(a.readme.content)}</article>`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function gitSection(a) {
|
|
113
|
+
const g = a.git;
|
|
114
|
+
if (!g) return section('git', 'History', '<p class="dim">Not a git repository.</p>');
|
|
115
|
+
const rows = [];
|
|
116
|
+
if (g.firstCommit || g.lastCommit) rows.push(`<p class="dim">Active ${escapeHtml(g.firstCommit ?? '?')} → ${escapeHtml(g.lastCommit ?? '?')}${g.commitCount != null ? ` · ${fmtInt(g.commitCount)} commits` : ''}</p>`);
|
|
117
|
+
if (g.authors.length) {
|
|
118
|
+
rows.push(`<h3>Contributors</h3><ul class="keyfiles">${g.authors.map((p) => `<li>${escapeHtml(p.name)} <span class="dim">${p.commits} commits</span></li>`).join('')}</ul>`);
|
|
119
|
+
}
|
|
120
|
+
if (g.recent.length) {
|
|
121
|
+
rows.push(`<h3>Recent commits</h3><pre class="cmd">${g.recent.map((l) => escapeHtml(l)).join('\n')}</pre>`);
|
|
122
|
+
}
|
|
123
|
+
return section('git', 'History', rows.join('\n'));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function filesSection(a) {
|
|
127
|
+
const truncated = a.files.length > MAX_EMBEDDED_FILES;
|
|
128
|
+
const data = truncated ? a.files.slice(0, MAX_EMBEDDED_FILES) : a.files;
|
|
129
|
+
const note = truncated ? `<p class="dim">Showing ${MAX_EMBEDDED_FILES.toLocaleString()} of ${a.files.length.toLocaleString()} files.</p>` : '';
|
|
130
|
+
return section('files', 'Files', `
|
|
131
|
+
<input id="file-filter" type="search" placeholder="Filter ${fmtInt(a.files.length)} files… (e.g. src/ or .ts)" autocomplete="off" spellcheck="false">
|
|
132
|
+
${note}
|
|
133
|
+
<ul id="file-list" class="file-list"></ul>
|
|
134
|
+
<p class="dim"><span id="file-count"></span></p>
|
|
135
|
+
<script id="file-data" type="application/json">${embedJson(data)}</script>`);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const CSS = `
|
|
139
|
+
:root { color-scheme: dark; --bg:#0d1117; --panel:#161b22; --border:#2d333b; --text:#e6edf3; --dim:#8b949e; --accent:#58a6ff; --accent2:#3fb950; }
|
|
140
|
+
* { box-sizing: border-box; }
|
|
141
|
+
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.55 -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif; }
|
|
142
|
+
header.top { padding: 28px 32px 0; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: rgba(13,17,23,.92); backdrop-filter: blur(6px); z-index: 10; }
|
|
143
|
+
header.top h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: -0.02em; }
|
|
144
|
+
header.top .sub { color: var(--dim); font-size: 13px; margin-bottom: 14px; }
|
|
145
|
+
nav.tabs { display: flex; gap: 2px; overflow-x: auto; }
|
|
146
|
+
nav.tabs a { color: var(--dim); text-decoration: none; padding: 8px 14px; border-bottom: 2px solid transparent; font-size: 13px; white-space: nowrap; }
|
|
147
|
+
nav.tabs a:hover { color: var(--text); }
|
|
148
|
+
nav.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
|
|
149
|
+
main { max-width: 1080px; margin: 0 auto; padding: 24px 32px 64px; }
|
|
150
|
+
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 20px 24px; margin: 18px 0; scroll-margin-top: 90px; }
|
|
151
|
+
.panel h2 { margin-top: 0; font-size: 18px; }
|
|
152
|
+
.panel h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); margin-top: 22px; }
|
|
153
|
+
.lede { font-size: 17px; }
|
|
154
|
+
.dim { color: var(--dim); }
|
|
155
|
+
.stats { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
|
|
156
|
+
.stat { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 18px; min-width: 110px; }
|
|
157
|
+
.stat-value { font-size: 20px; font-weight: 650; }
|
|
158
|
+
.stat-label { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
|
|
159
|
+
table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 12px; }
|
|
160
|
+
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); }
|
|
161
|
+
th { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
|
|
162
|
+
td code { font-size: 12px; }
|
|
163
|
+
.barcell { width: 35%; }
|
|
164
|
+
.bar { height: 8px; background: var(--accent); border-radius: 4px; opacity: .75; }
|
|
165
|
+
pre.cmd { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; overflow-x: auto; font-size: 13px; }
|
|
166
|
+
code { background: var(--bg); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; font-size: 12.5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
|
|
167
|
+
pre.cmd code { background: none; border: 0; padding: 0; }
|
|
168
|
+
.keyfiles { columns: 2; padding-left: 18px; }
|
|
169
|
+
.keyfiles li { margin: 3px 0; break-inside: avoid; }
|
|
170
|
+
.lang-row { display: grid; grid-template-columns: 190px 1fr 48px; gap: 10px; align-items: center; margin: 6px 0; }
|
|
171
|
+
.lang-name { display: flex; align-items: center; gap: 8px; font-size: 13px; }
|
|
172
|
+
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
|
|
173
|
+
.lang-track { background: var(--bg); border-radius: 5px; height: 10px; overflow: hidden; }
|
|
174
|
+
.lang-fill { height: 100%; border-radius: 5px; }
|
|
175
|
+
.lang-pct { color: var(--dim); font-size: 12px; text-align: right; }
|
|
176
|
+
#file-filter { width: 100%; padding: 10px 12px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font-size: 14px; margin: 6px 0 10px; }
|
|
177
|
+
.file-list { list-style: none; padding: 0; max-height: 480px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
|
|
178
|
+
.file-list li { display: flex; justify-content: space-between; gap: 16px; padding: 4px 12px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; border-bottom: 1px solid var(--border); }
|
|
179
|
+
.file-list li:nth-child(odd) { background: rgba(255,255,255,.02); }
|
|
180
|
+
.file-list .sz { color: var(--dim); }
|
|
181
|
+
.readme pre { background: var(--bg); border: 1px solid var(--border); padding: 12px; border-radius: 8px; overflow-x: auto; }
|
|
182
|
+
.readme h2,.readme h3,.readme h4 { margin-top: 1.2em; }
|
|
183
|
+
.readme img { max-width: 100%; }
|
|
184
|
+
footer { text-align: center; color: var(--dim); font-size: 12px; padding: 18px; border-top: 1px solid var(--border); }
|
|
185
|
+
@media (max-width: 640px) { .keyfiles { columns: 1; } .lang-row { grid-template-columns: 130px 1fr 44px; } main, header.top { padding-left: 16px; padding-right: 16px; } }
|
|
186
|
+
`;
|
|
187
|
+
|
|
188
|
+
const JS = `
|
|
189
|
+
const panels = [...document.querySelectorAll('.panel')];
|
|
190
|
+
const navLinks = [...document.querySelectorAll('nav.tabs a')];
|
|
191
|
+
const sections = [...document.querySelectorAll('main section.panel')];
|
|
192
|
+
function spy(){
|
|
193
|
+
let current = sections[0]?.id;
|
|
194
|
+
for (const s of sections) { if (s.getBoundingClientRect().top <= 120) current = s.id; }
|
|
195
|
+
navLinks.forEach(a => a.classList.toggle('active', a.getAttribute('href') === '#' + current));
|
|
196
|
+
}
|
|
197
|
+
document.addEventListener('scroll', spy, { passive: true });
|
|
198
|
+
const dataEl = document.getElementById('file-data');
|
|
199
|
+
if (dataEl) {
|
|
200
|
+
const files = JSON.parse(dataEl.textContent);
|
|
201
|
+
const list = document.getElementById('file-list');
|
|
202
|
+
const count = document.getElementById('file-count');
|
|
203
|
+
const fmt = (n) => n < 1024 ? n + ' B' : (n/1024).toFixed(1) + ' KB';
|
|
204
|
+
const render = (q) => {
|
|
205
|
+
const needle = q.trim().toLowerCase();
|
|
206
|
+
const hits = needle ? files.filter(f => f.path.toLowerCase().includes(needle)) : files;
|
|
207
|
+
const shown = hits.slice(0, 500);
|
|
208
|
+
list.innerHTML = shown.map(f => '<li><span>' + f.path.replace(/&/g,'&').replace(/</g,'<') + '</span><span class="sz">' + fmt(f.size) + '</span></li>').join('');
|
|
209
|
+
count.textContent = hits.length.toLocaleString() + ' files' + (shown.length < hits.length ? ' (first ' + shown.length + ' shown)' : '');
|
|
210
|
+
};
|
|
211
|
+
const input = document.getElementById('file-filter');
|
|
212
|
+
input.addEventListener('input', () => render(input.value));
|
|
213
|
+
render('');
|
|
214
|
+
}
|
|
215
|
+
spy();
|
|
216
|
+
`;
|
|
217
|
+
|
|
218
|
+
export function renderHtml(a) {
|
|
219
|
+
const title = escapeHtml(a.name);
|
|
220
|
+
const nav = [
|
|
221
|
+
['overview', 'Overview'], ['quickstart', 'Quick start'], ['structure', 'Structure'],
|
|
222
|
+
['languages', 'Languages'], ['readme', 'README'], ['files', 'Files'], ['git', 'History'],
|
|
223
|
+
].map(([id, label]) => `<a href="#${id}">${label}</a>`).join('');
|
|
224
|
+
|
|
225
|
+
return `<!doctype html>
|
|
226
|
+
<html lang="en">
|
|
227
|
+
<head>
|
|
228
|
+
<meta charset="utf-8">
|
|
229
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
230
|
+
<meta name="generator" content="repospect ${TOOL_VERSION}">
|
|
231
|
+
<title>${title} — repospect</title>
|
|
232
|
+
<style>${CSS}</style>
|
|
233
|
+
</head>
|
|
234
|
+
<body>
|
|
235
|
+
<header class="top">
|
|
236
|
+
<h1>${title}</h1>
|
|
237
|
+
<div class="sub">A one-page tour of this repository · generated by <strong>repospect</strong> on ${escapeHtml(new Date(a.generatedAt).toISOString().slice(0, 10))}</div>
|
|
238
|
+
<nav class="tabs">${nav}</nav>
|
|
239
|
+
</header>
|
|
240
|
+
<main>
|
|
241
|
+
${overviewSection(a)}
|
|
242
|
+
${quickStartSection(a)}
|
|
243
|
+
${structureSection(a)}
|
|
244
|
+
${languagesSection(a)}
|
|
245
|
+
${readmeSection(a)}
|
|
246
|
+
${filesSection(a)}
|
|
247
|
+
${gitSection(a)}
|
|
248
|
+
</main>
|
|
249
|
+
<footer>Generated by repospect v${TOOL_VERSION} · fully static, no external requests · <code>repospect</code> again to refresh</footer>
|
|
250
|
+
<script>${JS}</script>
|
|
251
|
+
</body>
|
|
252
|
+
</html>
|
|
253
|
+
`;
|
|
254
|
+
}
|