-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbin.ts
executable file
·40 lines (30 loc) · 913 Bytes
/
bin.ts
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
#! /usr/bin/env node
import linkInspector from "./index";
import {dirname, basename} from 'path';
import fs from 'fs';
const args: string[] = process.argv.slice(2);
if (args.length === 0) {
console.error("no link or path given");
}
async function writeLink(link: string, path: string, lineNumber: number) {
path = path.replace(/\/\//g, '/');
console.log("Broken Link:", link);
if (path) console.log("Path:", path);
if (lineNumber) console.log("Line:", lineNumber);
console.log("");
if (path) {
path = "output/" + path;
if (!fs.existsSync(path))
fs.mkdirSync(dirname(path), { recursive: true });
fs.appendFileSync(path, link + "\n");
}
}
for (const arg of args) {
let path: string = '';
try { new URL(arg) }
catch {
path = basename(arg);
}
linkInspector(arg, writeLink, path);
console.log("");
}