-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.ts
58 lines (50 loc) · 1.4 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Linter } from './src/linter';
import { Reader } from './src/core/reader';
import * as astList from './src/core/ast/index';
export * from './src/core/rule';
export const ast = astList;
export * from './src/doc';
export * from './src/linter';
export * from './src/commander';
export * from './src/core/content';
export * from './src/core/parser';
export * from './src/core/runner';
export * from './src/core/visitor';
export * from './src/core/translator';
export * from './src/core/line';
export * from './src/core/reader';
export * from './src/core/checker';
export * from './src/core/baseConfig';
/**
* Main stylus checker
*
* @param path
* @param content
* @param options
* @constructor
*/
export async function StylusLinter(path: string | string[], content?: string, options: Dictionary = {}): Promise<void> {
const
linter = new Linter(options),
first = () => Array.isArray(path) ? path[0] : path;
if (content) {
linter.lint(first(), content);
return linter.display();
}
if (!path) {
path = linter.config.path || process.cwd();
}
const
reader = new Reader(linter.config),
readAndDisplay = async () => {
await reader.read(path, linter.lint.bind(linter));
linter.display(!linter.config.watch);
};
if (linter.config.watch) {
linter.watch(Array.isArray(path) ? path[0] : path, () => {
console.log('Recheck files...');
readAndDisplay();
});
}
await readAndDisplay();
}