-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
35 lines (29 loc) · 1.13 KB
/
index.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
import * as fs from 'fs';
import { allowExtensions, ignoreDoubles, ignoreRegex, Logger } from 'crawler-ts/src';
import { createCrawler } from 'crawler-ts-fs/src';
const entryIsFile = ({ parsed }: { parsed: fs.Stats }) => parsed.isFile();
// Create filters for paths and FsEntry
const allowTypeScript = allowExtensions()(['ts']);
const pathIgnoreRegex = ignoreRegex();
const pathIgnoreDoubles = ignoreDoubles();
/**
* File crawler that finds all ".ts" files.
*/
const createTypeScriptCrawler = () =>
createCrawler({
// Ignore .git, dist and node_module files
shouldParse: pathIgnoreRegex([/\/\.git$/, /\/dist$/, /\/node_modules$/]),
// Only yield paths with extension ".ts" that are files
shouldYield: ({ location, parsed }) => entryIsFile({ parsed }) && allowTypeScript({ location }),
// Ignore doubles
shouldQueue: pathIgnoreDoubles(),
});
async function main() {
const root = process.argv?.[2] ?? process.cwd();
const crawler = createTypeScriptCrawler();
for await (const { location, parsed } of crawler(root)) {
// Do something with the crawled result
console.log(location, parsed.size);
}
}
main();